public void UpdateText(Rule rule)
 {
     this.Text = rule.Condition.GetExpression();
     this.SelectAll();
     this.SelectionColor = DEFAULT_COLOR;
     HighlightText();
 }
Пример #2
0
 public void AddRule(Rule rule)
 {
     if (rule == null) throw new ArgumentNullException(nameof(rule));
     string key = GetRuleKeyString(rule.Category.GetCategoryName());
     if (!m_ruleDict.ContainsKey(key))
         m_ruleDict[key] = new List<Rule>();
     m_ruleDict[key].Add(rule);
 }
Пример #3
0
 private void addNewRuleOperation()
 {
     var form = new RuleForm("Rule #" + (ruleTreeView.Nodes[0].Nodes.Count + 1));
     if (form.ShowDialog() == DialogResult.OK)
     {
         ICategory category = form.GetCategory();
         IAction action = form.GetAction();
         var newRule = new Rule(category, form.GetRuleName());
         newRule.Action = action;
         newRule.Condition = new AndCondition();
         TreeNode ruleSetNode = ruleTreeView.Nodes[0];
         var ruleSet = ruleSetNode.Tag as RuleSet;
         ruleSet.AddRule(newRule);
         // Add tree node.
         TreeNode ruleNode = RuleSet2TreeNodeProcessor.GetRuleTreeNode(newRule);
         ruleNode.ExpandAll();
         ruleSetNode.Nodes.Add(ruleNode);
         SetModified(true);
     }
 }
Пример #4
0
 private void addNewRuleFromHereOperation(IMatchTarget matchTarget)
 {
     if (!HasRuleSet())
     {
         MessageBox.Show(Resource.FormatString("Wrn_NoRuleFileToAddRuleTo"));
         return;
     }
     ICategory fixedCategory = matchTarget.GetCategory();
     var form = new RuleForm(fixedCategory,
         "Rule #" + (ruleTreeView.Nodes[0].Nodes.Count + 1));
     if (form.ShowDialog() == DialogResult.OK)
     {
         IAction action = form.GetAction();
         AndCondition andCondition = ExtractDefaultConditions(matchTarget);
         var newRule = new Rule(fixedCategory, action, andCondition, form.GetRuleName());
         var ruleSet = ruleTreeView.Nodes[0].Tag as RuleSet;
         ruleSet.AddRule(newRule);
         // Add tree node.
         TreeNode ruleNode = RuleSet2TreeNodeProcessor.GetRuleTreeNode(newRule);
         ruleNode.ExpandAll();
         ruleTreeView.Nodes[0].Nodes.Add(ruleNode);
         // set modified
         SetModified(true);
     }
 }
Пример #5
0
 public void RemoveRule(Rule rule)
 {
     var enumerator = m_ruleDict.GetEnumerator();
     while (enumerator.MoveNext())
     {
         List<Rule> value = enumerator.Current.Value;
         value.Remove(rule);
     }
 }
 public static TreeNode GetRuleTreeNode(Rule rule)
 {
     TreeNode ruleNode = new TreeNode();
     ruleNode.Text = rule.Name;
     TreeNode categoryNode = GetCategoryTreeNode(rule.Category);
     ruleNode.Nodes.Add(categoryNode);
     TreeNode conditionRootNode = GetConditionRootTreeNode(rule.Condition);
     ruleNode.Nodes.Add(conditionRootNode);
     TreeNode actionNode = GetActionTreeNode(rule.Action);
     ruleNode.Nodes.Add(actionNode);
     ruleNode.Tag = rule;
     SetRuleTreeNodeImage(ruleNode);
     return ruleNode;
 }
Пример #7
0
 private XmlNode WriteRuleToXmlNode(Rule rule)
 {
     XmlElement ruleElement = m_doc.CreateElement(RuleFileConstants.RuleElementName);
     ruleElement.SetAttribute(RuleFileConstants.RulesElementRuleNameAttributeName,
         rule.Name);
     ruleElement.SetAttribute(RuleFileConstants.RulesElementCategoryAttributeName,
         rule.Category.GetCategoryName());
     ruleElement.AppendChild(WriteMatchToXmlNode(rule.Condition));
     if (!rule.Action.IsInitialized)
     {
         throw new ActionUninitializedException(rule.Name);
     }
     else
     {
         ruleElement.AppendChild(WriteActionToXmlNode(rule.Action));
     }
     return ruleElement;
 }