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


C# IPEndPoint.ToHttpUri方法代码示例

本文整理汇总了C#中System.Net.IPEndPoint.ToHttpUri方法的典型用法代码示例。如果您正苦于以下问题:C# IPEndPoint.ToHttpUri方法的具体用法?C# IPEndPoint.ToHttpUri怎么用?C# IPEndPoint.ToHttpUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.IPEndPoint的用法示例。


在下文中一共展示了IPEndPoint.ToHttpUri方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateReplicationState

		/// <summary>Updates interinstance replication state.</summary>
		public static void UpdateReplicationState(IPEndPoint localEndPoint, ReplicationSettings settings)
		{
			var localCouchDBUri = localEndPoint.ToHttpUri();
			Log.InfoFormat("Saving replication documents using server URI: {0}", localCouchDBUri);

			var couchApi = Factory.CreateCouchApi(localCouchDBUri);
			
			CreateDatabases(couchApi, settings.DatabasesToReplicate);

			var descriptorsToCreate = (
				from endpoint in settings.EndPointsToReplicateTo
				from dbName in settings.DatabasesToReplicate
				let endpointUri = endpoint.ToHttpUri()
				let descriptorId = GetDescriptorId(endpointUri, dbName)
				let descriptor = new ReplicationTaskDescriptor {
					Id = descriptorId,
					Continuous = true,
					Source = new Uri(endpointUri, dbName),
					Target = new Uri(dbName, UriKind.Relative),
					UserContext = new ReplicationUserContext {
						Roles = new[] { "admin" }
					}
				}
				select descriptor
			).ToArray();

			Log.InfoFormat(
				"Replication descriptors should be created: {0}", 
				string.Join(", ", descriptorsToCreate.Select(d => d.Id))
			);

			var replicatorApi = couchApi.Replicator;
			replicatorApi.GetAllDescriptorNames()
				.ContinueWith(
					t => {
						Log.Info("Loading existing replication descriptors...");
						var loadTasks = (
							from descriptorId in t.Result
							select replicatorApi
											.RequestDescriptorById(descriptorId)
											.ContinueWith(pt => pt.IsCompleted? pt.Result: null)
							).ToArray();
						return Task.Factory.ContinueWhenAll(
							loadTasks,
							tasks => {
								var existingDescriptors = (
									from loadTask in tasks
									select loadTask.Result
									into descriptor
									where descriptor != null
									select descriptor).ToArray();

								Log.InfoFormat(
									"{0} replication descriptors found in the _replicator database: {1}",
									existingDescriptors.Length,
									string.Join(", ", existingDescriptors.Select(d => d.Id)));
								return existingDescriptors;
							});
					})
				.Unwrap()
				.ContinueWith(
					t => {
						var descritorsToDelete = t.Result;
						Log.InfoFormat(
							"Deleting {0} replication descriptors from _replicator database: {1}",
							descritorsToDelete.Length,
							string.Join(", ", descritorsToDelete.Select(d => d.Id)));
						var deleteTasks =
							from descritorToDelete in descritorsToDelete
							select replicatorApi.DeleteDescriptor(descritorToDelete);
						return Task.Factory.ContinueWhenAll(deleteTasks.ToArray(), ThrowAggregateIfFaulted);
					})
				.Unwrap()
				.ContinueWith(
					t => {
						Log.InfoFormat(
							"Creating {0} replication descriptors in _replicator database: {1}",
							descriptorsToCreate.Length,
							string.Join(", ", descriptorsToCreate.Select(d => d.Id))
							);
						var createDescriptorsTasks = (
							from descriptorToCreate in descriptorsToCreate
							select replicatorApi.SaveDescriptor(descriptorToCreate)
							).ToArray();
						return createDescriptorsTasks.Length == 0
							? Task.Factory.StartNew(() => { })
							: Task.Factory.ContinueWhenAll(createDescriptorsTasks, ThrowAggregateIfFaulted);
					})
				.Unwrap()
				.Wait();

			Log.Info("Replication descriptors have been created");
		}
开发者ID:artikh,项目名称:CouchDude.Bootstrapper,代码行数:94,代码来源:CouchDBReplicator.cs


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