9using System.ComponentModel;
10using System.Collections.Generic;
56 [EditorBrowsable(EditorBrowsableState.Never)]
62 public object Target {
get;
internal set; }
77 [EditorBrowsable(EditorBrowsableState.Never)]
84 return _dirtyProperties.
Value;
93 [EditorBrowsable(EditorBrowsableState.Never)]
98 if (!_outputPropertyValues.IsValueCreated)
100 return _outputPropertyValues.Value;
108 private List<RuleResult> _results;
113 [EditorBrowsable(EditorBrowsableState.Never)]
118 if (_results ==
null)
119 _results =
new List<RuleResult>();
128 private readonly Action<IRuleContext> _completeHandler;
134 [EditorBrowsable(EditorBrowsableState.Never)]
152 if (
BusinessRules.CanRunRule(innerRule, chainedContext.ExecuteContext))
155 syncRule.Execute(chainedContext);
157 asyncRule.ExecuteAsync(chainedContext).ContinueWith((t) => { chainedContext.Complete(); });
159 throw new ArgumentOutOfRangeException(innerRule.GetType().FullName);
169 [EditorBrowsable(EditorBrowsableState.Never)]
181 [EditorBrowsable(EditorBrowsableState.Never)]
193 [EditorBrowsable(EditorBrowsableState.Never)]
205 [EditorBrowsable(EditorBrowsableState.Never)]
211 internal RuleContext(Action<IRuleContext> completeHandler)
213 _completeHandler = completeHandler;
218 internal RuleContext(Action<IRuleContext> completeHandler,
RuleContextModes executeContext) : this(completeHandler)
223 internal RuleContext(Action<IRuleContext> completeHandler, LazySingleton<Dictionary<IPropertyInfo, object>> outputPropertyValues, LazySingleton<List<IPropertyInfo>> dirtyProperties,
RuleContextModes executeContext)
225 _completeHandler = completeHandler;
226 _outputPropertyValues = outputPropertyValues;
227 _dirtyProperties = dirtyProperties;
238 public RuleContext(Action<IRuleContext> completeHandler,
IBusinessRuleBase rule,
object target, Dictionary<Csla.Core.IPropertyInfo, object> inputPropertyValues)
239 : this(completeHandler)
409 _outputPropertyValues.Value[property] = value;
418 [EditorBrowsable(EditorBrowsableState.Never)]
423 _dirtyProperties.
Value.Add(property);
435 _completeHandler?.Invoke(
this);
An alternative to Lazy<T>
T Value
Gets the instance.
bool IsValueCreated
Gets a value indicating whether this instance is initilized and contains a value.
A strongly-typed resource class, for looking up localized strings, etc.
static string PropertyNotInAffectedPropertiesException
Looks up a localized string similar to Property {0} must be added to AffectedProperties.
Maintains metadata about a property.
Tracks the business rules for a business object.
Context information provided to a business rule when it is invoked.
void AddWarningResult(string description)
Add a Warning severity result to the Results list.
void AddSuccessResult(bool stopProcessing)
Add a Success severity result to the Results list.
object Target
Gets a reference to the target business object.
Dictionary< Csla.Core.IPropertyInfo, object > OutputPropertyValues
Gets a dictionary containing copies of property values that should be updated in the target object.
List< IPropertyInfo > DirtyProperties
Gets a list of dirty properties (value was updated).
bool IsPropertyChangedContext
Gets a value indicating whether this instance is property changed context.
bool IsCheckObjectRulesContext
Gets a value indicating whether this instance is check object rules context.
void AddErrorResult(Csla.Core.IPropertyInfo property, string description)
Add a Error severity result to the Results list.
List< RuleResult > Results
Gets a list of RuleResult objects containing the results of the rule.
void AddWarningResult(string description, bool stopProcessing)
Add a Warning severity result to the Results list.
RuleContextModes ExecuteContext
Gets the execution context.
void AddErrorResult(string description)
Add a Error severity result to the Results list.
void AddWarningResult(Csla.Core.IPropertyInfo property, string description)
Add a Warning severity result to the Results list.
void AddErrorResult(string description, bool stopProcessing)
Add a Error severity result to the Results list.
bool TryGetInputValue< T >(PropertyInfo< T > propertyInfo, ref T value)
Tries to get the value.
void ExecuteRule(IBusinessRuleBase innerRule)
Executes the inner rule from the outer rules context.
void AddOutValue(Csla.Core.IPropertyInfo property, object value)
Add an outbound value to update a property on the business object once the rule is complete.
void Complete()
Indicates that the rule processing is complete, so CSLA .NET will process the Results list.
RuleContext(Action< IRuleContext > completeHandler, IBusinessRuleBase rule, object target, Dictionary< Csla.Core.IPropertyInfo, object > inputPropertyValues)
Creates a RuleContext instance for testing.
void AddDirtyProperty(Csla.Core.IPropertyInfo property)
Adds a property name as a dirty field (changed value).
void AddInformationResult(string description, bool stopProcessing)
Add an Information severity result to the Results list.
void AddInformationResult(string description)
Add an Information severity result to the Results list.
Dictionary< Csla.Core.IPropertyInfo, object > InputPropertyValues
Gets a dictionary containing copies of property values from the target business object.
IRuleContext GetChainedContext(IBusinessRuleBase rule)
Gets a new RuleContext object for a chained rule.
string OriginPropertyName
Gets or sets the name of the origin property.
bool IsCascadeContext
Gets a value indicating whether this instance is cascade context as a result of AffectedProperties.
void AddOutValue(object value)
Add an outbound value to update the rule's primary property on the business object once the rule is c...
IBusinessRuleBase Rule
Gets the rule object.
bool IsCheckRulesContext
Gets a value indicating whether this instance is check rules context.
void AddInformationResult(Csla.Core.IPropertyInfo property, string description)
Add an Information severity result to the Results list.
T GetInputValue< T >(PropertyInfo< T > propertyInfo)
Gets the value.
Contains information about the result of a rule.
string Name
Gets the member name value.
Maintains metadata about a property.
Interface defining a business/validation rule implementation.
Interface defining a business/validation rule implementation.
bool IsAsync
Gets a value indicating whether the Execute() method will run asynchronous code.
bool ProvideTargetWhenAsync
Gets a value indicating that the Target property should be set even for an async rule (note that usin...
List< Csla.Core.IPropertyInfo > AffectedProperties
Gets a list of properties affected by this rule.
Csla.Core.IPropertyInfo PrimaryProperty
Gets the primary property affected by this rule.
string RuleName
Gets a unique rule:// URI for the specific instance of the rule within the context of the business ob...
Interface defining a business/validation rule implementation.
Context information provided to a business rule when it is invoked.
RuleContextModes
RuleContext mode flags
@ PropertyChanged
Called from PropertyHasChanged event on BO but not including cascade calls by AffectedProperties
@ CheckObjectRules
Called from CheckObjectRules
@ AsAffectedPoperty
Include cascaded calls by AffectedProperties
@ CheckRules
Called from CheckRules
@ Any
Default value, rule can run in any context