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(); }
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(); }
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(); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (Payment)context.Target; if (PrimaryProperty.Name == "Consignee") { if (target.Consignee == null) { context.AddErrorResult("Consignee is required."); } } if (PrimaryProperty.Name == "ORNumber") { if (target.PaymentDetails != null) { var totalamountdue = target.PaymentDetails.Sum(x => x.AmountDue); var totalamountpaid = target.PaymentDetails.Sum(x => x.AmountPaid); if (target.ORNumber.Length == 0 && totalamountpaid > 0 && (totalamountpaid >= totalamountdue)) { context.AddErrorResult("OR Number is required."); } } } }
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(); }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (PaymentDetail)context.Target; if (target.AmountPaid == null) { context.AddErrorResult("Amount paid is required"); } else { if (target.AmountPaid > target.AmountDue) { context.AddErrorResult("Amount paid should not exceed amount due."); } } }
protected override void Execute(Csla.Rules.RuleContext context) { var val = (string)context.InputPropertyValues[PrimaryProperty]; if (!val.Contains(" ")) { context.AddErrorResult("Value must contain a space"); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (Porterage)context.Target; if (target.Vessel == null) { context.AddErrorResult("Vessel is required."); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (Foreign)context.Target; if (target.Consignee == null) { context.AddErrorResult("Consignee is required."); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (LineItem)context.Target; if (!target.IsNew) { context.AddErrorResult("Value may only be changed if item is new"); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (PDV)context.Target; //var od = (DateTime)ReadProperty(target, PDV.StartDateProperty); //var doo = (DateTime)ReadProperty(target, PDV.FinishDateProperty); if (target.StartDate > target.FinishDate) { context.AddErrorResult("The date is not correct"); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (ProjectEdit)context.Target; var started = target.ReadProperty(StartedProperty); var ended = target.ReadProperty(EndedProperty); if (started.HasValue && ended.HasValue && started > ended || !started.HasValue && ended.HasValue) { context.AddErrorResult("Start date can't be after end date"); } }
protected override void Execute(Csla.Rules.RuleContext context) { var ce = (CustomerEdit)context.Target; bool result = string.IsNullOrEmpty(ce.Name) || !(from c in ce.Name.ToCharArray() where char.IsDigit(c) select c).Any(); if (!result) { context.AddErrorResult("Name must consist of only letters."); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (ProjectEdit)context.Target; foreach (var item in target.Resources) { var count = target.Resources.Count(r => r.ResourceId == item.ResourceId); if (count > 1) { context.AddErrorResult("Duplicate resources not allowed"); return; } } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (RoleEdit)context.Target; RoleEditList parent = (RoleEditList)target.Parent; if (parent != null) { foreach (RoleEdit item in parent) { if (item.Id == target.ReadProperty(IdProperty) && !(ReferenceEquals(item, target))) { context.AddErrorResult("Role Id must be unique"); break; } } } }
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(); }
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(); }