public string GetRuleDefinition(JObject ruleName) { string ruleNameStr = ruleName.ToObject <Name>().name; if (NullString(ruleNameStr)) { return("false"); } Rule rule = RulesManager.GetRuleByName(ruleNameStr).Value; RuleDefinition ruleDefinition = new RuleDefinition() { entityName = rule.EntityName, priority = rule.Priority, ruleName = rule.RuleName, ruleCondition = rule.RuleCondition, ruleGroup = rule.RuleGroup }; ruleDefinition.ruleExecution = new List <RuleExecutionDefinition>(); foreach (var ruleExecution in rule.RuleExecution) { ruleDefinition.ruleExecution.Add(new RuleExecutionDefinition() { propertyName = ruleExecution.PropertyName, execution = ruleExecution.Execution, order = ruleExecution.Order }); } return(JsonConvert.SerializeObject(ruleDefinition)); }
public void Execute() { Console.Write("Rule name: "); string ruleName = Console.ReadLine(); RulesManager manager = new RulesManager(); Rule rule = manager.Find(ruleName); if (rule != null) { Console.Write("Address: "); string address = Console.ReadLine(); if (rule.AddAddress(address)) { if (manager.Update(rule)) { Console.WriteLine("Address added successfully."); return; } Console.WriteLine("Rules file is not loaded."); return; } Console.WriteLine("Address is already contained in the rule."); return; } Console.WriteLine("Rule not found."); return; }
public IHttpActionResult ExecuteRuleGroup(ExecuteRuleDefinition executeRuleDefinition) { object entity = executeRuleDefinition.entity; string ruleGroupName = executeRuleDefinition.ruleName; return(Ok(RulesManager.ExecuteRuleGroup(ruleGroupName, entity))); }
public void AnyEmployeeWithOneShift() { RulesManager rm = new RulesManager(); rm.Initialize(@"C:\Projects\X.Scheduler\API\X.Scheduler\bin\Debug\netcoreapp3.1\"); List <int> inputList = new List <int>(); Random rnd = new Random(); for (int i = 0; i < 28; i++) { inputList.Add(rnd.Next(0, 9)); } List <int> resultList = new List <int>(); resultList = rm.ApplyRules(inputList, 9); foreach (var item in resultList) { int count = resultList.Where(x => x.Equals(item)).Count(); if (count.Equals(1)) { Assert.Fail(); } } }
public void AnyEmployeeWithTwoDaysSecondShift() { RulesManager rm = new RulesManager(); rm.Initialize(@"C:\Projects\X.Scheduler\API\X.Scheduler\bin\Debug\netcoreapp3.1\"); List <int> inputList = new List <int>(); Random rnd = new Random(); for (int i = 0; i < 28; i++) { inputList.Add(rnd.Next(0, 9)); } List <int> resultList = new List <int>(); resultList = rm.ApplyRules(inputList, 9); int index = 0; foreach (var item in resultList) { while (index > 0 && index % 2 == 0 && item.Equals(resultList[index - 2])) { Assert.Fail(); } index++; } }
/// <summary> /// Validation Rules will be executed if they are defined. /// </summary> /// <param name="rcvData"></param> /// <returns></returns> private bool executeValidationRules(TAdapterOutput rcvData, ICollection <ValidationRuleDescriptor> validatorRules, out ValidatorRulesResult validationResult) { validationResult = new ValidatorRulesResult(); if (validatorRules != null) { // TODO Log. ValidationRulesPipeline pipeline = new ValidationRulesPipeline() { EntityInstance = rcvData, Rules = validatorRules }; validationResult = RulesManager.RunPipeline(pipeline); } if ((validationResult != null && validationResult.HasFailed == false) || validationResult == null) { return(true); } else { return(false); } }
public void WaitForClose() { Task collectorTask = CollectorManager.WaitForCloseToCompleteAsync(); Task rulesTask = RulesManager.WaitForCloseToCompleteAsync(); Task.WaitAll(collectorTask, rulesTask); }
public void Execute() { Console.Write("Rule name: "); string ruleName = Console.ReadLine(); RulesManager manager = new RulesManager(); Rule rule = manager.Find(ruleName); if (rule != null) { Console.Write($"({rule.LocationFolderName} override) \n"); Console.Write("Folder name: "); string folderName = Console.ReadLine(); Folder folder = Folder.Find(folderName); if (folder != null) { rule.LocationFolderName = folder.Name; int mailsMoved = rule.Execute(); if (mailsMoved > -1) { Console.Write($"Moved {mailsMoved} mail "); Console.Write($"from {rule.LocationFolderName} "); Console.Write($"to {rule.DestinationFolderName} \n"); return; } } Console.WriteLine("Folder was not found."); } Console.WriteLine("Rule was not found."); }
//The IsTrading flag is the only state variable that is not reset by the rule that sets it override protected bool ExcuteRuleLogic() { if (BotState.IsAfterTerminateTime || BotState.IsReset) { RulesManager.Reset(); BotState.IsTrading = false; return(true); } return(false); }
void Awake() { // Only allow one in a scene if (g != null) { DestroyImmediate(gameObject); return; } g = this; }
void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } }
public string DeleteRule(JObject ruleName) { string ruleNameStr = ruleName.ToObject <Name>().name; if (NullString(ruleNameStr)) { return("false"); } RulesManager.DeleteRule(ruleNameStr); return("true"); }
public void Apply_should_apply_rules_for_new_membership() { //arrange var manager = new RulesManager(); var notify = new Mock <INotification <NewMembership> >(); var membership = Helpers.GetNewMembership(notify.Object); //act manager.Process(membership); //assert notify.Verify(n => n.SendNotification(membership), Times.Once()); }
void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); }
// Use this for initialization void Start() { if (manager == null) { RulesManager.manager = this; } else { Destroy(this); } turnTimeLeft = turnTime; }
public void Execute() { Console.Write("Rule name: "); string ruleName = Console.ReadLine(); RulesManager manager = new RulesManager(); if (manager.Remove(ruleName)) { Console.WriteLine("Rule removed succesfully!"); return; } Console.WriteLine("Something when wrong."); }
public void Apply_should_apply_rules_for_active_membership() { //arrange var manager = new RulesManager(); var notify = new Mock <INotification <ActiveMembership> >(); var membership = Helpers.GetActiveMembership(notify.Object); //act manager.Process(membership); //assert notify.Verify(n => n.SendNotification(membership), Times.Once()); Assert.True(DateTime.Now.AddDays(ActiveMembership._days).Date == membership.ExpiryDate.Date); }
public void Start() { _logger()?.Information("Manager Start Called"); _logger()?.Information("Starting Collector..."); CollectorManager.Start(); _logger()?.Information("Collector Starting Completed"); _logger()?.Information("Starting Rules..."); RulesManager.StartAsync().Wait(); _logger()?.Information("Rules Starting Completed"); _logger()?.Information("Starting Reports..."); ReportsManager.Start(); _logger()?.Information("Rules Starting Completed"); _logger()?.Information("Manager Start Completed"); }
public static async Task RunTestWithConfig(ILogger logger, string logFilePath, string configDir) { //string rootPath = configDir; string repositoryConfigPath = $"{configDir}{Path.DirectorySeparatorChar}repository.xml.config"; string machineSubscriptionsPath = $"{configDir}{Path.DirectorySeparatorChar}machines.xml.config"; string _loggingPath = $"{logFilePath}{Path.DirectorySeparatorChar}RulesEngine{Path.DirectorySeparatorChar}"; ILogger sublogger = new LoggerConfiguration() .WriteTo.Async(a => a.Logger(logger)) .WriteTo.Async(a => a.File($"{_loggingPath}Log_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.log").MinimumLevel.Verbose()) .MinimumLevel.Verbose() .CreateLogger(); sublogger.Information("{Class}.{Method} is Starting...", $"{nameof(RAL)}{nameof(RulesEngine)}{nameof(ConsoleTest)}{nameof(Program)}", nameof(RunTestNonConfig)); RulesManager rulesManager = new RulesManager(); var RepositoryConfig = new RepositoryFactory().LoadFrom(repositoryConfigPath).Config; var rulesFactory = new RulesFactory(sublogger) .LoadFromFile(machineSubscriptionsPath) .WithLogger(sublogger) .WithRepository( new RepositoryForRules( new MachineRepository( RepositoryConfig.DatabaseIPaddress, RepositoryConfig.DatabaseName, Convert.ToInt32(RepositoryConfig.DatabasePort) ) ) ); var rules = rulesFactory.Build(); rules = rulesManager.Rules = rules; await rulesManager.StartAsync(); sublogger.Information("{Class}.{Method} Waiting Indefinitely...", $"{nameof(RAL)}{nameof(RulesEngine)}{nameof(ConsoleTest)}{nameof(Program)}", nameof(RunTestNonConfig)); await Task.Run(() => rulesManager.WaitForStop()); //await rulesManager.StopAsync(); sublogger.Information("{Class}.{Method} Closing...", $"{nameof(RAL)}{nameof(RulesEngine)}{nameof(ConsoleTest)}{nameof(Program)}", nameof(RunTestNonConfig)); }
public TrafficLightUserControlViewModel() { RulesManager rules = new RulesManager { States = new Dictionary <int, int>() { { (int)PotentialStates.getReady, 2000 }, { (int)PotentialStates.go, 5000 }, { (int)PotentialStates.revertingToDefault, 2000 } }, DefaultState = (int)PotentialStates.stop }; this.trafficLight = new TrafficLight(); this.trafficLightManager = new TrafficLightManager(trafficLight, rules); trafficLight.PropertyChanged += (s, e) => SetColors(); }
public void Apply_should_not_apply_rules_for_videocontent() { //arrange var manager = new RulesManager(); var video = Helpers.GetVideContent(); video.IsELearning = false; //act manager.Process(video); //assert Assert.NotNull(video); Assert.DoesNotContain(video.CurrentOrder.Items, o => o is FreeVideoContent); }
public void Apply_should_not_apply_rules_for_active_completed_membership() { //arrange var notification = new Mock <INotification <ActiveMembership> >(); var manager = new RulesManager(); var membership = Helpers.GetActiveMembership(notification.Object); membership.ItemStatus = Status.Completed; //act manager.Process(membership); //assert notification.Verify(n => n.SendNotification(membership), Times.Never()); }
public void Apply_should_apply_rules_for_videocontent() { //arrange var manager = new RulesManager(); var video = Helpers.GetVideContent(); //book.ItemStatus = Status.Completed; //act manager.Process(video); //assert Assert.NotNull(video); Assert.Contains(video.CurrentOrder.Items, o => o is FreeVideoContent); }
public void Apply_should_not_apply_rules_for_completed_book() { //arrange var manager = new RulesManager(); var book = Helpers.GetBook(); book.ItemStatus = Status.Completed; //act manager.Process(book); //assert Assert.NotNull(book); Assert.True(book.PackingSlips == default(List <Packingslip>)); Assert.True(book.Agent?.CommissionEarned == 0); }
public void should_be_return_invalid_rules_if_pilot_are_alone_with_stewardess() { var passengers = new List <IPassenger>() { new PassengerBuilder().IsPilot().Create(), new PassengerBuilder().IsStewardess().Create() }; var airplane = new Airplane(passengers); var rulesManager = new RulesManager(airplane); rulesManager.ValidateRules(); rulesManager.IsValid().Should().BeFalse(); rulesManager.Errors.Any().Should().BeTrue(); }
public void Execute() { RulesManager manager = new RulesManager(); List <Rule> rules = manager.Values(); Console.Write($"{"Name", -10}\t"); Console.Write($"{"Location", -20}\t"); Console.Write($"{"Destination", -20}\t"); Console.Write($"{"Addresses", -10}\n"); foreach (Rule rule in rules) { Console.Write($"{rule.Name, -10}\t"); Console.Write($"{rule.LocationFolderName, -20}\t"); Console.Write($"{rule.DestinationFolderName,-20}\t"); Console.Write($"{rule.AddressesCount, -10}\n"); } }
public void should_be_return_invalid_rules_if_cabin_chief_are_alone_with_flight_official() { var passengers = new List <IPassenger>() { new PassengerBuilder().IsCabinChief().Create(), new PassengerBuilder().IsFlightOfficer().Create() }; var airplane = new Airplane(passengers); var rulesManager = new RulesManager(airplane); rulesManager.ValidateRules(); rulesManager.IsValid().Should().BeFalse(); rulesManager.Errors.Any().Should().BeTrue(); }
public void Apply_should_apply_rules_for_product() { //arrange var manager = new RulesManager(); var product = Helpers.GetProduct(); //act manager.Process(product); //assert Assert.NotNull(product); Assert.NotEmpty(product.PackingSlips); Assert.True(product.PackingSlips.Last().IsOriginal); Assert.NotNull(product.PackingSlips.Last().Id); Assert.True(product.Agent?.CommissionEarned == (float)(product.ItemPrice * 0.05)); }
public void Execute() { Console.Write("Rule name: "); string ruleName = Console.ReadLine(); RulesManager manager = new RulesManager(); Rule rule = manager.Find(ruleName); if (rule != null) { Console.Write("Folder name: "); string folderName = Console.ReadLine(); rule.LocationFolderName = folderName; manager.Update(rule); return; } Console.WriteLine("Rule not found."); return; }
public void Apply_should_apply_rules_for_book() { //arrange var manager = new RulesManager(); var book = Helpers.GetBook(); //act manager.Process(book); //assert Assert.NotNull(book); Assert.NotEmpty(book.PackingSlips); Assert.True(book.PackingSlips.First().IsOriginal); Assert.NotNull(book.PackingSlips.First().Id); Assert.True(!book.PackingSlips.Last().IsOriginal); Assert.NotNull(book.PackingSlips.Last().Id); Assert.True(book.Agent?.CommissionEarned == (float)(book.ItemPrice * 0.05)); }
public string AddUpdateRule(JObject ruleDefinition) { var o = ruleDefinition.ToObject <RuleDefinition>(); if (NullString(o.entityName) || NullString(o.ruleName) || NullString(o.ruleCondition) || NullString(o.ruleGroup)) { return("false"); } Rule rule = new Rule() { EntityName = o.entityName, Priority = o.priority, RuleName = o.ruleName, RuleCondition = o.ruleCondition, RuleGroup = o.ruleGroup }; rule.RuleExecution = new List <RuleExecution>(); foreach (var ruleExecution in o.ruleExecution) { if (NullString(ruleExecution.propertyName) || NullString(ruleExecution.execution)) { return("false"); } rule.RuleExecution.Add(new RuleExecution() { PropertyName = ruleExecution.propertyName, Execution = ruleExecution.execution, Order = ruleExecution.order }); } RulesManager.AddorUpdateRule(rule); return("true"); }