public WorkflowEngine(IWorkflowRepository flowRepository, ISessionProvider sessionProvider, IWorkflowExecutionHelper executionHelper, IRuleEngine ruleEngine) { _flowRepository = flowRepository; _sessionProvider = sessionProvider; _executionHelper = executionHelper; _ruleEngine = ruleEngine; }
static void Main(string[] args) { Registration register = new Registration(); Payment payment = new Payment(); payment.Item = "Product"; Payment("Rules is broken"); IRuleEngine <Registration> ruleEngine = RuleEngineFactory <Registration> .GetEngine(); register.UserName = ""; register.Password = "******"; register.Email = ""; register.EmailConfirm = "test"; var results = ruleEngine.Validate(register); foreach (var r in results) { if (r.IsBroken) { Console.WriteLine("{0} rule is broken and the error is {1}", r.Name, r.ErrorMessage); } } Console.Read(); }
/// <summary> /// Builds a TimeSeriesRequestHandler which validates messages using a /// provided IRuleEngine and dispatches valid messages to a queue. /// </summary> /// <param name="rulesEngine">The IRuleEngine to validate messages with. /// </param> /// <param name="messageQueueDispatcher">Queue dispatcher to use when request is successfully validated.</param> public TimeSeriesRequestHandler( IRuleEngine <TimeSeriesMessage> rulesEngine, IHubMessageQueueDispatcher messageQueueDispatcher) { _rulesEngine = rulesEngine; _messageDispatcher = messageQueueDispatcher; }
public Expression <Func <T, U> > Create <T, U>(Rule r) { var param = Expression.Parameter(typeof(T)); Expression expr = IRuleEngine.BuildExpr <T>(r, param); return(Expression.Lambda <Func <T, U> >(expr, param)); }
/// <summary> /// Builds a TimeSeriesCommandHandler which validates messages using a /// provided IRuleEngine and dispatches valid messages to a queue. /// </summary> /// <param name="rulesEngine">The IRuleEngine to validate messages with. /// </param> /// <param name="messageQueueDispatcher">Queue dispatcher to use when request is successfully validated.</param> public TimeSeriesCommandHandler( IRuleEngine <TimeSeriesMessage> rulesEngine, ITimeSeriesMessageQueueDispatcher messageQueueDispatcher) { _rulesEngine = rulesEngine; _messageDispatcher = messageQueueDispatcher; }
public Simulator(string strRuleEngine) { World.GetInstance().SetWorldPaths(strRuleEngine); m_TradeRule = InvokeTradeRule(strRuleEngine); //int nThreads = System.Environment.ProcessorCount; //threads = new Thread[nThreads]; }
public static IRuleEngine CreateInstance() { LightInject.ServiceContainer _container = new LightInject.ServiceContainer(); _container.Register(typeof(IRuleEngine), typeof(RuleEngine)); IRuleEngine obj = _container.GetInstance <IRuleEngine>(); return(obj); }
//-------------------------------------------------------------------------------- /// <summary> /// Fired when the watcher responsible for monitoring last write date/time /// changes is triggered. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void watcher_ChangedLastWrite(object sender, FileSystemEventArgs e) { Debug.WriteLine("EVENT - Changed LastWrite"); IRuleEngine obj = RuleEngineService.CreateInstance(); obj.UpdateDictionary(e.Name.Trim(), watcherInfo.WatchPath.Trim(), "Changed", e.FullPath, watcherInfo.MonitorPathInterval); EventDeleted(this, new WatcherExEventArgs(sender as FileSystemWatcherEx, e, ArgumentType.FileSystem)); EventChangedLastWrite(this, new WatcherExEventArgs(sender as FileSystemWatcherEx, e, ArgumentType.FileSystem, NotifyFilters.LastWrite)); }
public RuleEngineViewModel([ImportMany] IEnumerable <Lazy <IRuleEngine, IRuleEngineMetadata> > ruleEngines) { _ruleEngines = ruleEngines .OrderBy(re => re.Metadata.RuleName); _selectedRuleEngine = _ruleEngines .Where(re => re.Metadata.IsDefault) .Select(re => re.Value) .FirstOrDefault(); RegisterCommands(); }
public RuleEngineViewModel([ImportMany]IEnumerable<Lazy<IRuleEngine, IRuleEngineMetadata>> ruleEngines) { _ruleEngines = ruleEngines .OrderBy(re => re.Metadata.RuleName); _selectedRuleEngine = _ruleEngines .Where(re => re.Metadata.IsDefault) .Select(re => re.Value) .FirstOrDefault(); RegisterCommands(); }
public RequestChangeSupplierCommandHandler( IRuleEngine <RequestChangeOfSupplier> ruleEngine, IMeteringPointRepository meteringPointRepository, ISystemDateTimeProvider systemTimeProvider, IEnergySupplierRepository energySupplierRepository) { _ruleEngine = ruleEngine ?? throw new ArgumentNullException(nameof(ruleEngine)); _meteringPointRepository = meteringPointRepository ?? throw new ArgumentNullException(nameof(meteringPointRepository)); _systemTimeProvider = systemTimeProvider ?? throw new ArgumentNullException(nameof(systemTimeProvider)); _energySupplierRepository = energySupplierRepository ?? throw new ArgumentNullException(nameof(energySupplierRepository)); }
public override bool ApplyCommand(World world, IRuleEngine ruleEngine, IEnumerable <string> arguments) { Console.WriteLine(@"Help: h/help/?: Display this help text <x> <y>: Toggles the state of the cell at x,y sa/on/setalive <x> <y>: Sets the state of the cell at x,y to alive sd/off/setdead <x> <y>: Sets the state of the cell at x,y to dead s/r/step/run/[empty command]: Runs the simulation for one step g/glider <x> <y>: Places a Conway Glider with the top left at x,y q/quit/exit: Quites the program"); return(true); }
public override bool ApplyCommand(World world, IRuleEngine ruleEngine, IEnumerable <string> arguments) { var args = arguments.ToList(); if (args.Count == 3 && int.TryParse(args[1], out int xA) && int.TryParse(args[2], out int yA) && xA >= 0 && xA < world.Size.Item1 && yA >= 0 && yA < world.Size.Item2) { return(world.SetDead(xA, yA)); } return(false); }
public void RunOn() { CustomerMock customer = new CustomerMock { Salary = 1000, Expenses = 3000 }; CustomerRuleSetMock customerRuleSet = new CustomerRuleSetMock(); IRuleEngine <CustomerMock> customerRuleEngine = RuleEngineFactory.Create <CustomerMock>(customerRuleSet); IEnumerable <RuleResult> ruleResults = customerRuleEngine.RunOn(customer); ruleResults.Should().HaveCount(2); }
/// <summary> /// Gets the interceptor options. /// </summary> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="frameworkCommandInfo">The framework command info.</param> /// <returns>Options object to add to Command.</returns> public object GetInterceptorOptions <TOwner> (IFrameworkCommandInfo frameworkCommandInfo) { IRuleSelector ruleSelector; if (frameworkCommandInfo is IRuleCommandInfo) { ruleSelector = (frameworkCommandInfo as IRuleCommandInfo).RuleSelector; } else { ruleSelector = new SelectAllRulesInRuleSetSelector( frameworkCommandInfo.Name.EndsWith("RuleSet") ? frameworkCommandInfo.Name : frameworkCommandInfo.Name + "RuleSet"); } IRuleEngine <TOwner> ruleEngine = null; var triedCreateRuleEngine = false; var context = new RuleEngineContext <TOwner> (( TOwner )frameworkCommandInfo.Owner, ruleSelector); var ruleExecutor = new RuleExecutor { ExecuteRules = o => { if (!triedCreateRuleEngine) { triedCreateRuleEngine = true; ruleEngine = _ruleEngineFactory.CreateRuleEngine <TOwner>(); } if (ruleEngine != null) { context.Refresh(); if (o != null) { context.WorkingMemory.AddContextObject(o); if (context.RuleSelector is ITakeParameter) { (context.RuleSelector as ITakeParameter).Parameter = o; } } return(ruleEngine.ExecuteRules(context)); } return(new RuleExecutionResult(Enumerable.Empty <RuleViolation> ())); } }; return(ruleExecutor); }
public override bool Validate(LayersType below) { layerBelow = below; IRuleEngine <MultiplayLayer> ruleEngine = RuleEngineFactory <MultiplayLayer> .GetEngine(); var results = ruleEngine.Validate(this); foreach (var r in results) { if (r.IsBroken) { Debug.LogError(r.Name + " rule is broken and the error is " + r.ErrorMessage); } } return(results.Count == 0); }
static void Main(string[] args) { Registration register = new Registration(); IRuleEngine <Registration> ruleEngine = RuleEngineFactory <Registration> .GetEngine(); //assign the value to register.PaymentForPhysicalProduct else it will consider as the rule is broken and it will alert the error message. //"PaymentForPhysicalProduct" is hardcoded. This value can be map from config file also register.PaymentForPhysicalProduct = "PaymentForPhysicalProduct"; //assign the value to register.PaymentForBook else it will consider as the rule is broken and it will alert the error message. //"PaymentForBook" is hardcoded. This value can be map from config file also register.PaymentForBook = "PaymentForBook"; //assign the value to register.PaymentForMembership else it will consider as the rule is broken and it will alert the error message. //"PaymentForMembership" is hardcoded. This value can be map from config file also register.PaymentForMembership = "PaymentForMembership"; //assign the value to register.PaymentForUpgradeToMembership else it will consider as the rule is broken and it will alert the error message. //"PaymentForUpgradeToMembership" is hardcoded. This value can be map from config file also register.PaymentForUpgradeToMembership = "PaymentForUpgradeToMembership"; //assign the value to register.paymentForMembershipORUpgrade else it will consider as the rule is broken and it will alert the error message. //"paymentForMembershipORUpgrade" is hardcoded. This value can be map from config file also register.paymentForMembershipORUpgrade = "paymentForMembershipORUpgrade"; //assign the value to register.paymentForThevideoLearningToSkip else it will consider as the rule is broken and it will alert the error message. //"paymentForThevideoLearningToSkip" is hardcoded. This value can be map from config file also register.paymentForThevideoLearningToSkip = "paymentForThevideoLearningToSkip"; //assign the value to register.paymentIsForPhysicalProductOrABook else it will consider as the rule is broken and it will alert the error message. //"paymentIsForPhysicalProductOrABook" is hardcoded. This value can be map from config file also register.paymentIsForPhysicalProductOrABook = "paymentIsForPhysicalProductOrABook"; var results = ruleEngine.Validate(register); foreach (var r in results) { if (r.IsBroken) { Console.WriteLine("{0} rule is broken and the error is {1}", r.Name, r.ErrorMessage); } } Console.Read(); }
//-------------------------------------------------------------------------------- private void watcher_CreatedDeleted(object sender, FileSystemEventArgs e) { lock (thisLock) { IRuleEngine obj = RuleEngineService.CreateInstance(); switch (e.ChangeType) { case WatcherChangeTypes.Created: obj.UpdateDictionary(e.Name.Trim(), watcherInfo.WatchPath.Trim(), "Created", e.FullPath.Trim(), watcherInfo.MonitorPathInterval); EventCreated(this, new WatcherExEventArgs(sender as FileSystemWatcherEx, e, ArgumentType.FileSystem)); break; case WatcherChangeTypes.Deleted: break; } } }
public Engine( PieceFactory pieceFactory, IRuleEngine ruleEngine) { _pieceFactory = pieceFactory; _ruleEngine = ruleEngine; _board = new[, ] { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 } }; }
public void GetTaskTest() { var paymentData = new List <CustomerPayment> { new CustomerPayment { CustomerName = "Test Customer1", ForProductType = ProductType.Book, Amount = 400, Description = "Data Structure Usin C" }, new CustomerPayment { CustomerName = "Test Customer2", ForProductType = ProductType.NewSubscription, Amount = 600, Description = "Test new Membership 1" }, new CustomerPayment { CustomerName = "Test Customer3", ForProductType = ProductType.UpgradeSubscription, Amount = 1000, Description = "Test upgrade Membership" }, new CustomerPayment { CustomerName = "Test Customer4", ForProductType = ProductType.Video, Amount = 200, Description = "Learning to Ski" } }; var mock = new Mock <PaymentRuleProcessorEngine>(); mock.Setup(abs => abs.GetPaymentData()).Returns(paymentData); IRuleEngine paymentEngine = mock.Object; var result = paymentEngine.GetTask(); Assert.IsNotNull(result); Assertx.DoesNotThrowException <Exception>(() => result.Wait()); }
public override bool ApplyCommand(World world, IRuleEngine ruleEngine, IEnumerable <string> arguments) { var args = arguments.ToList(); if (args.Count == 3 && int.TryParse(args[1], out int xG) && int.TryParse(args[2], out int yG) && xG >= 0 && xG < world.Size.Item1 && yG >= 0 && yG < world.Size.Item2) { List <bool> status = new List <bool> { world.SetAlive(xG, yG), world.SetAlive(xG + 1, yG + 1), world.SetAlive(xG + 2, yG + 1), world.SetAlive(xG, yG + 2), world.SetAlive(xG + 1, yG + 2), }; return(status.All(x => x)); } return(false); }
public override bool ApplyCommand(World world, IRuleEngine ruleEngine, IEnumerable <string> arguments) { var args = arguments.ToList(); if (args.Count == 2 && int.TryParse(args[0], out int xT) && int.TryParse(args[1], out int yT) && xT >= 0 && xT < world.Size.Item1 && yT >= 0 && yT < world.Size.Item2) { if (world.GetState(xT, yT).Value) { return(world.SetDead(xT, yT)); } else { return(world.SetAlive(xT, yT)); } } return(false); }
public override void TotalPriceCalculation() { Console.WriteLine("Below Cart with Discounts"); double totalAmount = 0; var rulesId = _productList.Where(grp => grp.OfferGroupId != null).Select(x => x.OfferGroupId).Distinct().ToList(); foreach (var Id in rulesId) { var rule = groupPromotions.Where(gp => gp.OfferGroupId == Id).FirstOrDefault(); switch (rule.OfferType) { case "flat": ruleEngine = new FlatDiscount(rule.MinimumDiscountQty, rule.DiscountValue); var flatDiscountProducts = _productList.Where(prd => prd.OfferGroupId == rule.OfferGroupId).ToList(); ruleEngine.GetDiscountedPrice(flatDiscountProducts); break; case "combo": ruleEngine = new ComboDiscount(rule.MinimumDiscountQty, rule.DiscountValue); var comboDiscountProducts = _productList.Where(prd => prd.OfferGroupId == rule.OfferGroupId).ToList(); ruleEngine.GetDiscountedPrice(comboDiscountProducts); break; default: // double subTotal = product.ProductPrice * item.OrderedQty; break; } } var nonGroupProducts = _productList.Where(prd => prd.OfferGroupId == null).ToList(); foreach (var product in nonGroupProducts) { product.SubTotal = product.ProductPrice * product.OrderedQty; Console.WriteLine(product.OrderedQty + " * " + product.SKU + " " + product.SubTotal); } totalAmount = _productList.Sum(product => product.SubTotal); Console.WriteLine("Total amount for above cart is " + totalAmount); }
public void SetUp() { BasicConfigurator.Configure(); calledRules.Clear(); SUT = new RuleEngine(); }
public TestBase() { this.Pool = new MemoryRuleStore(); this.Engine = new RuleEngine(this.Pool); }
public BenefitsBLL(IRuleEngine ruleEngine, IBenefitRuleRepository ruleRepository, int numPayPeriods) { _ruleEngine = ruleEngine; _ruleRepository = ruleRepository; _numPayPeriods = numPayPeriods; }
public MessageHandler(IRuleEngine ruleEngine) { _ruleEngine = ruleEngine; }
/// <summary> /// /// </summary> /// <param name="ruleEngine"></param> /// <param name="ruleCreator"></param> public UpdateCalculateCartTaxBlock(IRuleEngine ruleEngine, IRuleCreator ruleCreator) : base(null) { _ruleEngine = ruleEngine; _ruleCreator = ruleCreator; }
public MyRuleService(ILogger <MyRuleService> logger, IRuleEngine ruleEngine) { _logger = logger; _ruleEngine = ruleEngine; }
public OrderProcessor(IRuleMatchService ruleMatchService, IRuleEngine ruleEngine, ILogger logger) { _ruleMatchService = ruleMatchService; _ruleEngine = ruleEngine; _logger = logger; }
/// <summary> /// Executes the completeness. /// </summary> /// <typeparam name="TAssessment">The type of the assessment.</typeparam> /// <param name="ruleEngine">The rule engine.</param> /// <param name="completenessCategory">The completeness category.</param> /// <param name="assessment">The assessment.</param> /// <param name="ruleSet">The rule set.</param> /// <returns></returns> private CompletenessResults ExecuteCompleteness <TAssessment> (IRuleEngine <TAssessment> ruleEngine, string completenessCategory, TAssessment assessment, string ruleSet) { var results = ruleEngine.ExecuteRuleSet(assessment, !ruleSet.EndsWith("RuleSet") ? ruleSet + "RuleSet" : ruleSet); return(new CompletenessResults(completenessCategory, results.NumberOfRulesExecuted, results.RuleViolations.Count())); }
public ShiftsController(IRuleEngine ruleEngine) { RuleEngine = ruleEngine; }
public OrderOperation(IRuleEngine<Order> ruleExecutor) { _ruleExecutor = ruleExecutor; }
public ChangeOfChargesInputValidator(IRuleEngine <ChangeOfChargesMessage> inputValidationRuleEngine) { _inputValidationRuleEngine = inputValidationRuleEngine; }
public void SetUp() { _propertyMatcher = Substitute.For<IPropertyMatcher>(); _ruleEngine = Substitute.For<IRuleEngine>(); }