public void ChangePrefixToEquation() { string equation = "e_test"; string changed = ConventionHelper.ChangePrefix(NamePrefixOptions.Evaluator, NamePrefixOptions.Equation, equation, this.CustomConfig.Convention); Assert.Equal("q_test", changed); }
public void ChangePrefixToActivity() { string test = "a_test"; string changed = ConventionHelper.ChangePrefix(NamePrefixOptions.Action, NamePrefixOptions.Activity, test, this.CustomConfig.Convention); Assert.Equal("v_test", changed); }
public void NegateFollowsConvention() { string equation = "q_test"; string negated = ConventionHelper.NegateEquationName(equation, this.CustomConfig.Convention); Assert.Equal("q_NOT_test", negated); }
public void NegateConventionNotFoundEx() { var exception = Assert.Throws <ConventionMisMatchException>(() => { string equation = "mismatch.test"; ConventionHelper.NegateEquationName(equation, this.DefaultConfig.Convention); }); }
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); } }
public ProxyEvaluatorFactory(Configuration.Config configuration) { this.Configuration = configuration; IRuleEvaluatorX <TModel> trueEvaluator = new AlwaysTrueEvaluator <TModel>(); this.evaluators.Add(ConventionHelper.TrueEvaluator(this.Configuration.Convention), trueEvaluator); }
public void RenameActionToEvaluatorEx() { var exception = Assert.Throws <ConventionMisMatchException>(() => { string action = "action.test"; ConventionHelper.ChangePrefix(NamePrefixOptions.Action, NamePrefixOptions.Evaluator, action, this.DefaultConfig.Convention); }); }
public void RenameEquationToActivityEx() { var exception = Assert.Throws <ConventionMisMatchException>(() => { string rule = "equation.test"; ConventionHelper.ChangePrefix(NamePrefixOptions.Equation, NamePrefixOptions.Activity, rule, this.DefaultConfig.Convention); }); }
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); } }
public void NegateActionEx() { var exception = Assert.Throws <ConventionMisMatchException>(() => { string action = "action.test"; ConventionHelper.NegateEquationName(action, DefaultConfig.Convention); }); }
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; }
public void Negate() { string action = "action.test"; string renamedActivity = ConventionHelper.ChangePrefix(NamePrefixOptions.Action, NamePrefixOptions.Activity, action, this.DefaultConfig.Convention); string evaluator = "evaluator.test"; string renamedEquation = ConventionHelper.ChangePrefix(NamePrefixOptions.Evaluator, NamePrefixOptions.Equation, evaluator, this.DefaultConfig.Convention); Assert.Equal("activity.test", renamedActivity); Assert.Equal("equation.test", renamedEquation); }
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); }
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; }
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)); }
public IRuleEvaluatorX <TModel> GetRuleEvaluator <TModel>(Evaluator definition) { if (definition.Id == ConventionHelper.TrueEvaluator(this.configuration.Convention)) { return(new AlwaysTrueEvaluator <TModel>()); } else { //in cases where the rule has context, then there will be a test case for //each individual context. in that case, pass all to the preset rule. List <Rule> toTest = this.TestCase.Rules.Where(r => r.Id == definition.Id).ToList(); return(new PreSetRuleEvaluator <TModel>(toTest)); } }
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); }
void IFluentExpressionBuilder <T> .And(Action <IFluentExpressionBuilder <T> > first, Action <IFluentExpressionBuilder <T> > second) { string equationId = string.Empty; //we are in a sub equation if (this.epxressionStack.Count > 0) { string lastEquationId = this.epxressionStack.Peek().Id; //string suffix = (this.epxressionStack.Count % 2 == 0) ? "2" : "1"; string suffix = equationSide.ToString(); equationId = lastEquationId + this.config.Convention.Delimeter + suffix; } else //we are at the root { string lastActivityId = this.activityStack.Peek().Id; equationId = ConventionHelper.ChangePrefix(NamePrefixOptions.Activity, NamePrefixOptions.Equation, lastActivityId, this.config.Convention); } LogicDefine.Equation toAdd = new LogicDefine.Equation() { Condition = Logic.Operand.And, Id = equationId }; this.epxressionStack.Push(toAdd); this.workflowManager.AddEquation(toAdd); string firstId, secondId = null; equationSide = 1; first(this); firstId = this.epxressionStack.Pop().ShortHand; equationSide = 2; second(this); secondId = this.epxressionStack.Pop().ShortHand; toAdd.First = firstId; toAdd.Second = secondId; //return new ExpressionRef(toAdd.ShortHand); }
IEngineLoader <TModel> IEngineLoader <TModel> .PreemptValidation <T>(string key, string context, string comment, string auditCode) { string typeOfT = typeof(T).Name; LogicDefine.Rule rule = new LogicDefine.Rule() { Id = typeOfT, Context = context }; string normalized = ConventionHelper.ApplyConvention(NamePrefixOptions.Evaluator, rule.RuleIdWithContext, this.Configuration.Convention) + "."; key = key.ToLower().Replace(normalized.ToLower(), ""); string orideKey = ConventionHelper.ApplyConvention(NamePrefixOptions.Evaluator, rule.RuleIdWithContext + "." + key, this.Configuration.Convention); ValidationOverride oride = new ValidationOverride(orideKey.ToLower(), comment, auditCode); this.preOverrides.Add(oride); return(this); }
void IFluentExpressionBuilder <T> .ExpIsFalse(Action <IFluentExpressionBuilder <T> > If) { string equationId = string.Empty; //we are in a sub equation if (this.epxressionStack.Count > 0) { string lastEquationId = this.epxressionStack.Peek().Id; string suffix = (this.epxressionStack.Count % 2 == 0) ? "2" : "1"; equationId = lastEquationId + this.config.Convention.Delimeter + suffix; } else //we are at the root { string lastActivityId = this.activityStack.Peek().Id; equationId = ConventionHelper.ChangePrefix(NamePrefixOptions.Activity, NamePrefixOptions.Equation, lastActivityId, this.config.Convention); } LogicDefine.Equation toAdd = new LogicDefine.Equation() { Condition = Logic.Operand.And, Id = equationId }; this.epxressionStack.Push(toAdd); this.workflowManager.AddEquation(toAdd); string firstId, secondId = null; If(this); LogicDefine.Rule firstRule = this.epxressionStack.Pop().ShortHand; firstRule.TrueCondition = !firstRule.TrueCondition; firstId = firstRule.ShortHand; secondId = ConventionHelper.TrueEvaluator(this.config.Convention); toAdd.First = firstId; toAdd.Second = secondId; }
private IRule <TModel> LoadLogic(string equationId) { StepTracer <LintTrace> trace = new StepTracer <LintTrace>(); StepTraceNode <LintTrace> root = trace.TraceFirst(new LintTrace(LintStatusOptions.Loading, "Loading Logic", equationId)); //Lint.... make sure we have everything we need first. Func <LogicDefine.Rule, StepTraceNode <LintTrace>, bool, IRule <TModel> > LoadRule = null; LoadRule = (rule, parentStep, inner) => { StepTraceNode <LintTrace> step = trace.TraceNext(parentStep, new LintTrace(LintStatusOptions.Inspecting, "Inspecting Rule", rule.Id)); IRule <TModel> toReturn = null; //if id is an equation, we are creating an expression //since we've formalized convention, we can just check that if (ConventionHelper.MatchesConvention(NamePrefixOptions.Equation, rule.Id, this.Configuration.Convention)) { LogicDefine.Equation eq = this.WorkflowManager.GetEquation(rule.Id); IRule <TModel> first = LoadRule(eq.First, step, true); IRule <TModel> second = LoadRule(eq.Second, step, true); toReturn = new Expression <TModel>(rule, eq.Condition, first, second, this, inner); } else { LogicDefine.Evaluator ev = this.WorkflowManager.GetEvaluator(rule.Id); toReturn = new Rule <TModel>(rule, this, inner); } return(toReturn); }; LogicDefine.Rule eqRule = equationId; IRule <TModel> loaded = LoadRule(eqRule, root, false); return(loaded); }
public IAction <TModel> getAction(WorkDefine.ActionDefinition def) { WorkDefine.ActionDefinition withoutConvention = new WorkDefine.ActionDefinition() { Id = ConventionHelper.RemoveConvention(def.Id, this.Configuration.Convention), Description = def.Description }; IAction <TModel> toReturn = default(IAction <TModel>); if (this.actions.ContainsKey(withoutConvention.Id)) { toReturn = this.actions[withoutConvention.Id]; } else { toReturn = this.actions[def.Id]; } return(toReturn); }
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(); }
public IRuleEvaluatorX <TModel> GetRuleEvaluator(LogicDefine.Evaluator def) { LogicDefine.Evaluator withoutConvention = new LogicDefine.Evaluator() { Id = ConventionHelper.RemoveConvention(def.Id, this.Configuration.Convention), Description = def.Description }; IRuleEvaluatorX <TModel> toReturn = default(IRuleEvaluatorX <TModel>); if (this.evaluators.ContainsKey(withoutConvention.Id)) { toReturn = this.evaluators[withoutConvention.Id]; } else { toReturn = this.evaluators[def.Id]; } return(toReturn); }
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 }
//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); }
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()); }
public List <LogicTest> LogicLint() { int id = 1; Func <int> newId = () => { return(id += 1); }; List <bool> tf = new List <bool>() { true, false }; Func <Equation, List <Rule> > getAllRulesForEquation = null; getAllRulesForEquation = (eq) => { List <Rule> rules = new List <Rule>(); //left hand side of equation if (ConventionHelper.MatchesConvention(NamePrefixOptions.Equation, eq.First.Id, this.configuration.Convention)) { Equation traverse = this.WorkflowManager.GetEquation(eq.First.Id); List <Rule> parsed = getAllRulesForEquation(traverse); rules = rules.Union(parsed, new RuleEqualityComparer()).ToList(); } else { if (!rules.Contains(eq.First, new RuleEqualityComparer())) { rules.Add((Rule)eq.First.Clone()); } } if (ConventionHelper.MatchesConvention(NamePrefixOptions.Equation, eq.Second.Id, this.configuration.Convention)) { Equation traverse = this.WorkflowManager.GetEquation(eq.Second.Id); List <Rule> parsed = getAllRulesForEquation(traverse); rules = rules.Union(parsed, new RuleEqualityComparer()).ToList(); } else { if (!rules.Contains(eq.Second, new RuleEqualityComparer())) { rules.Add((Rule)eq.Second.Clone()); } } string trueId = ConventionHelper.TrueEvaluator(this.configuration.Convention); return((from r in rules where r.Id != trueId select r).ToList()); }; Func <Stack <List <Case> >, List <Case> > mergeCases = null; mergeCases = (llc) => { List <Case> merged = llc.Pop(); if (llc.Count > 0) { List <Case> toMerge = mergeCases(llc); List <Case> newMerge = new List <Case>(); merged.ForEach(m => { toMerge.ForEach(g => { List <Rule> newCaseRules = new List <Rule>(from r in m.Rules select(Rule) r.Clone()); newCaseRules.AddRange(from r in g.Rules select(Rule) r.Clone()); Case newCase = new Case(newCaseRules); newMerge.Add(newCase); }); }); merged = newMerge; } return(merged); }; if (this.logicTests == default) { this.logicTests = new List <LogicTest>(); //get the root foreach (string rootEquationId in this.roots) { Stack <List <Case> > preMerge = new Stack <List <Case> >(); Equation root = this.WorkflowManager.GetEquation(rootEquationId); List <Rule> evalRules = getAllRulesForEquation(root); foreach (Rule evalRule in evalRules) { List <Case> evalRuleCases = new List <Case>(); if (evalRule.Context == null) { evalRuleCases.AddRange(from c in tf select new Case(new List <Rule>() { new Rule() { Context = evalRule.Context, Id = evalRule.Id, TrueCondition = c } })); } else { Stack <List <Case> > contextCases = new Stack <List <Case> >(); evalRule.Context.Keys.ForEach(k => { List <Case> cases = new List <Case>(); cases.AddRange(from c in tf select new Case(new List <Rule>() { new Rule() { Context = new Context(new List <string>() { k }, evalRule.Context.Name), Id = evalRule.Id, TrueCondition = c } })); contextCases.Push(cases); evalRuleCases = mergeCases(contextCases); contextCases.Push(evalRuleCases); }); var contextDef = this.WorkflowManager.GetContextDefinition(evalRule.Context.Name); if (contextDef.Validate == ValidateOptions.OneOf) { evalRuleCases.RemoveAll(c => c.Rules.Count(r => r.TrueCondition) != 1 && c.Rules.Any(r => r.TrueCondition)); } if (contextDef.Exclusive) { evalRuleCases.RemoveAll(c => c.Rules.Count(r => !r.TrueCondition) == c.Rules.Count() && c.Rules.Count == contextDef.Items.Count); } } preMerge.Push(evalRuleCases); } List <Case> finalCases = mergeCases(preMerge); LogicTest eqTest = new LogicTest(rootEquationId, true) { TestCases = finalCases }; this.logicTests.Add(eqTest); } } return(this.logicTests); }
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); }