public int CompareTo(sModel model) { int destModel = int.Parse(model.id); int scrModel = int.Parse(this.id); return(scrModel.CompareTo(destModel)); }
public void LoadProto() { string allText = System.IO.File.ReadAllText(protoPath).Trim(); string patternMsgCommon = @"(//.\w+\n|)message p.\w+ \{[\s\S]*?\}"; //匹配出“p_”开头的message,包含注释 string patternMsgModel = @"(//.\w+\n|)message [^p].\w+ \{[\s\S]*?\}"; //匹配出非“p_”开头的message,包含注释 string patternModel = @"##model_begin.*##model_end##"; //收集模块 string patternCommond = @"##begin.*##end##"; //收集协议号 string patternParam = @"[^#]+"; //解析指令 List <sMessage> modelMsgList = new List <sMessage> (); foreach (Match match in Regex.Matches(allText, patternMsgCommon, RegexOptions.Multiline)) { commonMsgList.Add(sMessage.ValueOf(match.Value)); } foreach (Match match in Regex.Matches(allText, patternMsgModel, RegexOptions.Multiline)) { modelMsgList.Add(sMessage.ValueOf(match.Value)); } foreach (Match match in Regex.Matches(allText, patternModel, RegexOptions.Multiline)) { modelList.Add(sModel.ValueOf(match.Value, patternParam)); } modelList.Sort((left, right) => { return(left.CompareTo(right)); }); foreach (Match match in Regex.Matches(allText, patternCommond, RegexOptions.Multiline)) { sCommand command = sCommand.ValueOf(match.Value, patternParam); command.msg_c2s = modelMsgList.Find(a => a.nameEn.Equals(command.nameEn + "_c2s")); if (command.msg_c2s != null) { command.msg_c2s.id = "1"; command.msg_c2s.nameCn = command.nameCn; command.msg_c2s.modelId = command.modelId; command.msg_c2s.commandId = command.id; } command.msg_s2c = modelMsgList.Find(a => a.nameEn.Equals(command.nameEn + "_s2c")); if (command.msg_s2c != null) { command.msg_s2c.id = "2"; command.msg_s2c.nameCn = command.nameCn; command.msg_s2c.modelId = command.modelId; command.msg_s2c.commandId = command.id; } sModel model = modelList.Find(a => a.id == command.modelId); if (model != null) { model.AddCommand(command); } else { Debug.LogError("found modelId:" + command.modelId); } } }
public ProtoTreeViewItem(sModel model) { Type = eType.model; this._model = model; this.id = int.Parse(model.id); this.depth = 0; this.displayName = "[" + this.id + "]" + model.nameEn; }
public ProtoTreeViewItem(sModel model, sCommand command) { Type = eType.command; this._model = model; this._command = command; this.id = int.Parse(command.modelId) * 100 + int.Parse(command.id); this.depth = 1; this.displayName = "[" + this.id + "]" + command.nameEn; }
public ProtoTreeViewItem(sModel model, sCommand command, sMessage message) { Type = eType.message; this._model = model; this._command = command; this._message = message; this.id = int.Parse(message.modelId) * 10000 + int.Parse(message.commandId) * 100 + int.Parse(message.id); this.depth = 2; this.displayName = message.nameEn; }
public static sModel ValueOf(string content, string pattern) { sModel model = new sModel(); MatchCollection matchCol = Regex.Matches(content, pattern, RegexOptions.Multiline); model.nameEn = matchCol [1].Value; model.id = matchCol [2].Value; model.nameCn = matchCol [3].Value; return(model); }
protected override TreeViewItem BuildRoot() { selected = -1; Clear(); LoadProto(); TreeViewItem root = new TreeViewItem() { depth = -1 }; SetupDepthsFromParentsAndChildren(root); for (int i = 0; i < modelList.Count; i++) { sModel model = modelList [i]; ProtoTreeViewItem modelItem = new ProtoTreeViewItem(model); for (int j = 0; j < model.cmdList.Count; j++) { sCommand command = model.cmdList [j]; ProtoTreeViewItem commonItem = new ProtoTreeViewItem(model, command); if (command.msg_c2s != null) { ProtoTreeViewItem c2sItem = new ProtoTreeViewItem(model, command, command.msg_c2s); commonItem.AddChild(c2sItem); itemDic [c2sItem.id] = c2sItem; } if (command.msg_s2c != null) { ProtoTreeViewItem s2cItem = new ProtoTreeViewItem(model, command, command.msg_s2c); commonItem.AddChild(s2cItem); itemDic [s2cItem.id] = s2cItem; } modelItem.AddChild(commonItem); itemDic [commonItem.id] = commonItem; } root.AddChild(modelItem); itemDic [modelItem.id] = modelItem; } SetupDepthsFromParentsAndChildren(root); return(root); }