コード例 #1
0
        /// <summary>
        /// Invokes all rule methods associated with
        /// the specified property.
        /// </summary>
        /// <param name="propertyName">The name of the property to validate.</param>
        public void CheckRules(string propertyName)
        {
            List <RuleMethod> list;

            // get the list of rules to check
            if (RulesList.ContainsKey(propertyName))
            {
                list = RulesList[propertyName];
                if (list == null)
                {
                    return;
                }

                // now check the rules
                foreach (RuleMethod rule in list)
                {
                    if (rule.Invoke())
                    {
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        BrokenRulesList.Add(rule);
                    }
                }
            }
        }
コード例 #2
0
		/// <summary>
		///	Provides a method to aggregate BrokenRuleList Collections Based on their Type 
		/// if they are invalid.
		/// </summary>
		public void AddBrokenRulesList(Type type, BrokenRulesList otherList)
		{
			//skip, no rules broken
			if (otherList == null || otherList.Count == 0)

			if (type == null)
				type = typeof(object);
			
			BrokenRulesLists.Add(type, otherList);
		}
コード例 #3
0
        /// <summary>
        ///	Provides a method to aggregate BrokenRuleList Collections Based on their Type
        /// if they are invalid.
        /// </summary>
        public void AddBrokenRulesList(Type type, BrokenRulesList otherList)
        {
            //skip, no rules broken
            if (otherList == null || otherList.Count == 0)
            {
                if (type == null)
                {
                    type = typeof(object);
                }
            }

            BrokenRulesLists.Add(type, otherList);
        }
コード例 #4
0
        /// <summary>
        /// Given a list
        /// containing IRuleMethod objects, this
        /// method executes all those rule methods.
        /// </summary>
        private void CheckRules(List <IRuleMethod> list)
        {
            bool previousRuleBroken = false;
            bool shortCircuited     = false;

            for (int index = 0; index < list.Count; index++)
            {
                IRuleMethod rule = list[index];
                // see if short-circuiting should kick in
                if (!shortCircuited && (previousRuleBroken && rule.Priority > _processThroughPriority))
                {
                    shortCircuited = true;
                }

                if (shortCircuited)
                {
                    // we're short-circuited, so just remove
                    // all remaining broken rule entries
                    BrokenRulesList.Remove(rule);
                }
                else
                {
                    // we're not short-circuited, so check rule
                    if (rule.Invoke(_target))
                    {
                        // the rule is not broken
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        // the rule is broken
                        BrokenRulesList.Add(rule);
                        if (rule.RuleArgs.Severity == RuleSeverity.Error)
                        {
                            previousRuleBroken = true;
                        }
                    }
                    if (rule.RuleArgs.StopProcessing)
                    {
                        shortCircuited = true;
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Invokes all rule methods for all properties
        /// in the object.
        /// </summary>
        public void CheckRules()
        {
            // get the rules for each rule name
            foreach (KeyValuePair <string, List <RuleMethod> > de in RulesList)
            {
                List <RuleMethod> list = de.Value;

                // now check the rules
                foreach (RuleMethod rule in list)
                {
                    if (rule.Invoke())
                    {
                        BrokenRulesList.Remove(rule);
                    }
                    else
                    {
                        BrokenRulesList.Add(rule);
                    }
                }
            }
        }
コード例 #6
0
 public EntitySaveResult(BrokenRulesList brokenRules) : base(brokenRules)
 {
 }
コード例 #7
0
 public GenericDataSaveResult(BrokenRulesList brokenRules, T item) : base(brokenRules)
 {
     Item = item;
 }
コード例 #8
0
 public GenericDataSaveResult(BrokenRulesList brokenRules) : this(brokenRules, null)
 {
 }
コード例 #9
0
 public static QueryResult <T> Fail(BrokenRulesList brokenRules) => new QueryResult <T>(brokenRules);
コード例 #10
0
 public QueryResult(BrokenRulesList brokenRules)
 {
     Succeeded   = brokenRules.Count == 0;
     BrokenRules = brokenRules ?? new BrokenRulesList();
     Message     = Succeeded ? "Success" : string.IsNullOrWhiteSpace(BrokenRules.Message) ? "Failed" : BrokenRules.Message;
 }
コード例 #11
0
 public static CommandResult Fail(BrokenRulesList brokenRules) => new CommandResult(brokenRules);