Esempio n. 1
0
        IFluentActivityBuilder <T> IFluentActivityBuilder <T> .Chain(IWorkflowBuilder <T> builder)
        {
            WorkDefine.Activity parent = default(WorkDefine.Activity);
            //get the parent, add this as a reaction

            parent = this.activityStack.Peek();

            string workflowId     = builder.GetBuilder().Workflow.Id;
            string origWorkflowId = workflowId;

            if (this.chained.ContainsKey(workflowId))
            {
                workflowId = workflowId + (this.chained.Count() + 1).ToString();
            }

            this.chained.Add(workflowId, builder);

            string actionId = $"chain{workflowId}";

            this.Do(a => a.Do(new ChainFlowAction <T>(actionId, builder)), () => new ActionDefinition()
            {
                Id = actionId, Description = $"Chain.{origWorkflowId}"
            });

            parent.Reactions.Add(new WorkDefine.Reaction()
            {
                Work = this.created.ToString()
            });

            return(this);
        }
Esempio n. 2
0
 public virtual void AddActivity(WorkDefine.Activity toAdd)
 {
     WorkDefine.Activity match = this.GetActivity(toAdd.Id);
     if (match == null)
     {
         this.WorkFlow.Activities.Add(toAdd);
     }
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        IFluentActivityBuilder <T> IFluentElseActivityBuilder <T> .Else(Action <IFluentActivityBuilder <T> > Then)
        {
            WorkDefine.Activity parent = this.activityStack.Peek();

            int subCount = this.subActivities[parent.Id];

            subCount++;
            this.subActivities[parent.Id] = subCount;

            var lastReaction = parent.Reactions.Last();

            LogicDefine.Rule equationAsRule = lastReaction.Logic;

            string activityId = string.Format("{0}{1}rx{2}", parent.Id, this.config.Convention.Delimeter, subCount);

            WorkDefine.Activity toBuild = new WorkDefine.Activity()
            {
                Id        = activityId,
                Reactions = new List <WorkDefine.Reaction>()
                {
                }
            };



            this.subActivities.Add(activityId, 0);
            activityStack.Push(toBuild);
            this.workflowManager.AddActivity(toBuild);


            //negate
            equationAsRule.TrueCondition = !equationAsRule.TrueCondition;

            string equationId = equationAsRule.ShortHand;

            Then(this);



            parent.Reactions.Add(new WorkDefine.Reaction()
            {
                Logic = equationId, Work = toBuild.Id
            });

            this.activityStack.Pop();

            return(this);
        }
Esempio n. 5
0
        IFluentActivityBuilder <T> IFluentActivityBuilder <T> .Do(Action <IActionBuilder <T> > builder)
        {
            WorkDefine.Activity parent = default(WorkDefine.Activity);
            //get the parent, add this as a reaction

            parent = this.activityStack.Peek();


            this.Do(builder);
            parent.Reactions.Add(new WorkDefine.Reaction()
            {
                Work = this.created.ToString()
            });

            return(this);
        }
Esempio n. 6
0
        IFluentElseActivityBuilder <T> IFluentActivityBuilder <T> .IfThenDo(Action <IFluentExpressionBuilder <T> > If, Action <IFluentActivityBuilder <T> > Then)
        {
            WorkDefine.Activity parent = this.activityStack.Peek();

            int subCount = this.subActivities[parent.Id];

            subCount++;
            this.subActivities[parent.Id] = subCount;

            string activityId = string.Format("{0}{1}rx{2}", parent.Id, this.config.Convention.Delimeter, subCount);

            WorkDefine.Activity toBuild = new WorkDefine.Activity()
            {
                Id        = activityId,
                Reactions = new List <WorkDefine.Reaction>()
                {
                }
            };



            this.subActivities.Add(activityId, 0);
            activityStack.Push(toBuild);
            this.workflowManager.AddActivity(toBuild);

            If(this);

            var eq = this.epxressionStack.Pop();


            LastEquation = eq;
            string logicId = eq.ShortHand;

            Then(this);



            parent.Reactions.Add(new WorkDefine.Reaction()
            {
                Logic = logicId, Work = toBuild.Id
            });

            this.activityStack.Pop();

            return(this);
        }
Esempio n. 7
0
        private void Build()
        {
            string workflowId = ConventionHelper.EnsureConvention(NamePrefixOptions.Activity, this.workflowManager.WorkFlow.Id, this.config.Convention);

            workflowId = workflowId + this.config.Convention.Delimeter + "Main";

            WorkDefine.Activity parent = new WorkDefine.Activity()
            {
                Id        = workflowId,
                Reactions = new List <WorkDefine.Reaction>()
                {
                }
            };
            this.activityStack.Push(parent);
            this.workflowManager.AddActivity(parent);
            this.subActivities.Add(parent.Id, 0);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 public Activity(Engine <TModel> engineRef, Define.Activity activityDefinition)
 {
     this.engineRef          = engineRef;
     this.activityDefinition = activityDefinition;
 }
Esempio n. 11
0
 public virtual WorkDefine.Activity GetActivity(string id)
 {
     WorkDefine.Activity definition = this.WorkFlow.Activities.FirstOrDefault(a => a.Id == id);
     return(definition);
 }