本文整理汇总了C#中System.Net.Http.HttpClient.GetXmlAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetXmlAsync方法的具体用法?C# HttpClient.GetXmlAsync怎么用?C# HttpClient.GetXmlAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetXmlAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoDiscoverHostedServices
Task<HostedServiceInfo[]> DoDiscoverHostedServices(HttpClient client, CancellationToken cancellationToken)
{
return client.GetXmlAsync<HostedServiceInfo[]>(
"services/hostedservices",
cancellationToken, _policies.RetryOnTransientErrors,
(xml, tcs) =>
{
var serviceNames = xml.AzureElements("HostedServices", "HostedService")
.Select(e => e.AzureValue("ServiceName"))
.ToArray();
Task.Factory.ContinueWhenAll(
serviceNames.Select(serviceName => DoDiscoverHostedService(client, serviceName, cancellationToken)).ToArray(),
tasks =>
{
// TODO (ruegg, 2011-05-27): Check task fault state and deal with it
try
{
tcs.TrySetResult(tasks.Select(t => t.Result).ToArray());
}
catch (Exception e)
{
tcs.TrySetException(e);
}
},
cancellationToken);
});
}
示例2: DoDiscoverDeployment
Task<DeploymentReference[]> DoDiscoverDeployment(HttpClient client, string serviceName, CancellationToken cancellationToken)
{
return client.GetXmlAsync<DeploymentReference[]>(
string.Format("services/hostedservices/{0}?embed-detail=true", serviceName),
cancellationToken, _policies.RetryOnTransientErrors,
(xml, tcs) =>
{
var xmlService = xml.AzureElement("HostedService");
var references = xmlService.AzureElements("Deployments", "Deployment").Select(d => new DeploymentReference
{
HostedServiceName = xmlService.AzureValue("ServiceName"),
DeploymentName = d.AzureValue("Name"),
DeploymentPrivateId = d.AzureValue("PrivateID")
}).ToArray();
tcs.TrySetResult(references);
});
}
示例3: DoDiscoverHostedService
Task<HostedServiceInfo> DoDiscoverHostedService(HttpClient client, string serviceName, CancellationToken cancellationToken)
{
return client.GetXmlAsync<HostedServiceInfo>(
string.Format("services/hostedservices/{0}?embed-detail=true", serviceName),
cancellationToken, _policies.RetryOnTransientErrors,
(xml, tcs) =>
{
var xmlService = xml.AzureElement("HostedService");
var xmlProperties = xmlService.AzureElement("HostedServiceProperties");
var info = new HostedServiceInfo
{
ServiceName = xmlService.AzureValue("ServiceName"),
Description = xmlProperties.AzureValue("Description"),
ServiceLabel = xmlProperties.AzureEncodedValue("Label"),
Deployments = xmlService.AzureElements("Deployments", "Deployment").Select(d =>
{
var config = d.AzureConfiguration();
var instanceCountPerRole = d.AzureElements("RoleInstanceList", "RoleInstance")
.GroupBy(ri => ri.AzureValue("RoleName"))
.ToDictionary(g => g.Key, g => g.Count());
return new DeploymentInfo
{
DeploymentName = d.AzureValue("Name"),
DeploymentLabel = d.AzureEncodedValue("Label"),
Slot = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), d.AzureValue("DeploymentSlot")),
PrivateId = d.AzureValue("PrivateID"),
Status = (DeploymentStatus)Enum.Parse(typeof(DeploymentStatus), d.AzureValue("Status")),
Roles = d.AzureElements("RoleList", "Role").Select(r =>
{
var roleName = r.AzureValue("RoleName");
var roleConfig = config.ServiceConfigElements("ServiceConfiguration", "Role")
.Single(role => role.AttributeValue("name") == roleName);
int instanceCount;
if (!instanceCountPerRole.TryGetValue(roleName, out instanceCount))
{
instanceCount = 0;
}
return new RoleInfo
{
RoleName = roleName,
ActualInstanceCount = instanceCount,
ConfiguredInstanceCount = Int32.Parse(roleConfig.ServiceConfigElement("Instances").AttributeValue("count")),
Settings = roleConfig.ServiceConfigElements("ConfigurationSettings", "Setting").ToDictionary(
x => x.AttributeValue("name"), x => x.AttributeValue("value"))
};
}).ToList()
};
}).ToList()
};
tcs.TrySetResult(info);
});
}
示例4: DoGetDeploymentConfiguration
Task<XDocument> DoGetDeploymentConfiguration(HttpClient client, string serviceName, DeploymentSlot deploymentSlot, CancellationToken cancellationToken)
{
return client.GetXmlAsync<XDocument>(
string.Format("services/hostedservices/{0}/deploymentslots/{1}", serviceName, deploymentSlot.ToString().ToLower()),
cancellationToken, _policies.RetryOnTransientErrors,
(xml, tcs) => tcs.TrySetResult(xml.AzureElement("Deployment").AzureConfiguration()));
}