本文整理汇总了C#中RavenJObject类的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject类的具体用法?C# RavenJObject怎么用?C# RavenJObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RavenJObject类属于命名空间,在下文中一共展示了RavenJObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TryResolve
public override bool TryResolve(string id, RavenJObject metadata, RavenJObject document, JsonDocument existingDoc,
Func<string, JsonDocument> getDocument, out RavenJObject metadataToSave,
out RavenJObject documentToSave)
{
var existingDocumentIsInConflict = existingDoc.Metadata[Constants.RavenReplicationConflict] != null;
var existingDocumentIsDeleted = existingDoc.Metadata[Constants.RavenDeleteMarker] != null
&& existingDoc.Metadata[Constants.RavenDeleteMarker].Value<bool>();
metadataToSave = null;
documentToSave = null;
if (existingDocumentIsInConflict && existingDocumentIsDeleted == false)
{
var conflictIds =
existingDoc.DataAsJson.Value<RavenJArray>("Conflicts")
.Select(x => x.Value<string>())
.ToArray();
if (conflictIds.Length == 0) return false;
if (conflictIds
.Select(getDocument)
.Where(x => x != null)
.All(doc => Historian.IsDirectChildOfCurrent(metadata, doc.Metadata)) == false)
return false;
metadataToSave = metadata;
documentToSave = document;
return true;
}
return false;
}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:34,代码来源:DefaultDocumentReplicationConflictResolver.cs
示例2: OnPut
public override void OnPut(string key, Stream data, RavenJObject metadata)
{
if (key.StartsWith("Raven/")) // we don't deal with system attachment
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var attachmentMetadata = GetAttachmentMetadata(key);
if (attachmentMetadata != null)
{
RavenJArray history = new RavenJArray(metadata.Value<RavenJArray>(Constants.RavenReplicationHistory));
metadata[Constants.RavenReplicationHistory] = history;
if (attachmentMetadata.ContainsKey(Constants.RavenReplicationVersion) &&
attachmentMetadata.ContainsKey(Constants.RavenReplicationSource))
{
history.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, attachmentMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, attachmentMetadata[Constants.RavenReplicationSource]}
});
}
if (history.Length > Constants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(HiLo.NextId());
metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
}
开发者ID:Nordis,项目名称:ravendb,代码行数:32,代码来源:AttachmentAncestryPutTrigger.cs
示例3: AllowPut
public override VetoResult AllowPut(string key,
RavenJObject document,
RavenJObject metadata,
TransactionInformation transactionInformation)
{
return VetoResult.Allowed;
}
开发者ID:nickchampion,项目名称:RavenDB.Bundles.Revisions,代码行数:7,代码来源:RevisionDocumentPutTrigger.cs
示例4: ToRavenJObject
public RavenJObject ToRavenJObject(JsValue jsObject, string propertyKey = null, bool recursiveCall = false)
{
var objectInstance = jsObject.AsObject();
if (objectInstance.Class == "Function")
{
// getting a Function instance here,
// means that we couldn't evaulate it using Jint
return null;
}
var rjo = new RavenJObject();
foreach (var property in objectInstance.Properties)
{
if (property.Key == Constants.ReduceKeyFieldName || property.Key == Constants.DocumentIdFieldName)
continue;
var value = property.Value.Value;
if (value.HasValue == false)
continue;
if (value.Value.IsRegExp())
continue;
var recursive = jsObject == value;
if (recursiveCall && recursive)
rjo[property.Key] = null;
else
rjo[property.Key] = ToRavenJToken(value.Value, CreatePropertyKey(property.Key, propertyKey), recursive);
}
return rjo;
}
开发者ID:j2jensen,项目名称:ravendb,代码行数:31,代码来源:JintOperationScope.cs
示例5: Execute
public void Execute(RavenJObject document)
{
if (Includes == null)
return;
foreach (var include in Includes)
{
if (string.IsNullOrEmpty(include))
continue;
var path = include;
string prefix = null;
var match = IncludePrefixRegex.Match(path);
if (match.Success && match.Groups.Count >= 2)
{
prefix = match.Groups[1].Value;
path = path.Replace(prefix, "");
prefix = prefix.Substring(1, prefix.Length - 2);
}
foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path))
{
ExecuteInternal(token.Item1, prefix);
}
}
}
开发者ID:royra,项目名称:ravendb,代码行数:25,代码来源:AddIncludesCommand.cs
示例6: AfterCommit
public override void AfterCommit(string key, Stream data, RavenJObject metadata, Guid etag)
{
// Make sure we have a filename
var filename = metadata.Value<string>("Raven-Attachment-Filename");
if (string.IsNullOrEmpty(filename))
return;
RavenJObject doc;
try
{
// Extract the text in the attachment as a json document
var extension = Path.GetExtension(filename);
doc = Extractor.GetJson(data, extension);
}
catch (InvalidOperationException ex)
{
// If there is no ifilter installed, don't do the extraction, but still do everything else.
if (!ex.Message.Contains("HRESULT: 0x80004005")) throw;
// Still write a dummmy doc so we get metadata in the index.
doc = new RavenJObject();
}
// Write the results to a document. Include all of the attachment's metadata, and a reference back to the attachment key.
var md = new RavenJObject(metadata) { { "Raven-Attachment-Key", key } };
Database.Put(key + "/text", null, doc, md, null);
}
开发者ID:tzarger,项目名称:contrib,代码行数:27,代码来源:PutAttachmentTrigger.cs
示例7: SetCachedDocument
public void SetCachedDocument(string key, Etag etag, RavenJObject doc, RavenJObject metadata, int size)
{
if (skipSettingDocumentInCache)
return;
var documentClone = ((RavenJObject)doc.CloneToken());
documentClone.EnsureCannotBeChangeAndEnableSnapshotting();
var metadataClone = ((RavenJObject)metadata.CloneToken());
metadataClone.EnsureCannotBeChangeAndEnableSnapshotting();
try
{
cachedSerializedDocuments.Set("Doc/" + key + "/" + etag, new CachedDocument
{
Document = documentClone,
Metadata = metadataClone,
Size = size
}, new CacheItemPolicy
{
SlidingExpiration = configuration.MemoryCacheExpiration,
});
}
catch (OverflowException)
{
// this is a bug in the framework
// http://connect.microsoft.com/VisualStudio/feedback/details/735033/memorycache-set-fails-with-overflowexception-exception-when-key-is-u7337-u7f01-u2117-exception-message-negating-the-minimum-value-of-a-twos-complement-number-is-invalid
// in this case, we just threat it as uncachable
}
}
开发者ID:925coder,项目名称:ravendb,代码行数:29,代码来源:DocumentCacher.cs
示例8: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/")) // we don't deal with system documents
return;
var doc = Database.Get(key, null);
if (doc != null)
{
var history = doc.Metadata.Value<RavenJArray>(ReplicationConstants.RavenReplicationHistory) ?? new RavenJArray();
metadata[ReplicationConstants.RavenReplicationHistory] = history;
history.Add(new RavenJObject
{
{ReplicationConstants.RavenReplicationVersion, doc.Metadata[ReplicationConstants.RavenReplicationVersion]},
{ReplicationConstants.RavenReplicationSource, doc.Metadata[ReplicationConstants.RavenReplicationSource]}
});
if (history.Length > ReplicationConstants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[ReplicationConstants.RavenReplicationVersion] = RavenJToken.FromObject(hiLo.NextId());
metadata[ReplicationConstants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
开发者ID:nzdunic,项目名称:ravendb,代码行数:25,代码来源:AncestryPutTrigger.cs
示例9: OnPut
public override void OnPut(string key, byte[] data, RavenJObject metadata)
{
if (key.StartsWith("Raven/")) // we don't deal with system attachment
return;
var attachment = Database.GetStatic(key);
if (attachment != null)
{
var history = attachment.Metadata.Value<RavenJArray>(ReplicationConstants.RavenReplicationHistory) ??
new RavenJArray();
metadata[ReplicationConstants.RavenReplicationHistory] = history;
history.Add(new RavenJObject
{
{ReplicationConstants.RavenReplicationVersion, attachment.Metadata[ReplicationConstants.RavenReplicationVersion]},
{ReplicationConstants.RavenReplicationSource, attachment.Metadata[ReplicationConstants.RavenReplicationSource]}
});
if (history.Length > ReplicationConstants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[ReplicationConstants.RavenReplicationVersion] = RavenJToken.FromObject(hiLo.NextId());
metadata[ReplicationConstants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
开发者ID:JPT123,项目名称:ravendb,代码行数:26,代码来源:AttachmentAncestryPutTrigger.cs
示例10: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) && // we don't deal with system documents
key.StartsWith("Raven/Hilo/", StringComparison.OrdinalIgnoreCase) == false) // except for hilos
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var documentMetadata = GetDocumentMetadata(key);
if (documentMetadata != null)
{
RavenJArray history = new RavenJArray(ReplicationData.GetHistory(documentMetadata));
metadata[Constants.RavenReplicationHistory] = history;
if (documentMetadata.ContainsKey(Constants.RavenReplicationVersion) &&
documentMetadata.ContainsKey(Constants.RavenReplicationSource))
{
history.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, documentMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, documentMetadata[Constants.RavenReplicationSource]}
});
}
while (history.Length > Constants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(HiLo.NextId());
metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:33,代码来源:AncestryPutTrigger.cs
示例11: can_update_a_doc_within_transaction_scope
public void can_update_a_doc_within_transaction_scope()
{
using (var documentStore = NewDocumentStore(requestedStorage: "esent"))
{
EnsureDtcIsSupported(documentStore);
var id1 = Guid.NewGuid();
RavenJObject dummy = null;
using (TransactionScope trnx = new TransactionScope())
{
using (var session = documentStore.OpenSession())
{
dummy = new RavenJObject();
dummy.Add("Name", "This is the object content");
dummy.Add("Id", RavenJToken.FromObject(id1));
session.Store(dummy);
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
session.Store(dummy);
session.SaveChanges();
}
trnx.Complete();
}
}
}
开发者ID:j2jensen,项目名称:ravendb,代码行数:29,代码来源:UsingDTCForUpdates.cs
示例12: RenameFileOperation
public RenameFileOperation(string name, string rename, Etag currentEtag, RavenJObject metadataAfterOperation)
{
Name = name;
Rename = rename;
Etag = currentEtag;
MetadataAfterOperation = metadataAfterOperation;
}
开发者ID:j2jensen,项目名称:ravendb,代码行数:7,代码来源:RenameFileOperation.cs
示例13: FilterDocuments
public bool FilterDocuments(string destinationId, string key, RavenJObject metadata)
{
if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase)) // don't replicate system docs
{
if (key.StartsWith("Raven/Hilo/", StringComparison.InvariantCultureIgnoreCase) == false) // except for hilo documents
return false;
}
if (metadata.ContainsKey(Constants.NotForReplication) && metadata.Value<bool>(Constants.NotForReplication)) // not explicitly marked to skip
return false;
if (metadata[Constants.RavenReplicationConflict] != null) // don't replicate conflicted documents, that just propagate the conflict
return false;
if (metadata.Value<string>(Constants.RavenReplicationSource) == destinationId) // prevent replicating back to source
return false;
switch (ReplicationOptionsBehavior)
{
case TransitiveReplicationOptions.None:
var value = metadata.Value<string>(Constants.RavenReplicationSource);
var replicateDoc = value == null || (value == CurrentDatabaseId);
return replicateDoc;
}
return true;
}
开发者ID:arelee,项目名称:ravendb,代码行数:25,代码来源:ReplicationStrategy.cs
示例14: CanProcess
public void CanProcess()
{
var document = new RavenJObject
{
{
"Data", new RavenJObject
{
{"Title", "Hi"}
}
}
};
const string name = @"Raven.Tests.Patching.x2js.js";
var manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
var code = new StreamReader(manifestResourceStream).ReadToEnd();
var jsonPatcher = new ScriptedJsonPatcher();
using (var scope = new DefaultScriptedJsonPatcherOperationScope())
{
scope.CustomFunctions = new JsonDocument
{
DataAsJson = new RavenJObject
{
{"Functions", code}
}
};
jsonPatcher.Apply(scope, document, new ScriptedPatchRequest
{
Script = "this.Xml = js2x(this.Data);"
});
}
}
开发者ID:GorelH,项目名称:ravendb,代码行数:33,代码来源:UseX2JsScript.cs
示例15: Set
public void Set(string name, string key, RavenJObject data, UuidType uuidType)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);
var exists = Api.TrySeek(session, Lists, SeekGrbit.SeekEQ);
using (var update = new Update(session, Lists, exists ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["name"], name, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["etag"], uuidGenerator.CreateSequentialUuid(uuidType).TransformToValueForEsentSorting());
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["created_at"], SystemTime.UtcNow);
using (var columnStream = new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"]))
{
if (exists)
columnStream.SetLength(0);
using (Stream stream = new BufferedStream(columnStream))
{
data.WriteTo(stream);
stream.Flush();
}
}
update.Save();
}
}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:Lists.cs
示例16: DetermineWork
public SynchronizationWorkItem DetermineWork(string file, RavenJObject localMetadata, RavenJObject destinationMetadata, string localServerUrl, out NoSyncReason reason)
{
reason = NoSyncReason.Unknown;
if (localMetadata == null)
{
reason = NoSyncReason.SourceFileNotExist;
return null;
}
if (destinationMetadata != null && destinationMetadata[SynchronizationConstants.RavenSynchronizationConflict] != null && destinationMetadata[SynchronizationConstants.RavenSynchronizationConflictResolution] == null)
{
reason = NoSyncReason.DestinationFileConflicted;
return null;
}
if (localMetadata[SynchronizationConstants.RavenSynchronizationConflict] != null)
{
reason = NoSyncReason.SourceFileConflicted;
return null;
}
if (localMetadata[SynchronizationConstants.RavenDeleteMarker] != null)
{
if (localMetadata.ContainsKey(SynchronizationConstants.RavenRenameFile))
{
var rename = localMetadata.Value<string>(SynchronizationConstants.RavenRenameFile);
if (destinationMetadata != null)
return new RenameWorkItem(file, rename, localServerUrl, storage);
return new ContentUpdateWorkItem(rename, localServerUrl, storage, sigGenerator);
// we have a rename tombstone but file does not exists on destination
}
return new DeleteWorkItem(file, localServerUrl, storage);
}
if (destinationMetadata != null && Historian.IsDirectChildOfCurrent(localMetadata, destinationMetadata))
{
reason = NoSyncReason.ContainedInDestinationHistory;
return null;
}
// file exists on dest and has the same content
if (destinationMetadata != null && localMetadata.Value<string>("Content-MD5") == destinationMetadata.Value<string>("Content-MD5"))
{
// check metadata to detect if any synchronization is needed
if (localMetadata.Keys.Except(new[] { Constants.MetadataEtagField, Constants.RavenLastModified, Constants.LastModified })
.Any(key => !destinationMetadata.ContainsKey(key) || localMetadata[key] != destinationMetadata[key]))
{
return new MetadataUpdateWorkItem(file, localServerUrl, destinationMetadata, storage);
}
reason = NoSyncReason.SameContentAndMetadata;
return null; // the same content and metadata - no need to synchronize
}
return new ContentUpdateWorkItem(file, localServerUrl, storage, sigGenerator);
}
开发者ID:heinnge,项目名称:ravendb,代码行数:60,代码来源:SynchronizationStrategy.cs
示例17: EnsureQuotasBundleActivated
private static void EnsureQuotasBundleActivated(RavenJObject settings)
{
RavenJToken value;
if (settings.TryGetValue(Constants.ActiveBundles, out value) == false)
settings[Constants.ActiveBundles] = value = new RavenJValue(string.Empty);
var activeBundles = value.Value<string>();
var bundles = activeBundles.GetSemicolonSeparatedValues();
if (bundles.Contains("Quotas", StringComparer.OrdinalIgnoreCase) == false)
bundles.Add("Quotas");
int hardLimitInKb;
if (int.TryParse(ConfigurationManager.AppSettings["Raven/Bundles/LiveTest/Quotas/Size/HardLimitInKB"], out hardLimitInKb) == false)
hardLimitInKb = QuotasHardLimitInKb;
int softMarginInKb;
if (int.TryParse(ConfigurationManager.AppSettings["Raven/Bundles/LiveTest/Quotas/Size/SoftLimitInKB"], out softMarginInKb) == false)
softMarginInKb = QuotasSoftMarginInKb;
settings[Constants.ActiveBundles] = string.Join(";", bundles);
settings[Constants.SizeHardLimitInKB] = hardLimitInKb;
settings[Constants.SizeSoftLimitInKB] = softMarginInKb;
settings[Constants.DocsHardLimit] = null;
settings[Constants.DocsSoftLimit] = null;
}
开发者ID:GorelH,项目名称:ravendb,代码行数:26,代码来源:LiveTestDatabaseDocumentPutTrigger.cs
示例18: Create
public ActionResult Create(CreateEditMenu showMenu)
{
try
{
var menu = new Menu
{
Name = showMenu.Name
};
_session.Store(menu);
var key = RavenDbKey.GenerateKey<Menu>(menu.Id);
var stream = showMenu.File.InputStream;
var optionalMetaData = new RavenJObject();
optionalMetaData["Format"] = showMenu.File.ContentType;
_session.Advanced.DocumentStore.DatabaseCommands.PutAttachment(key, null, stream, optionalMetaData);
return RedirectToAction("Index");
}
catch
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View(showMenu);
}
开发者ID:teamyudin,项目名称:LunchBox,代码行数:25,代码来源:MenuController.cs
示例19: DisableVersioning
public static RavenJToken DisableVersioning(RavenJObject metadata)
{
if (metadata != null)
metadata.Add(Constants.RavenIgnoreVersioning, true);
return metadata;
}
开发者ID:j2jensen,项目名称:ravendb,代码行数:7,代码来源:SmugglerHelper.cs
示例20: WriteJsonSnapshot
private static void WriteJsonSnapshot(RavenJObject ravenJObject, StringWriter sw, int margin, int intdent = 0)
{
foreach (var item in ravenJObject)
{
if (intdent > 0)
sw.Write(new string(' ', intdent * 4));
sw.Write(item.Key + ": ");
switch (item.Value.Type)
{
case JTokenType.Object:
sw.Write('{');
sw.Write(Environment.NewLine);
WriteJsonSnapshot((RavenJObject)item.Value, sw, margin, intdent + 1);
sw.Write('}');
break;
case JTokenType.Null:
sw.Write("null");
break;
case JTokenType.String:
sw.Write('"');
sw.Write(item.Value.ToString().ShortViewOfString(margin - 2));
sw.Write('"');
break;
default:
sw.Write(item.Value.ToString().ShortViewOfString(margin));
break;
}
sw.Write(Environment.NewLine);
}
}
开发者ID:maurodx,项目名称:ravendb,代码行数:30,代码来源:ViewableDocument.cs
注:本文中的RavenJObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论