Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static WfArgumentInstance GetArgInstance(this ActivityArgument targetArg, WfActivity activity)
        {
            WfArgumentInstance targetArgInst = null;
            var key = new Tuple <long, long>(activity.Id, targetArg.Id);


            targetArgInst =
                activity.ArgumentInstanceFromActivity.First(ai => ai.ArgumentInstanceArgument.Id == targetArg.Id);

            //var targetArgInst =
            //    targetArg.ArgumentInstanceFromArgument.First(ai => ai.ArgumentInstanceActivity.Id == activity.Id);        // this is probably less efficient



            return(targetArgInst);
        }
Ejemplo n.º 4
0
 ExprType TypeFromInstance(WfArgumentInstance ai)
 {
     if (ai.InstanceConformsToType != null)
     {
         if (ai.ArgumentInstanceArgument.Is <ResourceArgument>())
         {
             return(ExprTypeHelper.EntityOfType(ai.InstanceConformsToType));
         }
         else
         {
             return(ExprTypeHelper.EntityListOfType(ai.InstanceConformsToType));
         }
     }
     else
     {
         return(CalcExpressionType(ai.ArgumentInstanceArgument));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a workflow with a resource input argument of the specified type.
        /// </summary>
        /// <param name="alias">The alias given to the workflow.</param>
        /// <param name="name">The name given to the workflow.</param>
        /// <param name="description">The description given to the workflow.</param>
        /// <param name="type">The type to assign to the input argument.</param>
        /// <param name="argumentName">The name given to the input argument.</param>
        /// <param name="isListArgument">Whether the input argument is a resource list argument.</param>
        /// <returns>The created workflow entity.</returns>
        public static Workflow CreateWorkflow(string alias, string name, string description, EntityType type, string argumentName, bool isListArgument = false)
        {
            var workflow = Entity.Create <Workflow>();

            workflow.Alias       = alias;
            workflow.Name        = name;
            workflow.Description = description;

            //
            // Exit
            //
            var exitPoint = Entity.Create <ExitPoint>();

            exitPoint.Name = "Exit Point";
            exitPoint.IsDefaultExitPoint = true;
            workflow.ExitPoints.Add(exitPoint);

            //
            // Input
            //
            var wfActivity = workflow.AsWritable <WfActivity>();
            ActivityArgument activityArgument;

            if (isListArgument)
            {
                var recordListArgument = Entity.Create <ResourceListArgument>();
                recordListArgument.Name           = argumentName;
                recordListArgument.ConformsToType = type;

                activityArgument = recordListArgument.As <ActivityArgument>();
            }
            else
            {
                var recordArgument = Entity.Create <ResourceArgument>();
                recordArgument.Name           = argumentName;
                recordArgument.ConformsToType = type;

                activityArgument = recordArgument.As <ActivityArgument>();
            }

            workflow.InputArguments.Add(activityArgument);

            var instance = new WfArgumentInstance {
                Name = argumentName, ArgumentInstanceActivity = wfActivity, ArgumentInstanceArgument = activityArgument
            };

            wfActivity.ArgumentInstanceFromActivity.Add(instance);
            workflow.ExpressionParameters.Add(instance);

            workflow.InputArgumentForAction = activityArgument;

            //
            // Log
            //
            var message = "'Input: ' + [" + argumentName + "].Name";

            var logActivity = Entity.Create <LogActivity>();

            logActivity.Name = "Log";

            var wfLogActivity = logActivity.As <WfActivity>();

            var logActivityType = wfLogActivity.IsOfType.Select(t => t.As <ActivityType>()).First(t => t != null);

            var logInput = logActivityType.InputArguments.FirstOrDefault(a => a.Name == "Message");

            var expression = Entity.Create <WfExpression>();

            expression.ExpressionString     = message;
            expression.ArgumentToPopulate   = logInput;
            expression.ExpressionInActivity = wfLogActivity;
            expression.IsTemplateString     = false;

            logActivity.ExpressionMap.Add(expression);

            workflow.FirstActivity = wfLogActivity;
            workflow.ContainedActivities.Add(wfLogActivity);

            var logExit = logActivityType.ExitPoints.First(e => e.IsDefaultExitPoint ?? false);

            var termination = Entity.Create <Termination>();

            termination.Name              = logExit.Name;
            termination.FromActivity      = wfLogActivity;
            termination.FromExitPoint     = logExit;
            termination.WorkflowExitPoint = exitPoint;

            wfLogActivity.ForwardTransitions.Add(termination.As <TransitionStart>());

            workflow.Terminations.Add(termination);

            return(workflow);
        }