本文整理汇总了C#中Raven.Abstractions.Data.JsonDocument.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# JsonDocument.ToJson方法的具体用法?C# JsonDocument.ToJson怎么用?C# JsonDocument.ToJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Abstractions.Data.JsonDocument
的用法示例。
在下文中一共展示了JsonDocument.ToJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
private static async Task Save(string serverHash, JsonDocument document)
{
var path = "RavenDB Replication Information For - " + serverHash;
var file = await folder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
using (var stream = await file.OpenStreamForWriteAsync())
{
document.ToJson().WriteTo(stream);
}
}
示例2: TrySavingReplicationInformationToLocalCache
public static void TrySavingReplicationInformationToLocalCache(string serverHash, JsonDocument document)
{
try
{
using (var machineStoreForApplication = GetIsolatedStorageFileForReplicationInformation())
{
var path = "RavenDB Replication Information For - " + serverHash;
using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, machineStoreForApplication))
{
document.ToJson().WriteTo(stream);
}
}
}
catch (Exception e)
{
log.ErrorException("Could not persist the replication information", e);
}
}
示例3: GetDocumentsWithIdStartingWith
public void GetDocumentsWithIdStartingWith(string idPrefix, string matches, string exclude, int start, int pageSize,
CancellationToken token, ref int nextStart, Action<RavenJObject> addDoc,
string transformer = null, Dictionary<string, RavenJToken> transformerParameters = null,
string skipAfter = null)
{
if (idPrefix == null)
throw new ArgumentNullException("idPrefix");
idPrefix = idPrefix.Trim();
var canPerformRapidPagination = nextStart > 0 && start == nextStart;
var actualStart = canPerformRapidPagination ? start : 0;
var addedDocs = 0;
var matchedDocs = 0;
TransactionalStorage.Batch(
actions =>
{
var docsToSkip = canPerformRapidPagination ? 0 : start;
int docCount;
AbstractTransformer storedTransformer = null;
if (transformer != null)
{
storedTransformer = IndexDefinitionStorage.GetTransformer(transformer);
if (storedTransformer == null)
throw new InvalidOperationException("No transformer with the name: " + transformer);
}
do
{
docCount = 0;
var docs = actions.Documents.GetDocumentsWithIdStartingWith(idPrefix, actualStart, pageSize, string.IsNullOrEmpty(skipAfter) ? null : skipAfter);
var documentRetriever = new DocumentRetriever(actions, Database.ReadTriggers, Database.InFlightTransactionalState, transformerParameters);
foreach (var doc in docs)
{
token.ThrowIfCancellationRequested();
docCount++;
var keyTest = doc.Key.Substring(idPrefix.Length);
if (!WildcardMatcher.Matches(matches, keyTest) || WildcardMatcher.MatchesExclusion(exclude, keyTest))
continue;
DocumentRetriever.EnsureIdInMetadata(doc);
var nonAuthoritativeInformationBehavior = Database.InFlightTransactionalState.GetNonAuthoritativeInformationBehavior<JsonDocument>(null, doc.Key);
var document = nonAuthoritativeInformationBehavior != null ? nonAuthoritativeInformationBehavior(doc) : doc;
document = documentRetriever.ExecuteReadTriggers(document, null, ReadOperation.Load);
if (document == null)
continue;
matchedDocs++;
if (matchedDocs <= docsToSkip)
continue;
token.ThrowIfCancellationRequested();
if (storedTransformer != null)
{
using (new CurrentTransformationScope(Database, documentRetriever))
{
var transformed =
storedTransformer.TransformResultsDefinition(new[] { new DynamicJsonObject(document.ToJson()) })
.Select(x => JsonExtensions.ToJObject(x))
.ToArray();
if (transformed.Length == 0)
{
throw new InvalidOperationException("The transform results function failed on a document: " + document.Key);
}
var transformedJsonDocument = new JsonDocument
{
Etag = document.Etag.HashWith(storedTransformer.GetHashCodeBytes()).HashWith(documentRetriever.Etag),
NonAuthoritativeInformation = document.NonAuthoritativeInformation,
LastModified = document.LastModified,
DataAsJson = new RavenJObject { { "$values", new RavenJArray(transformed) } },
};
addDoc(transformedJsonDocument.ToJson());
}
}
else
{
addDoc(document.ToJson());
}
addedDocs++;
if (addedDocs >= pageSize)
break;
}
actualStart += pageSize;
}
while (docCount > 0 && addedDocs < pageSize && actualStart > 0 && actualStart < int.MaxValue);
});
//.........这里部分代码省略.........
示例4: UpdateBeforeDocument
private void UpdateBeforeDocument(JsonDocument doc)
{
recentDocuments.Add(doc);
OriginalDoc.SetText(doc.ToJson().ToString());
NewDoc.SetText("");
ShowBeforeAndAfterPrompt = false;
ShowAfterPrompt = true;
}