本文整理汇总了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");
}