Exemplo n.º 1
0
        private AdminCmd GetCmd()
        {
            // 执行
            TreeNode node = adminTreeView.SelectedNode;

            if (node == null)
            {
                return(null);
            }
            AdminCmd cmd = (AdminCmd)node.Tag;

            if (cmd == null)
            {
                WriteLog("请先选中一条指令");
                return(null);
            }

            // 回填数据
            for (int i = 0; i < argsPanel.Controls.Count; ++i)
            {
                ArgBox box = (ArgBox)argsPanel.Controls[i];
                if (!box.Visible)
                {
                    break;
                }
                AdminArg arg = (AdminArg)box.Tag;
                arg.Data = box.ArgData;
                if (arg.AddItem(arg.Data))
                {
                    m_mgr.MarkDirty();
                }
            }

            return(cmd);
        }
Exemplo n.º 2
0
        private void LoadUserData()
        {
            // 加载自定义数据
            if (!File.Exists(sUserDataPath))
            {
                return;
            }
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(sUserDataPath);
                XmlElement  root = doc.DocumentElement;
                XmlNodeList nodes;
                XmlElement  elem;
                nodes = root.GetElementsByTagName("last_uid");
                if (nodes.Count > 0)
                {
                    LastUID = (nodes[0] as XmlElement).InnerText;
                }
                nodes = root.GetElementsByTagName("uid");
                foreach (var node in nodes)
                {
                    elem = node as XmlElement;
                    Config.AddUID(elem.InnerText);
                }

                // 命令
                nodes = root.GetElementsByTagName("cmd");
                foreach (var node in nodes)
                {
                    elem = node as XmlElement;
                    string   key = elem.GetAttribute("name");
                    AdminCmd cmd = Config.FindCmd(key);
                    if (cmd == null)
                    {
                        continue;
                    }
                    XmlNodeList arg_nodes = elem.GetElementsByTagName("arg");
                    foreach (var arg_node in arg_nodes)
                    {
                        XmlElement arg_elem = arg_node as XmlElement;
                        AdminArg   arg      = cmd.GetArg(arg_elem.GetAttribute("name"));
                        if (arg == null)
                        {
                            continue;
                        }
                        if (arg_elem.HasAttribute("data"))
                        {
                            arg.Data = arg_elem.GetAttribute("data");
                        }
                        XmlNodeList val_nodes = arg_elem.GetElementsByTagName("value");
                        foreach (var val_node in val_nodes)
                        {
                            arg.AddItem((val_node as XmlElement).InnerText);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                WriteLog(e.Message);
            }
        }