void IRunNowActivity.OnRunNow(IRunState context, ActivityInputs inputs) { var haveStarted = GetArgumentKey("forEachHaveStarted"); var foreachList = GetArgumentKey("forEachResourceList"); var resourceListKey = GetArgumentKey("foreachList"); var selectedResourceKey = GetArgumentKey("foreachSelectedResource"); IEnumerable <IEntity> resourceList; if (!(context.GetArgValue <bool?>(ActivityInstance, haveStarted) ?? false)) { context.SetArgValue(ActivityInstance, haveStarted, true); // // it's the first time into the loop // object listObj; if (inputs.TryGetValue(resourceListKey, out listObj)) { if (listObj == null) { throw new ApplicationException("The [List] argument is null. This should never happen."); } resourceList = (IEnumerable <IEntity>)listObj; } else { throw new ApplicationException("The [List] is missing from the input arguments. This should never happen."); } } else { resourceList = context.GetArgValue <IEnumerable <IEntity> >(ActivityInstance, foreachList); } var selectedResourceRef = resourceList.FirstOrDefault(); if (selectedResourceRef != null) { context.SetArgValue(ActivityInstance, selectedResourceKey, selectedResourceRef); resourceList = resourceList.Skip(1); context.SetArgValue(ActivityInstance, foreachList, resourceList); context.ExitPointId = Entity.GetId(LoopExitPointAlias); } else { // We have finished context.SetArgValue(ActivityInstance, haveStarted, false); context.SetArgValue(ActivityInstance, foreachList, null); context.ExitPointId = Entity.GetId("core", "foreachCompletedExitPoint"); } }
public override bool OnResume(IRunState context, IWorkflowEvent resumeEvent) { if (resumeEvent is NotifyResumeFailedEvent) { throw new WorkflowRunException("Workflow failed with an internal error."); } var notification = context.GetArgValue <IEntity>(ActivityInstance, GetArgumentKey("core:outNotificationRecord")); if (notification == null) { throw new ArgumentException("notification"); } var writable = notification.AsWritable <Notification>(); if (writable.NPendingRun != null) { writable.NPendingRun = null; writable.Save(); } HandleTimeout(context, resumeEvent); return(true); // keep going }
public override bool OnResume(IRunState context, IWorkflowEvent resumeEvent) { var userTaskEntity = context.GetArgValue <IEntity>(ActivityInstance, GetArgumentKey("core:outDisplayFormUserTask")); var keepHistory = context.GetArgValue <bool>(ActivityInstance, GetArgumentKey("core:dfaInternalKeepHistory")); var userTask = userTaskEntity != null?userTaskEntity.As <DisplayFormUserTask>() : null; // We could have a combination of a deleted user task and a time-out if (!HandleTimeout(context, resumeEvent)) // handle timeout will set the exit point { HandleResumeTransition(context, (IWorkflowUserTransitionEvent)resumeEvent); if (!(userTask.HideComment ?? false)) { context.SetArgValue(ActivityInstance, GetArgumentKey("core:outTaskComment"), userTask.TaskComment); } if (keepHistory) { var writableTask = userTask.AsWritable <DisplayFormUserTask>(); writableTask.TaskStatus_Enum = TaskStatusEnum_Enumeration.TaskStatusCompleted; writableTask.Save(); } } if (userTask != null) { if (keepHistory) { if (userTask.LogEntryForUserAction != null) { UpdateLogEntry(userTask); } } else { context.SetArgValue(ActivityInstance, GetArgumentKey("core:outDisplayFormUserTask"), null); Entity.Delete(userTask); } } return(true); }
public override ICollection <WfExpression> GetInputArgumentsExpressions(IRunState runState, WfActivity activity) { var expressions = base.GetInputArgumentsExpressions(runState, activity); var haveStarted = GetArgumentKey("forEachHaveStarted"); // Only do the expression fetch if we are not in a running loop if (runState.GetArgValue <bool?>(ActivityInstance, haveStarted) ?? false) { expressions = expressions.Where(e => e.ArgumentToPopulate.Alias != "core:foreachList").ToList(); } return(expressions); }
/// <summary> /// Runs when the activity is run by the workflow. /// </summary> /// <param name="context">The run state.</param> /// <param name="inputs">The inputs.</param> public void OnRunNow(IRunState context, ActivityInputs inputs) { var startedKey = GetArgumentKey(StartedArgumentAlias); var listKey = GetArgumentKey(ListArgumentAlias); var appIdKey = GetArgumentKey(ApplicationIdArgumentAlias); var appVersionKey = GetArgumentKey(ApplicationVersionArgumentAlias); var ids = new List <Guid>(); var started = context.GetArgValue <bool?>(ActivityInstance, startedKey) ?? false; if (!started) { // set that the activity has started context.SetArgValue(ActivityInstance, startedKey, true); // retrieve the product var productSku = GetArgumentValue <string>(inputs, ProductSkuArgumentAlias); var product = MarketplaceService.GetProduct(productSku); if (product == null) { throw new WorkflowRunException("Product {0} was not found.", productSku); } // process the included apps and app versions and sort their ids ids.AddRange(GetSortedApplicationIds(product)); } else { // retrieve the current state of the ordered list from the context var list = context.GetArgValue <string>(ActivityInstance, listKey); if (!string.IsNullOrEmpty(list)) { ids.AddRange(list.Split(',').Select(Guid.Parse)); } } // loop over the next id on the list var current = ids.FirstOrDefault(); if (current != default(Guid)) { // set the application id and any specific version info on the output var variables = GetAppVariables(context, current); if (variables.Item1 != Guid.Empty) { context.SetArgValue(ActivityInstance, appIdKey, variables.Item1); context.SetArgValue(ActivityInstance, appVersionKey, variables.Item2); } // remove this id from the list and store it again ids = ids.Skip(1).ToList(); var list = string.Join(",", ids); context.SetArgValue(ActivityInstance, listKey, list); context.ExitPointId = new EntityRef(LoopExitPointAlias); } else { // we have finished context.SetArgValue(ActivityInstance, startedKey, false); context.SetArgValue(ActivityInstance, listKey, null); context.ExitPointId = new EntityRef(FinishedExitPointAlias); } }