예제 #1
0
        private void ReadCmd(XmlElement node)
        {
            string[] tokens;
            AdminCmd cmd = new AdminCmd();

            Cmds.Add(cmd);
            cmd.Group = node.GetAttribute("group");
            cmd.Name  = node.GetAttribute("name");
            cmd.Desc  = ReadAttribute(node, "note", "");
            string value = node.GetAttribute("value");

            tokens  = value.Split(new char[] { ',' });
            cmd.Cmd = tokens[0];
            for (int i = 1; i < tokens.Length; ++i)
            {
                AdminArg arg  = new AdminArg();
                string   data = tokens[i].Trim();
                if (string.IsNullOrEmpty(data))
                {
                    continue;
                }

                ParseArg(arg, data);
                cmd.Args.Add(arg);
            }

            // 解析详细信息
            XmlNodeList param_nodes = node.GetElementsByTagName("arg");

            foreach (var param in param_nodes)
            {
                XmlElement elem = (XmlElement)param;
                string     name = elem.GetAttribute("name");
                AdminArg   arg  = cmd.GetArg(name);
                if (arg == null)
                {
                    continue;
                }

                if (elem.HasAttribute("show"))
                {
                    arg.Show = elem.GetAttribute("show");
                }
                if (elem.HasAttribute("base64"))
                {
                    arg.Base64 = true;
                }
                if (elem.HasAttribute("style"))
                {
                    arg.Style = ParseStyle(elem.GetAttribute("style"));
                }

                if (elem.HasAttribute("limit"))
                {
                    UInt32.TryParse(elem.GetAttribute("limit"), out arg.Max);
                }

                if (elem.HasAttribute("options"))
                {
                    string options = elem.GetAttribute("options");
                    FindOption(arg, options);
                }

                if (elem.HasAttribute("items"))
                {
                    arg.Style = BoxStyle.Combox;
                    tokens    = elem.GetAttribute("items").Split(new char[] { ',', '|' });
                    foreach (var item in tokens)
                    {
                        arg.Items.Add(item.Trim());
                    }
                }
            }
        }
예제 #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);
            }
        }
예제 #3
0
        private void ReadCmd(XmlElement node)
        {
            string[] tokens;
            AdminCmd cmd = new AdminCmd();
            Cmds.Add(cmd);
            cmd.Group = node.GetAttribute("group");
            cmd.Name = node.GetAttribute("name");
            cmd.Desc = ReadAttribute(node, "note", "");
            string value = node.GetAttribute("value");
            tokens = value.Split(new char[] { ',' });
            cmd.Cmd = tokens[0];
            for(int i = 1; i < tokens.Length; ++i)
            {
                AdminArg arg = new AdminArg();
                string data = tokens[i].Trim();
                if (string.IsNullOrEmpty(data))
                    continue;

                ParseArg(arg, data);
                cmd.Args.Add(arg);
            }

            // 解析详细信息
            XmlNodeList param_nodes = node.GetElementsByTagName("arg");
            foreach(var param in param_nodes)
            {
                XmlElement elem = (XmlElement)param;
                string name = elem.GetAttribute("name");
                AdminArg arg = cmd.GetArg(name);
                if (arg == null)
                    continue;

                if (elem.HasAttribute("show"))
                    arg.Show = elem.GetAttribute("show");
                if (elem.HasAttribute("base64"))
                    arg.Base64 = true;
                if (elem.HasAttribute("style"))
                    arg.Style = ParseStyle(elem.GetAttribute("style"));

                if (elem.HasAttribute("limit"))
                    UInt32.TryParse(elem.GetAttribute("limit"), out arg.Max);

                if(elem.HasAttribute("options"))
                {
                    string options = elem.GetAttribute("options");
                    FindOption(arg, options);
                }

                if(elem.HasAttribute("items"))
                {
                    arg.Style = BoxStyle.Combox;
                    tokens = elem.GetAttribute("items").Split(new char[] { ',', '|' });
                    foreach(var item in tokens)
                    {
                        arg.Items.Add(item.Trim());
                    }
                }
            }
        }