Exemplo n.º 1
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                var target = (Roro)context.Target;

                if (!string.IsNullOrEmpty(target.ORNumber)) //&& target.Status.Id != CargoConstants.BillStatus.FullyPaid.Id
                {
                    CommandUniqueORNumber.Execute(target.Id, target.ORNumber, (o, e) =>
                    {
                        if (e.Error != null)
                        {
                            context.AddErrorResult(e.Error.Message, true);
                        }
                        else
                        {
                            if (!e.Object.IsValid)
                            {
                                context.AddErrorResult("ORNumber already exists.");
                            }
                        }
                        context.Complete();
                        target.OnUnknownPropertyChanged();
                    });
                }
                else
                {
                    context.Complete();
                }
            }
Exemplo n.º 2
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                var bw = new System.ComponentModel.BackgroundWorker();

                bw.DoWork += (o, e) =>
                {
                    System.Threading.Thread.Sleep(2500);
                    var  name   = (string)context.InputPropertyValues[PrimaryProperty];
                    bool result = string.IsNullOrEmpty(name) ||
                                  !(from c in name.ToCharArray()
                                    where char.IsDigit(c)
                                    select c)
                                  .Any();
                    if (!result)
                    {
                        context.AddErrorResult("Name must consist of only letters.");
                    }
                };
                bw.RunWorkerCompleted += (o, e) =>
                {
                    if (e.Error != null)
                    {
                        context.AddErrorResult(e.Error.Message);
                    }
                    context.Complete();
                };
                bw.RunWorkerAsync();
            }
Exemplo n.º 3
0
            protected override async void Execute(Csla.Rules.RuleContext context)
            {
                MyExpensiveCommand result = null;

                if (IsAsync)
                {
                    result = await MyExpensiveCommand.DoCommandAsync();
                }
                else
                {
                    result = MyExpensiveCommand.DoCommandAsync().Result;
                }
                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.º 4
0
 private static void HandleResult(Csla.Rules.RuleContext context, MyExpensiveCommand result)
 {
     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.º 5
0
            protected async override void Execute(Csla.Rules.RuleContext context)
            {
                var tcs = new TaskCompletionSource <bool>();

                new Task(() =>
                {
                    var name = (string)context.InputPropertyValues[PrimaryProperty];
                    tcs.SetResult(string.IsNullOrEmpty(name) ||
                                  !(from c in name.ToCharArray()
                                    where char.IsDigit(c)
                                    select c)
                                  .Any());
                }).Start();
                var result = await tcs.Task;

                if (!result)
                {
                    context.AddErrorResult("Name must consist of only letters.");
                }
                context.Complete();
            }
Exemplo n.º 6
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork             += (o, e) => Thread.Sleep(3000);
                worker.RunWorkerCompleted += (o, e) =>
                {
                    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!");
                    }
                    context.Complete();
                };
                worker.RunWorkerAsync();
            }