Пример #1
0
        /// <summary>
        /// Validates the given Expression and outputs a list of Errors if exist
        /// </summary>
        /// <param name="Expression">The Xml Expression to Validate</param>
        /// <param name="errors">The List generic of Error Objects that will be outputed</param>
        /// <returns>true if Valid, otherwise false</returns>
        public static bool IsExpressionValid(string Expression, out List <ErrorObject> errors)
        {
            List <ErrorObject> listErrors = new List <ErrorObject>();

            try
            {
                // Create a new RuleSet object so we dont lose our DefaultRuleSet
                RuleSetObject  ruleObject = new RuleSetObject(_defaultType, Expression);
                RuleValidation ruleValid  = new RuleValidation(_defaultType, null);
                ruleObject.ActivityRuleSet.Validate(ruleValid);

                // Add the errors if any
                for (int i = 0; i < ruleValid.Errors.Count; i++)
                {
                    ErrorObject err = new ErrorObject(ruleValid.Errors[i].ErrorText, ruleValid.Errors[i].ErrorNumber, ruleValid.Errors[i].IsWarning);
                    listErrors.Add(err);
                }

                errors = listErrors;
                return(ruleValid.Errors.Count == 0);
            }
            catch (Exception ex)
            {
                ErrorObject err = new ErrorObject(ex.Message, 0, false);
                listErrors.Add(err);
                errors = listErrors;
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a New DefaultRuleSet object with the ability to remove existing default if exists
        /// </summary>
        /// <param name="deleteDefault">Do you want to delete the current DefaultRuleSet</param>
        public static void CreateNewExpression(bool deleteDefault)
        {
            RuleSetObject ruleObject = new RuleSetObject(_defaultType, "");

            if (deleteDefault)
            {
                ruleSets.Remove(_defaultRuleSet);
            }

            LoadRuleSet(ruleObject);
        }
Пример #3
0
 /// <summary>
 /// Assigns DefaultRuleSet the given Xml Expression if DefaultRuleSet is not null
 /// otherwise creates new DefaultRuleSet with given Expression
 /// </summary>
 /// <param name="xmlData">Xml Expression</param>
 public static void LoadRuleSet(string xmlData)
 {
     if (_defaultRuleSet == null)
     {
         RuleSetObject ruleObject = new RuleSetObject(_defaultType, xmlData);
         LoadRuleSet(ruleObject);
     }
     else
     {
         DefaultRuleSet.RuleSetDefinition = xmlData;
     }
 }
Пример #4
0
 /// <summary>
 /// Loads the given RuleSet and assigns it as DefaultRuleSet
 /// </summary>
 /// <param name="ruleSet">RuleSet to add</param>
 public static void LoadRuleSet(RuleSetObject ruleSet)
 {
     ruleSets.Add(ruleSet);
     _defaultRuleSet = ruleSet;
 }