本文整理汇总了C#中WorkflowContext.SetState方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowContext.SetState方法的具体用法?C# WorkflowContext.SetState怎么用?C# WorkflowContext.SetState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkflowContext
的用法示例。
在下文中一共展示了WorkflowContext.SetState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var url = activityContext.GetState<string>("Url");
var verb = (activityContext.GetState<string>("Verb") ?? "GET").ToUpper();
var headers = activityContext.GetState<string>("Headers");
var formValues = activityContext.GetState<string>("FormValues") ?? "";
using (var httpClient = new HttpClient {BaseAddress = new Uri(url)}) {
HttpResponseMessage response;
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (!String.IsNullOrWhiteSpace(headers)) {
foreach (var header in ParseKeyValueString(headers)) {
httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
switch (verb) {
default:
case "GET":
response = httpClient.GetAsync("").Result;
break;
case "POST":
var format = activityContext.GetState<string>("FormFormat");
switch (format) {
default:
case "KeyValue":
var form = ParseKeyValueString(formValues);
response = httpClient.PostAsync("", new FormUrlEncodedContent(form)).Result;
break;
case "Json":
var json = formValues.Replace("((", "{").Replace("))", "}");
response = httpClient.PostAsync("", new StringContent(json, Encoding.UTF8, "application/json")).Result;
break;
}
break;
}
workflowContext.SetState("WebRequestResponse", response.Content.ReadAsStringAsync().Result);
if (response.IsSuccessStatusCode)
yield return T("Success");
else
yield return T("Error");
}
}