protected override void Execute(IRuleContext context) { var text = (string)ReadProperty(context.Target, PrimaryProperty); var count = text.Length; context.AddOutValue(AffectedProperties[1], count); }
protected override void Execute(IRuleContext context) { var birthdate = (DateTime)context.InputPropertyValues[PrimaryProperty]; int age = (int)(DateTime.Today - birthdate).TotalDays / 365; context.AddOutValue(AgeProperty, age); }
/// <summary> /// Look up State and set the state name /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(IRuleContext context) { var stateId = (string)context.InputPropertyValues[PrimaryProperty]; var state = DataPortal.Fetch <StatesNVL>().Where(p => p.Key == stateId).FirstOrDefault(); context.AddOutValue(StateName, state == null ? "Unknown state" : state.Value); }
/// <summary> /// Look up State and set the state name /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(IRuleContext context) { var stateId = (string)context.InputPropertyValues[PrimaryProperty]; var state = App.ApplicationContext.GetRequiredService <IDataPortal <StatesNVL> >().Fetch().Where(p => p.Key == stateId).FirstOrDefault(); context.AddOutValue(StateName, state == null ? "Unknown state" : state.Value); }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(IRuleContext context) { // Use linq Sum to calculate the sum value dynamic sum = context.InputPropertyValues.Aggregate <KeyValuePair <IPropertyInfo, object>, dynamic>(0, (current, item) => current + (dynamic)item.Value); // add calculated value to OutValues // When rule is completed the RuleEngine will update businessobject context.AddOutValue(PrimaryProperty, sum); }
protected override void Execute(IRuleContext context) { // Use linq Sum to calculate the sum value var sum = context.InputPropertyValues.Sum(property => (dynamic)property.Value); // add calculated value to OutValues // When rule is completed the RuleEngig will update businessobject context.AddOutValue(PrimaryProperty, sum); }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(IRuleContext context) { var id = (int)context.InputPropertyValues[PrimaryProperty]; // use a command or read-only object for lookup var lookup = LookupCustomerCommand.Execute(id); context.AddOutValue(NameProperty, lookup.Name); }
protected override void Execute(IRuleContext context) { //modify property value, to upper var val1 = (string)context.InputPropertyValues[PrimaryProperty]; if (!string.IsNullOrEmpty(val1)) { context.AddOutValue(PrimaryProperty, val1.ToUpper()); } }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(IRuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; context.AddOutValue(PrimaryProperty, value.ToUpper()); if (context.IsCheckRulesContext) { Console.WriteLine(".... Rule {0} running from CheckRules", this.GetType().Name); } else { Console.WriteLine(".... Rule {0} running from {1} was changed", this.GetType().Name, this.PrimaryProperty.Name); } }
/// <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 cn = (string)context.InputPropertyValues[PrimaryProperty]; var bw = new System.ComponentModel.BackgroundWorker(); bw.RunWorkerCompleted += (o, e) => { context.AddOutValue(_nameProperty, string.Format("customer name {0}", cn)); context.Complete(); }; bw.DoWork += (o, e) => { Thread.Sleep(50); }; 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(); }); }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context"> /// Rule context object. /// </param> protected override void Execute(IRuleContext context) { // Use linq Sum to calculate the sum value var sum = context.InputPropertyValues.Sum(property => (dynamic)property.Value); // add calculated value to OutValues // When rule is completed the RuleEngine will update businessobject context.AddOutValue(PrimaryProperty, sum); if (context.IsCascadeContext) { Console.WriteLine(".... Rule {0} running from affected property or input property", this.GetType().Name); } else if (context.IsCheckRulesContext) { Console.WriteLine(".... Rule {0} running from CheckRules", this.GetType().Name); } else { Console.WriteLine(".... Rule {0} running from {2} was changed", this.GetType().Name, this.PrimaryProperty.Name); } }
protected override async Task ExecuteAsync(IRuleContext context) { var customerId = (int)context.InputPropertyValues[PrimaryProperty]; await Task.Delay(200); string name; switch (customerId) { case 1: name = "Rocky Lhotka"; break; default: name = string.Format("Customer_{0}", customerId); break; } context.AddOutValue(NameProperty, name); context.Complete(); context.AddSuccessResult(false); }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context"> /// Rule context object. /// </param> protected override void Execute(IRuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; if (string.IsNullOrEmpty(value)) { return; } var newValue = value.Trim(' '); var r = new Regex(@" +"); newValue = r.Replace(newValue, @" "); context.AddOutValue(newValue); if (context.IsCheckRulesContext) { Console.WriteLine(".... Rule {0} running from CheckRules", this.GetType().Name); } else { Console.WriteLine(".... Rule {0} running from {1} was changed", this.GetType().Name, this.PrimaryProperty.Name); } }
protected override void Execute(IRuleContext context) { var customerId = (int)context.InputPropertyValues[PrimaryProperty]; var bw = new BackgroundWorker(); bw.DoWork += (o, e) => Thread.Sleep(200); bw.RunWorkerCompleted += (o, e) => { string name; switch (customerId) { case 1: name = "Rocky Lhotka"; break; default: name = string.Format("Customer_{0}", customerId); break; } context.AddOutValue(NameProperty, name); context.Complete(); }; bw.RunWorkerAsync(); }
protected override void Execute(IRuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; context.AddOutValue(PrimaryProperty, value.ToUpperInvariant()); }
protected override async Task ExecuteAsync(IRuleContext context) { await Task.Delay(0); context.AddOutValue("abc"); }
protected override void Execute(IRuleContext context) { var source = context.GetInputValue(_sourceProperty); context.AddOutValue(source); }
protected override void Execute(IRuleContext context) { var source = context.GetInputValue(_sourceProperty); context.AddOutValue(Math.Round(source * _fraction, 2, MidpointRounding.AwayFromZero)); }
protected override void Execute(IRuleContext context) { var val = context.GetInputValue(_primaryProperty); context.AddOutValue(_affectedProperty, val + 1); }