/// <summary> /// Creates an instance of the object. /// </summary> /// <param name="rule">Instance of rule.</param> /// <param name="property">Property to which the rule is attached.</param> /// <param name="priority">Rule priority.</param> internal RuleMethod(IBusinessRule rule, Core.IPropertyInfo property, int priority) { Rule = rule; PrimaryProperty = property; Priority = priority; RuleName = new Rules.RuleUri(Rule, PrimaryProperty).ToString(); }
/// <summary> /// Creates a successful result. /// </summary> /// <param name="ruleName">Unique name of the rule creating /// this result.</param> /// <param name="property">Property to which this result should /// be attached.</param> public RuleResult(string ruleName, Core.IPropertyInfo property) { RuleName = ruleName; PrimaryProperty = property; Success = true; Severity = RuleSeverity.Success; }
/// <summary> /// Specify the roles denied the right to execute /// a given method. /// </summary> /// <param name="propertyInfo">PropertyInfo for the method.</param> /// <param name="roles">List of roles denied execute access.</param> /// <remarks> /// This method may be called multiple times, with the roles in /// each call being added to the end of the list of denied roles. /// In other words, each call is cumulative, adding more roles /// to the list. /// </remarks> public void DenyExecute(Core.IPropertyInfo propertyInfo, params string[] roles) { RolesForProperty currentRoles = TypeRules.GetRolesForProperty(propertyInfo.Name); foreach (string item in roles) { currentRoles.ExecuteDenied.Add(item); } }
/// <summary> /// Specify the roles allowed to write a given /// property. /// </summary> /// <param name="propertyInfo">PropertyInfo for the property.</param> /// <param name="roles">List of roles granted write access.</param> /// <remarks> /// This method may be called multiple times, with the roles in /// each call being added to the end of the list of allowed roles. /// In other words, each call is cumulative, adding more roles /// to the list. /// </remarks> public void AllowWrite(Core.IPropertyInfo propertyInfo, params string[] roles) { RolesForProperty currentRoles = TypeRules.GetRolesForProperty(propertyInfo.Name); foreach (string item in roles) { currentRoles.WriteAllowed.Add(item); } }
protected override object ReadProperty(Core.IPropertyInfo propertyInfo) { if (ReferenceEquals(propertyInfo, NameProperty)) { return(_name); } else { return(base.ReadProperty(propertyInfo)); } }
/// <summary> /// Creates a failure result. /// </summary> /// <param name="ruleName">Unique name of the rule creating /// this result.</param> /// <param name="property">Property to which this result should /// be attached.</param> /// <param name="description">Human-readable description of /// why the rule failed.</param> public RuleResult(string ruleName, Core.IPropertyInfo property, string description) { RuleName = ruleName; PrimaryProperty = property; Description = description; Success = string.IsNullOrEmpty(description); if (!Success) { Severity = RuleSeverity.Error; } }
/// <summary> /// Creates a failure result. /// </summary> /// <param name="ruleName">Unique name of the rule creating /// this result.</param> /// <param name="property">Property to which this result should /// be attached.</param> /// <param name="description">Human-readable description of /// why the rule failed.</param> public RuleResult(string ruleName, Core.IPropertyInfo property, string description) { if (string.IsNullOrEmpty(description)) { throw new ArgumentException(string.Format(Resources.RuleMessageRequired, ruleName), "description"); } RuleName = ruleName; PrimaryProperty = property; Description = description; Success = string.IsNullOrEmpty(description); Severity = RuleSeverity.Error; }
protected override void OnPropertyChanged(Core.IPropertyInfo propertyInfo) { using (BypassPropertyChecks) { if (AuthLevel == 3) { FirstName = "New First Name Value"; LastName = "New Last Name Value"; MiddleName = "New Middle Name Value"; PlaceOfBirth = "New PlaceOfBirth Value"; } } base.OnPropertyChanged(propertyInfo); }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo for the property.</param> /// <param name="severity">The default severity for the rule.</param> /// <param name="stopProcessing"> /// Initial default value for the StopProcessing property. /// </param> /// <remarks> /// <para> /// The <b>severity</b> and <b>stopProcessing</b> parameters /// define only the initial default values. If the rule /// changes these values by setting e.Severity or /// e.StopProcessing, then the new values will become /// the default for all subsequent rule invocations. /// </para><para> /// To avoid confusion, It is recommended that the /// <b>severity</b> and <b>stopProcessing</b> constructor /// parameters only be used for rule methods that do /// not explicitly set e.Severity or e.StopProcessing. /// </para> /// </remarks> public RuleArgs(Core.IPropertyInfo propertyInfo, RuleSeverity severity, bool stopProcessing) : this(propertyInfo, severity) { _stopProcessing = stopProcessing; }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo for the property.</param> /// <param name="severity">Initial default severity for the rule.</param> /// <remarks> /// <para> /// The <b>severity</b> parameter defines only the initial default /// severity value. If the rule changes this value by setting /// e.Severity, then that new value will become the default for all /// subsequent rule invocations. /// </para><para> /// To avoid confusion, it is recommended that the /// <b>severity</b> constructor parameter /// only be used for rule methods that do not explicitly set /// e.Severity. /// </para> /// </remarks> public RuleArgs(Core.IPropertyInfo propertyInfo, RuleSeverity severity) : this(propertyInfo) { _severity = severity; }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo object for the property.</param> public RuleArgs(Core.IPropertyInfo propertyInfo) : this(propertyInfo.Name) { _propertyFriendlyName = propertyInfo.FriendlyName; }
private void BindSingleProperty(ModelBindingContext bindingContext, object result, Core.IPropertyInfo item, string index) { try { var value = bindingContext.ActionContext.HttpContext.Request.Form[index].FirstOrDefault(); try { if (item.Type.Equals(typeof(string))) { Reflection.MethodCaller.CallPropertySetter(result, item.Name, value); } else if (value != null) { Reflection.MethodCaller.CallPropertySetter(result, item.Name, Utilities.CoerceValue(item.Type, value.GetType(), null, value)); } else { Reflection.MethodCaller.CallPropertySetter(result, item.Name, null); } } catch { if (item.Type.Equals(typeof(string))) { LoadProperty(result, item, value); } else if (value != null) { LoadProperty(result, item, Utilities.CoerceValue(item.Type, value.GetType(), null, value)); } else { LoadProperty(result, item, null); } } } catch (Exception ex) { throw new Exception($"Could not map {index} to model", ex); } }
bool IManageProperties.FieldExists(Core.IPropertyInfo property) { return(FieldManager.FieldExists(property)); }
/// <summary> /// Specify the roles allowed to read a given /// property. /// </summary> /// <param name="businessRules">Business rules</param> /// <param name="propertyInfo">PropertyInfo for the property.</param> /// <param name="roles">List of roles granted read access.</param> /// <remarks> /// This method may be called multiple times, with the roles in /// each call being added to the end of the list of allowed roles. /// In other words, each call is cumulative, adding more roles /// to the list. /// </remarks> public static void AllowRead(this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params string[] roles) { businessRules.AddRule(new IsInRole(AuthorizationActions.ReadProperty, propertyInfo, roles)); }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo for the property to be validated.</param> public DecoratedRuleArgs(Core.IPropertyInfo propertyInfo) : base(propertyInfo) { _decorations = new Dictionary <string, object>(); }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo for the property to be validated.</param> /// <param name="severity">The default severity for the rule.</param> /// <param name="stopProcessing"> /// Initial default value for the StopProcessing property. /// </param> /// <param name="args">Reference to a Dictionary containing /// name/value arguments for use by the rule method.</param> /// <remarks> /// <para> /// The <b>severity</b> and <b>stopProcessing</b> parameters /// define only the initial default values. If the rule /// changes these values by setting e.Severity or /// e.StopProcessing, then the new values will become /// the default for all subsequent rule invocations. /// </para><para> /// To avoid confusion, It is recommended that the /// <b>severity</b> and <b>stopProcessing</b> constructor /// parameters only be used for rule methods that do /// not explicitly set e.Severity or e.StopProcessing. /// </para> /// </remarks> public DecoratedRuleArgs(Core.IPropertyInfo propertyInfo, RuleSeverity severity, bool stopProcessing, Dictionary <string, object> args) : base(propertyInfo, severity, stopProcessing) { _decorations = args; }
/// <summary> /// Creates an instance of RuleArgs. /// </summary> /// <param name="propertyInfo">The PropertyInfo for the property to be validated.</param> /// <param name="args">Reference to a Dictionary containing /// name/value arguments for use by the rule method.</param> public DecoratedRuleArgs(Core.IPropertyInfo propertyInfo, Dictionary <string, object> args) : base(propertyInfo) { _decorations = args; }
/// <summary> /// Specify the roles denied write access to /// a given property. /// </summary> /// <param name="businessRules">Business rules</param> /// <param name="propertyInfo">PropertyInfo for the property.</param> /// <param name="roles">List of roles denied write access.</param> /// <remarks> /// This method may be called multiple times, with the roles in /// each call being added to the end of the list of denied roles. /// In other words, each call is cumulative, adding more roles /// to the list. /// </remarks> public static void DenyWrite(this BusinessRules businessRules, Core.IPropertyInfo propertyInfo, params string[] roles) { businessRules.AddRule(new IsNotInRole(AuthorizationActions.WriteProperty, propertyInfo, roles)); }