Ejemplo n.º 1
0
 public WorkflowEngine(IWorkflowRepository flowRepository, ISessionProvider sessionProvider, IWorkflowExecutionHelper executionHelper, IRuleEngine ruleEngine)
 {
     _flowRepository  = flowRepository;
     _sessionProvider = sessionProvider;
     _executionHelper = executionHelper;
     _ruleEngine      = ruleEngine;
 }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
 /// <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;
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 /// <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;
 }
Ejemplo n.º 6
0
 public Simulator(string strRuleEngine)
 {
     World.GetInstance().SetWorldPaths(strRuleEngine);
     m_TradeRule = InvokeTradeRule(strRuleEngine);
     //int nThreads = System.Environment.ProcessorCount;
     //threads = new Thread[nThreads];
 }
Ejemplo n.º 7
0
        public static IRuleEngine CreateInstance()
        {
            LightInject.ServiceContainer _container = new LightInject.ServiceContainer();
            _container.Register(typeof(IRuleEngine), typeof(RuleEngine));
            IRuleEngine obj = _container.GetInstance <IRuleEngine>();

            return(obj);
        }
Ejemplo n.º 8
0
        //--------------------------------------------------------------------------------
        /// <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));
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
 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));
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
    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);
    }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
        //--------------------------------------------------------------------------------
        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;
                }
            }
        }
Ejemplo n.º 19
0
 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());
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 public void SetUp()
 {
     BasicConfigurator.Configure();
     calledRules.Clear();
     SUT = new RuleEngine();
 }
Ejemplo n.º 25
0
 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;
 }
Ejemplo n.º 27
0
 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;
 }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 31
0
        /// <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()));
        }
Ejemplo n.º 32
0
 public ShiftsController(IRuleEngine ruleEngine)
 {
     RuleEngine = ruleEngine;
 }
Ejemplo n.º 33
0
 public OrderOperation(IRuleEngine<Order> ruleExecutor)
 {
     _ruleExecutor = ruleExecutor;
 }
 public ChangeOfChargesInputValidator(IRuleEngine <ChangeOfChargesMessage> inputValidationRuleEngine)
 {
     _inputValidationRuleEngine = inputValidationRuleEngine;
 }
Ejemplo n.º 35
0
 public void SetUp()
 {
     _propertyMatcher = Substitute.For<IPropertyMatcher>();
     _ruleEngine = Substitute.For<IRuleEngine>();
 }