/// <summary> /// Invokes all rules attached at the class level /// of the business type. /// </summary> /// <returns> /// Returns a list of property names affected by the invoked rules. /// The PropertyChanged event should be raised for each affected /// property. /// </returns> public List <string> CheckObjectRules() { if (_suppressRuleChecking) { return(new List <string>()); } var oldRR = RunningRules; RunningRules = true; var rules = from r in TypeRules.Rules where r.PrimaryProperty == null orderby r.Priority select r; BrokenRules.ClearRules(null); var affectedProperties = RunRules(rules); RunningRules = oldRR; if (!RunningRules && !RunningAsyncRules) { _target.AllRulesComplete(); } return(affectedProperties.Distinct().ToList()); }
/// <summary> /// Invokes all rules attached at the class level /// of the business type. /// </summary> /// <returns> /// Returns a list of property names affected by the invoked rules. /// The PropertyChanged event should be raised for each affected /// property. /// </returns> private List <string> CheckObjectRules(RuleContextModes executionContext, bool cascade) { if (_suppressRuleChecking) { return(new List <string>()); } var oldRR = RunningRules; RunningRules = true; var rules = from r in TypeRules.Rules where r.PrimaryProperty == null && CanRunRule(r, executionContext) orderby r.Priority select r; BrokenRules.ClearRules(null); // Changed to cascade propertyrule to make async ObjectLevel rules rerun PropertLevel rules. var firstResult = RunRules(rules, false, executionContext); // rerun property level rules for affected properties if (cascade) { var propertiesToRun = new List <Csla.Core.IPropertyInfo>(); foreach (var item in rules) { if (!item.IsAsync) { foreach (var p in item.AffectedProperties) { propertiesToRun.Add(p); } } } // run rules for affected properties foreach (var item in propertiesToRun.Distinct()) { var doCascade = false; if (CascadeOnDirtyProperties) { doCascade = firstResult.DirtyProperties.Any(p => p == item.Name); } firstResult.AffectedProperties.AddRange(CheckRulesForProperty(item, doCascade, executionContext | RuleContextModes.AsAffectedPoperty)); } } RunningRules = oldRR; if (!RunningRules && !RunningAsyncRules) { _target.AllRulesComplete(); } return(firstResult.AffectedProperties.Distinct().ToList()); }
/// <summary> /// Invokes all rules for a specific property. /// </summary> private List <string> CheckRulesForProperty(Csla.Core.IPropertyInfo property, bool cascade) { var rules = from r in TypeRules.Rules where ReferenceEquals(r.PrimaryProperty, property) orderby r.Priority select r; var affectedProperties = new List <string> { property.Name }; BrokenRules.ClearRules(property); affectedProperties.AddRange(RunRules(rules)); if (cascade) { // get properties affected by all rules var propertiesToRun = new List <Csla.Core.IPropertyInfo>(); foreach (var item in rules) { foreach (var p in item.AffectedProperties) { if (!ReferenceEquals(property, p)) { propertiesToRun.Add(p); } } } // run rules for affected properties foreach (var item in propertiesToRun.Distinct()) { CheckRulesForProperty(item, false); } } return(affectedProperties.Distinct().ToList()); }
/// <summary> /// Invokes all rules for a specific property. /// </summary> /// <param name="property">The property.</param> /// <param name="cascade">if set to <c>true</c> [cascade].</param> /// <param name="executionContext">The execute context.</param> /// <returns></returns> private List <string> CheckRulesForProperty(Csla.Core.IPropertyInfo property, bool cascade, RuleContextModes executionContext) { var rules = from r in TypeRules.Rules where ReferenceEquals(r.PrimaryProperty, property) && CanRunRule(r, executionContext) orderby r.Priority select r; BrokenRules.ClearRules(property); var firstResult = RunRules(rules, cascade, executionContext); if (CascadeOnDirtyProperties) { cascade = cascade || firstResult.DirtyProperties.Any(); } if (cascade) { // get properties affected by all rules var propertiesToRun = new List <Csla.Core.IPropertyInfo>(); foreach (var item in rules) { if (!item.IsAsync) { foreach (var p in item.AffectedProperties) { if (!ReferenceEquals(property, p)) { propertiesToRun.Add(p); } } } } // add PrimaryProperty where property is in InputProperties var input = from r in TypeRules.Rules where !ReferenceEquals(r.PrimaryProperty, property) && r.PrimaryProperty != null && r.InputProperties != null && r.InputProperties.Contains(property) select r.PrimaryProperty; foreach (var p in input) { if (!ReferenceEquals(property, p)) { propertiesToRun.Add(p); } } // run rules for affected properties foreach (var item in propertiesToRun.Distinct()) { var doCascade = false; if (CascadeOnDirtyProperties) { doCascade = firstResult.DirtyProperties.Any(p => p == item.Name); } firstResult.AffectedProperties.AddRange(CheckRulesForProperty(item, doCascade, executionContext | RuleContextModes.AsAffectedPoperty)); } } // always make sure to add PrimaryProperty firstResult.AffectedProperties.Add(property.Name); return(firstResult.AffectedProperties.Distinct().ToList()); }