コード例 #1
0
 public WorkflowValidationException(long _workflowRunId, Workflow wf, WfActivity activity, IEnumerable <string> messages)
     : base("")
 {
     ValidationMessages = messages.ToList();
     Workflow           = wf;
     Activity           = activity;
 }
コード例 #2
0
        /// <summary>
        /// Create a transition between the given activity instances for the provided exit point
        /// </summary>
        public static void AddTransition(Workflow wf, WfActivity from, WfActivity to, ExitPoint exitPoint)
        {
            // remove any existing
            var toRemove = from.ForwardTransitions.FirstOrDefault(t => t.FromExitPoint.Id == exitPoint.Id);

            if (toRemove != null)
            {
                from.ForwardTransitions.Remove(toRemove);

                var asTerm = toRemove.As <Termination>();
                if (asTerm != null)
                {
                    wf.Terminations.Remove(asTerm);
                }

                var asTrans = toRemove.As <Transition>();
                if (asTrans != null)
                {
                    wf.Transitions.Remove(asTrans);
                }

                toRemove.Delete();
            }

            var trans = new Transition()
            {
                Name = exitPoint.Name, FromActivity = @from, ToActivity = to, FromExitPoint = exitPoint
            };

            from.ForwardTransitions.Add(trans.As <TransitionStart>());
            wf.Transitions.Add(trans);
        }
