本文整理汇总了C#中ActivityContext.GetState方法的典型用法代码示例。如果您正苦于以下问题:C# ActivityContext.GetState方法的具体用法?C# ActivityContext.GetState怎么用?C# ActivityContext.GetState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityContext
的用法示例。
在下文中一共展示了ActivityContext.GetState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
{
var part = workflowContext.Content.As<WXMsgPart>();
var apiUrl = activityContext.GetState<string>("api_url");
var apiToken = activityContext.GetState<string>("api_token");
var timestamp = HttpContext.Current.Request.QueryString["timestamp"];
var nonce = HttpContext.Current.Request.QueryString["nonce"];
string[] arr = { apiToken, timestamp, nonce };
Array.Sort(arr); //字典排序
string tmpStr = string.Join("", arr);
var signature = _winXinService.GetSHA1(tmpStr);
signature = signature.ToLower();
var client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8;
var url = string.Format("{0}?timestamp={1}&nonce={2}&signature={3}"
, apiUrl, timestamp, nonce, signature);
string postData = part.XML;
//using (var stream = HttpContext.Current.Request.InputStream)
//{
// var reader = new StreamReader(stream);
// postData = reader.ReadToEnd();
//}
string result = null;
try
{
result = client.UploadString(url, postData);
}
catch (System.Net.WebException ex)
{
string msg = null;
using (var stream = ex.Response.GetResponseStream())
{
var reader = new StreamReader(stream);
msg = reader.ReadToEnd();
}
Logger.Warning(ex, ex.Message);
}
catch (Exception ex)
{
var innerEx = ex;
while (innerEx.InnerException != null)
innerEx = innerEx.InnerException;
Logger.Warning(ex, innerEx.Message);
}
if (result == null)
{
yield return T("Error");
}
else
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(result);
HttpContext.Current.Response.End();
yield return T("Success");
}
}
示例2: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var userName = activityContext.GetState<string>("UserName");
var email = activityContext.GetState<string>("Email");
var password = activityContext.GetState<string>("Password");
var approved = activityContext.GetState<bool>("Approved");
if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(email)) {
yield return T("InvalidUserNameOrEmail");
yield break;
}
if (String.IsNullOrWhiteSpace(password)) {
yield return T("InvalidPassword");
yield break;
}
if (!_userService.VerifyUserUnicity(userName, email)) {
yield return T("UserNameOrEmailNotUnique");
yield break;
}
var user = _membershipService.CreateUser(
new CreateUserParams(
userName,
password,
email,
isApproved: approved,
passwordQuestion: null,
passwordAnswer: null));
workflowContext.Content = user;
yield return T("Done");
}
示例3: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var key = activityContext.GetState<string>("Key");
var message = activityContext.GetState<string>("ErrorMessage");
var updater = (IUpdateModel) workflowContext.Tokens["Updater"];
updater.AddModelError(key, T(message));
return new[] { T("Done") };
}
示例4: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var notification = activityContext.GetState<string>("Notification");
var message = activityContext.GetState<string>("Message");
var notificationType = (NotifyType)Enum.Parse(typeof(NotifyType), notification);
_notifier.Add(notificationType, T(message));
yield return T("Done");
}
示例5: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var levelString = activityContext.GetState<string>("Level");
var message = activityContext.GetState<string>("Message");
LogLevel level;
Enum.TryParse(levelString, true, out level);
Logger.Log(level, null, message);
yield return T("Done");
}
示例6: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var userName = activityContext.GetState<string>("UserName");
var email = activityContext.GetState<string>("Email");
if (_userService.VerifyUserUnicity(userName, email)) {
yield return T("Unique");
}
else {
yield return T("NotUnique");
}
}
示例7: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var body = activityContext.GetState<string>("Body");
var subject = activityContext.GetState<string>("Subject");
var recipients = activityContext.GetState<string>("Recipients");
var replyTo = activityContext.GetState<string>("ReplyTo");
var bcc = activityContext.GetState<string>("Bcc");
var cc = activityContext.GetState<string>("CC");
var parameters = new Dictionary<string, object> {
{"Subject", subject},
{"Body", body},
{"Recipients", recipients},
{"ReplyTo", replyTo},
{"Bcc", bcc},
{"CC", cc}
};
var queued = activityContext.GetState<bool>("Queued");
if (!queued) {
_messageService.Send(SmtpMessageChannel.MessageType, parameters);
}
else {
var priority = activityContext.GetState<int>("Priority");
_jobsQueueService.Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority);
}
yield return T("Done");
}
示例8: IsExpired
private bool IsExpired(WorkflowContext workflowContext, ActivityContext activityContext) {
DateTime started;
if (!workflowContext.HasStateFor(activityContext.Record, "StartedUtc")) {
workflowContext.SetStateFor(activityContext.Record, "StartedUtc", started = _clock.UtcNow);
}
else {
started = workflowContext.GetStateFor<DateTime>(activityContext.Record, "StartedUtc");
}
var amount = activityContext.GetState<int>("Amount");
var type = activityContext.GetState<string>("Unity");
return _clock.UtcNow > When(started, amount, type);
}
示例9: 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");
}
}
示例10: CanExecute
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
try {
var state = activityContext.GetState<string>("CustomForms");
// "" means 'any'
if (String.IsNullOrEmpty(state)) {
return true;
}
var content = workflowContext.Tokens["CustomForm"] as ContentItem;
if (content == null) {
return false;
}
var contentManager = content.ContentManager;
var identities = state.Split(',').Select(x => new ContentIdentity(x));
var customForms = identities.Select(contentManager.ResolveIdentity);
return customForms.Any(x => x == content);
}
catch {
return false;
}
}
示例11: CanExecute
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext)
{
try {
var contentTypesState = activityContext.GetState<string>("ContentTypes");
// "" means 'any'
if (String.IsNullOrEmpty(contentTypesState)) {
return true;
}
string[] contentTypes = contentTypesState.Split(',');
var content = workflowContext.Content;
if (content == null) {
return false;
}
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
}
catch {
return false;
}
}
示例12: GetBranches
private IEnumerable<string> GetBranches(ActivityContext context) {
var branches = context.GetState<string>("Branches");
if (String.IsNullOrEmpty(branches)) {
return Enumerable.Empty<string>();
}
return branches.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
}
示例13: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
{
string recipient = activityContext.GetState<string>("Recipient");
var properties = new Dictionary<string, string> {
{"Body", activityContext.GetState<string>("Body")},
{"Subject", activityContext.GetState<string>("Subject")}
};
if (recipient == "owner") {
var content = workflowContext.Content;
if (content.Has<CommonPart>()) {
var owner = content.As<CommonPart>().Owner;
if (owner != null && owner.ContentItem != null && owner.ContentItem.Record != null) {
_messageManager.Send(owner.ContentItem.Record, MessageType, "email", properties);
}
_messageManager.Send(
SplitEmail(owner.As<IUser>().Email), MessageType, "email", properties);
}
}
else if (recipient == "author") {
var user = _orchardServices.WorkContext.CurrentUser;
// can be null if user is anonymous
if (user != null && String.IsNullOrWhiteSpace(user.Email)) {
_messageManager.Send(user.ContentItem.Record, MessageType, "email", properties);
}
}
else if (recipient == "admin") {
var username = _orchardServices.WorkContext.CurrentSite.SuperUser;
var user = _membershipService.GetUser(username);
// can be null if user is no super user is defined
if (user != null && !String.IsNullOrWhiteSpace(user.Email)) {
_messageManager.Send(user.ContentItem.Record, MessageType, "email", properties);
}
}
else if (recipient == "other") {
var email = properties["RecipientOther"];
_messageManager.Send(SplitEmail(email), MessageType, "email", properties);
}
yield return T("Sent");
}
示例14: IsExpired
private bool IsExpired(WorkflowContext workflowContext, ActivityContext activityContext) {
DateTime started;
if (!workflowContext.HasStateFor(activityContext.Record, "StartedUtc")) {
var dateString = activityContext.GetState<string>("Date");
var date = _dateServices.ConvertFromLocalizedString(dateString);
started = date ?? _clock.UtcNow;
workflowContext.SetStateFor(activityContext.Record, "StartedUtc", started);
}
else {
started = workflowContext.GetStateFor<DateTime>(activityContext.Record, "StartedUtc");
}
var amount = activityContext.GetState<int>("Amount");
var type = activityContext.GetState<string>("Unity");
return _clock.UtcNow > When(started, amount, type);
}
示例15: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
var script = activityContext.GetState<string>("Script");
object outcome = null;
_csharpService.SetParameter("Services", _orchardServices);
_csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
_csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
_csharpService.SetFunction("T", (Func<string, string>)(x => T(x).Text));
_csharpService.SetFunction("SetOutcome", (Action<object>)(x => outcome = x));
_csharpService.Run(script);
yield return T(Convert.ToString(outcome));
}