本文整理汇总了C#中System.Net.Http.HttpClient.GetResource方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetResource方法的具体用法?C# HttpClient.GetResource怎么用?C# HttpClient.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetResource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(Command command)
{
var client = new HttpClient { BaseAddress = new Uri(command.Server) };
client.DefaultRequestHeaders.Add("X-Octopus-ApiKey", command.ApiKey);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var api = client.GetResource<Api>("/api");
var projects = client.GetResource<IEnumerable<Project>>(api.Links.Projects);
var project = projects.FirstOrDefault(x => x.Name.Equals(command.ProjectName, StringComparison.InvariantCultureIgnoreCase));
var variables = client.GetResource<IEnumerable<Variable>>(project.Links.Variables);
var environmentLookup = client.GetResource<IEnumerable<Environment>>(api.Links.Environments).ToDictionary(x=> x.Id);
var csv = new StringBuilder();
const string format = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"";
csv.AppendLine("Name,Value,Environment,Role,Step");
foreach (var variable in variables)
{
var data = new VariableData();
data.Name = variable.Name;
data.Value = variable.Value;
data.Environment = !string.IsNullOrEmpty(variable.EnvironmentId) ? environmentLookup[variable.EnvironmentId].Name : string.Empty;
data.Role = variable.Role;
data.Step = string.Empty;
csv.AppendFormat(format, data.Name, data.Value, data.Environment, data.Role, data.Step);
csv.AppendLine();
}
var content = csv.ToString();
File.WriteAllText(command.FilePath, content, Encoding.UTF8);
}