Exemple #1
0
 private void Do(WorkDefine.ActionRef ToDo)
 {
     ToDo.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, ToDo.Id, this.config.Convention);
     this.workflowManager.AddAction(new WorkDefine.ActionDefinition()
     {
         Id = ToDo.Id, Description = "Builder"
     });
     this.created = ToDo;
 }
Exemple #2
0
        private void LoadActivity(WorkDefine.Workflow workFlow, string activityId)
        {
            WorkDefine.Activity definition = workFlow.Activities.FirstOrDefault(a => a.Id == activityId);


            Action <WorkDefine.Activity, bool> LoadReactions = null;

            LoadReactions = (d, isroot) =>
            {
                if (d.Reactions != null && d.Reactions.Count > 0)
                {
                    d.Reactions.ForEach(r =>
                    {
                        WorkDefine.Activity toCreatedef = workFlow.Activities.FirstOrDefault(z => z.Id == r.Work);

                        if (null == toCreatedef)
                        {
                            //if we can't find activity... look for a matching action.  if found, create an activity from it.
                            WorkDefine.ActionRef asActionRef           = r.Work;
                            WorkDefine.ActionDefinition toCreateAction = workFlow.Actions.FirstOrDefault(z => z.Id == asActionRef.Id);

                            //didn't bother to add the action definition, we will create it for them
                            if (null == toCreateAction)
                            {
                                workFlow.Actions.Add(new WorkDefine.ActionDefinition()
                                {
                                    Id          = asActionRef.Id,
                                    Description = ""
                                });
                            }


                            toCreatedef = new WorkDefine.Activity()
                            {
                                //Action = asActionRef,
                                Id        = Guid.NewGuid().ToString(),
                                Reactions = new List <WorkDefine.Reaction>()
                            };
                        }

                        if (string.IsNullOrEmpty(r.Logic))
                        {
                            r.Logic = ConventionHelper.TrueEquation(this.config.Convention);
                        }

                        r.Logic = LoadLogic(workFlow, r.Logic);


                        LoadReactions(toCreatedef, false);
                    });
                }
            };

            LoadReactions(definition, true);
        }
Exemple #3
0
        void IActionBuilder <T> .Do(IAction <T> action)
        {
            this.action = action;

            string typeName = action.GetType().Name;

            this.actionRef = new WorkDefine.ActionRef()
            {
                Id = typeName
            };
        }
Exemple #4
0
        private void  Do(Action <IActionBuilder <T> > builder, Func <WorkDefine.ActionDefinition> overrideName = null)
        {
            ActionBuilder <T> builderRef = new ActionBuilder <T>(this);

            builder.Invoke(builderRef);

            WorkDefine.ActionRef        ToDo      = builderRef.actionRef;
            WorkDefine.ActionDefinition actionDef = new ActionDefinition();

            if (overrideName != null)
            {
                actionDef    = overrideName();
                actionDef.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, actionDef.Id, this.config.Convention);
                ToDo         = actionDef.Id;
            }
            else
            {
                ToDo.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, ToDo.Id, this.config.Convention);

                string actionName  = builderRef.action.GetType().Name;
                string description = ConventionHelper.ParseMethodName(actionName, this.config.Convention.ParseMethodNamesAs).Literal;

                var descAttr = builderRef.action.GetType().GetCustomAttributes(typeof(ArticulateOptionsAttribute), true)
                               .OfType <ArticulateOptionsAttribute>()
                               .FirstOrDefault();
                if (descAttr != null)
                {
                    description = descAttr.Description;
                }
                actionDef = new WorkDefine.ActionDefinition()
                {
                    Id = ToDo.Id, Description = description
                };
            }


            this.workflowManager.AddAction(actionDef);

            if (!this.actions.ContainsKey(ToDo.Id))
            {
                this.actions.Add(ToDo.Id, builderRef.action);
            }
            else
            {
                //if attmpeting to add another implementation with the same id, throw an exception
                //we can't handle this
                if ((this.actions[ToDo.Id].GetType()) != builderRef.action.GetType())
                {
                    throw new BuilderException(ToDo.Id);
                }
            }

            this.created = ToDo;
        }
Exemple #5
0
        private Activity <TModel> LoadActivity(string activityId)
        {
            WorkDefine.Activity definition = this.WorkflowManager.GetActivity(activityId);



            Activity <TModel> toReturn = new Activity <TModel>(this, definition);

            Action <Activity <TModel>, WorkDefine.Activity> LoadReactions = null;

            LoadReactions = (a, d) =>
            {
                if (d.Reactions != null && d.Reactions.Count > 0)
                {
                    d.Reactions.ForEach(r =>
                    {
                        WorkDefine.ActionRef work       = r.Work;
                        WorkDefine.Activity toCreatedef = this.WorkflowManager.GetActivity(work.Id);
                        LoadLogic(r.Logic);

                        if (null == a.Reactions)
                        {
                            a.Reactions = new List <Reaction <TModel> >();
                        }

                        if (toCreatedef != null)
                        {
                            Activity <TModel> toCreate = new Activity <TModel>(this, toCreatedef);
                            LoadReactions(toCreate, toCreatedef);
                            a.Reactions.Add(new Reaction <TModel>(r.Logic, toCreate));
                        }
                        else
                        {
                            a.Reactions.Add(new Reaction <TModel>(r.Logic, r.Work));
                        }
                    });
                }
            };

            LoadReactions(toReturn, definition);

            return(toReturn);
        }
