Ejemplo n.º 1
0
        public void InferredEvaluatorAddedOnlyOnce()
        {
            WorkDefine.Workflow testWF = new WorkDefine.Workflow("test")
            {
                Activities = new List <WorkDefine.Activity>()
                {
                    new WorkDefine.Activity()
                    {
                        //Action = "action.test",
                        Id        = "activity.test",
                        Reactions = new List <WorkDefine.Reaction>()
                        {
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            }
                        }
                    }
                }
            };
            StepTracer <LintTrace> tracer = new StepTracer <LintTrace>();

            tracer.TraceFirst(new LintTrace(LintStatusOptions.Sanitizing, "Testing Sanitizer"));
            Sanitizer toTest = new Sanitizer(tracer, this.defaultConfig);

            WorkDefine.Workflow sanitized = toTest.Sanitize(testWF);
            Assert.Equal(1, sanitized.Evaluators.Count(g => g.Id == "evaluator.test"));
        }
Ejemplo n.º 2
0
        public virtual WorkDefine.Workflow GetWorkflow(IWorkflowBuilder <TModel> workflowBuilder)
        {
            Builder <TModel> builder = (Builder <TModel>)workflowBuilder.GetBuilder();

            foreach (var action in builder.actions)
            {
                this.ActionFactory.AddAction(action.Key, action.Value);
            }

            foreach (var eval in builder.evaluators)
            {
                this.EvaluatorFactory.AddEvaluator(eval.Key, eval.Value);
            }
            if (builder.chained != null && builder.chained.Count > 0)
            {
                this.BuilderFactory.Builders = builder.chained;
            }



            WorkDefine.Workflow toReturn = ((IBuilderWorkflow <TModel>)builder).Workflow;

            if (this.Configuration.Ordinal > 0)
            {
                WorkflowManager mgr = new WorkflowManager(toReturn, this.Configuration);
                mgr.RenameWorkflow(string.Format("{0}{1}{2}", toReturn.Id, Configuration.Convention.Delimeter, this.Configuration.Ordinal));
            }

            return(toReturn);
        }
Ejemplo n.º 3
0
        private void LoadWorkflow(IWorkflowBuilder <TModel> builder)
        {
            WorkDefine.Workflow wf = null;
            if (this.WorkflowManager != null)
            {
                wf = this.WorkflowManager.WorkFlow;
            }
            else
            {
                wf = this.ImplementationManager.GetWorkflow(builder);
                this.WorkflowManager = new WorkflowManager(wf, this.Configuration);
            }

            if (RunManager == null)
            {
                RunManager = new RunManager(this.Configuration.Convention, wf.Id);
            }
            else
            {
                this.RunManager.WorkflowId = wf.Id;
            }

            this.ValidationContainer = ValidationContainer.CreateValidationContainer();

            if (this.preOverrides.Count() > 0)
            {
                this.preOverrides.ForEach(o =>
                {
                    ((IValidationContainer)this.ValidationContainer).AddOverride(o.Key, o.Comment, o.AuditCode);
                });
            }

            this.WorkflowCache = this.Configuration.Cache.Spawn(wf.Id);
        }
Ejemplo n.º 4
0
 public FakeImplementationManager(Case testCase, WorkDefine.Workflow workflow, Configuration.Config configuration)
 {
     this.workFlow      = workflow;
     this.configuration = configuration;
     this.ef            = new LogicTestEvaluatorFactory(testCase, this.configuration);
     this.af            = new LogicTestActionFactory();
     this.df            = new LogicTestDefintionFactory(this.configuration);
 }
Ejemplo n.º 5
0
        public WorkDefine.Workflow Sanitize(WorkDefine.Workflow toSanitize)
        {
            List <string> activityIds = (from a in toSanitize.Activities select a.Id).ToList();

            foreach (string a in activityIds)
            {
                LoadActivity(toSanitize, a);
            }
            return(toSanitize);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public Builder(string workflowId, Action <Configuration.Config> configure)
        {
            configure?.Invoke(this.config);


            WorkDefine.Workflow workflow = new WorkDefine.Workflow(workflowId)
            {
                Actions            = new List <WorkDefine.ActionDefinition>(),
                Activities         = new List <WorkDefine.Activity>(),
                Equations          = new List <LogicDefine.Equation>(),
                Evaluators         = new List <LogicDefine.Evaluator>(),
                ContextDefinitions = new List <ContextDefinition>()
            };
            this.workflowManager = new WorkflowManager(workflow, this.config);
        }
Ejemplo n.º 8
0
        public void InferredNegatedEquationAddedOnlyOnce()
        {
            WorkDefine.Workflow testWF = new WorkDefine.Workflow("test")
            {
                Equations = new List <LogicDefine.Equation>()
                {
                    new LogicDefine.Equation()
                    {
                        Condition = Mchnry.Flow.Logic.Operand.And, First = "evaluator.first", Id = "equation.testeq"
                    }
                },
                Activities = new List <WorkDefine.Activity>()
                {
                    new WorkDefine.Activity()
                    {
                        //Action = "action.test",
                        Id        = "activity.test",
                        Reactions = new List <WorkDefine.Reaction>()
                        {
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "!equation.testeq", Work = "action.badreaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "!equation.testeq", Work = "action.anotherbadreaction"
                            }
                        }
                    }
                }
            };
            StepTracer <LintTrace> tracer = new StepTracer <LintTrace>();

            tracer.TraceFirst(new LintTrace(LintStatusOptions.Sanitizing, "Testing Sanitizer"));
            Sanitizer toTest = new Sanitizer(tracer, this.defaultConfig);

            WorkDefine.Workflow sanitized = toTest.Sanitize(testWF);
            Assert.Equal(1, sanitized.Equations.Count(g => g.Id == "equation.NOT.testeq"));
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 public Articulator(WorkDefine.Workflow workflow, Configuration.Config configuration)
 {
     this.workflow      = workflow;
     this.configuration = configuration;
 }
Ejemplo n.º 11
0
 public WorkflowManager(WorkDefine.Workflow workFlow, Configuration.Config config)
 {
     this.WorkFlow = workFlow;
     this.config   = config;
 }
Ejemplo n.º 12
0
 public LintInspector(LintResult result, WorkDefine.Workflow workflow, Configuration.Config configuration)
 {
     this.Result        = result;
     this.workflow      = workflow;
     this.configuration = configuration;
 }