public static void Deserialize(TreeView tree, string dir) { DirectoryInfo info = new DirectoryInfo(dir + "/XML"); if (info.Exists) { foreach (FileInfo info2 in info.GetFiles()) { if (((info2.Extension == ".xml") && (info2.Name != "Module.xml")) && (info2.Name != "ProtocolConfig.xml")) { XmlDocument document = new XmlDocument(); document.Load(info2.FullName); TreeNode node = tree.Nodes[0]; TreeNode node2 = tree.Nodes[1]; if (info2.Name == "PublicStruct.xml") { foreach (XmlNode node3 in document.SelectSingleNode("Root").ChildNodes) { DataStruct struct2 = new DataStruct(); XmlElement element = (XmlElement)node3; struct2.StructName = element.GetAttribute("Name"); struct2.CNName = element.GetAttribute("CName"); struct2.ProtoType = struct2.getProtoTypeValue(element.GetAttribute("ProtoType")); struct2.Comment = element.GetAttribute("Comment"); struct2.MaxFieldId = Convert.ToInt32(element.GetAttribute("MaxFieldId")); TreeNode node4 = node.Nodes.Add(struct2.StructName); node4.Name = "NewDataStruct"; node4.ImageIndex = 2; node4.Tag = struct2; foreach (XmlNode node5 in node3) { XmlElement element2 = (XmlElement)node5; DataStruct.FieldDescriptor descriptor = new DataStruct.FieldDescriptor { dataStruct = struct2 }; struct2.fieldItem.Add(descriptor); descriptor.FieldName = element2.GetAttribute("Name"); descriptor.CNName = element2.GetAttribute("CName"); descriptor.FieldType = element2.GetAttribute("FieldType"); descriptor.Comment = element2.GetAttribute("Comment"); descriptor.FieldId = Convert.ToInt32(element2.GetAttribute("FieldId")); descriptor.ValueSet = element2.GetAttribute("ValueSet"); descriptor.MaxValue = Convert.ToInt32(element2.GetAttribute("MaxValue")); descriptor.MinValue = Convert.ToInt32(element2.GetAttribute("MinValue")); string attribute = element2.GetAttribute("PreDefine"); descriptor.PreDefine = (attribute == "optional") ? DataStruct.FieldDescriptor.PreDefineType.optional : DataStruct.FieldDescriptor.PreDefineType.repeated; if (DataStruct.IsBaseType(descriptor.FieldType)) { descriptor.DefaultValue = element2.GetAttribute("DefaultValue"); } TreeNode node6 = node4.Nodes.Add(descriptor.FieldName); node6.Name = "NewField"; node6.ImageIndex = 3; node6.Tag = descriptor; } DataStructConverter.CommDataStruct.Add(struct2); DataStruct.DataStructDic.Add(struct2.getFullName(), struct2); } } else { Module module = new Module(); XmlElement element3 = (XmlElement)document.SelectSingleNode("Root"); module.ModuleName = element3.GetAttribute("Module"); module.CNName = element3.GetAttribute("CName"); module.Comment = element3.GetAttribute("Comment"); module.StartIdNum = Convert.ToInt32(element3.GetAttribute("MsgNumStart")); module.SyncDataVersion = Convert.ToInt32(element3.GetAttribute("SyncDataVersion")); Module.ModuleDic.Add(module.ModuleName, module); TreeNode node7 = node2.Nodes.Add(module.ModuleName); int startIdNum = module.StartIdNum; if (startIdNum == 0) { startIdNum = new Random().Next(0x3e8, 0x270f); } ArrayList list2 = new ArrayList(); Module.errorDic.Add(startIdNum, list2); Module.ErrorModuleName name = new Module.ErrorModuleName { en = module.ModuleName, cn = module.CNName }; Module.moduleNameDic.Add(startIdNum, name); node7.Name = "NewModule"; node7.ImageIndex = 4; node7.Tag = module; TreeNode node8 = node7.Nodes.Add("Client RPC"); node8.Name = "clientRpc"; TreeNode node9 = node7.Nodes.Add("RPC Parameters"); node9.Name = "rpcProto"; TreeNode node10 = node7.Nodes.Add("Module Data"); node10.Name = "syncData"; TreeNode node11 = node7.Nodes.Add("Configuration Files"); node11.Name = "configFile"; module.rpcProtoNode = node9; foreach (XmlNode node12 in document.SelectSingleNode("Root").ChildNodes) { if (node12.Name == "Operate") { XmlElement element4 = (XmlElement)node12; Module.OperaterItem item = new Module.OperaterItem { module = module }; module.operateItem.Add(item); item.Name = element4.GetAttribute("Name"); item.CNName = element4.GetAttribute("CName"); item.Comment = element4.GetAttribute("Comment"); TreeNode node13 = node8.Nodes.Add(item.Name); node13.Name = "NewOperate"; node13.ImageIndex = 5; node13.Tag = item; foreach (XmlNode node14 in node12) { XmlElement element5 = (XmlElement)node14; Module.OperaterItem.SubOperaterItem item2 = new Module.OperaterItem.SubOperaterItem(); item.subOperateItem.Add(item2); item2.operaterItem = item; item2.Type = item2.getOperateType(element5.Name); item2.toSetOpType(element5.Name); item2.toSetName(element5.GetAttribute("Name")); item2.toSetCnName(element5.GetAttribute("CName")); item2.Comment = element5.GetAttribute("Comment"); item2.toSetDataStructName(element5.GetAttribute("DataStruct")); TreeNode node15 = node13.Nodes.Add(element5.GetAttribute("Name")); node15.Name = "NewSubOperate"; node15.ImageIndex = 6; node15.Tag = item2; } } else if (node12.Name == "Struct") { TreeNode node16; XmlElement element6 = (XmlElement)node12; DataStruct struct3 = new DataStruct { module = module }; module.moduleDataStruct.Add(struct3); struct3.StructName = element6.GetAttribute("Name"); struct3.CNName = element6.GetAttribute("CName"); struct3.Comment = element6.GetAttribute("Comment"); struct3.MaxFieldId = Convert.ToInt32(element6.GetAttribute("MaxFieldId")); struct3.ProtoType = struct3.getProtoTypeValue(element6.GetAttribute("ProtoType")); struct3.ToSetDataType(struct3.ConvertDataType(element6.GetAttribute("DataType"))); struct3.saveToDB = element6.GetAttribute("SaveToDB").ToLower() == "true"; struct3.SyncToClient = element6.GetAttribute("SyncToClient").ToLower() == "true"; if (struct3.ProtoType == DataStruct.protoTypeE.RpcProto) { node16 = node9.Nodes.Add(struct3.StructName); } else { node16 = node10.Nodes.Add(struct3.StructName); } node16.Name = "NewDataStruct"; node16.ImageIndex = 2; node16.Tag = struct3; struct3.selfTreeNode = node16; foreach (XmlNode node17 in node12) { XmlElement element7 = (XmlElement)node17; DataStruct.FieldDescriptor descriptor2 = new DataStruct.FieldDescriptor { dataStruct = struct3 }; struct3.fieldItem.Add(descriptor2); descriptor2.FieldName = element7.GetAttribute("Name"); descriptor2.CNName = element7.GetAttribute("CName"); descriptor2.Comment = element7.GetAttribute("Comment"); descriptor2.FieldType = element7.GetAttribute("FieldType"); descriptor2.FieldId = Convert.ToInt32(element7.GetAttribute("FieldId")); string str2 = element7.GetAttribute("PreDefine"); descriptor2.PreDefine = (str2 == "optional") ? DataStruct.FieldDescriptor.PreDefineType.optional : DataStruct.FieldDescriptor.PreDefineType.repeated; descriptor2.ValueSet = element7.GetAttribute("ValueSet"); descriptor2.MaxValue = Convert.ToInt32(element7.GetAttribute("MaxValue")); descriptor2.MinValue = Convert.ToInt32(element7.GetAttribute("MinValue")); if (DataStruct.IsBaseType(descriptor2.FieldType)) { descriptor2.DefaultValue = element7.GetAttribute("DefaultValue"); } TreeNode node18 = node16.Nodes.Add(descriptor2.FieldName); node18.Name = "NewField"; node18.ImageIndex = 3; node18.Tag = descriptor2; } DataStruct.DataStructDic.Add(struct3.getFullName(), struct3); } else if (node12.Name == "ConfigFile") { XmlElement element8 = (XmlElement)node12; ConfigFile file = new ConfigFile { module = module }; module.configFiles.Add(file); file.toSetConfigName(element8.GetAttribute("Name")); file.CNName = element8.GetAttribute("CName"); file.Comment = element8.GetAttribute("Comment"); TreeNode node19 = node11.Nodes.Add(file.ConfigName); node19.Name = "NewConfigFile"; node19.ImageIndex = 2; node19.Tag = file; foreach (XmlNode node20 in node12) { XmlElement element9 = (XmlElement)node20; ConfigFile.ConfigField field = new ConfigFile.ConfigField { configFile = file }; file.fieldItem.Add(field); field.toSetFieldName(element9.GetAttribute("Name")); field.toSetCnName(element9.GetAttribute("CName")); field.toSetComment(element9.GetAttribute("Comment")); field.toSetFieldType(element9.GetAttribute("FieldType")); field.toSetDefaultValue(element9.GetAttribute("DefaultValue")); field.toSetCheckIndex(element9.GetAttribute("CheckIndex")); field.toSetValueSet(element9.GetAttribute("ValueSet")); field.toSetIsPri(element9.GetAttribute("IsPri").ToLower() == "true"); field.toSetIsSvr(element9.GetAttribute("IsSvr").ToLower() == "true"); field.toSetIsDes(element9.GetAttribute("IsDes").ToLower() == "true"); field.toSetMaxValue(Convert.ToInt32(element9.GetAttribute("MaxValue"))); field.toSetMinValue(Convert.ToInt32(element9.GetAttribute("MinValue"))); TreeNode node21 = node19.Nodes.Add(field.FieldName); node21.Name = "NewConfigField"; node21.ImageIndex = 3; node21.Tag = field; } ConfigFile.ConfigFileDic[file.ConfigName] = file; } } } } } } }
private static void GenRpcCode(Module m, Module.OperaterItem operate, ref string OperationDeclare, ref string OperationImpl, ref string OperationImplement, ref int num, ref int num2, ref string RpcValues, ref string CallBack, ref string InitController, ref string ContCallBacks, ref string Layer, ref string LayerCtor, ref string LayerCtoF, ref string EnterLayer, ref string EnterFunctions, ref string EnterFunctionsF, ref string CallBackARGS, ref string TestProtocol, ref string TestArgs, ref string Test2, ref string Test3, ref string Test4) { DataStruct struct2 = null; DataStruct struct3 = null; DataStruct struct4 = null; foreach (Module.OperaterItem.SubOperaterItem item in operate.subOperateItem) { string text1 = operate.Name + item.Name; if (item.Type == Module.OperateType.OP_ASK) { if (!DataStruct.DataStructDic.TryGetValue(item.DataStructName, out struct2)) { DataStruct.DataStructDic.TryGetValue(m.ModuleName + item.DataStructName, out struct2); } struct2.getFullName(); if (" 'AskName': [" != TestArgs) { TestArgs = TestArgs + ",\r\n"; TestArgs = TestArgs + " \"" + operate.Name + "\""; } else { TestArgs = TestArgs + "\"" + operate.Name + "\""; } if (" 'AskList':[" != Test3) { Test3 = Test3 + ",\r\n"; Test3 = Test3 + " @" + operate.Name; } else { Test3 = Test3 + "@" + operate.Name; } object obj2 = OperationImpl; OperationImpl = string.Concat(new object[] { obj2, "RPC_CODE_", operate.Name.ToUpper(), "_REQUEST = ", (int)num, "\r\n" }); num++; OperationImplement = OperationImplement + operate.Name + "AskPB = null\r\n"; DiGui(ref m, ref RpcValues, "Rpc" + operate.Name + "Ask", false); string str = " " + operate.Name + "Ask = " + operate.Name + "AskPB.prototype\r\n"; CallBack = CallBack + " " + operate.Name + " : ("; int num3 = 0; if (" 'ParamterTypelist': [" != Test4) { Test4 = Test4 + ",\r\n"; Test4 = Test4 + " ["; } else { Test4 = Test4 + "["; } if (" 'ParamterList': [" != Test2) { Test2 = Test2 + ",\r\n"; Test2 = Test2 + " ["; } else { Test2 = Test2 + "["; } foreach (DataStruct.FieldDescriptor descriptor in struct2.fieldItem) { Test2 = Test2 + ((num3 == 0) ? "" : ","); Test2 = Test2 + "\"" + descriptor.FieldName + "\""; Test4 = Test4 + ((num3 == 0) ? "" : ","); Test4 = Test4 + "\"" + descriptor.FieldType + "\""; CallBack = CallBack + ((num3 == 0) ? "" : ","); CallBack = CallBack + descriptor.FieldName; string str3 = str; str = str3 + " " + operate.Name + "Ask.set" + descriptor.FieldName + " " + descriptor.FieldName + "\r\n"; num3++; } Test2 = Test2 + "]"; Test4 = Test4 + "]"; string str4 = InitController; InitController = str4 + " " + operate.Name + "AskPB = Proto.build(\"Rpc" + operate.Name + "Ask\")\r\n"; string str5 = str; str = str5 + " mLayerMgr.sendAsk(RPC_CODE_" + operate.Name.ToUpper() + "_REQUEST," + operate.Name + "Ask, (data)->\r\n"; if (operate.Name.ToLower().IndexOf("syncdata") == -1) { str = str + " NetTipController.hideNetTip()\r\n"; } str = (str + " replyCB( " + operate.Name + "ReplyPB.decode(data)) if typeof(replyCB) is \"function\"\r\n") + " )\r\n"; if (operate.Name.ToLower().IndexOf("syncdata") == -1) { str = str + " NetTipController.showNetTip()\r\n"; } CallBack = CallBack + ((num3 == 0) ? "" : ","); CallBack = CallBack + "replyCB) ->\r\n"; CallBack = CallBack + str; } if (item.Type == Module.OperateType.OP_REPLY) { if (!DataStruct.DataStructDic.TryGetValue(item.DataStructName, out struct3)) { DataStruct.DataStructDic.TryGetValue(m.ModuleName + item.DataStructName, out struct3); } struct3.getFullName(); DiGui(ref m, ref RpcValues, "Rpc" + operate.Name + "Reply", false); OperationImplement = OperationImplement + operate.Name + "ReplyPB = null\r\n"; string str6 = InitController; InitController = str6 + " " + operate.Name + "ReplyPB = Proto.build(\"Rpc" + operate.Name + "Reply\")\r\n"; } if (((item.Type == Module.OperateType.OP_NOTIFY) || (item.Type == Module.OperateType.OP_SERVER_NOTIFY)) || ((item.Type == Module.OperateType.OP_CLIENT_NOTIFY) || (item.Type == Module.OperateType.OP_DUPLEX_NOTIFY))) { Module.OperateType type = item.Type; if (!DataStruct.DataStructDic.TryGetValue(item.DataStructName, out struct4)) { DataStruct.DataStructDic.TryGetValue(m.ModuleName + item.DataStructName, out struct4); } struct4.getFullName(); object obj3 = OperationImpl; OperationImpl = string.Concat(new object[] { obj3, "RPC_CODE_", operate.Name.ToUpper(), "_NOTIFY = ", (int)num, "\r\n" }); string str7 = LayerCtoF; LayerCtoF = str7 + " _model.Set" + operate.Name + "NotifyCB(@" + operate.Name + "CBNotify)\r\n"; LayerCtor = LayerCtor + " " + operate.Name + "CBNotify:(ret_msg)->\r\n"; LayerCtor = LayerCtor + " cc.log \"" + operate.Name + "CBNotify Respond \"\r\n"; OperationImplement = OperationImplement + operate.Name + "NotifyPB = null\r\n"; DiGui(ref m, ref RpcValues, "Rpc" + operate.Name + "Notify", false); string str8 = InitController; InitController = str8 + " " + operate.Name + "NotifyPB = Proto.build(\"Rpc" + operate.Name + "Notify\")\r\n"; OperationDeclare = OperationDeclare + item.DataStructName + "CB = null\r\n"; if ((item.Type == Module.OperateType.OP_SERVER_NOTIFY) || (item.Type == Module.OperateType.OP_DUPLEX_NOTIFY)) { string str9 = InitController; InitController = str9 + " mLayerMgr.registerNotify(RPC_CODE_" + operate.Name.ToUpper() + "_NOTIFY,@" + operate.Name + "CB)\r\n"; string str10 = ContCallBacks; ContCallBacks = str10 + " Set" + operate.Name + "NotifyCB : (cb) -> " + item.DataStructName + "CB = cb\r\n"; ContCallBacks = ContCallBacks + " " + operate.Name + "CB : (data)->\r\n"; string str11 = ContCallBacks; ContCallBacks = str11 + " " + item.DataStructName + "CB( " + operate.Name + "NotifyPB.decode(data)) if typeof(" + item.DataStructName + "CB) is \"function\"\r\n"; } if ((item.Type == Module.OperateType.OP_CLIENT_NOTIFY) || (item.Type == Module.OperateType.OP_DUPLEX_NOTIFY)) { if (" 'AskName': [" != TestArgs) { TestArgs = TestArgs + ",\r\n"; TestArgs = TestArgs + " \"" + operate.Name + "\""; } else { TestArgs = TestArgs + "\"" + operate.Name + "\""; } if (" 'AskList':[" != Test3) { Test3 = Test3 + ",\r\n"; Test3 = Test3 + " @" + operate.Name; } else { Test3 = Test3 + operate.Name; } string str2 = " " + operate.Name + "Notify = " + operate.Name + "NotifyPB.prototype\r\n"; CallBack = CallBack + " " + operate.Name + " : ("; int num4 = 0; if (" 'ParamterTypelist': [" != Test4) { Test4 = Test4 + ",\r\n"; Test4 = Test4 + " ["; } else { Test4 = Test4 + "["; } if (" 'ParamterList': [" != Test2) { Test2 = Test2 + ",\r\n"; Test2 = Test2 + " ["; } else { Test2 = Test2 + "["; } foreach (DataStruct.FieldDescriptor descriptor2 in struct4.fieldItem) { Test2 = Test2 + ((num4 == 0) ? "" : ","); Test2 = Test2 + "\"" + descriptor2.FieldName + "\""; Test4 = Test4 + ((num4 == 0) ? "" : ","); Test4 = Test4 + "\"" + descriptor2.FieldType + "\""; CallBack = CallBack + ((num4 == 0) ? "" : ","); CallBack = CallBack + descriptor2.FieldName; string str12 = str2; str2 = str12 + " " + operate.Name + "Notify.set" + descriptor2.FieldName + " " + descriptor2.FieldName + "\r\n"; num4++; } Test2 = Test2 + "]"; Test4 = Test4 + "]"; CallBack = CallBack + ") ->\r\n"; string str13 = str2; str2 = str13 + " mLayerMgr.sendNotify(RPC_CODE_" + operate.Name.ToUpper() + "_NOTIFY," + operate.Name + "Notify)\r\n"; CallBack = CallBack + str2; } num++; num2++; } } }