Example #1
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);
        }
Example #2
0
        internal Linter(WorkflowManager workflowManager, Configuration.Config configuration)
        {
            this.WorkflowManager = workflowManager;
            this.configuration   = configuration;

            //infer intents
            this.lefts = (from e in this.WorkflowManager.WorkFlow.Equations
                          where e.First != null
                          select e.First.Id).ToList();

            this.rights = (from e in this.WorkflowManager.WorkFlow.Equations
                           where null != e.Second
                           select e.Second.Id).ToList();

            this.roots = (from e in this.WorkflowManager.WorkFlow.Equations
                          where !lefts.Contains(e.Id) && !rights.Contains(e.Id) &&
                          e.Id != ConventionHelper.TrueEquation(this.configuration.Convention)
                          select e.Id).ToList();



            this.ExtractContextRules();
        }
Example #3
0
        //this needs to
        // * ensure reaction rule is an equation
        // * ensure that any evaluators exist in the evaluators list
        private string LoadLogic(WorkDefine.Workflow workFlow, string equationId)
        {
            StepTraceNode <LintTrace> root = this.tracer.Root;


            //load conventions

            LogicDefine.Evaluator trueDef = workFlow.Evaluators.FirstOrDefault(z => z.Id == ConventionHelper.TrueEvaluator(this.config.Convention));
            if (null == trueDef)
            {
                trueDef = new LogicDefine.Evaluator()
                {
                    Id = ConventionHelper.TrueEvaluator(this.config.Convention), Description = "Always True"
                };
                workFlow.Evaluators.Add(trueDef);
            }
            LogicDefine.Equation trueEqDef = workFlow.Equations.FirstOrDefault(z => z.Id == ConventionHelper.TrueEquation(this.config.Convention));
            if (null == trueEqDef)
            {
                trueEqDef = new LogicDefine.Equation()
                {
                    Condition = Logic.Operand.Or, First = trueDef.Id, Second = trueDef.Id, Id = ConventionHelper.TrueEquation(this.config.Convention)
                };
                workFlow.Equations.Add(trueEqDef);
            }



            //Lint.... make sure we have everything we need first.
            Action <LogicDefine.Rule, StepTraceNode <LintTrace>, bool> LoadRule = null;

            LoadRule = (rule, parentStep, isRoot) =>
            {
                StepTraceNode <LintTrace> step = this.tracer.TraceNext(parentStep, new LintTrace(LintStatusOptions.Inspecting, "Inspecting Rule", rule.Id));

                //if id is an equation, we are creating an expression
                LogicDefine.Equation eq = workFlow.Equations.FirstOrDefault(g => g.Id.Equals(rule.Id));
                if (null != eq)
                {
                    if (null != eq.First)
                    {
                        LoadRule(eq.First, step, false);
                    }
                    else
                    {
                        eq.First = new LogicDefine.Rule()
                        {
                            Id = ConventionHelper.TrueEvaluator(this.config.Convention), Context = string.Empty, TrueCondition = true
                        };
                    }

                    if (null != eq.Second)
                    {
                        LoadRule(eq.Second.Id, step, false);
                    }
                    else
                    {
                        eq.Second = new LogicDefine.Rule()
                        {
                            Id = ConventionHelper.TrueEvaluator(this.config.Convention), Context = string.Empty, TrueCondition = true
                        };
                    }

                    if (!rule.TrueCondition)
                    {
                        //create a negation equation.
                        string           negationId = ConventionHelper.NegateEquationName(rule.Id, this.config.Convention);
                        LogicDefine.Rule negated    = (LogicDefine.Rule)rule.Clone();
                        //negated.TrueCondition = false;

                        if (workFlow.Equations.Count(g => g.Id == negationId) == 0)
                        {
                            this.tracer.TraceNext(parentStep, new LintTrace(LintStatusOptions.InferringEquation, string.Format("Inferring negation equation from {0}", rule.Id), negationId));
                            LogicDefine.Equation toAdd = new LogicDefine.Equation()
                            {
                                First     = negated,
                                Id        = negationId,
                                Condition = Logic.Operand.And,
                                Second    = ConventionHelper.TrueEvaluator(this.config.Convention)
                            };
                            workFlow.Equations.Add(toAdd);

                            rule.TrueCondition = true;
                            rule.Id            = negationId;
                        }
                    }
                }
                else
                {
                    //if reaction ruleid is not an equation, create an equation and update reaction

                    LogicDefine.Evaluator ev = workFlow.Evaluators.FirstOrDefault(g => g.Id.Equals(rule.Id));

                    if (null == ev)
                    {
                        this.tracer.TraceNext(parentStep, new LintTrace(LintStatusOptions.LazyDefinition, "No definition found for evaluator", rule.Id));
                        ev = new LogicDefine.Evaluator()
                        {
                            Id          = rule.Id,
                            Description = string.Empty
                        };

                        workFlow.Evaluators.Add(ev);
                    }

                    //if this is the rule referenced by the reaction, then create an equation also,
                    //and  update the equation.  This isn't necessary, but consistent.
                    if (isRoot)
                    {
                        LogicDefine.Rule cloned    = (LogicDefine.Rule)rule.Clone();
                        string           newId     = string.Empty;
                        Logic.Operand    condition = Logic.Operand.And;
                        if (rule.Id == ConventionHelper.TrueEquation(this.config.Convention))
                        {
                            newId     = ConventionHelper.TrueEquation(this.config.Convention);
                            condition = Logic.Operand.Or;
                        }
                        else
                        {
                            newId = ConventionHelper.ChangePrefix(NamePrefixOptions.Evaluator, NamePrefixOptions.Equation, rule.Id, this.config.Convention);
                        }

                        if (!rule.TrueCondition)
                        {
                            newId = ConventionHelper.NegateEquationName(newId, this.config.Convention);
                        }
                        if (workFlow.Equations.Count(g => g.Id == newId) == 0)
                        {
                            this.tracer.TraceNext(parentStep, new LintTrace(LintStatusOptions.InferringEquation, string.Format("Inferring equation from {0}", rule.Id), newId));
                            workFlow.Equations.Add(new LogicDefine.Equation()
                            {
                                Condition = condition,
                                First     = cloned,
                                Second    = ConventionHelper.TrueEvaluator(this.config.Convention),
                                Id        = newId
                            });
                        }
                        rule.Id = newId;
                    }
                }
            };



            LogicDefine.Rule eqRule = equationId;
            LoadRule(eqRule, root, true);

            return(eqRule.Id);
        }
Example #4
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);
        }