Пример #1
0
 /// <summary>
 /// Create action using the IActionDef whose name is "actionName".
 /// The return action's IsInitialized property is set false.
 /// <returns></returns>
 public IAction CreateAction(string actionName)
 {
     if (m_registeredActionDef.ContainsKey(actionName))
     {
         IActionDef actionDef = m_registeredActionDef[actionName];
         IAction    action    = actionDef.Create();
         action.IsInitialized = false;
         return(action);
     }
     return(null);
 }
Пример #2
0
 /// <summary>
 /// Create action using the IActionDef whose name is "actionName".
 /// Use "parameters" to initialize the action.
 /// The return action's IsInitialized property is set true.
 /// </summary>
 public IAction CreateAction(string actionName, Dictionary <string, string> parameters)
 {
     if (m_registeredActionDef.ContainsKey(actionName))
     {
         IActionDef actionDef = m_registeredActionDef[actionName];
         IAction    action    = actionDef.Create(parameters);
         action.IsInitialized = true;
         return(action);
     }
     return(null);
 }
Пример #3
0
 /// <summary>
 /// Get the all rules if the rule have the same category with the parameter,
 /// the same ActionDef with the parameter, and the "target" satisified the rule.
 /// </summary>
 public List<Rule> GetRule(ICategory category, IActionDef actionDef, IMatchTarget target)
 {
     var matchedRuleList = new List<Rule>();
     if (category == null) throw new ArgumentNullException(nameof(category));
     string key = GetRuleKeyString(category.GetCategoryName());
     if (!m_ruleDict.ContainsKey(key))
         return matchedRuleList;
     List<Rule> ruleList = m_ruleDict[key];
     foreach (Rule rule in ruleList)
     {
         if (rule.Action.GetActionDef() == actionDef &&
             rule.Condition.Match(target))
         {
             matchedRuleList.Add(rule);
         }
     }
     return matchedRuleList;
 }
Пример #4
0
        private void actionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (actionComboBox.SelectedItem == null)
            {
                return;
            }
            string actionName = actionComboBox.SelectedItem as string;
            AbstractActionManager actionManager = RuleEngine.GetActionManager();
            IActionDef            actionDef     = actionManager.GetActionDef(actionName);

            if (actionDef == null)
            {
                return;
            }
            string actionDescription =
                Resource.FormatString("Msg_ActionDescription_" + actionDef.GetActionName());

            textBoxDescription.Text = actionDescription;
            CheckOKButtonEnabled();
        }
        private static string GetActionParamString(IAction action)
        {
            StringBuilder sb        = new StringBuilder();
            IActionDef    actionDef =
                RuleEngine.GetActionManager().GetActionDef(action.GetActionDef().GetActionName());
            List <string> paramNameList = actionDef.GetParameterNames();

            foreach (string paramName in paramNameList)
            {
                if (sb.Length != 0)
                {
                    sb.Append(", ");
                }
                sb.Append(paramName);
                sb.Append("='");
                sb.Append(action.GetParameterValue(paramName));
                sb.Append("'");
            }
            return(sb.ToString());
        }
Пример #6
0
        /// <summary>
        /// Get the all rules if the rule have the same category with the parameter,
        /// the same ActionDef with the parameter, and the "target" satisified the rule.
        /// </summary>
        public List <Rule> GetRule(ICategory category, IActionDef actionDef, IMatchTarget target)
        {
            List <Rule> matchedRuleList = new List <Rule>();
            string      key             = GetRuleKeyString(category.GetCategoryName());

            if (!m_ruleDict.ContainsKey(key))
            {
                return(matchedRuleList);
            }
            List <Rule> ruleList = m_ruleDict[key];

            foreach (Rule rule in ruleList)
            {
                if (rule.Action.GetActionDef() == actionDef &&
                    rule.Condition.Match(target))
                {
                    matchedRuleList.Add(rule);
                }
            }
            return(matchedRuleList);
        }
Пример #7
0
        private XmlNode WriteActionToXmlNode(IAction action)
        {
            // <Action>
            XmlElement actionNode = m_doc.CreateElement(RuleFileConstants.ActionElementName);

            actionNode.SetAttribute(RuleFileConstants.Name, action.GetActionDef().GetActionName());

            AbstractActionManager actionManager = RuleEngine.GetActionManager();
            IActionDef            actionDef     = actionManager.GetActionDef(action.GetActionDef().GetActionName());
            List <string>         paramList     = actionDef.GetParameterNames();

            foreach (string paramName in paramList)
            {
                // <Param>
                XmlElement newNameParamNode = m_doc.CreateElement(RuleFileConstants.Parameter);
                newNameParamNode.SetAttribute(RuleFileConstants.Key, paramName);
                newNameParamNode.SetAttribute(RuleFileConstants.Value,
                                              action.GetParameterValue(paramName));
                actionNode.AppendChild(newNameParamNode);
            }
            return(actionNode);
        }
        public static TreeNode GetActionTreeNode(IAction action)
        {
            TreeNode actionNode = new TreeNode();

            actionNode.Text = ACTION_NODE_TEXT + " : " + action.GetActionDef().GetActionName();
            if (!action.IsInitialized)
            {
                actionNode.Text += " <" + Resource.FormatString("Msg_EditUninitializedActionTip") + ">";
            }
            actionNode.Tag = action;

            IActionDef actionDef =
                RuleEngine.GetActionManager().GetActionDef(action.GetActionDef().GetActionName());
            List <string> paramNameList = actionDef.GetParameterNames();

            foreach (string paramName in paramNameList)
            {
                TreeNode      actionParameterNode = new TreeNode();
                StringBuilder sb = new StringBuilder();
                sb.Append(paramName);
                sb.Append(" = '");
                if (action.IsInitialized)
                {
                    sb.Append(action.GetParameterValue(paramName));
                }
                else
                {
                    sb.Append(TreeNodeConstants.Uninitialized_Value);
                }
                sb.Append("'");
                actionParameterNode.Text = sb.ToString();
                actionParameterNode.Tag  = action;
                SetRuleTreeNodeImage(actionParameterNode);
                actionNode.Nodes.Add(actionParameterNode);
            }

            SetRuleTreeNodeImage(actionNode);
            return(actionNode);
        }
Пример #9
0
 /// <summary>
 /// Register an action in this manager.
 /// The action name is used as the key of IActionDef in the register collection.
 /// Usually, this method is called in the ctor of AbstractActionManager's sub classes.
 /// <param name="actionDef"></param>
 protected void RegisterAction(string actionName, IActionDef actionDef)
 {
     m_registeredActionDef.Add(actionName, actionDef);
 }
Пример #10
0
 /// <summary>
 /// Register an action in this manager.
 /// The action name is used as the key of IActionDef in the register collection.
 /// Usually, this method is called in the ctor of AbstractActionManager's sub classes.
 /// <param name="actionDef"></param>
 protected void RegisterAction(string actionName, IActionDef actionDef)
 {
     m_registeredActionDef.Add(actionName, actionDef);
 }