コード例 #3
0
        /// <summary>
        /// The default exit point for an activity
        /// </summary>
        public static ExitPoint GetDefaultExitPoint(this WfActivity activity)
        {
            ExitPoint result = null;

            var ioe = activity.As <EntityWithArgsAndExits>();

            if (ioe != null)
            {
                result = ioe.ExitPoints.FirstOrDefault(ep => ep.IsDefaultExitPoint ?? false);
            }

            if (result == null)
            {
                var aType = activity.IsOfType.FirstOrDefault(t => t.Is <ActivityType>());

                if (aType != null)
                {
                    result = aType.Cast <ActivityType>().ExitPoints.FirstOrDefault(ep => ep.IsDefaultExitPoint ?? false);
                }
            }

            if (result == null)
            {
                throw new ApplicationException(string.Format("Unable to find the default exit point for {0}({1})", activity.Name ?? "[Unnamed]", activity.Id));
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Generate a parameter name that is unique to the workflow. Use the argument name if possible, otherwise append a number.
        /// </summary>
        private static string GeneratetUniqueNameForExpressionParameter(Workflow wf, WfActivity activity, ActivityArgument argument)
        {
            if (argument.Name == null)
            {
                throw new ArgumentException("Argument missing name");
            }

            var composedName = activity.Is <Workflow>()
                                   ? argument.Name
                                   : string.Format("{0}_{1}", (activity.Name ?? string.Empty), argument.Name);


            if (!wf.ExpressionParameters.Any(expPar => expPar.Name == composedName))
            {
                return(composedName);
            }

            var    count = 0;
            string proposedName;

            do
            {
                count++;
                proposedName = String.Format("{0}{1}", composedName, count);
            }while (wf.ExpressionParameters.Any(expPar => expPar.Name == proposedName));

            return(proposedName);
        }
コード例 #5
0
        public static Workflow AddUpdateExpressionToArgument(this Workflow wf, WfActivity activity, ActivityArgument arg, string expressionString, bool isTemplate)
        {
            if (isTemplate)
            {
                expressionString = ConvertTemplateToExpressionString(expressionString);
            }

            if (expressionString == null)
            {
                throw new ArgumentNullException("expressionString");
            }

            var exp = activity.ExpressionMap.FirstOrDefault(x => x.ArgumentToPopulate?.Id == arg.Id);

            if (exp == null)
            {
                var newExp = new WfExpression()
                {
                    ExpressionString     = expressionString,
                    ArgumentToPopulate   = arg,
                    ExpressionInActivity = activity,
                    IsTemplateString     = false
                };

                activity.ExpressionMap.Add(newExp.As <WfExpression>());
            }
            else
            {
                var wrExp = exp.AsWritable <WfExpression>();
                wrExp.ExpressionString = expressionString;
                wrExp.Save();
            }

            return(wf);
        }
コード例 #6
0
        /// <summary>
        /// Create a transition between the given activity instances for the named exit point
        /// </summary>
        public static void AddTermination(Workflow wf, WfActivity from, string fromExitPointName = null, string wfExitPointName = null)
        {
            ExitPoint fromExitPoint = fromExitPointName == null? @from.GetDefaultExitPoint() : GetNamedExitPoint(@from, fromExitPointName);

            ExitPoint wfExitPoint = null;

            if (wfExitPointName == null)
            {
                wfExitPoint = wf.GetDefaultExitPoint();

                if (wfExitPoint == null)
                {
                    wf.AddDefaultExitPoint();
                    wfExitPoint = wf.GetDefaultExitPoint();
                }
            }
            else
            {
                wfExitPoint = GetNamedExitPoint(wf.As <WfActivity>(), wfExitPointName);
            }

            if (fromExitPoint == null)
            {
                throw new ArgumentException("From activity missing named exit point.");
            }

            if (wfExitPoint == null)
            {
                throw new ArgumentException("Workflow missing named exit point.");
            }

            AddTermination(wf, @from, fromExitPoint, wfExitPoint);
        }
コード例 #7
0
        public static Workflow AddUpdateEntityExpression(this Workflow wf, WfActivity activity, ActivityArgument arg, EntityRef entityRef)
        {
            var exp = activity.ExpressionMap.FirstOrDefault(x => x.ArgumentToPopulate?.Id == arg.Id);
            var r   = Entity.Get(entityRef).As <Resource>();

            var expName = r.Id.ToString();

            if (!string.IsNullOrEmpty(r.Name))
            {
                expName = r.Name;
            }

            if (exp == null)
            {
                exp = new WfExpression {
                    ArgumentToPopulate = arg, ExpressionInActivity = activity, ExpressionString = string.Format("[{0}]", expName)
                };
                exp.WfExpressionKnownEntities.Add(new NamedReference {
                    Name = expName, ReferencedEntity = r
                });
                activity.ExpressionMap.Add(exp);
            }
            else
            {
                var wrExp = exp.AsWritable <WfExpression>();
                wrExp.ExpressionString = string.Format("[{0}]", expName);
                wrExp.WfExpressionKnownEntities.Clear();
                wrExp.WfExpressionKnownEntities.Add(new NamedReference {
                    Name = expName, ReferencedEntity = r
                });
                wrExp.Save();
            }

            return(wf);
        }
コード例 #8
0
        void MarkRunSuspended(IRunState runState, WfActivity currentActivity)
        {
            Debug.Assert(currentActivity != null);

            using (new SecurityBypassContext())
            {
                runState.PendingActivity = currentActivity;
                runState.RunStatus       = WorkflowRunState_Enumeration.WorkflowRunSuspended;
            }
        }
コード例 #9
0
        public static Workflow AddEntityExpressionToInputArgument(this Workflow wf, WfActivity activity, string argumentName, EntityRef entityRef)
        {
            var destination = activity.GetInputArgument(argumentName);

            if (destination == null)
            {
                throw new ArgumentException();
            }

            return(AddEntityExpression(wf, activity, destination, entityRef));
        }
コード例 #10
0
        public static Workflow AddUpdateExpressionToArgument(this Workflow wf, WfActivity activity, string argumentName, string expressionString, bool isTemplate = false)
        {
            var destination = activity.GetInputArgument(argumentName);

            if (destination == null)
            {
                throw new ArgumentException();
            }

            return(AddUpdateExpressionToArgument(wf, activity, destination, expressionString, isTemplate));
        }
コード例 #11
0
        public static Workflow AddExpressionToActivityArgument(this Workflow wf, WfActivity activity, string argumentName, string expressionString, bool isTemplate = false)
        {
            var destination = activity.GetInputArgument(argumentName);

            if (destination == null)
            {
                throw new ArgumentException(String.Format("No matching argument name for activity. Activity='{0}' Argument='{1}'", activity.Name ?? "<unnamed>", argumentName ?? "<unnamed>"));
            }

            return(AddExpressionToArgument(wf, activity, destination, expressionString, isTemplate));
        }
コード例 #12
0
        private async Task GetRoleUsers(List <WfActivitySelectModel> model, WfActivity act)
        {
            var users = await UserRoleSvc.GetUserListByRoleIds(act.roleIds);

            if (users != null && users.Count > 0)
            {
                model.Add(new WfActivitySelectModel()
                {
                    Activity = act,
                    UserList = users
                });
            }
        }
コード例 #13
0
        /// <summary>
        /// Run the next step in the workflow by scheduling the activity. This call in turn will schedule other activities.
        /// </summary>
        private void ScheduleNextStep(IRunState context, WfActivity childActivity)
        {
            var nextWindowsActivity = context.Metadata.CachedInstances[childActivity.Id];

            // ensure all child's input expressions are updated
            var inputExpressions = nextWindowsActivity.GetInputArgumentsExpressions(context, childActivity);

            var resolvedExpressions = ResolveExpressions(context, inputExpressions);

            var inputs = CreateInputDictionaryForNextStep(context, childActivity, resolvedExpressions);

            context.WorkflowInvoker.ScheduleActivity(context, nextWindowsActivity, inputs, NextStepCompletionCallback, NextStepPausedCallback);
        }
コード例 #14
0
        ///// <summary>
        ///// Update all the output arguments
        ///// </summary>
        //void UpdateWfOutputs(IRunState context, Dictionary<WfExpression, object> resolvedExpressions)
        //{
        //    UpdateWorkflowArguments(context, resolvedExpressions);
        //}

        /// <summary>
        /// Create an input dictionary using the applicable values in the ArgumentValueStore
        /// </summary>
        ActivityInputs CreateInputDictionaryForNextStep(IRunState context, WfActivity nextActivity, Dictionary <WfExpression, object> evaluatedExpressions)
        {
            var result = new ActivityInputs();

            // add expressions
            foreach (var kvp in evaluatedExpressions)
            {
                var arg = kvp.Key.ArgumentToPopulate;
                result.Add(arg, kvp.Value);
            }

            return(result);
        }
コード例 #15
0
        public Transition GetTransitionForExitPoint(WfActivity activity, EntityRef exitPointRef)
        {
            Transition result;

            if (_transitionCache.TryGetValue(new Tuple <long, long>(activity.Id, exitPointRef.Id), out result))
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
コード例 #16
0
        public static Workflow AddEntityExpression(this Workflow wf, WfActivity activity, ActivityArgument arg, EntityRef entityRef)
        {
            var r   = Entity.Get(entityRef).As <Resource>();
            var exp = new WfExpression {
                ArgumentToPopulate = arg, ExpressionInActivity = activity, ExpressionString = string.Format("[{0}]", r.Id.ToString())
            };

            exp.WfExpressionKnownEntities.Add(new NamedReference {
                Name = r.Id.ToString(), ReferencedEntity = r
            });
            activity.ExpressionMap.Add(exp);

            return(wf);
        }
コード例 #17
0
ファイル: WorkflowSvc.cs プロジェクト: RaulSteven/Hei10Stock
 private WfActivityInstance CreateActivityInstance(WfProcess process,
                                                   WfProcessInstance processInstance,
                                                   WfActivity activity,
                                                   WfActivityState state,
                                                   long assignToUserId,
                                                   string assignToUserName)
 {
     return(CreateActivityInstance(process,
                                   processInstance,
                                   activity,
                                   state,
                                   $"[{assignToUserId}]",
                                   assignToUserName));
 }
コード例 #18
0
        /// <summary>
        /// Create a windows activity instance for the given model activity
        /// </summary>
        /// <param name="nextActivity"></param>
        /// <param name="workflowRunId">The ID of the workflow run to record information against. 0 indicates there is no run.</param>
        /// <returns></returns>
        public static ActivityImplementationBase CreateWindowsActivity(this WfActivity nextActivity)
        {
            if ((nextActivity as IEntityInternal).IsTemporaryId)
            {
                throw new ArgumentException(string.Format("The activity '{0}':{1} has not been saved. All activities must be saved before being used.", nextActivity.Name, nextActivity.Id));
            }


            var result = ActivityHelper.GetBackingClassInstanceForWfActivity(nextActivity);

            result.Initialize(nextActivity);

            return(result);
        }
コード例 #19
0
        public WfExpression GetPopulatedBy(WfActivity activity, ActivityArgument argument)
        {
            WfExpression result;
            var          key = new Tuple <long, long>(activity.Id, argument.Id);

            if (_populatedByCache.TryGetValue(key, out result))
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
コード例 #20
0
        /// <summary>
        /// Create a transition between the given activity instances for the provided exit point
        /// </summary>
        public static void AddTransition(Workflow wf, WfActivity from, WfActivity to, string exitPointName)
        {
            var exitPoint = GetNamedExitPoint(@from, exitPointName);

            if (exitPoint == null)
            {
                throw new ArgumentException(String.Format("Attempted to create a transition from a non-existent exit point. '{0}'", exitPointName));
            }

            var trans = new Transition()
            {
                Name = exitPointName, FromActivity = @from, ToActivity = to, FromExitPoint = exitPoint
            };

            wf.Transitions.Add(trans);
        }
コード例 #21
0
ファイル: RunState.cs プロジェクト: hardin253874/Platform
        public WfArgumentInstance GetArgInstance(ActivityArgument targetArg, WfActivity activity)
        {
            WfArgumentInstance targetArgInst = null;
            var key = new Tuple <long, long>(activity.Id, targetArg.Id);

            if (_argInstCache.TryGetValue(key, out targetArgInst))
            {
                return(targetArgInst);
            }

            targetArgInst = targetArg.GetArgInstance(activity);

            _argInstCache.Add(key, targetArgInst);

            return(targetArgInst);
        }
コード例 #22
0
        /// <summary>
        /// Add an expression parameter, return the parameters substitution name
        /// </summary>
        /// <param name="wf"></param>
        /// <param name="from"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public static string CreateArgumentInstance(Workflow wf, WfActivity from, ActivityArgument argument)
        {
            var uniqueName     = GeneratetUniqueNameForExpressionParameter(wf, from, argument);
            var sourceInstance = new WfArgumentInstance {
                Name = uniqueName, ArgumentInstanceActivity = @from, ArgumentInstanceArgument = argument
            };

            if (@from.IsReadOnly)
            {
                @from = @from.AsWritable <WfActivity>();
            }
            @from.ArgumentInstanceFromActivity.Add(sourceInstance);
            wf.ExpressionParameters.Add(sourceInstance);

            return(uniqueName);
        }
コード例 #23
0
        public static IEnumerable <ActivityArgument> GetInputArguments(this WfActivity activity)
        {
            // for a workflow the input arguments are on the instance, for an activity they are on the type
            var typeArguments = activity.IsOfType.Select(t => t.As <ActivityType>()).First(t => t != null).InputArguments;

            var entityWithArgsAndExits = activity.As <EntityWithArgsAndExits>();

            if (entityWithArgsAndExits != null)
            {
                return(entityWithArgsAndExits.InputArguments.Union(typeArguments));
            }
            else
            {
                return(typeArguments); // note that his code assumes the first type is an activity type
            }
        }
コード例 #24
0
        public static void AddFirstActivityWithMapping(Workflow workflow, WfActivity firstActivity, IDictionary <string, string> newArgumentMappings)
        {
            workflow.FirstActivity = firstActivity;
            workflow.ContainedActivities.Add(firstActivity);

            if (newArgumentMappings != null)
            {
                foreach (var entry in newArgumentMappings)
                {
                    var source = workflow.As <WfActivity>().GetInputArgument(entry.Key);

                    var subName = CreateArgumentInstance(workflow, firstActivity, source);

                    AddExpressionToActivityArgument(workflow, firstActivity, entry.Value, String.Format("[{0}]", subName), false);
                }
            }
        }
コード例 #25
0
        public static IEnumerable <ActivityArgument> GetOutputArguments(this WfActivity activity)
        {
            IEnumerable <ActivityArgument> result;
            // get the type defined arguments
            var type = activity.IsOfType.Select(t => t.As <ActivityType>()).First(t => t != null);

            result = type.OutputArguments;

            // get the instance defined arguments
            var entityWithArgsAndExits = activity.As <EntityWithArgsAndExits>();

            if (entityWithArgsAndExits != null)
            {
                result = result.Union(entityWithArgsAndExits.OutputArguments);
            }

            return(result);
        }
コード例 #26
0
        /// <summary>
        /// Create a transition between the given activity instances for the provided exit point and field mappings
        /// </summary>
        public static void AddTransitionWithMapping(Workflow wf, WfActivity from, WfActivity to, ExitPoint exitPoint, IDictionary <string, string> argumentMappings)
        {
            var trans = new Transition()
            {
                FromActivity = @from, ToActivity = to, FromExitPoint = exitPoint
            };

            wf.Transitions.Add(trans);

            if (argumentMappings != null)
            {
                foreach (var entry in argumentMappings)
                {
                    //AddExpressionToActivityArgument(wf, to, entry.Value, entry.Key);
                    AddExpressionToMapArguments(wf, @from, to, entry.Key, entry.Value);
                }
            }
        }
コード例 #27
0
        public static void SetActivityArgumentToResource(Workflow wf, WfActivity activity, string argumentName, Resource resource)
        {
            var arg = activity.GetInputArgument(argumentName);

            if (arg == null)
            {
                throw new ArgumentException(String.Format("No matching argument name for activity. Activity='{0}' Argument='{1}'", activity.Name ?? "<unnamed>", argumentName ?? "<unnamed>"));
            }

            var exp = new WfExpression {
                ArgumentToPopulate = arg, ExpressionInActivity = activity, ExpressionString = null
            };

            exp.WfExpressionKnownEntities.Add(new NamedReference()
            {
                Name = "E1", ReferencedEntity = resource
            });
            activity.ExpressionMap.Add(exp);  // BUG: needed to work around an issue saving relationships
        }
コード例 #28
0
        public static ExitPoint GetNamedExitPoint(this WfActivity activity, string name)
        {
            ExitPoint result = null;

            var actAsDyn = activity.As <EntityWithArgsAndExits>();

            if (actAsDyn != null)
            {
                result = actAsDyn.ExitPoints.FirstOrDefault(ep => ep.Name == name);
            }

            if (result != null)
            {
                return(result);
            }
            else
            {
                return(activity.IsOfType.Select(t => t.As <EntityWithArgsAndExits>()).First(t => t != null).ExitPoints.FirstOrDefault(ep => ep.Name == name));
            }
        }
コード例 #29
0
        ///// <summary>
        ///// The default time before an activity timeouts
        ///// </summary>
        //public static TimeSpan DefaultActivityTimeout { get { return new TimeSpan(0, 1, 0); } } //TODO: move into system configuration

        ///// <summary>
        ///// The default number of times a workflow will execute directly contained activities.
        ///// </summary>
        //public static int DefaultWorkflowMaxActivityExecutes { get { return 1000; } } //TODO: move into system configuration


        /// <summary>
        /// The default exit point for an activity
        /// </summary>
        public static IEnumerable <ExitPoint> GetExitPoints(this WfActivity activity)
        {
            IEnumerable <ExitPoint> result = new List <ExitPoint>();

            var ioe = activity.As <EntityWithArgsAndExits>();

            if (ioe != null)
            {
                result = ioe.ExitPoints.ToList();
            }

            var aType = activity.IsOfType.FirstOrDefault(t => t.Is <ActivityType>());

            if (aType != null)
            {
                result = result.Union(aType.Cast <ActivityType>().ExitPoints.ToList());
            }

            return(result);
        }
コード例 #30
0
ファイル: WorkflowSvc.cs プロジェクト: RaulSteven/Hei10Stock
 /// <summary>
 /// 创建节点实例
 /// </summary>
 /// <param name="process"></param>
 /// <param name="processInstance"></param>
 /// <param name="activity"></param>
 /// <returns></returns>
 private WfActivityInstance CreateActivityInstance(WfProcess process,
                                                   WfProcessInstance processInstance,
                                                   WfActivity activity,
                                                   WfActivityState state,
                                                   string assignToUserId,
                                                   string assignToUserName)
 {
     return(new WfActivityInstance()
     {
         ActivityGuid = activity.key,
         ActivityName = activity.text,
         ActivityState = state,
         ActivityType = activity.activityType,
         CommonStatus = CommonStatus.Enabled,
         ProcessId = process.Id,
         ProcessInstanceId = processInstance.Id,
         ProcessName = process.Name,
         AssignToUserIds = assignToUserId,
         AssignToUserNames = assignToUserName
     });
 }