Пример #1
0
 public void AddEvaluator(string id, IRuleEvaluatorX <TModel> evaluator)
 {
     id = ConventionHelper.EnsureConvention(NamePrefixOptions.Evaluator, id, this.Configuration.Convention);
     if (!this.evaluators.ContainsKey(id))
     {
         this.evaluators.Add(id, evaluator);
     }
 }
Пример #2
0
 public void AddAction(string id, IAction <TModel> action)
 {
     id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, id, this.Configuration.Convention);
     if (!this.actions.ContainsKey(id))
     {
         this.actions.Add(id, action);
     }
 }
Пример #3
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;
 }
Пример #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;
        }
Пример #5
0
        async Task <IEngineFinalize <TModel> > IEngineRunner <TModel> .ExecuteAsync(CancellationToken token)
        {
            if (!this.Sanitized)
            {
                this.Sanitize();
            }

            string workflowId = ConventionHelper.EnsureConvention(NamePrefixOptions.Activity, this.WorkflowManager.WorkFlow.Id, this.Configuration.Convention);

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

            return(await this.ExecuteAsync(workflowId, token));
        }
Пример #6
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);
        }
Пример #7
0
        public async Task <LintInspector> LintAsync(Action <Case> mockCase, CancellationToken token)
        {
            if (!this.Sanitized)
            {
                this.Sanitize();
            }


            Linter linter = new Linter(this.WorkflowManager, this.Configuration);


            List <ActivityTest> activityTests = linter.AcvityLint();
            List <ActivityTest> mockTests     = null;

            //temporarily supplant implementationmanager with fake
            IImplementationManager <TModel> holdIM = this.ImplementationManager;

            //loop through each activity in activityTests and run them
            foreach (ActivityTest at in activityTests)
            {
                foreach (Case tc in at.TestCases)
                {
                    string activityId = ConventionHelper.EnsureConvention(NamePrefixOptions.Activity, at.ActivityId, this.Configuration.Convention);
                    this.ImplementationManager = new FakeImplementationManager <TModel>(tc, this.WorkflowManager.WorkFlow, this.Configuration);
                    await this.ExecuteAsync(activityId, token);

                    tc.Trace = this.Tracer.tracer.AllNodes;
                    this.Reset(true);
                }
            }

            //restore original implementation manager
            this.ImplementationManager = holdIM;

            //if the caller provided a mock callback, then we'll
            //run through it through again, but this time using the
            //existing implementation manager.
            if (mockCase != null)
            {
                mockTests = (from t in activityTests
                             select new ActivityTest(t.ActivityId)
                {
                    TestCases = (from z in t.TestCases select(Case) z.Clone()).ToList()
                }).ToList();

                foreach (ActivityTest at in mockTests)
                {
                    foreach (Case tc in at.TestCases)
                    {
                        mockCase(tc);
                        await this.ExecuteAsync(at.ActivityId, token);

                        tc.Trace = this.Tracer.tracer.AllNodes;
                        this.Reset(true);
                    }
                }
            }

            CaseAnalyzer analyzer     = new CaseAnalyzer(this.WorkflowManager, activityTests, mockTests, this.Configuration);
            List <Audit> auditResults = analyzer.Analyze();



            int lintHash = this.WorkflowManager.WorkFlow.GetHashCode();

            return(new LintInspector(new LintResult(this.lintTracer, activityTests, null, auditResults, lintHash.ToString()), this.Workflow, this.Configuration));
            //return new LintResult(this.lintTracer, activityTests, null, auditResults, lintHash.ToString());
        }
Пример #8
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);
        }
Пример #9
0
        void IFluentExpressionBuilder <T> .Rule(Action <IRuleBuilder <T> > action)
        {
            RuleBuilder <T> builderRef = new RuleBuilder <T>(this);

            action.Invoke(builderRef);

            LogicDefine.Rule evaluatorId = builderRef.rule;



            evaluatorId.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Evaluator, evaluatorId.Id, this.config.Convention);

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

            var descAttr = builderRef.evaluatorx.GetType().GetCustomAttributes(typeof(ArticulateOptionsAttribute), true)
                           .OfType <ArticulateOptionsAttribute>()
                           .FirstOrDefault();

            if (descAttr != null)
            {
                description = descAttr.Description;
            }

            this.workflowManager.AddEvaluator(new LogicDefine.Evaluator()
            {
                Id = evaluatorId.Id, Description = description
            });
            bool isRoot = this.epxressionStack.Count == 0;

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

            if (isRoot)
            {
                string equationId = ConventionHelper.ChangePrefix(NamePrefixOptions.Evaluator, NamePrefixOptions.Equation, evaluatorId.Id, this.config.Convention);
                bool   trueCond   = true;;
                if (!evaluatorId.TrueCondition)
                {
                    equationId = ConventionHelper.NegateEquationName(equationId, this.config.Convention);
                    trueCond   = false;
                }
                LogicDefine.Equation toAdd = new LogicDefine.Equation()
                {
                    Condition = Logic.Operand.And,
                    First     = evaluatorId,
                    Id        = equationId,
                    Second    = ConventionHelper.TrueEvaluator(this.config.Convention),
                    //TrueCondition = trueCond
                };
                this.epxressionStack.Push(toAdd);

                this.workflowManager.AddEquation(toAdd);
            }
            else
            {
                this.epxressionStack.Push(evaluatorId);
            }
            //if root... then create euqations
            //otherwise, just use as evaluator
        }