本文整理汇总了C#中ActivityContext类的典型用法代码示例。如果您正苦于以下问题:C# ActivityContext类的具体用法?C# ActivityContext怎么用?C# ActivityContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActivityContext类属于命名空间,在下文中一共展示了ActivityContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLocation
public override Location GetLocation(ActivityContext context)
{
Location location;
if (context == null)
{
throw FxTrace.Exception.ArgumentNull("context");
}
this.ThrowIfNotInTree();
if (!context.AllowChainedEnvironmentAccess)
{
if (this.IsPublic || !object.ReferenceEquals(this.Owner, context.Activity))
{
throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.VariableOnlyAccessibleAtScopeOfDeclaration(context.Activity, this.Owner)));
}
if (!context.Environment.TryGetLocation(base.Id, out location))
{
throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.VariableDoesNotExist(this.Name)));
}
return location;
}
if (!context.Environment.TryGetLocation(base.Id, this.Owner, out location))
{
throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.VariableDoesNotExist(this.Name)));
}
return location;
}
示例2: UserIsApproved
private bool UserIsApproved(ActivityContext context) {
// checking if user is in an accepted role
var workContext = _workContextAccessor.GetContext();
var user = workContext.CurrentUser;
if (user == null) return false;
return user.As<UserPart>().RegistrationStatus == UserStatus.Approved;
}
示例3: 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");
}
示例4: 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");
}
示例5: OnActivityExecuted
public override void OnActivityExecuted(WorkflowContext workflowContext, ActivityContext activityContext) {
// for blocking activities only
if (!activityContext.Activity.IsEvent) {
return;
}
// activity records pointing to the executed activity
var inboundActivities = workflowContext.GetInboundTransitions(activityContext.Record);
// if a direct target of a Branch Activity is executed, then suppress all other direct waiting activities
var parentBranchActivities = inboundActivities
.Where(x => x.SourceActivityRecord.Name == this.Name)
.Select(x => x.SourceActivityRecord)
.ToList();
if (parentBranchActivities.Any()) {
foreach (var parentBranch in parentBranchActivities) {
// remove all other waiting activities after the parent branch
var siblings = workflowContext.GetOutboundTransitions(parentBranch).Select(x => x.DestinationActivityRecord).ToList();
var awaitings = workflowContext.Record.AwaitingActivities.Where(x => siblings.Contains(x.ActivityRecord));
foreach (var awaiting in awaitings) {
workflowContext.Record.AwaitingActivities.Remove(awaiting);
}
}
}
}
示例6: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
if (UserIsApproved(activityContext)) {
yield return T("Yes");
}
yield return T("No");
}
示例7: 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;
}
}
示例8: Execute
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
{
var user = workflowContext.Content.As<IUserRoles>();
// if the current workflow subject is not a user, use current user
if (user == null) {
user = _workContextAccessor.GetContext().CurrentUser.As<IUserRoles>();
}
var roles = GetRoles(activityContext);
if (user != null) {
foreach (var role in roles) {
if (!user.Roles.Contains(role)) {
var roleRecord = _roleService.GetRoleByName(role);
if (roleRecord != null) {
_repository.Create(new UserRolesPartRecord {UserId = user.Id, Role = roleRecord});
}
else {
Logger.Debug("Role not found: {0}", role);
}
}
}
}
yield return T("Done");
}
示例9: 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;
}
}
示例10: 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");
}
}
示例11: GetPossibleOutcomes
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
return new[] {
T("InvalidUserNameOrEmail"),
T("InvalidPassword"),
T("UserNameOrEmailNotUnique"),
T("Done")
};
}
示例12: Get
public object Get(ActivityContext context)
{
if (context == null)
{
throw FxTrace.Exception.ArgumentNull("context");
}
return context.GetValue<object>((LocationReference) this);
}
示例13: 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();
}
示例14: 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");
}
示例15: 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") };
}