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); }
private void procBtn_Click(object sender, EventArgs e) { AdminCmd cmd = GetCmd(); if (cmd == null) { return; } // set uid if (string.IsNullOrEmpty(uidCbx.Text)) { WriteLog("uid不能为空"); return; } // 计算uid string uid = uidCbx.Text; if (char.IsDigit(uid[0])) { uid = "u" + uid; } cmd.Uid = uid; if (m_mgr.UpdateUID(uid)) { UpdateUID(); } // 发送gm string msg = cmd.Concat(); m_mgr.Execute(msg, (int)countNum.Value); }
public void InitForm() { // 初始化命令列表 adminTreeView.Nodes.Clear(); Dictionary <string, TreeNode> nodes = new Dictionary <string, TreeNode>(); List <AdminCmd> cmds = m_mgr.Cmds; for (int i = 0; i < cmds.Count; ++i) { AdminCmd cmd = cmds[i]; TreeNode node = new TreeNode(); node.Text = cmd.Name; node.Tag = cmd; // root? TreeNode parent; if (!nodes.TryGetValue(cmd.Group, out parent)) { parent = new TreeNode(); parent.Text = cmd.Group; parent.Tag = null; nodes[cmd.Group] = parent; adminTreeView.Nodes.Add(parent); } parent.Nodes.Add(node); } // 展开所有 adminTreeView.ExpandAll(); // init host hostCbx.Items.Clear(); List <string> hosts = m_mgr.Hosts; if (hosts.Count > 0) { for (int i = 0; i < hosts.Count; ++i) { hostCbx.Items.Add(hosts[i]); } hostCbx.Text = hosts[0]; } // init uid UpdateUID(); }
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(); }
// 批量执行 private void batchBtn_Click(object sender, EventArgs e) { AdminCmd cmd = GetCmd(); if (cmd == null) { return; } string uidstr = uidListRTB.Text; if (string.IsNullOrEmpty(uidstr)) { WriteLog("uid不能为空"); return; } string[] uids = uidstr.Split(new char[] { '\n', ',', '|' }, StringSplitOptions.RemoveEmptyEntries); if (uids.Length == 0) { WriteLog("uid不能为空"); return; } for (int i = 0; i < uids.Length; ++i) { string uid = uids[i]; if (char.IsDigit(uid[0])) { uid = "u" + uid; } cmd.Uid = uid; string msg = cmd.Concat(); m_mgr.Execute(msg, 1); } }
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); } }
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()); } } } }
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()); } } } }