本文整理汇总了C#中IAsyncDatabaseCommands.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAsyncDatabaseCommands.GetAsync方法的具体用法?C# IAsyncDatabaseCommands.GetAsync怎么用?C# IAsyncDatabaseCommands.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAsyncDatabaseCommands
的用法示例。
在下文中一共展示了IAsyncDatabaseCommands.GetAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AfterExecuteAsync
internal static async Task AfterExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, string indexName, ScriptedIndexResults scripts, CancellationToken token)
{
var documentId = GetScriptedIndexResultsDocumentId(indexName);
scripts.Id = documentId;
var oldDocument = await asyncDatabaseCommands.GetAsync(documentId, token).ConfigureAwait(false);
var newDocument = RavenJObject.FromObject(scripts);
if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
return;
await asyncDatabaseCommands.PutAsync(documentId, null, newDocument, null, token).ConfigureAwait(false);
await asyncDatabaseCommands.ResetIndexAsync(indexName, token).ConfigureAwait(false);
}
示例2: GetDocumentAsync
private Task<JsonDocument> GetDocumentAsync(IAsyncDatabaseCommands databaseCommands)
{
return databaseCommands.GetAsync(new[] { HiLoDocumentKey, RavenKeyServerPrefix }, new string[0])
.ContinueWith(task =>
{
var documents = task.Result;
if (documents.Results.Count == 2 && documents.Results[1] != null)
{
lastServerPrefix = documents.Results[1].Value<string>("ServerPrefix");
}
else
{
lastServerPrefix = string.Empty;
}
if (documents.Results.Count == 0 || documents.Results[0] == null)
return (JsonDocument)null;
var jsonDocument = documents.Results[0].ToJsonDocument();
foreach (var key in jsonDocument.Metadata.Keys.Where(x => x.StartsWith("@")).ToArray())
{
jsonDocument.Metadata.Remove(key);
}
return jsonDocument;
});
}
示例3: GetNextMaxAsyncInner
private Task<RangeValue> GetNextMaxAsyncInner(IAsyncDatabaseCommands databaseCommands)
{
var minNextMax = Range.Max;
return GetDocumentAsync(databaseCommands)
.ContinueWith(task =>
{
try
{
JsonDocument document;
try
{
document = task.Result;
}
catch (ConflictException e)
{
// resolving the conflict by selecting the highest number
var highestMax = e.ConflictedVersionIds
.Select(conflictedVersionId => databaseCommands.GetAsync(conflictedVersionId)
.ContinueWith(t => GetMaxFromDocument(t.Result, minNextMax)))
.AggregateAsync(Enumerable.Max);
return highestMax
.ContinueWith(t => PutDocumentAsync(databaseCommands, new JsonDocument
{
Etag = e.Etag,
Metadata = new RavenJObject(),
DataAsJson = RavenJObject.FromObject(new {Max = t.Result}),
Key = HiLoDocumentKey
}))
.Unwrap()
.ContinueWithTask(() => GetNextRangeAsync(databaseCommands));
}
long min, max;
if (document == null)
{
min = minNextMax + 1;
max = minNextMax + capacity;
document = new JsonDocument
{
Etag = Guid.Empty,
// sending empty guid means - ensure the that the document does NOT exists
Metadata = new RavenJObject(),
DataAsJson = RavenJObject.FromObject(new {Max = max}),
Key = HiLoDocumentKey
};
}
else
{
var oldMax = GetMaxFromDocument(document, minNextMax);
min = oldMax + 1;
max = oldMax + capacity;
document.DataAsJson["Max"] = max;
}
return PutDocumentAsync(databaseCommands, document).WithResult(new RangeValue(min, max));
}
catch (ConcurrencyException)
{
return GetNextMaxAsyncInner(databaseCommands);
}
}).Unwrap();
}
示例4: HandleConflictsAsync
private async Task<RangeValue> HandleConflictsAsync(IAsyncDatabaseCommands databaseCommands, ConflictException e, long minNextMax)
{
// resolving the conflict by selecting the highest number
long highestMax = -1;
if (e.ConflictedVersionIds.Length == 0)
throw new InvalidOperationException("Got conflict exception, but no conflicted versions",e);
foreach (var conflictedVersionId in e.ConflictedVersionIds)
{
var doc = await databaseCommands.GetAsync(conflictedVersionId).ConfigureAwait(false);
highestMax = Math.Max(highestMax, GetMaxFromDocument(doc, minNextMax));
}
await PutDocumentAsync(databaseCommands, new JsonDocument
{
Etag = e.Etag,
Metadata = new RavenJObject(),
DataAsJson = RavenJObject.FromObject(new { Max = highestMax }),
Key = HiLoDocumentKey
}).ConfigureAwait(false);
return await GetNextRangeAsync(databaseCommands).ConfigureAwait(false);
}
示例5: HandleDatabaseInServerAsync
private static async Task HandleDatabaseInServerAsync(ServerRecord server, string databaseName, IAsyncDatabaseCommands dbCmds, IAsyncDocumentSession session)
{
var databaseRecord = await session.LoadAsync<DatabaseRecord>(server.Id + "/" + databaseName);
if (databaseRecord == null)
return;
var replicationDocument = await dbCmds.GetAsync(Constants.RavenReplicationDestinations);
if (replicationDocument == null)
return;
databaseRecord.IsReplicationEnabled = true;
var document = replicationDocument.DataAsJson.JsonDeserialization<ReplicationDocument>();
databaseRecord.ReplicationDestinations = document.Destinations;
var replicationStatistics = await dbCmds.Info.GetReplicationInfoAsync();
if (replicationStatistics != null)
{
databaseRecord.ReplicationStatistics = replicationStatistics;
}
// Monitor the replicated destinations
foreach (var replicationDestination in databaseRecord.ReplicationDestinations)
{
if (replicationDestination.Disabled)
continue;
var url = replicationDestination.Url;
var databasesIndex = url.IndexOf("/databases/", StringComparison.OrdinalIgnoreCase);
if (databasesIndex > 0)
{
url = url.Substring(0, databasesIndex);
}
var replicationDestinationServer = await session.LoadAsync<ServerRecord>("serverRecords/" + ReplicationTask.EscapeDestinationName(url));
if (replicationDestinationServer == null)
{
replicationDestinationServer = new ServerRecord
{
Url = url,
};
await session.StoreAsync(replicationDestinationServer);
}
else
{
if (DateTimeOffset.UtcNow - server.LastTriedToConnectAt <= TimeSpan.FromHours(1))
continue;
}
await FetchServerDatabasesAsync(replicationDestinationServer, session);
}
}