public async Task <string> Get() { var workRules = new RulesEngine.Models.WorkflowRules(); workRules.WorkflowName = "折扣"; workRules.Rules = new List <Rule> { new Rule { RuleName = "活动一", SuccessEvent = "10", ErrorMessage = "One or more adjust rules failed.", ErrorType = ErrorType.Error, RuleExpressionType = RuleExpressionType.LambdaExpression, Expression = "input1.country == \"india\" AND input1.loyalityFactor <= 2 AND input1.totalPurchasesToDate >= 5000" }, new Rule { RuleName = "活动二", SuccessEvent = "20", ErrorMessage = "One or more adjust rules failed.", ErrorType = ErrorType.Error, RuleExpressionType = RuleExpressionType.LambdaExpression, Expression = "input1.country == \"india\" AND input1.loyalityFactor >= 3 AND input1.totalPurchasesToDate >= 10000" }, }; var rulesEngine = new RulesEngine.RulesEngine(new WorkflowRules[] { workRules }, _logger, new ReSettings()); var resultList = await rulesEngine.ExecuteAllRulesAsync("折扣", new Country { loyalityFactor = 5, totalPurchasesToDate = 20000 }); var discountOffered = ""; resultList.OnSuccess((eventName) => { discountOffered = $"Discount offered is {eventName} % over MRP."; }); resultList.OnFail(() => { discountOffered = "The user is not eligible for any discount."; }); return(discountOffered); }
public void EvaluateRule(IMessage <ICRMMessage> message) { var settings = new ReSettings() { NestedRuleExecutionMode = NestedRuleExecutionMode.Performance }; var wflw = repo.GetWorkflow(message); foreach (var stp in wflw.Steps) { //var lst = JsonConvert.DeserializeObject<List<WorkflowRules>>(stp.JsonRules); var bre = new RulesEngine.RulesEngine(stp.Rules, null, settings); var result = bre.ExecuteAllRulesAsync("NewLead-Immediate", message.Payload.Opportunity, message.Payload.Opportunity.Leads[0], message.Payload.Opportunity.VehicleOfInterest).Result; result.OnSuccess((eventName) => { Console.WriteLine($"NewLead-Immediate evaluation resulted in succees - {eventName}"); }).OnFail(() => { Console.WriteLine($"NewLead-Immediate evaluation resulted in failure"); }); } }