protected override void Execute(IRuleContext context) { var id = (string)context.InputPropertyValues[PrimaryProperty]; var key = (int)context.InputPropertyValues[PrimaryKeyProperty]; if (string.IsNullOrEmpty(id)) { context.AddErrorResult("Sales Order Type Id is required."); return; } if (SalesOrderTypeEdit.Exists(id) == false) { context.AddSuccessResult(false); } else { var Key = SalesOrderTypeEdit.GetKey(id); if (Key == key) { context.AddSuccessResult(false); } else { context.AddErrorResult(String.Format("Sales Order Type Id: {0} already exists.", id)); } } }
protected override void Execute(IRuleContext context) { if (Csla.ApplicationContext.LogicalExecutionLocation == Csla.ApplicationContext.LogicalExecutionLocations.Client) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { System.Threading.Thread.Sleep(2000); var value = context.InputPropertyValues[PrimaryProperty]; if (value == null || value.ToString().ToUpper() == "ERROR") { context.AddErrorResult("error detected"); } }; worker.RunWorkerCompleted += (s, e) => context.Complete(); // simulating an asynchronous process. worker.RunWorkerAsync(); } else { var value = context.InputPropertyValues[PrimaryProperty]; if (value == null || value.ToString().ToUpper() == "ERROR") { context.AddErrorResult("error detected"); } context.Complete(); } }
/// <summary> /// Rule implementation. /// </summary> /// <param name="context">Rule context.</param> protected override void Execute(IRuleContext context) { #if NETFX_CORE var ctx = new System.ComponentModel.DataAnnotations.ValidationContext(context.Target); #else var ctx = new System.ComponentModel.DataAnnotations.ValidationContext(context.Target, null, null); #endif if (PrimaryProperty != null) { ctx.MemberName = PrimaryProperty.FriendlyName; } System.ComponentModel.DataAnnotations.ValidationResult result = null; try { if (PrimaryProperty != null) { object value = context.InputPropertyValues[PrimaryProperty]; result = this.Attribute.GetValidationResult(value, ctx); } else { result = this.Attribute.GetValidationResult(null, ctx); } } catch (Exception ex) { context.AddErrorResult(ex.Message); } if (result != null) { context.AddErrorResult(result.ErrorMessage); } }
protected override void Execute(IRuleContext context) { var customerId = (int)ReadProperty(context.Target, RuleBaseClassesRoot.CustomerIdProperty); switch (customerId) { case 4: context.AddErrorResult(RuleBaseClassesRoot.NameProperty, "customer name required"); context.AddErrorResult(RuleBaseClassesRoot.CountryProperty, "country required"); context.AddErrorResult(RuleBaseClassesRoot.StateProperty, "state required"); break; case 5: context.AddWarningResult(RuleBaseClassesRoot.NameProperty, "customer name required"); context.AddWarningResult(RuleBaseClassesRoot.CountryProperty, "country required"); context.AddWarningResult(RuleBaseClassesRoot.StateProperty, "state required"); break; case 6: context.AddInformationResult(RuleBaseClassesRoot.NameProperty, "customer name required"); context.AddInformationResult(RuleBaseClassesRoot.CountryProperty, "country required"); context.AddInformationResult(RuleBaseClassesRoot.StateProperty, "state required"); break; } }
/// <summary> /// Does the check for primary propert less than compareTo property /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(IRuleContext context) { var value1 = (IComparable)context.InputPropertyValues[PrimaryProperty]; var value2 = (IComparable)context.InputPropertyValues[CompareTo]; if (value1.CompareTo(value2) >= 0) { context.AddErrorResult(string.Format("{0} must be less than {1}", PrimaryProperty.FriendlyName, CompareTo.FriendlyName)); context.AddErrorResult(CompareTo, string.Format("{0} must be larger than {1}", CompareTo.FriendlyName, PrimaryProperty.FriendlyName)); } }
protected override async void Execute(IRuleContext context) { var name = (string)context.InputPropertyValues[NameProperty]; NameExistsCommand.Execute(name, (result) => { if (result) { context.AddErrorResult(NameProperty, "Name already exists"); } }); context.Complete(); //---------------------------------------------------------------------------------- // Second Method //---------------------------------------------------------------------------------- //var cmd = await NameExistsCommand.ExecuteAsync(name); //if (cmd.isExist == true) //{ // context.AddErrorResult("Name already exists"); //} //context.Complete(); }
protected override async Task ExecuteAsync(IRuleContext context) { // TODO: I'm not sure how I would replicate this exact check in Csla 6. // For now, I've had to stop it running at all in the server-side portal - but this is not the same as before! // What the rule used to do was run everywhere but finish immediately if on the server, now it doesn't // run at all on the server :-( //if (Csla.ApplicationContext.LogicalExecutionLocation == Csla.ApplicationContext.LogicalExecutionLocations.Client) //{ await Task.Delay(2000); var value = context.InputPropertyValues[PrimaryProperty]; if (value == null || value.ToString().ToUpper() == "ERROR") { context.AddErrorResult("error detected"); } //} //else //{ // var value = context.InputPropertyValues[PrimaryProperty]; // if (value == null || value.ToString().ToUpper() == "ERROR") // context.AddErrorResult("error detected"); // context.Complete(); //} }
protected override void Execute(IRuleContext context) { var target = (Foo)context.Target; if (target.Name == "2") { context.AddErrorResult("Name can not be 2"); } }
protected override async Task ExecuteAsync(IRuleContext context) { var result = await MyExpensiveCommand.DoCommandAsync(); if (result == null) { context.AddErrorResult("Command failed to run"); } else if (result.Result) { context.AddInformationResult(result.ResultText); } else { context.AddErrorResult(result.ResultText); } context.Complete(); }
protected override void Execute(IRuleContext context) { var text = (string)ReadProperty(context.Target, PrimaryProperty); if (text.ToLower().Contains("z")) { context.AddErrorResult("No letter Z allowed"); } }
protected override void Execute(IRuleContext context) { var cust = (Customer)context.Target; if (cust.Zipcode == "12345") { context.AddErrorResult("private rule failed"); } }
/// <summary> /// Does the check for primary propert less than compareTo property /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(IRuleContext context) { var value1 = (dynamic)context.InputPropertyValues[PrimaryProperty]; var value2 = (dynamic)context.InputPropertyValues[CompareTo]; if (value1 > value2) { context.AddErrorResult(string.Format("{0} must be less than or equal {1}", PrimaryProperty.FriendlyName, CompareTo.FriendlyName)); } }
protected override async Task ExecuteAsync(IRuleContext context) { int role = (int)context.InputPropertyValues[PrimaryProperty]; var roles = await RoleList.CacheListAsync(); if (!roles.ContainsKey(role)) { context.AddErrorResult("Role must be in RoleList"); } }
protected override async Task ExecuteAsync(IRuleContext context) { var portal = context.ApplicationContext.GetRequiredService <IDataPortal <MyExpensiveCommand> >(); var cmd = portal.Create(); var result = await portal.ExecuteAsync(cmd); if (result == null) { context.AddErrorResult("Command failed to run"); } else if (result.Result) { context.AddInformationResult(result.ResultText); } else { context.AddErrorResult(result.ResultText); } }
protected override void Execute(IRuleContext context) { var value1 = (int)context.InputPropertyValues[PrimaryProperty]; var value2 = (string)context.InputPropertyValues[SecondaryProperty]; // uses the async methods in DataPortal to perform data access on a background thread. DuplicateCompanyCommand.BeginExecute(value1, value2, (o, e) => { if (e.Error != null) { context.AddErrorResult(string.Format("Error checking for duplicate company name. {0}", e.Error)); } else if (e.Object.IsDuplicate) { context.AddErrorResult("Duplicate company name."); } context.Complete(); }); }
protected override void Execute(IRuleContext context) { if (context.InputPropertyValues[PrimaryProperty] != null) { var val = (T)context.InputPropertyValues[PrimaryProperty]; if (!ListOfValues.Contains(val)) { context.AddErrorResult(string.Format("'{0}' is not in the list of expected values.", PrimaryProperty.FriendlyName)); } } }
protected override void Execute(IRuleContext context) { var target = (RoadmapGroupEdit)context.Target; var startYear = target.ReadProperty(StartYearProperty); var endYear = target.ReadProperty(EndYearProperty); if (startYear.ToString().Length == 4 && endYear.ToString().Length == 4 && startYear > endYear) { context.AddErrorResult("Start year can't be after end year"); } }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(IRuleContext context) { var bo = (Csla.Core.BusinessBase)context.Target; var name = (string)ReadProperty(context.Target, Root.NameProperty); if (string.IsNullOrEmpty(name)) { context.AddErrorResult(NameProperty, "Name is required."); } else if (name.Length > 50) { context.AddErrorResult(NameProperty, "Name cannot be longer then 50 chars."); } var num1 = (int)ReadProperty(context.Target, Root.Num1Property); if (num1 < 5) { context.AddErrorResult(Root.Num1Property, "Num1 must be larger than or equal to 5"); } }
protected override void Execute(IRuleContext context) { var optionalVal = (string)context.InputPropertyValues[OptionalProperty]; var requiredVal = (string)context.InputPropertyValues[RequiredProperty]; if (!string.IsNullOrEmpty(optionalVal)) { if (string.IsNullOrEmpty(requiredVal)) { context.AddErrorResult(string.Format("'{0}' is required since '{1}' has been set.", RequiredProperty.FriendlyName, OptionalProperty.FriendlyName)); } } }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override async Task ExecuteAsync(IRuleContext context) { var id = (int)context.InputPropertyValues[PrimaryProperty]; try { var cmd = await LookupCustomerCommand.ExecuteAsync(id); context.AddOutValue(NameProperty, cmd.Name); } catch (Exception ex) { context.AddErrorResult(ex.Message); } }
protected override void Execute(IRuleContext context) { var target = (RoadmapGroupEdit)context.Target; var endYear = target.ReadProperty(EndYearProperty); //var endYear = target.ReadProperty(EndYearProperty); if (endYear.ToString().Length != 4) { context.AddErrorResult("The end year has an incorrect value"); } //if (endYear.ToString().Length != 4) { // context.AddErrorResult("The end year has an incorrect value"); //} }
protected override void Execute(IRuleContext context) { var name = (string)context.InputPropertyValues[NameProperty]; if (string.IsNullOrEmpty(name)) { context.AddErrorResult(NameProperty, "Name required"); } //NameRequiredCommand.Execute(name, (result) => //{ // if (result) // { // context.AddErrorResult(NameProperty, "Name required"); // } //}); context.Complete(); }
protected override void Execute(IRuleContext context) { var bw = new System.ComponentModel.BackgroundWorker(); bw.DoWork += (o, e) => { throw new InvalidOperationException(); }; bw.RunWorkerCompleted += (o, e) => { if (e.Error != null) { context.AddErrorResult(e.Error.Message); } context.Complete(); }; bw.RunWorkerAsync(); }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(IRuleContext context) { var id = (int)context.InputPropertyValues[PrimaryProperty]; // uses the async methods in DataPortal to perform data access on a background thread. LookupCustomerCommand.BeginExecute(id, (o, e) => { if (e.Error != null) { context.AddErrorResult(e.Error.ToString()); } else { context.AddOutValue(NameProperty, e.Object.Name); } context.Complete(); }); }
protected override async Task ExecuteAsync(IRuleContext context) { await Task.Delay(3000); string val = (string)context.InputPropertyValues[PrimaryProperty]; if (val == "Error") { context.AddErrorResult("Invalid data!"); } else if (val == "Warning") { context.AddWarningResult("This might not be a great idea!"); } else if (val == "Information") { context.AddInformationResult("Just an FYI!"); } }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(IRuleContext context) { var name = (string)context.InputPropertyValues[PrimaryProperty]; // uses the async methods in DataPortal to perform data access on a background thread. //NameCustomerCommand.BeginExecute(name, (o, e) => //{ // if (e.Error != null) // throw e.Error; // else if(e.Object.IsExist) // context.AddErrorResult("Name already exist"); // context.Complete(); //}); var IsExist = NameCustomerCommand.Execute(name); if (IsExist) { context.AddErrorResult("Name already exist"); } }
protected override async Task ExecuteAsync(IRuleContext context) { string value; // Get the value of the property we are validating and check it has a value value = ReadProperty(context.InputPropertyValues, PrimaryProperty)?.ToString(); if (value is null) { // An object that has no value does not fail this rule context.AddSuccessResult(false); return; } // Peform the validation test on the value we have been provided CharacterSetValidator validator = context.ApplicationContext.CreateInstanceDI <CharacterSetValidator>(); if (!await validator.GetIsValidAsync(value, _allowedCharacterSetName)) { context.AddErrorResult($"{PrimaryProperty.FriendlyName} contains invalid characters!"); } // If all rules have been met then the property is valid context.AddSuccessResult(false); }
protected override void Execute(IRuleContext context) { context.AddErrorResult("Broken: " + PrimaryProperty.FriendlyName); }
private void TestRuleAction(IRuleContext context) { context.AddErrorResult("lambda rule broken"); }