private void ProcessActionRuleModule <T>(RuleModule ruleModule, T entity, HashSet <IEntityChangeInformation> entityChangeInformationSet, bool applyActions) { foreach (var rule in ruleModule.Rules) { if (rule.Type == RuleCompilableType.Rule) { var compiledActionRuleResult = this._actionRuleCompiler.Compile <T>(rule as IRule); if (this._evaluationPath != null) { compiledActionRuleResult.EntityChangeInformation.EvaluationPath = this._evaluationPath; } entityChangeInformationSet.Add(compiledActionRuleResult.EntityChangeInformation); if (applyActions) { compiledActionRuleResult.Compiled(entity); } } else { ProcessEntity(rule as RuleModule, entity, entityChangeInformationSet, applyActions); } } }
public static LogManager ConfigureForTextWriter(StringWriter tw) { var twTarg = TextWriter.Create( TextWriter.TextWriterConf.Create(tw, tw, new Microsoft.FSharp.Core.FSharpOption <Formatting.StringFormatter>(Formatting.StringFormatterModule.levelDatetimeMessagePathNl), new Microsoft.FSharp.Core.FSharpOption <object>(new object())), "tw"); var twRule = RuleModule.Create(new Regex(@"^Logary\.CSharp\.Tests"), "tw", LogLevel.Verbose, message => true); var internalTarg = Console.Create(Console.empty, "console"); return(Config.Configure( "Logary.CSharp.Tests C# low level API", new[] { twTarg }, new Metric.MetricConf[0], new[] { twRule }, LogLevel.Warn, internalTarg) .ToTask() .Result); }
public IRuleProcessorResult <T> Process <T>(RuleModule module, T entity, HashSet <IEntityChangeInformation> entitiesChangeInformationSet = null, bool applyActions = true) { entitiesChangeInformationSet = entitiesChangeInformationSet ?? new HashSet <IEntityChangeInformation>(); var resultEntity = ProcessEntity(module, entity, entitiesChangeInformationSet, applyActions); return(new RuleProcessorResult <T>(resultEntity, _evaluationPath, entitiesChangeInformationSet)); }
private RuleModule GetNextModule <T>(RuleModule module, T entity) { var evalResult = EvalBooleanRuleModule(module, entity); var nextModule = evalResult ? module.IfTrue : module.IfFalse; return(nextModule); }
public void FindActionRules(RuleModule ruleModule, HashSet <IRuleModuleActionContainer> actionRules) { if (ruleModule.RuleModuleType == RuleType.Boolean) { if (ruleModule.IfTrue != null) { FindActionRules(ruleModule.IfTrue, actionRules); } if (ruleModule.IfFalse != null) { if (ruleModule.IfTrue != null) { actionRules = new HashSet <IRuleModuleActionContainer>(); actionGroups.Add(actionRules); } FindActionRules(ruleModule.IfFalse, actionRules); } } else { FindActionRulesFromSet(ruleModule, actionRules); } }
private void InitSingleModule() { var booleanRules = new [] { CreateBooleanRule( expression: "Label.Contains(@0)", arguments: new [] { new RuleArgument("Order") } ), CreateBooleanRule( expression: "Label.Contains(@0)", arguments: new [] { new RuleArgument("Test Order") } ), }; var actionRules = new [] { CreateActionRule( expression: "Amount.Round(@0)", arguments: new [] { new RuleArgument(2) } ), CreateActionRule( expression: "Amount.Add(@0)", arguments: new [] { new RuleArgument(10) } ), }; singleModule = new RuleModule(RuleType.Boolean, booleanRules) { BooleanEvalLogic = BooleanRuleModuleEvalLogic.And, IfTrue = new RuleModule(RuleType.Action, actionRules) }; }
private bool EvalBooleanRuleModule <T>(RuleModule ruleModule, T entity) { if (ruleModule.BooleanEvalLogic.Value == BooleanRuleModuleEvalLogic.And) { return(ruleModule.Rules.All(EvalBooleanRule(entity))); } return(ruleModule.Rules.Any(EvalBooleanRule(entity))); }
private void InitModuleChain() { // Boolean rules var ordersWithLabelContainingOrder = CreateBooleanRule( expression: "Label.Contains(@0)", arguments: new[] { new RuleArgument("Order") } ); var ordersWithAmountGreaterThan500 = CreateBooleanRule( expression: "Amount.GreaterThan(@0)", arguments: new[] { new RuleArgument(500) } ); var ordersFromCalifornia = CreateBooleanRule( expression: "FromAddress.State.Equals(@0)", arguments: new[] { new RuleArgument("CA") } ); // Action rules var roundAmountAction = CreateActionRule( expression: "Amount.Round(@0)", arguments: new[] { new RuleArgument(2) } ); var add10ToAmountAction = CreateActionRule( expression: "Amount.Add(@0)", arguments: new[] { new RuleArgument(10) } ); var changeShippingStatusToFullyShippedAction = CreateActionRule( expression: "ShippingStatus.Assign(@0)", arguments: new[] { new RuleArgument(OrderShippingStatus.FullyShipped) { ValueType = typeof(OrderShippingStatus).AssemblyQualifiedName } } ); var updateOrderItemNameToSent = CreateActionRule( expression: "Items.Each(Name.Assign(@0))", arguments: new[] { new RuleArgument("Sent") } ); moduleChain = new RuleModule(RuleType.Boolean, ordersWithLabelContainingOrder, ordersWithAmountGreaterThan500) { BooleanEvalLogic = BooleanRuleModuleEvalLogic.Or, IfFalse = new RuleModule { RuleModuleType = RuleType.Boolean, BooleanEvalLogic = BooleanRuleModuleEvalLogic.And, Rules = new HashSet <IRuleCompilable> { ordersFromCalifornia }, IfFalse = new RuleModule(RuleType.Action, roundAmountAction), IfTrue = new RuleModule(RuleType.Action, add10ToAmountAction) }, IfTrue = new RuleModule(RuleType.Action, updateOrderItemNameToSent, changeShippingStatusToFullyShippedAction) }; }
public IEnumerable <IEnumerable <IConflictingRules> > Validate <T>(RuleModule ruleModule) { var actionRulesSet = new HashSet <IRuleModuleActionContainer>(); var actionGroups = new HashSet <IEnumerable <IRuleModuleActionContainer> > { actionRulesSet }; var ruleModuleValidator = new RuleModuleValidator(actionGroups); ruleModuleValidator.FindActionRules(ruleModule, actionRulesSet); var res = actionGroups.AsParallel().Select(GetForConflicts <T>); return(res.Where(l => l.Any()).ToList()); }
private void FindActionRulesFromSet(RuleModule ruleModule, HashSet <IRuleModuleActionContainer> actionRules) { foreach (var rule in ruleModule.Rules) { if (rule.Type == RuleCompilableType.Module) { FindActionRules(rule as RuleModule, actionRules); } else { var ruleModuleActionContainer = new RuleModuleActionContainer(ruleModule.Id, rule as IRule); actionRules.Add(ruleModuleActionContainer); } } }
public static LogManager ConfigureForTextWriter(StringWriter tw) { var twTarg = TextWriter.Create(Formatting.StringFormatter.LevelDatetimeMessagePathNl, tw, tw, false, LogLevel.Error, "tw"); var twRule = RuleModule.Create(new Regex(@"^Intelliplan\.Logary\.Specs"), "tw", l => true, m => true, LogLevel.Verbose); var internalTarg = Console.Create("cons", Console.empty); return(Config.Configure( "Logary Specs C# low level API", new[] { twTarg }, Duration.FromSeconds(4L), new Metric.MetricConf[0], new[] { twRule }, LogLevel.Verbose, internalTarg)); }
private T ProcessEntity <T>(RuleModule module, T entity, HashSet <IEntityChangeInformation> entityChangeInformationSet, bool applyActions) { if (module != null) { _evaluationPath?.Add(module.Id); if (module.RuleModuleType == RuleType.Boolean) { var nextModule = GetNextModule(module, entity); return(ProcessEntity(nextModule, entity, entityChangeInformationSet, applyActions)); } else { ProcessActionRuleModule(module, entity, entityChangeInformationSet, applyActions); } } return(entity); }
public static LogManager ConfigureForTextWriter(StringWriter tw) { var twTarg = TextWriter.Create( TextWriter.TextWriterConf.Create(tw, tw, new Microsoft.FSharp.Core.FSharpOption <Formatting.StringFormatter>(Formatting.StringFormatterModule.levelDatetimeMessagePathNl)), PointNameModule.OfSingle("tw")); var twRule = RuleModule.Create(new Regex(@"^Logary\.Specs"), PointNameModule.Parse("tw"), LogLevel.Verbose, message => true); var internalTarg = Console.Create(Console.empty, PointNameModule.Parse("console")); return(Config.Configure( "Logary Specs C# low level API", new[] { twTarg }, new Metric.MetricConf[0], new[] { twRule }, LogLevel.Verbose, internalTarg) .ToTask() .Result); }