コード例 #1
0
        private void LoadActionsFromXml(XmlNode subNode)
        {
            foreach (XmlNode ac in subNode)
            {
                if (ac is XmlComment || ac.Name != "Action")
                {
                    continue;
                }
                var level2Item = (XmlElement)ac;
                var name       = level2Item.GetAttribute("Name");
                var actionType = level2Item.GetAttribute("Type");
                var action     = ActionsManagement.CreateAction(actionType, name);

                try
                {
                    action.LoadFromConfig(level2Item);
                    action.ActionContainer = this;
                    AddAction(action);
                }
                catch (Exception e)
                {
                    Log.Error($"加载CommonResource: {ResourceName} Action:{name}出错,{e.Message}");
                }
            }
        }
コード例 #2
0
        //public abstract void CreateActions();

        public BaseAction GetAction(string name)
        {
            if (_actionNames.Contains(name))
            {
                var action = ActionsManagement.CreateAction(name, name);
                action.ActionContainer = this;
                return(action);
            }

            return(_actions[name]);
        }
コード例 #3
0
        private void LoadActionsFromXml(IEnumerable level1Node)
        {
            #region actions

            foreach (XmlNode level2Node in level1Node)
            {
                // level2 --  "actions"

                //add
                if (level2Node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                //add:gu 20170223

                var level2Item = (XmlElement)level2Node;

                // 动态创建Action
                var name       = level2Item.GetAttribute("Name");
                var actionType = level2Item.GetAttribute("Type");

                var action = (MachineAction)ActionsManagement.CreateAction(actionType, name);
                action.OwnerMachine = this;

                if (action.LoadFromConfig(level2Item))
                {
                    // 加入到Machine的Action集合
                    try
                    {
                        AddAction(action);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"加载机器{ResourceName} 的Action:{name}出错:{ex}");
                    }
                }
                else
                {
                    Log.Error($"加载机器{ResourceName} 的Action:{name}出错");
                }
            }

            #endregion
        }