static void Main(string[] args) { var repository = new RuleRepository(); repository.Load(x => x.From(typeof(AssignFirstSeat).Assembly)); var factory = repository.Compile(); var session = factory.CreateSession(); session.Events.FactInsertingEvent += EventProviderOnFactInsertingEvent; session.Events.FactUpdatingEvent += EventProviderOnFactUpdatingEvent; session.Events.FactRetractingEvent += EventProviderOnFactRetractingEvent; session.Events.ActivationCreatedEvent += EventProviderOnActivationCreatedEvent; session.Events.ActivationDeletedEvent += EventProviderOnActivationDeletedEvent; session.Events.RuleFiringEvent += EventProviderOnRuleFiringEvent; session.Insert(new Guest("N1", Gender.Male, new Hobby("H1"))); session.Insert(new Guest("N2", Gender.Female, new Hobby("H1"))); session.Insert(new Guest("N2", Gender.Female, new Hobby("H3"))); session.Insert(new Guest("N3", Gender.Male, new Hobby("H3"))); session.Insert(new Guest("N4", Gender.Male, new Hobby("H1"))); session.Insert(new Guest("N4", Gender.Female, new Hobby("H2"))); session.Insert(new Guest("N4", Gender.Female, new Hobby("H3"))); session.Insert(new Guest("N5", Gender.Female, new Hobby("H2"))); session.Insert(new Guest("N5", Gender.Female, new Hobby("H1"))); session.Insert(new Count(1)); session.Insert(new LastSeat(5)); var context = new Context(); session.Insert(context); session.Fire(); }
private ISessionFactory CreateTarget() { var repository = new RuleRepository(); repository.Load(x => x.NestedTypes().From(typeof(TestRule))); return(repository.Compile()); }
public void Test1() { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model var customer = new Customer("John Doe") { IsPreferred = true }; var order1 = new Order(123456, customer, 2, 25.0); var order2 = new Order(123457, customer, 1, 100.0); session.Insert(customer); session.Insert(order1); session.Insert(order2); session.Fire(); }
private static void RestReaminingSample() { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(NoticeNewRequestRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Fake Web Action var fakeAction = new FakeAction(); //設定補修只有2天 var person = fakeAction.GetFakePerson("皓之", 2); session.Insert(person); session.Fire(); //請假 var request = fakeAction.SendAskForRestRequest(); session.Insert(request); session.Fire(); }
static void Main(string[] args) { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model var customer = new Customer("John Doe") { IsPreferred = true }; var order1 = new Order(123456, customer, 2, 25.0); var order2 = new Order(123457, customer, 1, 100.0); Console.WriteLine($"Order1 price: {order1.Price}"); Console.WriteLine($"Order2 price: {order2.Price}"); //Insert facts into rules engine's memory session.Insert(customer); session.Insert(order1); session.Insert(order2); //Start match/resolve/act cycle session.Fire(); Console.WriteLine($"Order1 price: {order1.Price}"); Console.WriteLine($"Order2 price: {order2.Price}"); }
public async Task <string> TipMessageAsync() { TipList = new List <Tip>(); var tipList = await MainDialog.QueryTipsAsync(); // Rules engine here // Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(TipChooseRule).Assembly)); // Compile rules var factory = repository.Compile(); // Create a working session var session = factory.CreateSession(); // Insert facts into rules engine's memory session.Insert(PersonalDetailsDialog.PersonalDetails); foreach (Tip obj in tipList) { session.Insert(obj); } // Start match/resolve/act cycle session.Fire(); return(RandomiseList(TipList.Select(l => l.TipMessage).ToList())); }
static void Main(string[] args) { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model var customer = new Customer("John Doe") { IsPreferred = false }; var order1 = new Order(123456, customer, 2, 25.0); var order2 = new Order(123457, customer, 1, 100.0); session.Insert(customer); session.Insert(order1); session.Insert(order2); var fire = session.Fire(); Console.WriteLine(fire); Console.Read(); }
public void Compile() { //Load rules var repository = new RuleRepository(); // Here is for the scriptedAssembly ... // repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly)); // Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model // var customer = new Customer("John Doe") { IsPreferred = true }; // var order1 = new Order(123456, customer, 2, 25.0); // var order2 = new Order(123457, customer, 1, 100.0); //Insert facts into rules engine's memory // session.Insert(customer); // session.Insert(order1); // session.Insert(order2); //Start match/resolve/act cycle session.Fire(); }
public bool Shipped([FromBody] Shipment s) { Shipment shipment = _context.Shipment .Where(x => x.TrackingNumber == s.TrackingNumber) .FirstOrDefault(); shipment.IsFullShipment = true; //When the shipment is done, //then update the shipment _context.Shipment.Update(shipment); SalesOrder salesOrder = _context.SalesOrder.Where(s1 => s1.SalesOrderId == shipment.SalesOrderId).Single(); Customer customer = _context.Customer.Where(cust => cust.CustomerId == salesOrder.CustomerId).Single(); salesOrder.OrderProgressTypeId = OrderProgressStatus.CLOSED; //rule start var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); var factory = repository.Compile(); var session = factory.CreateSession(); session.Insert(salesOrder); session.Fire(); //rule end _context.SaveChanges(); return(true); }
public void RuleRepositoryExtension_Compile_CancellationRequested() { using (var cancellationSource = new CancellationTokenSource()) { // Arrange var ruleCompiler = new RuleCompiler(); var rule1 = CreateRuleDefinitionMock(); var rule2 = CreateRuleDefinitionMock(); rule2.Setup(r => r.LeftHandSide).Returns(() => { cancellationSource.Cancel(); return(new AndElement(Enumerable.Empty <RuleElement>())); }); var rule3 = CreateRuleDefinitionMock(); var rules = new RuleSet("R1"); rules.Add(new[] { rule1.Object, rule2.Object, rule3.Object }); var ruleRepository = new RuleRepository(); ruleRepository.Add(rules); // Act ruleRepository.Compile(cancellationSource.Token); // Assert rule1.Verify(r => r.LeftHandSide, Times.AtLeastOnce); rule2.Verify(r => r.LeftHandSide, Times.AtLeastOnce); rule3.Verify(r => r.LeftHandSide, Times.Never); } }
private static void Main(string[] args) { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model var ToWinMarket = new Market("ToWin"); var Scoreboard = new Scoreboard(); //Insert facts into rules engine's memory session.Insert(ToWinMarket); session.Insert(Scoreboard); //Start match/resolve/act cycle //session.Update(ToWinMarket); session.Fire(); foreach (Participant part in ToWinMarket.Participants) { Console.WriteLine(part.Description + " - " + part.isWinner); } Console.ReadLine(); }
protected void SetupRule <T>() where T : Rule { var repository = new RuleRepository(); repository.Load(x => x.NestedTypes().PrivateTypes().From(xx => xx.Type(typeof(T)))); Factory = repository.Compile(); }
public void Execute(AddressValueObject address) { RuleRepository repository = new RuleRepository(); repository.Load(x => x.From(typeof(AddressRule).Assembly)); ISessionFactory factory = repository.Compile(); ISession session = factory.CreateSession(); session.Insert(address); session.Fire(); }
public void Execute(CustomerEntity customer) { RuleRepository repository = new RuleRepository(); repository.Load(x => x.From(typeof(CustomerRule).Assembly)); ISessionFactory factory = repository.Compile(); ISession session = factory.CreateSession(); session.Insert(customer); session.Fire(); }
private void RunRule(SalesOrder salesOrder) { //rule start var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); var factory = repository.Compile(); var session = factory.CreateSession(); session.Insert(salesOrder); session.Fire(); //rule end }
public RuleService() { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(UserShouldBeBornIn1984Rule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session this.RulesSession = factory.CreateSession(); }
public ISessionFactory InitializeEngine() { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(TestRule).Assembly)); //Compile rules return(repository.Compile()); //Create a working session //return factory.CreateSession(); }
private void setupRuleEngine() { var ruleRepo = new RuleRepository(); ruleRepo.Load(x => x.From(typeof(PeriodicRuleEngine).Assembly)); // rules are (should be ?) in the same assembly as PeriodicRuleEngine ISessionFactory factory = ruleRepo.Compile(); engineSession = factory.CreateSession(); engineSession.DependencyResolver = new AspNetCoreDepResolver(serviceProvider); }
public static void BeforeTest() { var repository = new RuleRepository(); repository.Load(x => x.From(typeof(NotifyDevelopersAboutMissingEstimateRule).Assembly)); factory = repository.Compile(); container = new Container(); container.Register(typeof(IHandle <>), typeof(CommandHandler)); container.Register(() => factory); container.Verify(); factory.DependencyResolver = new SimpleInjectorDependencyResolver(container); }
static void Main(string[] args) { //Load rules var repository = new RuleRepository(); //repository.Load(x => x.From(Assembly.GetExecutingAssembly())); repository.Load(x => x.From(typeof(ActiveCustomerAccountRule).Assembly)); repository.Load(x => x.From(typeof(PerfCustDiscountRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load domain model var customer1 = new Customer("John Doe") { IsPreferred = true }; var account11 = new Account("12456789", customer1); var account12 = new Account("12456790", customer1); var account13 = new Account("12456791", customer1) { IsActive = false, IsDelinquent = true }; var order11 = new Order(123456, customer1, 2, 25.0); var order12 = new Order(123457, customer1, 1, 100.0); var order13 = new Order(123458, customer1, 1, 5.0); var customer2 = new Customer("Sarah Jones"); var account21 = new Account("22456789", customer2); var order21 = new Order(223456, customer2, 2, 2225.0); //Insert facts into rules engine's memory session.Insert(customer1); session.Insert(account11); session.Insert(account12); session.Insert(account13); session.Insert(order11); session.Insert(order12); session.Insert(order13); session.Insert(customer2); session.Insert(account21); session.Insert(order21); //Start match/resolve/act cycle session.Update(customer1); session.Fire(); }
private static void Main(string[] args) { var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); ISessionFactory factory = repository.Compile(); ISession session = factory.CreateSession(); session.Insert(new Fact1 { TestProperty = "Valid Value" }); VisualizerHost.Visualize(session); }
public void SetUp() { _firedRulesMap = new Dictionary <string, List <AgendaEventArgs> >(); _ruleMap = new Dictionary <Type, IRuleMetadata>(); Repository = new RuleRepository { Activator = new InstanceActivator() }; SetUpRules(); ISessionFactory factory = Repository.Compile(); Session = factory.CreateSession(); Session.Events.RuleFiredEvent += (sender, args) => _firedRulesMap[args.Rule.Name].Add(args); }
public void SetUp() { _notifiers = new Dictionary <Type, Mock <INotifier> >(); _rules = new List <BaseRule>(); SetUpRules(); var repository = new RuleRepository { Activator = new InstanceActivator(_rules) }; repository.Load("Test", x => x.From(_rules.Select(r => r.GetType()).ToArray())); ISessionFactory factory = repository.Compile(); Session = factory.CreateSession(); }
public void RunProject() { //Load rules var repository = new RuleRepository(); //repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly)); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Start match/resolve/act cycle session.Fire(); }
public SchemaValidator() { Validation = new List <ValidationContext>(); _fields = new FieldList(); var repository = new RuleRepository(); repository.Load(x => x.Where(r => r.IsTagged("FieldValidation"))); repository.Load(x => x.From(typeof(NullFieldRule).Assembly)); var factory = repository.Compile(); _session = factory.CreateSession(); _session.Events.RuleFiredEvent += OnRuleFiredEventHandler; }
public void Execute(Patient patient) { var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); var factory = repository.Compile(); var session = factory.CreateSession(); //Load Domain session.Insert(patient); session.Fire(); }
public void OneTimeSetup() { mail = Substitute.For <IMailService>(); var repository = new RuleRepository(); repository.Load(x => x.From(typeof(NotifyDevelopersAboutMissingEstimateRule).Assembly)); factory = repository.Compile(); container = new Container(); container.Register(typeof(IHandle <>), typeof(CommandHandler)); container.Register(() => factory); container.Register(() => mail); container.Verify(); factory.DependencyResolver = new SimpleInjectorDependencyResolver(container); }
static void Main(string[] args) { //Load the rules var repository = new RuleRepository(); repository.Load(x => x.From(typeof(Program).Assembly)); //Compile the rule var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); //Load model var passenger1 = new Passenger("Rajkumar", Gender.Male, 39) { IsSeniorCitizen = true }; var passenger2 = new Passenger("Selvakumar", Gender.Male, 61); var passenger3 = new Passenger("Nancy", Gender.Female, 62); var passenger4 = new Passenger("Jenifer", Gender.Female, 4); // To insert the fact into rule engine memory session.Insert(passenger1); session.Insert(passenger2); session.Insert(passenger3); session.Insert(passenger4); //Start rule validation Console.WriteLine("Running rules:"); session.Fire(); var errorList = session.Query <string>().ToList(); if (errorList.Count > 0) { Console.WriteLine("=============="); } foreach (var item in errorList) { Console.WriteLine(item); } Console.Read();//To show the validation message in console }
public void BootStrapEngine() { var rulesRepo = new RuleRepository(); try { Assembly targetassembly = RuleEngineHelper.GetRuleAssembly(typeof(Rule)); rulesRepo.Load(x => x.From(targetassembly)); var factory = rulesRepo.Compile(); _session = factory.CreateSession(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Run(List <Node> nodes) { //Load rules var repository = new RuleRepository(); repository.Load(x => x.From(Assembly.GetExecutingAssembly())); //Compile rules var factory = repository.Compile(); //Create a working session var session = factory.CreateSession(); session.Events.RuleFiringEvent += OnRuleFiringEvent; foreach (var node in nodes) { session.Insert(node); } session.Fire(); }