示例#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);
        }
示例#2
0
        public void AddArg(string name, string data, bool canEdit)
        {
            AdminArg arg = new AdminArg();

            arg.Name    = name;
            arg.Data    = data;
            arg.CanEdit = canEdit;
            Args.Add(arg);
        }
示例#3
0
        private void FindOption(AdminArg arg, string data)
        {
            arg.Style = BoxStyle.Option;

            if (data.StartsWith("@"))
            {
                string opt_name = data.Substring(1);
                arg.OptionList = OptionMap[opt_name];
            }
            else
            {
                arg.OptionList = new AdminOptionList();
                ParseOption(arg.Options, data);
            }
        }
示例#4
0
        internal void Init(AdminArg arg)
        {
            // 先清空
            this.dataBox.Text = null;
            this.dataBox.Items.Clear();
            dataBox.SuspendLayout();
            switch (arg.Style)
            {
            case BoxStyle.Text:
            {
                this.Style = ComboBoxStyle.Simple;
            }
            break;

            case BoxStyle.Combox:
            {        // 下拉菜单
                this.Style = ComboBoxStyle.DropDown;
                if (arg.Items.Count > 0)
                {
                    foreach (var item in arg.Items)
                    {
                        dataBox.Items.Add(item);
                    }
                    this.dataBox.SelectedIndex = 0;
                }
            }
            break;

            case BoxStyle.Option:
            {
                this.Style = ComboBoxStyle.DropDownList;
                if (arg.Options != null && arg.Options.Count > 0)
                {
                    foreach (var option in arg.Options)
                    {
                        dataBox.Items.Add(option);
                    }
                    this.dataBox.SelectedIndex = 0;
                }
            }
            break;
            }

            this.Tag     = arg;
            this.ArgName = arg.Show;
            this.ArgData = arg.Data;
            dataBox.ResumeLayout();
        }
示例#5
0
        public void Init()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(Name);
            builder.Append(":");
            builder.Append(Cmd);
            builder.Append(",uid");
            for (int i = 1; i < Args.Count; ++i)
            {
                AdminArg arg = Args[i];
                builder.Append(",");
                builder.Append(arg.Name);
            }
            Desc = builder.ToString();
        }
示例#6
0
        private void adminTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = adminTreeView.SelectedNode;

            statusLabel.Text = "Group:" + node.Text;
            argsPanel.SuspendLayout();
            foreach (Control control in argsPanel.Controls)
            {
                control.Visible = false;
            }

            if (node.Tag != null)
            {
                AdminCmd cmd = (AdminCmd)node.Tag;
                statusLabel.Text = cmd.Desc;
                // 先创建足够多
                if (argsPanel.Controls.Count < cmd.Args.Count)
                {
                    int count = cmd.Args.Count - argsPanel.Controls.Count;
                    for (int i = 0; i < count; ++i)
                    {
                        ArgBox box = new ArgBox();
                        box.Visible = false;
                        argsPanel.Controls.Add(box);
                    }
                }
                // 初始化arg
                int box_index = 0;
                for (int i = 0; i < cmd.Args.Count; ++i)
                {
                    AdminArg arg = cmd.Args[i];
                    if (!arg.CanEdit)
                    {
                        continue;
                    }
                    ArgBox box = argsPanel.Controls[box_index++] as ArgBox;
                    box.Visible = true;
                    box.Init(arg);
                }
            }
            argsPanel.ResumeLayout();
            //argsPanel.Controls.Clear();
        }
示例#7
0
        public string ConcatRecord()
        {
            // 去除了UID信息,因为不会解析uid,而且太长
            StringBuilder builder = new StringBuilder();

            builder.Append(Cmd);
            builder.Append(",$uid");
            for (int i = 1; i < Args.Count; ++i)
            {
                AdminArg arg = Args[i];
                builder.Append(",");
                if (arg.Base64)
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(arg.Data);
                    string str   = Convert.ToBase64String(bytes);
                    builder.Append(str);
                }
                else
                {
                    builder.Append(arg.Data);
                }
            }
            return(builder.ToString());
        }
示例#8
0
        public string Concat()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(Cmd);
            builder.Append(",");
            builder.Append(Uid);
            for (int i = 0; i < Args.Count; ++i)
            {
                AdminArg arg = Args[i];
                builder.Append(",");
                if (arg.Base64)
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(arg.Data);
                    string str   = Convert.ToBase64String(bytes);
                    builder.Append(str);
                }
                else
                {
                    builder.Append(arg.Data);
                }
            }
            return(builder.ToString());
        }
示例#9
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);
            }
        }
示例#10
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());
                    }
                }
            }
        }
