public void AddOperation(UserOperation operation)
        {
			//添加元素
            _operations.Add(operation);
        }
        public void RemoveOperation(UserOperation operation)
        {
			//删除元素
            _operations.Remove(operation);
        }
        /// <summary>
        /// 加载配置文件
        /// </summary>
        private void LoadConfig()
        {
            try
            {
                XmlDocument config = new XmlDocument();
                config.Load(_configFile);

                XmlNode root = config.SelectSingleNode("Root");

                #region LoadNormalCommand
                XmlNodeList areas = root.SelectNodes("Area");
                _areas.Clear();
                foreach (XmlNode area in areas)
                {
                    string areaName = area.SelectSingleNode("AreaName").InnerText;
                    Area tempArea = new Area(areaName);
                    _areas.Add(tempArea);

                    XmlNodeList actions = area.SelectNodes("Action");
                    foreach (XmlNode action in actions)
                    {
                        string actionName = action.SelectSingleNode("ActionName").InnerText;
                        string actionReceiveData = action.SelectSingleNode("ActionReceiveData").InnerText;
                        UserAction useraction = new UserAction(actionName,actionReceiveData);
                        //tempArea.Actions.Add(useraction);
                        _userAction.Add(useraction);
                        XmlNodeList oprations = action.SelectNodes("Operation");
                        foreach (XmlNode operation in oprations)
                        {
                            string operationName = operation.SelectSingleNode("OperationName").InnerText;
                            string operationTypeString = operation.SelectSingleNode("OperationType").InnerText;
                            OprationType operationType = (OprationType)Enum.Parse(typeof(OprationType),operationTypeString,true);
                            XmlNode operationSetting = operation.SelectSingleNode("OperationSetting");
                            object setting = null;
                            if (operationType == OprationType.Com)
                            {
                                ComSetting cs = new ComSetting();
                                cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText;
                                cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText);
                                cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText);
                                cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText);
                                cs.Parity = (Parity)Enum.Parse(typeof(Parity),operationSetting.SelectSingleNode("Parity").InnerText);

                                setting = cs;
                            }
                            else if (operationType == OprationType.TCP || operationType == OprationType.UDP)
                            {
                                NetworkSetting ns = new NetworkSetting();
                                ns.Ip = operationSetting.SelectSingleNode("IP").InnerText;
                                ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText);
                                setting = ns;
                            }

                            string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText;
                            DataType dataType = (DataType)Enum.Parse(typeof(DataType),dataTypeString,true);
                            string data = operation.SelectSingleNode("OperationData").InnerText;
                            int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText);
                            UserOperation userOperation = new UserOperation(operationName,operationType,dataType,setting,data,time);
                            _userOperation.Add(userOperation);
                        }
                    }

                }
                _arealist.Refresh();
                #endregion
            }
            catch(Exception ex)
            {
                MessageBox.Show("未找到配置命令!");
                
            }

        }
        private static void SaveComSetting(XmlDocument config, UserOperation operation, XmlNode operationSetting)
        {
            ComSetting cs = operation.Setting as ComSetting;
            XmlNode comNumber = config.CreateNode(XmlNodeType.Element, "ComNumber", null);
            comNumber.InnerText = cs.ComNumber;

            XmlNode baudRate = config.CreateNode(XmlNodeType.Element, "BaudRate", null);
            baudRate.InnerText = cs.BaudRate.ToString();

            XmlNode dataBit = config.CreateNode(XmlNodeType.Element, "DataBit", null);
            dataBit.InnerText = cs.DataBits.ToString();

            XmlNode stopBit = config.CreateNode(XmlNodeType.Element, "StopBit", null);
            stopBit.InnerText = cs.StopBits.ToString();

            XmlNode parity = config.CreateNode(XmlNodeType.Element, "Parity", null);
            parity.InnerText = cs.Parity.ToString();

            operationSetting.AppendChild(comNumber);
            operationSetting.AppendChild(baudRate);
            operationSetting.AppendChild(dataBit);
            operationSetting.AppendChild(stopBit);
            operationSetting.AppendChild(parity);
        }
        private static void SaveIPSetting(XmlDocument config, UserOperation operation, XmlNode operationSetting)
        {
            NetworkSetting ns = operation.Setting as NetworkSetting;
            XmlNode ip = config.CreateNode(XmlNodeType.Element, "IP", null);
            ip.InnerText = ns.Ip;

            XmlNode port = config.CreateNode(XmlNodeType.Element, "Port", null);
            port.InnerText = ns.Port.ToString();

            operationSetting.AppendChild(ip);
            operationSetting.AppendChild(port);
        }
 public void RemoveOperation(UserOperation operation)
 {
     //删除元素
     _operations.Remove(operation);
 }
 public void AddOperation(UserOperation operation)
 {
     //添加元素
     _operations.Add(operation);
 }