public void Run(Payment payment) { var rules = RuleFactory.GetRules(payment); var evaaluator = new RuleEvaluator(rules); evaaluator.ExecuteRules(); }
/// <summary> /// Verify the specified credentials in the system /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="verifiedUser"></param> /// <returns></returns> public MethodResult <bool> VerifyUserCredentials(string username, string password, out User verifiedUser) { verifiedUser = null; var engine = RuleEvaluator <string> .New(); engine.ReSetup() .Register(new NotNullOrEmptyString()) .Execute(username); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <bool> >(username); return(_result); } engine.ReSetup() .Register(new NotNullOrEmptyString()) .Execute(password); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <bool> >(); return(_result); } User _verifiedUser; var _isVerifiedUser = BussinesProcesses.VerifyUserCredentials(username, password, out _verifiedUser); verifiedUser = _verifiedUser; return(BussinesProcesses.VerifyUserCredentials(username, password, out verifiedUser)); }
public void TestRuleEvaluation() { var desirability = this.GetDesirabilitySet(); var distance = this.GetDistanceToTargetSet(); var ammo = this.GetAmmoStatusSet(); var rocketLaucherRules = this.GetRocketLauncherRules(); FuzzyValueSet inputs = new FuzzyValueSet(); distance.Evaluate(200f, inputs); ammo.Evaluate(8f, inputs); IRuleEvaluator <Desirability> ruleEvaluator = new RuleEvaluator <Desirability>(); var result = ruleEvaluator.EvaluateRules(new List <FuzzyRule <Desirability> >(rocketLaucherRules), inputs); this.AssertFuzzyValue <Desirability>(Desirability.Desirable, 0.0f, result[0]); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.33f, result[1]); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.2f, result[2]); this.AssertFuzzyValue <Desirability>(Desirability.VeryDesirable, 0.0f, result[3]); this.AssertFuzzyValue <Desirability>(Desirability.VeryDesirable, 0.67f, result[4]); this.AssertFuzzyValue <Desirability>(Desirability.Desirable, 0.2f, result[5]); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.0f, result[6]); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.0f, result[7]); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.0f, result[8]); }
public void ReturnsEmptyLogIfnoRules() { var evaluator = new RuleEvaluator(new List <IPaymentRule>()); var actual = evaluator.Run(new Payment { }); Assert.Empty(actual); }
public void RunRulesOnAnOrderAndReturnRuleLog() { var evaluator = new RuleEvaluator(new List <IPaymentRule>()); var actual = evaluator.Run(new Payment { }); Assert.IsType(typeof(List <RuleLog>), actual); }
public RuleSteps() { var rules = new List <IPaymentRule>() { new PhysicalProductRule(), new BookRule(), new MemberShipRule(), new MemberShipUpgradeRule(), new VideoRule() }; this.ruleEvaluator = new RuleEvaluator(rules); }
public void SkipNotApplicableRules() { var paymentRule = new Mock <IPaymentRule>(); paymentRule.Setup(r => r.IsApplicable(It.IsAny <Item>())).Returns(false); paymentRule.Verify(r => r.Apply(It.IsAny <Item>()), Times.AtMostOnce()); var evaluator = new RuleEvaluator(new List <IPaymentRule>()); var actual = evaluator.Run(new Payment { }); paymentRule.Verify(r => r.Apply(It.IsAny <Item>()), Times.Never()); }
/// <summary> /// Register a new user /// </summary> /// <param name="user"></param> /// <param name="shouldNotify"></param> public MethodResult <int> Register(User user, bool shouldNotify = true) { var engine = RuleEvaluator <User> .New(); engine.Register(new NewUserValidationContainer(() => UserRepository.IsExistingUser(user.Username))) .Execute(user); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <int> >(user); return(_result); } return(BussinesProcesses.Register(user, shouldNotify)); }
/// <summary> /// Check if an user is exiting (check is done by both username and email) /// </summary> /// <param name="requestingUser"></param> /// <param name="user"></param> /// <returns></returns> public MethodResult <bool> IsExistingUser(User requestingUser, User user) { var engine = RuleEvaluator <User> .New(); engine.Register(new ExistingUserValidationContainer()) .Execute(user); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <bool> >(); return(_result); } return(BussinesProcesses.IsExistingUser(requestingUser, user)); }
/// <summary> /// Returns user by its username /// </summary> /// <param name="username"></param> /// <returns></returns> public MethodResult <User> GetUserByUsername(string username) { var engine = RuleEvaluator <User> .New(); engine.Register(new UsernameMatchingSpecification()) .Execute(new User { Username = username }); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <User> >(username); return(_result); } return(BussinesProcesses.GetUserByUsername(username)); }
/// <summary> /// Get content by id /// </summary> /// <param name="requestingUser"></param> /// <param name="id"></param> /// <returns></returns> public MethodResult <User> GetById(User requestingUser, int id) { var engine = RuleEvaluator <User> .New(); engine.Register(new UserIdMatchingSpecification()) .Execute(new User { Id = id }); if (!engine.ExecutionResult.Result) { var _result = engine.ExecutionResult.CreateFaultedResponse <MethodResult <User> >(); return(_result); } return(BussinesProcesses.GetById(requestingUser, id)); }
private void buttonPrecheck_Click(object sender, EventArgs e) { try { List <Rule> rules = RulesReader.readRules(); RuleEvaluator evaluator = new RuleEvaluator(rules); RuleInterpreter interpreter = new RuleInterpreter(settings.SmallBlind, settings.BigBlind); DateTime startCheck = DateTime.Now; interpreter.precheck(rules); Log.Info("# prechecking rules took " + DateTime.Now.Subtract(startCheck).TotalMilliseconds + " ms"); } catch (Exception ex) { ErrorHandler.ReportException(ex, "precheck rules"); MessageBox.Show(ex.Message, "Error Precheck", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void TestValueMergeByOr() { var desirability = this.GetDesirabilitySet(); var distance = this.GetDistanceToTargetSet(); var ammo = this.GetAmmoStatusSet(); var rocketLaucherRules = this.GetRocketLauncherRules(); FuzzyValueSet inputs = new FuzzyValueSet(); distance.Evaluate(200f, inputs); ammo.Evaluate(8f, inputs); IRuleEvaluator <Desirability> ruleEvaluator = new RuleEvaluator <Desirability>(); var ruleOutputs = ruleEvaluator.EvaluateRules(new List <FuzzyRule <Desirability> >(rocketLaucherRules), inputs); IFuzzyValuesMerger <Desirability> merger = new CachedOutputsFuzzyValuesMerger <Desirability>(); FuzzyValueSet mergedValues = new FuzzyValueSet(); merger.MergeValues(ruleOutputs, mergedValues); this.AssertFuzzyValue <Desirability>(Desirability.Undesirable, 0.33f, mergedValues.Get(Desirability.Undesirable)); this.AssertFuzzyValue <Desirability>(Desirability.Desirable, 0.2f, mergedValues.Get(Desirability.Desirable)); this.AssertFuzzyValue <Desirability>(Desirability.VeryDesirable, 0.67f, mergedValues.Get(Desirability.VeryDesirable)); }
public static void Main(string[] args) { Log.SetLevel(Log.Level.FINE); BotAppLogic.Beep(settings); Point offset; Iterator <Image> screen; DeviceControl deviceControl; if (INPUT_MODE == InputMode.WIN32) { Console.WriteLine("## win32 mode ##"); deviceControl = new Win32Control(); // wait Log.Info("waiting ..."); Thread.Sleep(10000); // full screen Console.WriteLine("## scanning for table ##"); Image fullScreen = new ScreenImageIterator(deviceControl).next(); offset = PatternLocator.locateTable(fullScreen); Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y); // desk screen = new ScreenImageIterator(deviceControl, new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height)); screen = new WaitDeltaImageIterator(screen); } else if (INPUT_MODE == InputMode.VM) { Console.WriteLine("## vm mode ##"); // boot deviceControl = new VirtualBoxControl(BotAppLogic.ReadConfig()["vm"]); // poker Console.WriteLine("waiting for pokerstars ..."); Console.ReadKey(); // mouse deviceControl.ResetMouse(); // full screen Console.WriteLine("## scanning for table ##"); Image fullScreen = new ScreenImageIterator(deviceControl).next(); offset = PatternLocator.locateTable(fullScreen); Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y); // desk screen = new ScreenImageIterator(deviceControl, new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height)); screen = new WaitDeltaImageIterator(screen); } else { Console.WriteLine("## mock mode ##"); screen = new MockWaitImageIterator(1000, ImageTools.toImage(new Bitmap("test/table_check_free.png"))); offset = new Point(renderer.Control.Location.X + 5, renderer.Control.Location.Y + 15); deviceControl = new Win32Control(); } // identifier TableLayout layout = new TableLayout9(offset); TableIdentifier tableIdentifier = new TableIdentifier(layout); tableIdentifier.Renderer = renderer; // evaluator List <Rule> rules = RulesReader.readRules(); RuleEvaluator evaluator = new RuleEvaluator(rules); RuleInterpreter interpreter = new RuleInterpreter(settings.SmallBlind, settings.BigBlind); // controller double betSlideTextLimit = settings.PlayMoney ? 100 : 0.2; Mouse mouse = new HumanMouse(deviceControl); Keyboard keyboard = new Keyboard(deviceControl); Controller controller = new Controller(keyboard, mouse, betSlideTextLimit, tableIdentifier, new ScreenImageIterator(deviceControl)); // replayer Replayer replayer = new Replayer(deviceControl); // auto-click RandomClicker clicker = new RandomClicker(new Point(deviceControl.DisplayWidth, 0), mouse); // initial table Console.WriteLine("## initial table scan ##"); string player = BotAppLogic.ReadConfig()["name"]; Console.WriteLine("looking for '" + player + "'"); int seat = -1; /*while (seat == -1) * { * Table previousTable = tableIdentifier.identifyTable(screen.next(), TableIdentifier.PlayerInfoEnum.BOTH); * seat = BotAppLogic.IdentifySeat(previousTable, player); * Thread.Sleep(1000); * } * Console.WriteLine("my seat = " + (seat+1)); */ seat = 4; // loop while (screen.hasNext()) { // start Console.WriteLine("## iteration -> start ##"); DateTime start = DateTime.Now; // table Console.WriteLine("# next table image"); Image tableImage = screen.next(); // render table renderer.clearImages(); renderer.renderImage(tableImage, 0, 0); // identify table //try //{ if (tableIdentifier.identifyMove(tableImage)) { Table table = tableIdentifier.identifyTable(tableImage, seat); List <TableControl> controls = tableIdentifier.identifyControls(tableImage); table.MaxBet = BotAppLogic.GetMaxBet(controls); TableContainer container = new TableContainer(0, null, null, layout, seat, false, null); new BotAppLogic(deviceControl).ProcessTable(settings, tableImage, renderer, table, container, evaluator, interpreter, controller, replayer, clicker, controls); } else { BotAppLogic.Sleep(settings, 1000); } /*} * catch(Exception ex) * { * Console.WriteLine("Unable to identify table"); * Console.WriteLine(ex.ToString()); * Thread.Sleep(5000); * continue; * }*/ // end double time = DateTime.Now.Subtract(start).TotalMilliseconds; Console.WriteLine("## iteration -> end -> " + time + " ms ##"); } }
public InlineRule(RuleEvaluator ruleEvaluator) { _ruleEvaluator = ruleEvaluator; }
public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args) { using (new MailboxRulesPerformanceTracker(this.stopwatch)) { StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args; if (storeDriverDeliveryEventArgsImpl.IsPublicFolderRecipient) { MailboxRulesAgent.tracer.TraceDebug(0L, "Will not process rules in transport for public folder."); } else { this.testMessageConfig = this.GetTestMessageConfig(storeDriverDeliveryEventArgsImpl); this.evaluationContext = this.CreateEvaluationContext(storeDriverDeliveryEventArgsImpl); this.evaluationContext.PropertiesForAllMessageCopies = storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies; this.evaluationContext.PropertiesForDelegateForward = storeDriverDeliveryEventArgsImpl.PropertiesForDelegateForward; this.evaluationContext.SharedPropertiesBetweenAgents = storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents; this.evaluationContext.ShouldSkipMoveRule = storeDriverDeliveryEventArgsImpl.ShouldSkipMoveRule; this.evaluationContext.SenderAddress = this.GetSenderSmtpAddress(storeDriverDeliveryEventArgsImpl); if (!this.ShouldProcessRuleInTransport(storeDriverDeliveryEventArgsImpl)) { this.evaluationContext.TraceDebug("Skipping inbox rules processing."); this.HandleTestMessage(storeDriverDeliveryEventArgsImpl); } else { this.SetCalculatedProperties(storeDriverDeliveryEventArgsImpl.ReplayItem); RuleEvaluator ruleEvaluator = new RuleEvaluator(this.evaluationContext); this.evaluationResult = ruleEvaluator.Evaluate(); storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents = this.evaluationContext.SharedPropertiesBetweenAgents; if (this.testMessageConfig.SuppressDelivery) { this.HandleTestMessage(storeDriverDeliveryEventArgsImpl); } this.evaluationResult.Execute(ExecutionStage.OnPromotedMessage); if (this.evaluationResult.TargetFolder != null) { this.evaluationContext.TraceDebug(string.Format("Target folder name: {0}, ID: {1}.", this.evaluationResult.TargetFolder.DisplayName, this.evaluationResult.TargetFolder.Id)); MailboxSession mailboxSession = this.evaluationContext.StoreSession as MailboxSession; if (mailboxSession != null) { StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox); if (!this.evaluationResult.TargetFolder.Id.ObjectId.Equals(defaultFolderId)) { this.evaluationContext.TraceDebug("Setting delivery folder."); storeDriverDeliveryEventArgsImpl.SetDeliveryFolder(this.evaluationResult.TargetFolder); } else { this.evaluationContext.TraceDebug("DeliverToFolder is same as inbox folder."); } } if (storeDriverDeliveryEventArgsImpl.DeliverToFolder == null || storeDriverDeliveryEventArgsImpl.DeliverToFolder.Equals(this.evaluationResult.TargetFolder.Id)) { storeDriverDeliveryEventArgsImpl.RetentionPolicyTag = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(StoreObjectSchema.PolicyTag); storeDriverDeliveryEventArgsImpl.RetentionPeriod = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(StoreObjectSchema.RetentionPeriod); storeDriverDeliveryEventArgsImpl.RetentionFlags = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags); storeDriverDeliveryEventArgsImpl.ArchiveTag = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(StoreObjectSchema.ArchiveTag); storeDriverDeliveryEventArgsImpl.ArchivePeriod = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(StoreObjectSchema.ArchivePeriod); storeDriverDeliveryEventArgsImpl.CompactDefaultRetentionPolicy = this.evaluationResult.TargetFolder.GetValueOrDefault <object>(FolderSchema.RetentionTagEntryId); } } else { this.HandleTestMessage(storeDriverDeliveryEventArgsImpl); SmtpResponse smtpResponseForBounceCode = this.GetSmtpResponseForBounceCode(this.evaluationResult.BounceCode, storeDriverDeliveryEventArgsImpl); if (!this.evaluationResult.FolderResults.Any((FolderEvaluationResult folderResult) => folderResult.WorkItems.Any((WorkItem workItem) => workItem is DelegateWorkItem)) || !ObjectClass.IsMeetingMessage(storeDriverDeliveryEventArgsImpl.ReplayItem.ClassName) || !MeetingMessage.IsDelegateOnlyFromSession(storeDriverDeliveryEventArgsImpl.MailboxSession)) { throw new SmtpResponseException(smtpResponseForBounceCode, base.Name); } storeDriverDeliveryEventArgsImpl.ShouldCreateItemForDelete = true; storeDriverDeliveryEventArgsImpl.BounceSmtpResponse = smtpResponseForBounceCode; storeDriverDeliveryEventArgsImpl.BounceSource = base.Name + ".DelegateAccess"; } } } } }