Example #1
0
        protected override void Execute(IRuleContext context)
        {
            var text  = (string)ReadProperty(context.Target, PrimaryProperty);
            var count = text.Length;

            context.AddOutValue(AffectedProperties[1], count);
        }
Example #2
0
        protected override void Execute(IRuleContext context)
        {
            var birthdate = (DateTime)context.InputPropertyValues[PrimaryProperty];
            int age       = (int)(DateTime.Today - birthdate).TotalDays / 365;

            context.AddOutValue(AgeProperty, age);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        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);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        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());
            }
        }
Example #9
0
        /// <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);
            }
        }
Example #10
0
        /// <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);
            }
        }
Example #11
0
            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();
            }
Example #12
0
        /// <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();
            });
        }
Example #13
0
        /// <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);
            }
        }
Example #14
0
        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);
        }
Example #15
0
        /// <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);
            }
        }
Example #16
0
        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();
        }
Example #17
0
            protected override void Execute(IRuleContext context)
            {
                var value = (string)context.InputPropertyValues[PrimaryProperty];

                context.AddOutValue(PrimaryProperty, value.ToUpperInvariant());
            }
Example #18
0
            protected override async Task ExecuteAsync(IRuleContext context)
            {
                await Task.Delay(0);

                context.AddOutValue("abc");
            }
Example #19
0
        protected override void Execute(IRuleContext context)
        {
            var source = context.GetInputValue(_sourceProperty);

            context.AddOutValue(source);
        }
Example #20
0
        protected override void Execute(IRuleContext context)
        {
            var source = context.GetInputValue(_sourceProperty);

            context.AddOutValue(Math.Round(source * _fraction, 2, MidpointRounding.AwayFromZero));
        }
Example #21
0
        protected override void Execute(IRuleContext context)
        {
            var val = context.GetInputValue(_primaryProperty);

            context.AddOutValue(_affectedProperty, val + 1);
        }