Exemple #6
0
        void IActionBuilder <T> .DoInLine(string actionName, string description, string input, Func <IEngineScope <T>, IEngineTrace, CancellationToken, Task <bool> > actionToDo)
        {
            ContextBuilder builder = new ContextBuilder();
            Context        ctx     = default;

            //if (context != null)
            //{
            //    context.Invoke(builder);
            //    builderRef.workflowManager.AddContextDefinition(builder.builder.definition);
            //    ctx = builder.context;
            //}
            this.action = new DynamicAction <T>(new WorkDefine.ActionDefinition()
            {
                Id = actionName, Description = description ?? "Dynamic"
            }, actionToDo);
            this.actionRef = new WorkDefine.ActionRef()
            {
                Id = actionName, Input = input
            };
        }
Exemple #7
0
        public ArticulateActivity ArticulateFlow(bool removeConvention, bool verbose)
        {
            Func <WorkDefine.ActionRef, IArticulateActivity> createAction = (s) =>
            {
                var actionDef           = this.workflow.Actions.FirstOrDefault(g => g.Id == s.Id);
                ArticulateAction action = new ArticulateAction()
                {
                    Id = s.Id, Literal = actionDef.Description
                };


                if (s.Id == "*placeHolder")
                {
                    return(new NothingAction());
                }
                else
                {
                    if (s.Input != null)
                    {
                        ArticulateContext articulateContext = new ArticulateContext()
                        {
                            Literal = "Input",
                            Value   = s.Input
                        };
                        action.Context = articulateContext;
                    }

                    return(action);
                }
            };

            ArticulateActivity toReturn = new ArticulateActivity();

            string activityId = workflow.Id;

            activityId = $"{ConventionHelper.EnsureConvention(NamePrefixOptions.Activity, activityId, this.configuration.Convention)}.Main";

            WorkDefine.Activity toArticulate = this.workflow.Activities.FirstOrDefault(g => g.Id == activityId);
            toReturn.Id = toArticulate.Id;



            Func <LogicDefine.Rule, IArticulateExpression> traverseExpression = null;

            traverseExpression = (x) =>
            {
                IArticulateExpression buildExpression = null;


                if (ConventionHelper.MatchesConvention(NamePrefixOptions.Evaluator, x.Id, this.configuration.Convention))
                {
                    buildExpression = this.ArticulateEvaluator(x);
                }
                else
                {
                    ArticulateExpression toBuild = new ArticulateExpression()
                    {
                        Id = x.Id
                    };
                    LogicDefine.Equation eq = this.workflow.Equations.FirstOrDefault(g => g.Id == x.Id);
                    toBuild.Condition = (eq.Condition == Logic.Operand.And) ? "and": "or";
                    Rule asRule = x.ShortHand;
                    toBuild.TrueCondition = asRule.TrueCondition;
                    toBuild.First         = traverseExpression(eq.First);
                    toBuild.Second        = traverseExpression(eq.Second);
                    buildExpression       = toBuild;
                }


                return(buildExpression);
            };

            Action <ArticulateActivity, WorkDefine.Activity> traverseActivity = null;

            traverseActivity = (a, d) =>
            {
                if (d.Reactions != null && d.Reactions.Count() > 0)
                {
                    a.Reactions = new List <ArticulateReaction>();
                    d.Reactions.ForEach(r =>
                    {
                        //all logic at this point should be equations
                        //if logic = true, then if = "Always".
                        ArticulateReaction toAdd = new ArticulateReaction();
                        if (r.Logic == ConventionHelper.TrueEquation(this.configuration.Convention))
                        {
                            toAdd.If = new TrueExpression();
                        }
                        else
                        {
                            toAdd.If = traverseExpression(r.Logic);
                        }

                        WorkDefine.ActionRef aref = r.Work;
                        if (ConventionHelper.MatchesConvention(NamePrefixOptions.Action, aref.Id, this.configuration.Convention))
                        {
                            toAdd.Then = createAction(aref);
                        }
                        else
                        {
                            WorkDefine.Activity toTraverse = this.workflow.Activities.FirstOrDefault(g => g.Id == aref.Id);
                            ArticulateActivity Then        = new ArticulateActivity()
                            {
                                Id = aref.Id
                            };
                            traverseActivity(Then, toTraverse);
                            toAdd.Then = Then;
                        }
                        a.Reactions.Add(toAdd);
                    });
                }
            };

            traverseActivity(toReturn, toArticulate);


            return(toReturn);
        }