/// <summary> /// Splits the condition flags. /// </summary> /// <param name="flags">The flags.</param> /// <returns></returns> protected IConditionFlagProcessor SplitConditionFlags(string flags) { IConditionFlagProcessor dictionary = new ConditionFlagProcessor(); foreach (string flag in flags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { IConditionFlag conditionFlag = AddConditionFlag(flag); if (conditionFlag != null) dictionary.Add(conditionFlag); } return dictionary; }
/// <summary> /// Gets the condition. /// </summary> /// <param name="conditionElement">The condition element.</param> /// <param name="matchAll">if set to <see langword="true"/> [match all].</param> /// <returns></returns> private ICondition GetCondition(XmlNode conditionElement, LogicalGrouping logicalGrouping) { string input = "-"; MatchType matchType = MatchType.Pattern; // from schema definition string pattern = "(.*)"; bool ignoreCase = true; // from schema definition bool negate = false; // from schema definition if (conditionElement.Attributes["input"] != null) input = conditionElement.Attributes["input"].Value; if (conditionElement.Attributes["matchType"] != null) { try { matchType = (MatchType)Enum.Parse(typeof(MatchType), conditionElement.Attributes["matchType"].Value, true); } catch (Exception exc) { Manager.Log("Condition: " + exc.Message, "Error"); } } if (conditionElement.Attributes["pattern"] != null) pattern = conditionElement.Attributes["pattern"].Value; if (conditionElement.Attributes["ignoreCase"] != null) ignoreCase = XmlConvert.ToBoolean(conditionElement.Attributes["ignoreCase"].Value); if (conditionElement.Attributes["negate"] != null) negate = XmlConvert.ToBoolean(conditionElement.Attributes["negate"].Value); RegexOptions conditionOptions = Manager.RuleOptions; IConditionFlagProcessor conditionFlags = new ConditionFlagProcessor(); if (ignoreCase) { conditionFlags.Add(new CF.NoCaseFlag()); conditionOptions |= RegexOptions.IgnoreCase; } if (logicalGrouping == LogicalGrouping.MatchAny) conditionFlags.Add(new CF.OrNextFlag()); ICondition condition = null; // create the condition switch (matchType) { case MatchType.IsFile: condition = new IsFileCondition(); break; case MatchType.IsDirectory: condition = new IsDirectoryCondition(); break; case MatchType.Pattern: condition = new DefaultCondition(); break; } Pattern compiledPattern = new Pattern(pattern, negate, conditionOptions); var conditionTest = new DefaultConditionTestValue(input); // initialize condition condition.Init(compiledPattern, conditionTest, conditionFlags); return condition; }