protected override void Execute(RuleContext context) { var activityIdValue = (int)context.InputPropertyValues[PrimaryProperty]; var activityStatusProperty = this.InputProperties.Single(p => p.Name == this.StatusName); var activtyStatusValue = (ActivitySubmissionStatus)context.InputPropertyValues[activityStatusProperty]; var approvedByIdProperty = this.InputProperties.Single(p => p.Name == this.ApprovedByIdName); var approvedByIdValue = (ActivitySubmissionStatus)context.InputPropertyValues[approvedByIdProperty]; if (approvedByIdValue == 0 && (activtyStatusValue == ActivitySubmissionStatus.Unset || activtyStatusValue == ActivitySubmissionStatus.AwaitingApproval || activtyStatusValue == ActivitySubmissionStatus.Approved)) { try { var activityTask = Task.Run(() => IoC.Container.Resolve<IObjectFactory<IActivityEdit>>().FetchAsync(activityIdValue)); var activity = activityTask.Result; context.AddOutValue(activityStatusProperty, activity.RequiresApproval ? ActivitySubmissionStatus.AwaitingApproval : ActivitySubmissionStatus.Approved); } catch (Exception) { context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.CurrentCulture, "Activity id {0} was not able to be retrieved.", activityIdValue)); } } }
/// <summary> /// Look up State and set the state name /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { var stateId = (string)context.InputPropertyValues[PrimaryProperty]; var state = StatesNVL.GetNameValueList().Where(p => p.Key == stateId).FirstOrDefault(); context.AddOutValue(StateName, state == null ? "Unknown state" : state.Value); }
protected override void Execute(RuleContext context) { //modify property value, to upper var val1 = (string)context.InputPropertyValues[PrimaryProperty]; if (!string.IsNullOrEmpty(val1)) context.AddOutValue(PrimaryProperty, val1.ToUpper()); }
protected override void Execute(RuleContext context) { var activityIdValue = (int)context.InputPropertyValues[PrimaryProperty]; var activityStatusProperty = this.InputProperties.Single(p => p.Name == this.StatusName); var activtyStatusValue = (ActivitySubmissionStatus)context.InputPropertyValues[activityStatusProperty]; var approvedByIdProperty = this.InputProperties.Single(p => p.Name == this.ApprovedByIdName); var approvedByIdValue = (ActivitySubmissionStatus)context.InputPropertyValues[approvedByIdProperty]; if (approvedByIdValue == 0 && (activtyStatusValue == ActivitySubmissionStatus.Unset || activtyStatusValue == ActivitySubmissionStatus.AwaitingApproval || activtyStatusValue == ActivitySubmissionStatus.Approved)) { try { var activityTask = Task.Run(() => IoC.Container.Resolve <IObjectFactory <IActivityEdit> >().FetchAsync(activityIdValue)); var activity = activityTask.Result; context.AddOutValue(activityStatusProperty, activity.RequiresApproval ? ActivitySubmissionStatus.AwaitingApproval : ActivitySubmissionStatus.Approved); } catch (Exception) { context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.CurrentCulture, "Activity id {0} was not able to be retrieved.", activityIdValue)); } } }
/// <summary> /// Business rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { object value = context.InputPropertyValues[PrimaryProperty]; var message = string.Format(GetMessage(), PrimaryProperty.FriendlyName); var newValue = Convert.ToString(value); var words = newValue.Split(' '); if (words.Length > 3) { context.Results.Add(new RuleResult(RuleName, PrimaryProperty, message) { Severity = RuleSeverity.Error }); } else { context.Results.Add(new RuleResult(RuleName, PrimaryProperty, message) { Severity = RuleSeverity.Information }); } context.AddOutValue(newValue); }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext 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); }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(RuleContext 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(RuleContext 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(RuleContext 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); }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(RuleContext 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> /// Business or validation rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { if (context == null) return; var input = context.InputPropertyValues[PrimaryProperty] as int?; if (input.HasValue && input.Value <= 0) context.AddOutValue(null); }
protected override void Execute(RuleContext context) { //modify property value, to upper var val1 = (string)context.InputPropertyValues[PrimaryProperty]; if (!string.IsNullOrEmpty(val1)) { context.AddOutValue(PrimaryProperty, val1.ToUpper()); } }
/// <summary> /// Business rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { var value = (string) context.InputPropertyValues[PrimaryProperty]; if (string.IsNullOrEmpty(value)) return; var newValue = value.Trim(); var r = new Regex(@"\s+"); newValue = r.Replace(newValue, @" "); context.AddOutValue(PrimaryProperty, newValue); }
/// <summary> /// Rule implementation. /// </summary> /// <param name="context">Rule context.</param> protected override void Execute(RuleContext context) { var valueAsString = (string) context.InputPropertyValues[PrimaryProperty]; if (valueAsString != null && valueAsString.IsNotEmpty()) { if (!valueAsString.IsUpper()) { context.AddOutValue(PrimaryProperty, valueAsString.ToUpper()); } } }
/// <summary> /// Rule implementation. /// </summary> /// <param name="context">Rule context.</param> protected override void Execute(RuleContext context) { var valueAsString = (string)context.InputPropertyValues[PrimaryProperty]; if (valueAsString != null && valueAsString.IsNotEmpty()) { if (!valueAsString.IsLower()) { context.AddOutValue(PrimaryProperty, valueAsString.ToLower()); } } }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; if (string.IsNullOrEmpty(value)) { return; } var newValue = value.ToLower(); context.AddOutValue(PrimaryProperty, newValue); }
protected override void Execute(RuleContext context) { var pollDeletedFlagProperty = this.InputProperties[0]; var isActiveProperty = this.InputProperties[1]; var pollDeletedFlag = context.InputPropertyValues[pollDeletedFlagProperty] as bool?; var isActive = (bool)context.InputPropertyValues[isActiveProperty]; if (pollDeletedFlag != null && pollDeletedFlag.Value) { context.AddErrorResult(pollDeletedFlagProperty, "The poll is deleted."); context.AddOutValue(isActiveProperty, false); } }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(RuleContext 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> /// Business rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; if (string.IsNullOrEmpty(value)) { return; } var newValue = value.Trim(); var r = new Regex(@"\s+"); newValue = r.Replace(newValue, @" "); context.AddOutValue(PrimaryProperty, newValue); }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context"> /// Rule context object. /// </param> protected override void Execute(RuleContext 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(RuleContext context) { var dateProperty = this.InputProperties[0]; var value = context.InputPropertyValues[dateProperty]; if (value != null) { if (typeof(DateTime?).GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo())) { var nullableDate = value as DateTime?; if (nullableDate != null) { context.AddOutValue(dateProperty, nullableDate.Value.ToUniversalTime()); } } else if (typeof(DateTime).GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo())) { var date = (DateTime)context.InputPropertyValues[dateProperty]; context.AddOutValue(dateProperty, date.ToUniversalTime()); } } }
protected override void Execute(RuleContext context) { var badgeTypeValue = (BadgeType)context.InputPropertyValues[PrimaryProperty]; var badgeStatusProperty = this.InputProperties.Single(p => p.Name == this.StatusName); var badgeStatusValue = (BadgeStatus)context.InputPropertyValues[badgeStatusProperty]; var approvedByIdProperty = this.InputProperties.Single(p => p.Name == this.ApprovedByIdName); var approvedByIdValue = (int)context.InputPropertyValues[approvedByIdProperty]; if (approvedByIdValue == 0 && (badgeStatusValue == BadgeStatus.AwaitingApproval || badgeStatusValue == BadgeStatus.Approved || badgeStatusValue == BadgeStatus.Unset)) { context.AddOutValue(badgeStatusProperty, badgeTypeValue == BadgeType.Community ? BadgeStatus.AwaitingApproval : BadgeStatus.Approved); } }
protected override void Execute(RuleContext context) { var pollEndDateProperty = this.InputProperties[0]; var isActiveProperty = this.InputProperties[1]; var pollEndDate = (DateTime)context.InputPropertyValues[pollEndDateProperty]; var isActive = (bool)context.InputPropertyValues[isActiveProperty]; var now = DateTime.UtcNow; if (pollEndDate < now) { context.AddErrorResult(pollEndDateProperty, "The poll has ended."); context.AddOutValue(isActiveProperty, false); } }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context"> /// Rule context object. /// </param> protected override void Execute(RuleContext 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 void Execute(RuleContext 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(RuleContext 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> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> protected override void Execute(RuleContext 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(RuleContext 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); } }
/// <summary> /// Business rule implementation. /// </summary> /// <param name="context">Rule context object.</param> protected override void Execute(RuleContext context) { object value = context.InputPropertyValues[PrimaryProperty]; var newValue = Convert.ToString(value); if (!string.IsNullOrEmpty(newValue)) { newValue = newValue.Replace(" ", string.Empty); newValue = newValue.ToUpper(); if (!CheckFormat(newValue)) { var message = string.Format(GetMessage(), PrimaryProperty.FriendlyName); context.Results.Add(new RuleResult(RuleName, PrimaryProperty, message) { Severity = Severity }); } context.AddOutValue(newValue); } }
/// <summary> /// Business or validation rule implementation. /// </summary> /// <param name="context"> /// Rule context object. /// </param> protected override void Execute(RuleContext 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(RuleContext 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(RuleContext context) { var val = context.GetInputValue(_primaryProperty); context.AddOutValue(_affectedProperty, val + 1); }
protected override void Execute(RuleContext context) { var source = context.GetInputValue(_sourceProperty); context.AddOutValue(Math.Round(source * _fraction, 2, MidpointRounding.AwayFromZero)); }
protected override void Execute(RuleContext context) { var source = context.GetInputValue(_sourceProperty); context.AddOutValue(source); }
protected override void Execute(RuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; context.AddOutValue(PrimaryProperty, CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value)); }
protected override void Execute(RuleContext context) { var value = (int)context.InputPropertyValues[PrimaryProperty]; context.AddOutValue(PrimaryProperty, value * 17 / 100); }
protected override void Execute(RuleContext context) { var value = (string)context.InputPropertyValues[PrimaryProperty]; context.AddOutValue(PrimaryProperty, value.ToUpperInvariant()); }