示例#11
0
        private bool ParseArg(AdminArg arg, string data)
        {
            // format:($)name:(show)(=default)[(options=a:1|b:2);(base64=1)]
            string name;
            string show = null;
            string info;
            int    index_beg = data.IndexOf('[');

            if (index_beg != -1)
            {
                int index_end = data.IndexOf(']');
                if (index_end == -1)
                {
                    return(false);
                }
                name = data.Substring(0, index_beg);
                info = data.Substring(index_beg + 1, index_end - index_beg - 1);
            }
            else
            {
                name = data;
                info = null;
            }

            // check default
            int index_def = name.IndexOf('=');

            if (index_def != -1)
            {
                arg.Data = name.Substring(index_def + 1);
                name     = name.Substring(0, index_def);
            }

            // check show
            int index_show = name.IndexOf(':');

            if (index_show != -1)
            {
                show = name.Substring(index_show + 1);
                name = name.Substring(0, index_show);
            }

            if (name[0] == '$')
            {// 可编辑变量
                arg.CanEdit = true;
                arg.Name    = name.Substring(1);
                arg.Show    = arg.Name;
            }
            else
            {// 不能编辑常量
                arg.CanEdit = false;
                arg.Name    = name;
                arg.Show    = arg.Name;
                arg.Data    = arg.Name;
            }

            if (!string.IsNullOrEmpty(show))
            {
                arg.Show = show;
            }

            // check info
            if (!string.IsNullOrEmpty(info))
            {
                string[] tokens = info.Split(';');
                if (tokens.Length != 0)
                {
                    foreach (string token in tokens)
                    {
                        int index = token.IndexOf('=');
                        if (index == -1)
                        {
                            continue;
                        }
                        string key   = token.Substring(0, index).Trim();
                        string value = token.Substring(index + 1);
                        switch (key)
                        {
                        case "options":
                        {
                            FindOption(arg, value);
                        }
                        break;

                        case "base64":
                        {
                            int isBase64 = int.Parse(value);
                            arg.Base64 = (isBase64 != 0);
                        }
                        break;
                        }
                    }
                }
            }

            return(true);
        }
示例#12
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());
                    }
                }
            }
        }
示例#13
0
        private bool ParseArg(AdminArg arg, string data)
        {
            // format:($)name:(show)(=default)[(options=a:1|b:2);(base64=1)]
            string name;
            string show = null;
            string info;
            int index_beg = data.IndexOf('[');
            if(index_beg != -1)
            {
                int index_end = data.IndexOf(']');
                if (index_end == -1)
                    return false;
                name = data.Substring(0, index_beg);
                info = data.Substring(index_beg + 1, index_end - index_beg - 1);
            }
            else
            {
                name = data;
                info = null;
            }

            // check default
            int index_def = name.IndexOf('=');
            if(index_def != -1)
            {
                arg.Data = name.Substring(index_def + 1);
                name = name.Substring(0, index_def);
            }

            // check show
            int index_show = name.IndexOf(':');
            if(index_show != -1)
            {
                show = name.Substring(index_show + 1);
                name = name.Substring(0, index_show);
            }

            if(name[0] == '$')
            {// 可编辑变量
                arg.CanEdit = true;
                arg.Name = name.Substring(1);
                arg.Show = arg.Name;
            }
            else
            {// 不能编辑常量
                arg.CanEdit = false;
                arg.Name = name;
                arg.Show = arg.Name;
                arg.Data = arg.Name;
            }

            if(!string.IsNullOrEmpty(show))
            {
                arg.Show = show;
            }

            // check info
            if(!string.IsNullOrEmpty(info))
            {
                string[] tokens = info.Split(';');
                if(tokens.Length != 0)
                {
                    foreach(string token in tokens)
                    {
                        int index = token.IndexOf('=');
                        if (index == -1)
                            continue;
                        string key = token.Substring(0, index).Trim();
                        string value = token.Substring(index + 1);
                        switch(key)
                        {
                            case "options":
                                {
                                    FindOption(arg, value);
                                }
                                break;
                            case "base64":
                                {
                                    int isBase64 = int.Parse(value);
                                    arg.Base64 = (isBase64 != 0);
                                }
                                break;
                        }
                    }
                }
            }

            return true;
        }
示例#14
0
        private void FindOption(AdminArg arg, string data)
        {
            arg.Style = BoxStyle.Option;

            if (data.StartsWith("@"))
            {
                string opt_name = data.Substring(1);
                arg.OptionList = OptionMap[opt_name];
            }
            else
            {
                arg.OptionList = new AdminOptionList();
                ParseOption(arg.Options, data);
            }
        }
示例#15
0
 public void AddArg(string name, string data, bool canEdit)
 {
     AdminArg arg = new AdminArg();
     arg.Name = name;
     arg.Data = data;
     arg.CanEdit = canEdit;
     Args.Add(arg);
 }
示例#16
0
        internal void Init(AdminArg arg)
        {
            // 先清空
            this.dataBox.Text = null;
            this.dataBox.Items.Clear();
            dataBox.SuspendLayout();
            switch(arg.Style)
            {
                case BoxStyle.Text:
                    {
                        this.Style = ComboBoxStyle.Simple;
                    }
                    break;
                case BoxStyle.Combox:
                    {// 下拉菜单
                        this.Style = ComboBoxStyle.DropDown;
                        if(arg.Items.Count > 0)
                        {
                            foreach (var item in arg.Items)
                            {
                                dataBox.Items.Add(item);
                            }
                            this.dataBox.SelectedIndex = 0;
                        }
                    }
                    break;
                case BoxStyle.Option:
                    {
                        this.Style = ComboBoxStyle.DropDownList;
                        if(arg.Options != null && arg.Options.Count > 0)
                        {
                            foreach (var option in arg.Options)
                            {
                                dataBox.Items.Add(option);
                            }
                            this.dataBox.SelectedIndex = 0;
                        }
                    }
                    break;
            }

            this.Tag = arg;
            this.ArgName = arg.Show;
            this.ArgData = arg.Data;
            dataBox.ResumeLayout();
        }