39 public static class RuleExtensions
56 var target = (T)o.Target;
57 using (
new ObjectAccessor().BypassPropertyChecks(target))
59 if (!ruleHandler(target, ruleArgs))
61 o.Results.Add(
new RuleResult(o.Rule.RuleName, o.Rule.PrimaryProperty, ruleArgs.
Description) { Severity = ruleArgs.Severity, StopProcessing = ruleArgs.StopProcessing });
65 o.AddSuccessResult(
true);
69 o.AddSuccessResult(
false);
76 var methodName = Guid.NewGuid().ToString();
78 var methodName = ruleHandler.Method.ToString();
80 rule.AddQueryParameter(
"r", Convert.ToBase64String(Encoding.Unicode.GetBytes(methodName)));
81 rule.Priority = priority;
96 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), 0);
110 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), priority);
122 public static void AddRule<T>(
this BusinessRules businessRules, RuleHandler<T, RuleArgs> ruleHandler,
string primaryPropertyName,
int priority) where T :
BusinessBase<T>
124 if (
string.IsNullOrEmpty(primaryPropertyName))
throw new ArgumentException(
"primaryPropertyName");
126 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, primaryPropertyName);
127 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), priority);
140 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, args.
PropertyName);
141 AddRule(businessRules, ruleHandler, primaryProperty, args, 0);
155 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, args.
PropertyName);
156 AddRule(businessRules, ruleHandler, primaryProperty, args, priority);
168 public static void AddRule<T>(
this BusinessRules businessRules, RuleHandler<T, RuleArgs> ruleHandler,
string primaryPropertyName) where T :
BusinessBase<T>
170 if (
string.IsNullOrEmpty(primaryPropertyName))
throw new ArgumentException(
"primaryPropertyName");
172 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, primaryPropertyName);
173 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), 0);
192 using (
new ObjectAccessor().BypassPropertyChecks(target))
194 if (!ruleHandler(target, ruleArgs))
196 o.Results.Add(
new RuleResult(o.Rule.RuleName, o.Rule.PrimaryProperty, ruleArgs.
Description) { Severity = ruleArgs.Severity, StopProcessing = ruleArgs.StopProcessing });
200 o.AddSuccessResult(
true);
204 o.AddSuccessResult(
false);
211 var methodName = Guid.NewGuid().ToString();
213 var methodName = ruleHandler.Method.ToString();
215 rule.AddQueryParameter(
"r", Convert.ToBase64String(Encoding.Unicode.GetBytes(methodName)));
216 rule.Priority = priority;
230 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), 0);
243 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), priority);
254 public static void AddRule(
this BusinessRules businessRules,
RuleHandler ruleHandler,
string primaryPropertyName,
int priority)
256 if (
string.IsNullOrEmpty(primaryPropertyName))
throw new ArgumentException(
"primaryPropertyName");
257 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, primaryPropertyName);
258 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), priority);
271 if (
string.IsNullOrEmpty(primaryPropertyName))
throw new ArgumentException(
"primaryPropertyName");
273 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, primaryPropertyName);
274 AddRule(businessRules, ruleHandler, primaryProperty,
new RuleArgs(primaryProperty), 0);
286 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, args.
PropertyName);
287 AddRule(businessRules, ruleHandler, primaryProperty, args, 0);
300 var primaryProperty = PropertyHelper.GetRegisteredProperty(businessRules, args.
PropertyName);
301 AddRule(businessRules, ruleHandler, primaryProperty, args, priority);
315 if (propertyInfo ==
null)
throw new ArgumentNullException(
"propertyInfo");
316 if (dependentPropertyInfo ==
null)
throw new ArgumentNullException(
"dependentPropertyInfo");
332 AddDependentProperty(businessRules, propertyInfo, dependentPropertyInfo,
false);
342 public static void AddDependentProperty(
this BusinessRules businessRules,
string propertyName,
string dependentPropertyName)
344 AddDependentProperty(businessRules, propertyName, dependentPropertyName,
false);
355 public static void AddDependentProperty(
this BusinessRules businessRules,
string propertyName,
string dependentPropertyName,
bool isBidirectional)
357 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
358 var dependentPropertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, dependentPropertyName);
360 AddDependentProperty(businessRules, propertyInfo, dependentPropertyInfo, isBidirectional);
363 #region Add Per-Type Roles
378 public static void AllowRead(
this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params
string[] roles)
396 public static void AllowRead(
this BusinessRules businessRules,
string propertyName, params
string[] roles)
398 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
415 public static void DenyRead(
this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params
string[] roles)
433 public static void DenyRead(
this BusinessRules businessRules,
string propertyName, params
string[] roles)
435 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
452 public static void AllowWrite(
this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params
string[] roles)
470 public static void AllowWrite(
this BusinessRules businessRules,
string propertyName, params
string[] roles)
472 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
489 public static void DenyWrite(
this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params
string[] roles)
507 public static void DenyWrite(
this BusinessRules businessRules,
string propertyName, params
string[] roles)
509 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
526 public static void AllowExecute(
this BusinessRules businessRules, Core.IMemberInfo memberInfo, params
string[] roles)
544 public static void AllowExecute(
this BusinessRules businessRules,
string methodName, params
string[] roles)
563 public static void DenyExecute(
this BusinessRules businessRules, Core.IMemberInfo methodInfo, params
string[] roles)
581 public static void DenyExecute(
this BusinessRules businessRules,
string methodName, params
string[] roles)
600 public static bool HasReadAllowedRoles(
this BusinessRules businessRules,
string propertyName)
615 public static bool IsReadAllowed(
this BusinessRules businessRules,
string propertyName)
617 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
630 public static bool HasReadDeniedRoles(
this BusinessRules businessRules,
string propertyName)
645 public static bool IsReadDenied(
this BusinessRules businessRules,
string propertyName)
647 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
660 public static bool HasWriteAllowedRoles(
this BusinessRules businessRules,
string propertyName)
675 public static bool IsWriteAllowed(
this BusinessRules businessRules,
string propertyName)
677 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
690 public static bool HasWriteDeniedRoles(
this BusinessRules businessRules,
string propertyName)
705 public static bool IsWriteDenied(
this BusinessRules businessRules,
string propertyName)
707 var propertyInfo = PropertyHelper.GetRegisteredProperty(businessRules, propertyName);
720 public static bool HasExecuteAllowedRoles(
this BusinessRules businessRules,
string methodName)
735 public static bool IsExecuteAllowed(
this BusinessRules businessRules,
string methodName)
750 public static bool HasExecuteDeniedRoles(
this BusinessRules businessRules,
string methodName)
765 public static bool IsExecuteDenied(
this BusinessRules businessRules,
string methodName)
This is the non-generic base class from which most business objects will be derived.
Maintains metadata about a method.
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
void AddRule(IBusinessRuleBase rule)
Associates a business rule with the business object.
A rule that establishes a dependency between two properties.
IsInRole authorization rule.
IsNotInRole authorization rule.
A business rule defined by a lambda expression.
Contains information about the result of a rule.
Intermediate base class for BusinessBase
Object providing extra information to methods that implement business rules.
string Description
Set by the rule handler method to describe the broken rule.
string PropertyName
The name of the property to be validated.
bool StopProcessing
Gets or sets a value indicating whether this broken rule should stop the processing of subsequent rul...
Maintains metadata about a property.
AuthorizationActions
Authorization actions.
delegate bool RuleHandler< T, R >(T target, R e)
The delegate definition for CSLA 3.8 generic rule handler
delegate bool RuleHandler(object target, RuleArgs e)
The delegate definition for CSLA 3.8 rule handler