Exemplo n.º 1
0
        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));
                }
            }
        }
Exemplo n.º 2
0
            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();
                }
            }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        /// <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));
            }
        }
Exemplo n.º 6
0
            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();
            }
Exemplo n.º 7
0
            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();
                //}
            }
Exemplo n.º 8
0
            protected override void Execute(IRuleContext context)
            {
                var target = (Foo)context.Target;

                if (target.Name == "2")
                {
                    context.AddErrorResult("Name can not be 2");
                }
            }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        protected override void Execute(IRuleContext context)
        {
            var text = (string)ReadProperty(context.Target, PrimaryProperty);

            if (text.ToLower().Contains("z"))
            {
                context.AddErrorResult("No letter Z allowed");
            }
        }
Exemplo n.º 11
0
            protected override void Execute(IRuleContext context)
            {
                var cust = (Customer)context.Target;

                if (cust.Zipcode == "12345")
                {
                    context.AddErrorResult("private rule failed");
                }
            }
Exemplo n.º 12
0
        /// <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));
            }
        }
Exemplo n.º 13
0
        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");
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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();
            });
        }
Exemplo n.º 16
0
 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));
         }
     }
 }
Exemplo n.º 17
0
            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");
                }
            }
Exemplo n.º 18
0
            /// <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");
                }
            }
Exemplo n.º 19
0
        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));
                }
            }
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
            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");
                //}
            }
Exemplo n.º 22
0
            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();
            }
Exemplo n.º 23
0
            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();
            }
Exemplo n.º 24
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();
            });
        }
Exemplo n.º 25
0
        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!");
            }
        }
Exemplo n.º 26
0
        /// <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);
        }
Exemplo n.º 28
0
 protected override void Execute(IRuleContext context)
 {
     context.AddErrorResult("Broken: " + PrimaryProperty.FriendlyName);
 }
Exemplo n.º 29
0
 private void TestRuleAction(IRuleContext context)
 {
     context.AddErrorResult("lambda rule broken");
 }