当前位置: 首页>>代码示例>>C#>>正文


C# IAsyncDatabaseCommands.GetAsync方法代码示例

本文整理汇总了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);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:13,代码来源:AbstractScriptedIndexCreationTask.cs

示例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;
				});
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:25,代码来源:AsyncHiLoKeyGenerator.cs

示例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();
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:64,代码来源:AsyncHiLoKeyGenerator.cs

示例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);
	    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:21,代码来源:AsyncHiLoKeyGenerator.cs

示例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);
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:50,代码来源:HealthMonitorTask.cs


注:本文中的IAsyncDatabaseCommands.GetAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。