protected override async void Execute(Csla.Rules.IRuleContext 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.IRuleContext context) { var bw = new System.ComponentModel.BackgroundWorker(); bw.DoWork += (o, e) => { 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 void Execute(Csla.Rules.IRuleContext 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.IRuleContext 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.IRuleContext context) { var bb = (BusinessBase)context.Target; if (!bb.IsNew) { base.Execute(context); } }
protected override void Execute(Csla.Rules.IRuleContext context) { var bb = (BusinessBase)context.Target; if (bb.CanWriteProperty(PrimaryProperty)) { base.Execute(context); } }
protected override void Execute(Csla.Rules.IRuleContext context) { var target = (Csla.Core.BusinessBase)context.Target; if (!target.CanReadProperty(PrimaryProperty)) { context.AddInformationResult("Not allowed to read property"); } }
protected override void Execute(Csla.Rules.IRuleContext context) { var obj = (CustomerEdit)context.Target; if (obj.BrokenRulesCollection.Where(c => c.Property == PrimaryProperty.Name).Count() > 0) { context.AddInformationResult(null, true); } }
protected override void Execute(Csla.Rules.IRuleContext context) { var input = (string)context.InputPropertyValues[PrimaryProperty]; if (string.IsNullOrEmpty(input)) { context.AddOutValue(_clearProperty, null); } }
protected override void Execute(Csla.Rules.IRuleContext 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.IRuleContext context) { var sender = (Root)context.Target; using (sender.BypassPropertyChecks) { var value = (string)context.InputPropertyValues[PrimaryProperty]; if (!string.IsNullOrEmpty(value)) { context.AddOutValue(PrimaryProperty, value.ToUpper()); } } }
protected override void Execute(Csla.Rules.IRuleContext 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 async override void Execute(Csla.Rules.IRuleContext 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.IRuleContext 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(); }