예제 #1
0
        public void CreateAsContainer(ExcelData sheet, CAsDataConfig dataConfig)
        {
            string        name         = Global.FirstCharToUpper(sheet.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = dataConfig.folder + @"\com\game\data\container\" + name + "Container.as";
            string        templatePath = @".\Templates\AS\temp_as_res_container.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            needReplace.Add("importList");
            needReplace.Add("Name");
            needReplace.Add("ContainerName");
            replace.Add(dataConfig.package);
            List <string> import = new List <string>();

            if (dataConfig.containerImport.Length > 0)
            {
                foreach (var container in dataConfig.containerImport)
                {
                    import.Add(container);
                }
            }
            replace.Add(import);
            replace.Add(name);
            replace.Add(name + "Container");
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + "Container.as文件生成完毕");
        }
예제 #2
0
        public void CreateJavaResBean(ExcelData excelSheetData, CJavaDataConfig javaDataConfig)
        {
            string[,] data = Global.GetSheetFromExcel(excelSheetData.ExcelName, excelSheetData.SheetName);
            string        name         = Global.FirstCharToUpper(excelSheetData.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = javaDataConfig.folder + @"\src\com\game\data\bean\" + name + "Bean.java";
            string        templatePath = @".\Templates\Java\temp_java_res_bean.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            needReplace.Add("BeanName");

            replace.Add(javaDataConfig.package);
            replace.Add(name);
            if (data.GetLength(1) > 0)
            {
                needReplace.Add("fieldList");
                List <BeanVar> beanList = new List <BeanVar>();
                for (int i = 0; i < data.GetLength(1); i++)
                {
                    BeanVar beanVar = new BeanVar();
                    beanVar.name      = data[1, i];
                    beanVar.className = data[2, i];
                    beanVar.explain   = data[4, i];
                    beanList.Add(beanVar);
                }
                replace.Add(beanList);
            }
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + "Bean.java文件生成完毕");
        }
예제 #3
0
        public void CreateJavaResContainer(ExcelData excelSheetData, CJavaDataConfig javaDataConfig)
        {
            string[,] data = Global.GetSheetFromExcel(excelSheetData.ExcelName, excelSheetData.SheetName);
            string        name         = Global.FirstCharToUpper(excelSheetData.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = javaDataConfig.folder + @"\src\com\game\data\mapsql\" + name + "Container.java";
            string        templatePath = @".\Templates\Java\temp_java_res_container.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            needReplace.Add("Name");
            needReplace.Add("TimeNow");
            replace.Add(javaDataConfig.package);
            replace.Add(name);
            replace.Add(DateTime.Now.ToString("yy-MM-dd HH:mm:ss"));
            for (int i = 0; i < data.GetLength(1); i++)
            {
                if (!string.IsNullOrEmpty(data[0, i]) && data[0, i] == "1")
                {
                    needReplace.Add("ID");
                    replace.Add(Global.FirstCharToUpper(data[1, i]));
                    break;
                }
            }

            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + "Container.java文件生成完毕");
        }
예제 #4
0
        public void CreateJavaResMapSql(ExcelData excelSheetData, CJavaDataConfig javaDataConfig)
        {
            string[,] data = Global.GetSheetFromExcel(excelSheetData.ExcelName, excelSheetData.SheetName);
            string        name         = excelSheetData.SheetName.Replace("'", "").Replace("$", "");
            string        filePath     = javaDataConfig.folder + @"\src\com\game\data\sqlmap\" + name + ".xml";
            string        templatePath = @".\Templates\Java\temp_java_res_sqlmap.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("Name");
            replace.Add(name);
            if (data.GetLength(1) > 0)
            {
                needReplace.Add("fieldList");
                List <BeanVar> beanVars = new List <BeanVar>();
                for (int i = 0; i < data.GetLength(1); i++)
                {
                    BeanVar bean = new BeanVar();
                    bean.name      = data[1, i];
                    bean.className = data[2, i];
                    beanVars.Add(bean);
                }
                replace.Add(beanVars);
            }

            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + ".xml文件生成完毕");
        }
예제 #5
0
        private static void CreateAsHandler(CMessages msg, string path)
        {
            foreach (var message in msg.messages)
            {
                if (message.name.Contains("Res"))
                {
                    FileStream fs = new FileStream(path + @"\" + message.name + "Handler.as",
                                                   FileMode.Create, FileAccess.Write);
                    StreamWriter    sw     = new StreamWriter(fs);
                    Template        temp   = CNVelociryHelp.GetTemplate(@".\Templates\AS\" + Global.AsHandleTemplatePath.Substring(Global.AsHandleTemplatePath.LastIndexOf(@"\")));
                    VelocityContext vltCtx = new VelocityContext();
                    vltCtx.Put("PackageString", msg.import);
                    vltCtx.Put("HandlerName", message.name + "Handler");
                    vltCtx.Put("MessageName", message.name + "Message");

                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    temp.Merge(vltCtx, vltWriter);

                    Console.WriteLine(vltWriter.ToString());

                    sw.Write(vltWriter.ToString());
                    sw.Close();
                    fs.Close();
                    Debug.Log(message.name + "Handler.as生成成功");
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 生成CS表格资源
        /// </summary>
        /// <param name="checkedListBox1"></param>
        /// <param name="excelDatas"></param>
        /// <param name="label1"></param>
        public void CreateCsResBean(ExcelData sheet, CAsDataConfig dataConfig, bool isSet = true)
        {
            string[,] data = Global.GetSheetFromExcel(sheet.ExcelName, sheet.SheetName);
            string        name         = Global.FirstCharToUpper(sheet.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = dataConfig.folder + @"\" + name + ".cs";
            string        templatePath = @".\Templates\CS\temp_cs_res_bean.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("DateTime");
            replace.Add(DateTime.Now.ToString("yyyy-M-d HH:mm:ss"));
            needReplace.Add("PackageString");
            replace.Add(dataConfig.package);
            needReplace.Add("BeanName");
            replace.Add(name);
            List <string> import = new List <string>();

            if (dataConfig.beanImport != null && dataConfig.beanImport.Length > 0)
            {
                needReplace.Add("importList");
                foreach (var bean in dataConfig.beanImport)
                {
                    import.Add(bean);
                }
                replace.Add(import);
            }
            needReplace.Add("fieldList");
            List <BeanVar> fieldList = new List <BeanVar>();

            for (int i = 0; i < data.GetLength(1); i++)
            {
                if (!string.IsNullOrWhiteSpace(data[1, i]) && !data[0, i].Contains("备注") && !data[1, i].Contains("备注") && !data[2, i].Contains("备注") && !data[3, i].Contains("备注") && !data[4, i].Contains("备注"))
                {
                    BeanVar field = new BeanVar();
                    field.name      = data[1, i];
                    field.className = data[2, i];
                    field.explain   = data[4, i].Replace("\n", "").Replace("\r", "");
                    fieldList.Add(field);
                }
            }
            replace.Add(fieldList);
            if (isSet)
            {
                needReplace.Add("getFieldList");
                replace.Add(fieldList);
            }
            if (File.Exists(templatePath))
            {
                CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
                Debug.Log(name + ".cs文件生成完毕");
            }
            else
            {
                Debug.Log("模板文件不存在请检查." + templatePath);
            }
        }
예제 #7
0
        private void WriteToDataConfig(ExcelData excelSheetData, string dataConfigPath, CJavaDataConfig javaDataConfig, MapperNode[] mapperNodes)
        {
            string        name         = excelSheetData.SheetName.Replace("'", "").Replace("$", "");
            string        filePath     = dataConfigPath;
            string        templatePath = @".\Templates\Java\temp_java_res_dataconfig.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("SqlType");
            replace.Add(javaDataConfig.dbType);
            needReplace.Add("SqlIP");
            replace.Add(javaDataConfig.dbIp);
            needReplace.Add("SqlPort");
            replace.Add(javaDataConfig.dbport);
            needReplace.Add("DBName");
            replace.Add(javaDataConfig.dbName);
            needReplace.Add("UserName");
            replace.Add(javaDataConfig.dbUser);
            needReplace.Add("Psw");
            replace.Add(javaDataConfig.dbPsw);
            needReplace.Add("sheetList");
            List <MapperSheet> sheetList = new List <MapperSheet>();
            MapperSheet        sheet     = new MapperSheet(name, DateTime.Now.ToString("yyyy-M-d HH:mm:ss"));

            if (mapperNodes != null)
            {
                foreach (var mn in mapperNodes)
                {
                    MapperSheet ms = new MapperSheet(mn.name, mn.time);
                    sheetList.Add(ms);
                }
                bool sampFlag = false;
                for (int i = 0; i < sheetList.Count; i++)
                {
                    if (sheet.sheetName == sheetList[i].sheetName)
                    {
                        sampFlag             = true;
                        sheetList[i].nowTime = sheet.nowTime;
                        break;
                    }
                }
                if (!sampFlag)
                {
                    sheetList.Add(sheet);
                }
            }
            else
            {
                sheetList.Add(sheet);
            }

            replace.Add(sheetList);
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
        }
예제 #8
0
 private void CreateJavaMsMessage(CMessages messages, string path)
 {
     foreach (var cMes in messages.messages)
     {
         string        msgMane      = cMes.name + "Message";
         string        filePath     = path + @"\message\" + msgMane + ".java";
         string        templatePath = @".\Templates\Java\temp_java_message_message.vm";
         List <string> needReplace  = new List <string>();
         ArrayList     replace      = new ArrayList();
         needReplace.Add("PackageString");
         replace.Add(messages.import);
         needReplace.Add("BeanSuper");
         replace.Add(messages.beanSuper);
         needReplace.Add("MessageName");
         replace.Add(msgMane);
         needReplace.Add("Explain");
         replace.Add(cMes.explain);
         if (cMes.fields != null && cMes.fields.Length > 0)
         {
             needReplace.Add("fieldList");
             List <BeanVar> beanList = new List <BeanVar>();
             foreach (var cField in cMes.fields)
             {
                 BeanVar bean = new BeanVar();
                 bean.name      = cField.name;
                 bean.className = cField.fieldType;
                 bean.explain   = cField.explain;
                 beanList.Add(bean);
             }
             replace.Add(beanList);
         }
         if (cMes.lists != null && cMes.lists.Length > 0)
         {
             needReplace.Add("beanList");
             List <BeanVar> beanList = new List <BeanVar>();
             foreach (var cList in cMes.lists)
             {
                 BeanVar bean = new BeanVar();
                 bean.name      = cList.name;
                 bean.className = cList.listType;
                 bean.explain   = cList.explain;
                 beanList.Add(bean);
             }
             replace.Add(beanList);
         }
         CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
         Debug.Log(msgMane + ".java文件生成完毕");
     }
 }
예제 #9
0
        public void CreateAsResBean(ExcelData sheet, CAsDataConfig dataConfig, bool isSet = true)
        {
            string[,] data = Global.GetSheetFromExcel(sheet.ExcelName, sheet.SheetName);
            string        name         = Global.FirstCharToUpper(sheet.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = dataConfig.folder + @"\com\game\data\bean\" + name + ".as";
            string        templatePath = @".\Templates\AS\temp_as_res_bean.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            needReplace.Add("importList");
            needReplace.Add("BeanName");
            needReplace.Add("fieldList");
            replace.Add(dataConfig.package);
            List <string> import = new List <string>();

            if (dataConfig.beanImport.Length > 0)
            {
                foreach (var bean in dataConfig.beanImport)
                {
                    import.Add(bean);
                }
            }
            replace.Add(import);
            replace.Add(name);
            List <BeanVar> fieldList = new List <BeanVar>();

            for (int i = 0; i < data.GetLength(1); i++)
            {
                if (!string.IsNullOrWhiteSpace(data[1, i]))
                {
                    BeanVar field = new BeanVar();
                    field.name      = data[1, i];
                    field.className = data[2, i];
                    field.explain   = data[4, i];
                    fieldList.Add(field);
                }
            }
            replace.Add(fieldList);
            if (isSet)
            {
                needReplace.Add("getFieldList");
                replace.Add(fieldList);
            }
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + ".as文件生成完毕");
        }
예제 #10
0
        private static void CreateAsMessages(CMessages msg, string path)
        {
            foreach (var message in msg.messages)
            {
                FileStream fs = new FileStream(path + @"\" + message.name + "Message.as",
                                               FileMode.Create, FileAccess.Write);
                StreamWriter    sw     = new StreamWriter(fs);
                Template        temp   = CNVelociryHelp.GetTemplate(@".\Templates\AS\" + Global.AsMessageTemplatePath.Substring(Global.AsMessageTemplatePath.LastIndexOf(@"\")));
                VelocityContext vltCtx = new VelocityContext();
                vltCtx.Put("PackageString", msg.import);
                vltCtx.Put("Explain", message.explain);
                vltCtx.Put("MessageName", message.name + "Message");
                vltCtx.Put("MessageID", msg.ID + message.ID);
                if (message.fields != null && message.fields.Length > 0)
                {
                    List <BeanVar> beanVarList = new List <BeanVar>();
                    //List<CField> beanWriteList = new List<CField>();
                    foreach (var field in message.fields)
                    {
                        BeanVar var = new BeanVar(field);
                        beanVarList.Add(var);
                    }
                    vltCtx.Put("fildList", beanVarList);
                }
                if (message.lists != null && message.lists.Length > 0)
                {
                    List <BeanVar> beanVarList = new List <BeanVar>();
                    foreach (var list in message.lists)
                    {
                        BeanVar var = new BeanVar(list);
                        beanVarList.Add(var);
                    }
                    vltCtx.Put("vectorList", beanVarList);
                }

                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                temp.Merge(vltCtx, vltWriter);

                Console.WriteLine(vltWriter.ToString());

                sw.Write(vltWriter.ToString());
                sw.Close();
                fs.Close();
                Debug.Log(message.name + "Message.as生成成功");
            }
        }
예제 #11
0
        private void WriteToMsgPool(CMessages messages, string filePath, List <MessgaeField> fieldList)
        {
            string        templatePath = @".\Templates\Java\temp_java_message_messagepool.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("MessageList");
            List <MessgaeField> mf = new List <MessgaeField>();

            if (fieldList != null)
            {
                foreach (var messgaeField in fieldList)
                {
                    mf.Add(messgaeField);
                }
            }
            foreach (var cMessage in messages.messages)
            {
                MessgaeField mft = new MessgaeField();
                mft.name = cMessage.name;
                mft.id   = messages.ID + cMessage.ID;
                if (fieldList != null)
                {
                    bool flag = false;
                    foreach (var messgaeField in fieldList)
                    {
                        if (messgaeField.id == mft.id)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        mf.Add(mft);
                    }
                }
                else
                {
                    mf.Add(mft);
                }
            }
            replace.Add(mf);
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
        }
예제 #12
0
        private void WriteToDataManager(string sheetDataName, string dataManagerPath, string packageString, List <BeanVar> sheetNameList)
        {
            string        name         = sheetDataName.Replace("'", "").Replace("$", "");
            string        filePath     = dataManagerPath;
            string        templatePath = @".\Templates\Java\temp_java_res_datamanager.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            replace.Add(packageString);
            needReplace.Add("TimeNow");
            replace.Add(DateTime.Now.ToString("yyyy-M-d HH:mm:ss"));
            needReplace.Add("containerList");
            BeanVar beanVar = new BeanVar();

            beanVar.name = name;
            List <BeanVar> beanVarLiseList = new List <BeanVar>();

            if (sheetNameList != null)
            {
                foreach (var sheetName in sheetNameList)
                {
                    beanVarLiseList.Add(sheetName);
                }
                bool sampFlag = false;
                for (int i = 0; i < sheetNameList.Count; i++)
                {
                    if (beanVar.UpperName == sheetNameList[i].UpperName)
                    {
                        sampFlag = true;
                        break;
                    }
                }
                if (!sampFlag)
                {
                    beanVarLiseList.Add(beanVar);
                }
            }
            else
            {
                beanVarLiseList.Add(beanVar);
            }
            replace.Add(beanVarLiseList);
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
        }
예제 #13
0
        public void CreateJavaResDao(ExcelData excelSheetData, CJavaDataConfig javaDataConfig)
        {
            string        name         = Global.FirstCharToUpper(excelSheetData.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = javaDataConfig.folder + @"\src\com\game\data\dao\" + name + "Dao.java";
            string        templatePath = @".\Templates\Java\temp_java_res_dao.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("PackageString");
            needReplace.Add("Name");
            needReplace.Add("TimeNow");
            needReplace.Add("BaseDao");
            replace.Add(javaDataConfig.package);
            replace.Add(name);
            replace.Add(DateTime.Now.ToString("yy-MM-dd HH:mm:ss"));
            replace.Add(javaDataConfig.baseDao);
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + "Dao.java文件生成完毕");
        }
예제 #14
0
 private void CreateJavaMsHandler(CMessages messages, string path)
 {
     foreach (var cMes in messages.messages)
     {
         string        msgMane      = cMes.name + "Handler";
         string        filePath     = path + @"\handler\" + msgMane + ".java";
         string        templatePath = @".\Templates\Java\temp_java_message_handler.vm";
         List <string> needReplace  = new List <string>();
         ArrayList     replace      = new ArrayList();
         needReplace.Add("PackageString");
         replace.Add(messages.import);
         needReplace.Add("Handler");
         replace.Add(messages.handler);
         needReplace.Add("MessageName");
         replace.Add(cMes.name);
         CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
         Debug.Log(msgMane + ".java文件生成完毕");
     }
 }
예제 #15
0
 private static void CreateHandler(CMessages msg, string path)
 {
     foreach (var message in msg.messages)
     {
         if (message.name != "")
         {
             if (!message.name.Contains("Req") && message.msType.Substring(0, 1) != "C" &&
                 message.msType.Substring(1) != "S" && !message.msType.Contains("W"))
             {
                 if (File.Exists(path + @"\" + message.name + "Handler.cs"))
                 {
                     Debug.Log(message.name + "Handler.cs已经存在!不会生成", 2);
                 }
                 else
                 {
                     FileStream      fs       = new FileStream(path + @"\" + message.name + "Handler.cs", FileMode.Create, FileAccess.Write);
                     StreamWriter    sw       = new StreamWriter(fs);
                     string          tempPath = @".\Templates\CS\temp_cs_handler.vm";
                     Template        temp     = CNVelociryHelp.GetTemplate(tempPath);
                     VelocityContext vltCtx   = new VelocityContext();
                     vltCtx.Put("HandlerName", message.name + "Handler");
                     vltCtx.Put("ResMessageName", message.name + "Message");
                     System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                     temp.Merge(vltCtx, vltWriter);
                     sw.Write(vltWriter.ToString());
                     sw.Close();
                     fs.Close();
                     Debug.Log(message.name + "Handler.cs生成成功");
                 }
             }
         }
         else
         {
             Debug.Log("Message文件名称为空", 3);
         }
     }
 }
예제 #16
0
        /*private static void CreateMessageTypeEnum(string outPath,CMessages csMessages, TextBox label1)
         * {
         *  if (csMessages.messages.Length>0)
         *  {
         *      FileStream fs = new FileStream(outPath + "/MessagePool.cs",
         *              FileMode.OpenOrCreate, FileAccess.Read);
         *      StreamReader sr = new StreamReader(fs);
         *      List<string> lines=new List<string>();
         *      while (!sr.EndOfStream)
         *      {
         *          lines.Add(sr.ReadLine());
         *      }
         *      //string contents = sr.ReadToEnd();
         *      sr.Close();
         *      fs.Close();
         *      FileStream fs1 = new FileStream(outPath + "/MessagePool.cs",
         *              FileMode.Create, FileAccess.Write);
         *      StreamWriter sw = new StreamWriter(fs1);
         *      //string[] lines = contents.Split('\n');
         *      List<string> newMessage=new List<string>();
         *      List<string> listeners =new List<string>();
         *      List<string> cases =new List<string>();
         *      foreach (var mess in csMessages.messages)
         *      {
         *          if (mess.name.Contains("Res") || mess.msType.Substring(0, 1) == "C" &&
         *              mess.msType.Substring(1) == "S")
         *          {
         *              bool flag = false;//该消息是否已经存在
         *              string mId = csMessages.ID + mess.ID;
         *              if (!string.IsNullOrWhiteSpace(mess.name))
         *              {
         *                  string mName = "";
         *                  if (mess.name.Contains("Res") || mess.name.Contains("Req"))
         *                  {
         *                      mName = mess.name.Substring(3).Replace("Message", "");
         *                  }
         *                  else
         *                  {
         *                      mName = mess.name.Replace("Message", "");
         *                  }
         *
         *                  for (int i = 0; i < lines.Count; i++)
         *                  {
         *                      if (lines[i].Contains(mName) && lines[i].Contains(mId))//该消息已存在
         *                      {
         *                          if (lines[i - 1].Contains("</summary>"))
         *                          {
         *                              if (lines[i-2].Contains("<summary>"))
         *                              {
         *                                  lines[i - 2] = "        ///" + mess.explain;
         *                              }
         *                              else
         *                              {
         *                                  lines[i - 1] = "        ///<summary>" + mess.explain + "</summary>";
         *                              }
         *                          }
         *                          lines[i] = "        " + mName + " = " + mId + ",";
         *                          flag = true;
         *                          break;
         *                      }
         *                  }
         *              }
         *              else
         *              {
         *                  label1.Text += "消息号为" + csMessages.ID + mess.ID + "名称为空";
         *              }
         *              //该消息不存在
         *              if (!flag)
         *              {
         *                  if (!string.IsNullOrWhiteSpace(mess.name))
         *                  {
         *                      string mName = "";
         *                      if (mess.name.Contains("Res") || mess.name.Contains("Req"))
         *                      {
         *                          mName = mess.name.Substring(3).Replace("Message", "");
         *                      }
         *                      else
         *                      {
         *                          mName = mess.name.Replace("Message", "");
         *                      }
         *                      newMessage.Add("        ///<summary>" + mess.explain + "</summary>        " + mName + " = " + mId + ",");
         *                      listeners.Add("            ClientNetwork.Instance.AddListener(GameMessageType." + mName+", \"Res"+ mName+"Handler\");");
         *                      cases.Add("                case \"Res" + mName + "Handler\":                    return new Res" + mName + "Handler();");
         *                  }
         *                  else
         *                  {
         *                      newMessage.Add("        ///<summary>" + mess.explain + "</summary>	    " + mId + ",");
         *                  }
         *              }
         *          }
         *
         *      }
         *      List<string> allMessage =new List<string>();
         *      for(int i=0;i<lines.Count;i++)
         *      {
         *          lines[i].Replace("\r", "");
         *          if (i>0 && lines[i].Contains("="))
         *          {
         *              string str = "";
         *              if (lines[i-1].Contains("<summary>") && lines[i-1].Contains("</summary>"))
         *              {
         *                  str+=lines[i - 1];
         *              }
         *              str+=lines[i];
         *              allMessage.Add(str);
         *          }
         *      }
         *      if (newMessage.Count>0)
         *      {
         *          foreach (var mess in newMessage)
         *          {
         *              allMessage.Add(mess);
         *          }
         *      }
         *      List<string> allListener = new List<string>();
         *      for (int i = 0; i < lines.Count; i++)
         *      {
         *          if (lines[i].Contains("ClientNetwork.Instance.AddListener"))
         *          {
         *              allListener.Add(lines[i]);
         *          }
         *      }
         *      if (listeners.Count>0)
         *      {
         *          foreach (var listen in listeners)
         *          {
         *              allListener.Add(listen);
         *          }
         *      }
         *
         *      List<string> allCases = new List<string>();
         *      for (int i = 0; i < lines.Count; i++)
         *      {
         *          if (lines[i].Contains("case") || lines[i].Contains("return new"))
         *          {
         *              allCases.Add(lines[i]);
         *          }
         *      }
         *      if (cases.Count>0)
         *      {
         *          foreach (var cas in cases)
         *          {
         *              allCases.Add(cas);
         *          }
         *      }
         *      CCmessageTypeTemplate.Instance.Init(fs1,sw);
         *      CCmessageTypeTemplate.Instance.Write(allMessage,allListener,allCases);
         *      CCmessageTypeTemplate.Instance.Close();
         *      label1.Text += "MessagePool.cs" + "生成成功" + "";
         *  }
         *  GC.Collect();
         * }*/
        private static void CreateMessageTypeEnum(string outPath, CMessages csMessages)
        {
            if (csMessages.messages.Length > 0)
            {
                FileStream fs = new FileStream(outPath + "/MessagePool.cs",
                                               FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr       = new StreamReader(fs);
                string       contents = sr.ReadToEnd();
                sr.Close();
                fs.Close();
                string[]      licont     = contents.Split('\r', '\n');
                List <string> lines      = new List <string>();
                List <string> newMessage = new List <string>();
                for (int i = 0; i < licont.Length; i++)
                {
                    lines.Add(licont[i]);
                }
                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i] == "")
                    {
                        lines.RemoveAt(i);
                        i--;
                    }
                }
                List <string> listeners = new List <string>();
                List <string> cases     = new List <string>();
                foreach (var mess in csMessages.messages)
                {
                    if (!mess.name.Contains("Req") && mess.msType.Substring(0, 1) != "C" &&
                        mess.msType.Substring(1) != "S" && !mess.msType.Contains("W"))
                    {
                        bool   flag = false;//该消息是否已经存在
                        string mId  = csMessages.ID + mess.ID;
                        if (!string.IsNullOrWhiteSpace(mess.name))
                        {
                            string mName = "";
                            if (mess.name.Contains("Res") || mess.name.Contains("Req"))
                            {
                                mName = mess.name.Substring(3).Replace("Message", "");
                            }
                            else
                            {
                                mName = mess.name.Replace("Message", "");
                            }

                            for (int i = 0; i < lines.Count; i++)
                            {
                                if (lines[i].Contains(mName) && lines[i].Contains(mId))//该消息已存在
                                {
                                    if (lines[i - 1].Contains("</summary>"))
                                    {
                                        if (lines[i - 2].Contains("<summary>"))
                                        {
                                            lines[i - 2] = "        ///" + mess.explain;
                                        }
                                        else
                                        {
                                            lines[i - 1] = "        ///<summary>" + mess.explain + "</summary>";
                                        }
                                    }
                                    lines[i] = "        " + mName + " = " + mId + ",";
                                    flag     = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Debug.Log("消息号为" + csMessages.ID + mess.ID + "名称为空", 3);
                        }
                        //该消息不存在
                        if (!flag)
                        {
                            string mName = "";
                            if (!string.IsNullOrWhiteSpace(mess.name))
                            {
                                if (mess.name.Contains("Res") || mess.name.Contains("Req"))
                                {
                                    mName = mess.name.Substring(3).Replace("Message", "");
                                }
                                else
                                {
                                    mName = mess.name.Replace("Message", "");
                                }
                                newMessage.Add("        ///<summary>" + mess.explain + "</summary>");
                                newMessage.Add("        " + mName + " = " + mId + ",");
                            }
                            else
                            {
                                newMessage.Add("        ///<summary>" + mess.explain + "</summary>");
                                newMessage.Add("        " + mId + ",");
                            }
                            listeners.Add("            ClientNetwork.Instance.AddListener(GameMessageType." + mName + ", \"" + mess.name + "Handler\");");
                            cases.Add("                case \"" + mess.name + "Handler\":");
                            cases.Add("                    return new " + mess.name + "Handler();");;
                        }
                    }
                }
                for (int i = 0; i < lines.Count; i++)
                {
                    lines[i].Replace('\r', ' ');
                }
                List <string> allMessage = new List <string>();
                for (int i = 0; i < lines.Count; i++)
                {
                    lines[i].Replace("\r", "");
                    if (lines[i].Contains("="))
                    {
                        //string str = "";
                        if (lines[i - 1].Contains("<summary>") && lines[i - 1].Contains("</summary>"))
                        {
                            //str += lines[i - 1];
                            allMessage.Add(lines[i - 1]);
                        }
                        //str += lines[i];
                        allMessage.Add(lines[i]);
                    }
                }
                if (newMessage.Count > 0)
                {
                    foreach (var mess in newMessage)
                    {
                        allMessage.Add(mess);
                    }
                }
                List <string> allListener = new List <string>();
                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i].Contains("ClientNetwork.Instance.AddListener"))
                    {
                        allListener.Add(lines[i]);
                    }
                }
                if (listeners.Count > 0)
                {
                    foreach (var listen in listeners)
                    {
                        allListener.Add(listen);
                    }
                }

                List <string> allCases = new List <string>();
                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i].Contains("case") || lines[i].Contains("return new"))
                    {
                        allCases.Add(lines[i]);
                    }
                }
                if (cases.Count > 0)
                {
                    foreach (var cas in cases)
                    {
                        allCases.Add(cas);
                    }
                }
                Template temp = CNVelociryHelp.GetTemplate(@".\Templates\CS\" +
                                                           Global.CsMessageTypeTemplatePath.Substring(
                                                               Global.CsMessageTypeTemplatePath.LastIndexOf(@"\")));
                VelocityContext vltCtx = new VelocityContext();
                vltCtx.Put("MessageType", allMessage);
                vltCtx.Put("Listeners", allListener);
                vltCtx.Put("CaseHanders", allCases);
                StringWriter vltWriter = new StringWriter();
                try
                {
                    temp.Merge(vltCtx, vltWriter);
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message, 3);
                }
                FileStream fs1 = new FileStream(outPath + "/MessagePool.cs",
                                                FileMode.Create, FileAccess.Write);
                StreamWriter sw   = new StreamWriter(fs1);
                string       str1 = vltWriter.ToString();
                sw.Write(vltWriter.ToString());
                sw.Close();
                fs1.Close();
                Debug.Log("MessagePool.cs" + "生成成功");
            }
        }
예제 #17
0
        public void CreateCsContainer(ExcelData sheet, CAsDataConfig dataConfig)
        {
            string        name         = Global.FirstCharToUpper(sheet.SheetName.Replace("'", "").Replace("$", ""));
            string        filePath     = dataConfig.folder + @"\" + name + "Container.cs";
            string        templatePath = @".\Templates\CS\temp_cs_res_container.vm";
            List <string> needReplace  = new List <string>();
            ArrayList     replace      = new ArrayList();

            needReplace.Add("DateTime");
            replace.Add(DateTime.Now.ToString("yyyy-M-d HH:mm:ss"));
            if (dataConfig.package != null)
            {
                needReplace.Add("PackageString");
                replace.Add(dataConfig.package);
                needReplace.Add("BeanPackage");
                replace.Add(dataConfig.package);
            }
            needReplace.Add("Name");
            replace.Add(name);
            needReplace.Add("ContainerName");
            replace.Add(name + "Container");
            List <string> import = new List <string>();

            if (dataConfig.containerImport != null && dataConfig.containerImport.Length > 0)
            {
                needReplace.Add("importList");
                foreach (var bean in dataConfig.containerImport)
                {
                    import.Add(bean);
                }
                replace.Add(import);
            }
            string[,] sheetdata = Global.GetSheetFromExcel(sheet.ExcelName, sheet.SheetName);
            if (sheetdata != null && sheetdata.GetLength(1) > 0)
            {
                string Id = "";
                Dictionary <int, string> KeyDict = new Dictionary <int, string>();
                for (int i = 0; i < sheetdata.GetLength(1); i++)
                {
                    if (sheetdata[0, i] != "" && sheetdata[0, i] != " ")
                    {
                        int index = int.Parse(sheetdata[0, i]);
                        KeyDict.Add(index, sheetdata[1, i]);
                    }
                }
                if (KeyDict.Count > 0)
                {
                    Id += string.Format("bean.{0}.ToString()", KeyDict[1]);;
                    for (int i = 0; i < KeyDict.Count - 1; i++)
                    {
                        Id += string.Format("+\"_\"+bean.{0}.ToString()", KeyDict[2 + i]);
                    }
                }

                needReplace.Add("ID");
                if (Id == "")
                {
                    replace.Add("IAMNULL");
                }
                else
                {
                    replace.Add(Id);
                }
            }
            CNVelociryHelp.CreateFileByTemplate(filePath, templatePath, needReplace, replace);
            Debug.Log(name + "Container.cs文件生成完毕");
        }
예제 #18
0
        private static void CreateServices(CMessages msg, string path)
        {
            string     name = Global.FirstCharToUpper(msg.name);
            FileStream fs   = new FileStream(path + @"\" + "CService" + name + ".cs",
                                             FileMode.Create, FileAccess.Write);
            StreamWriter    sw       = new StreamWriter(fs);
            string          tempPath = @".\Templates\CS\temp_cs_cservice.vm";
            Template        temp     = CNVelociryHelp.GetTemplate(tempPath);
            VelocityContext vltCtx   = new VelocityContext();

            vltCtx.Put("CServiceName", "CService" + name);
            StringBuilder sb = new StringBuilder();

            string listusing  = "";
            string importBean = "";

            foreach (var message in msg.messages)
            {
                if (message.name != "")
                {
                    if (message.name.Contains("Req") || message.msType.Substring(0, 1) == "C" ||
                        message.msType.Substring(1) == "S" || message.msType.Contains("W"))//生成Send函数
                    {
                        sb.Append("        /// <summary>\n        /// " + message.explain + "\n        /// </summary>\n");
                        if (message.items != null && message.items.Count > 0)
                        {
                            for (int i = 0; i < message.items.Count; i++)
                            {
                                if (message.items[i] != null)
                                {
                                    sb.Append("        /// <param name=\"" + message.items[i].name + "\">" + message.items[i].explain + "</param>\n");
                                }
                            }
                        }
                        sb.Append("        public static void Send" + message.name.Replace("Req", "") + "(");
                        if (message.items != null && message.items.Count > 0)
                        {
                            for (int i = 0; i < message.items.Count - 1; i++)
                            {
                                if (message.items[i] != null)
                                {
                                    if (!message.items[i].isList)
                                    {
                                        if (message.items[i].classType == "String")
                                        {
                                            sb.Append("string " + message.items[i].name + ",");
                                        }
                                        else
                                        {
                                            sb.Append(message.items[i].classType + " " + message.items[i].name + ",");
                                        }
                                    }
                                    else
                                    {
                                        if (message.items[i].classType == "String")
                                        {
                                            sb.Append("List<string>" + " " +
                                                      message.items[i].name +
                                                      ",");
                                        }
                                        else
                                        {
                                            sb.Append("List<" + message.items[i].classType + ">" + " " +
                                                      message.items[i].name +
                                                      ",");
                                        }
                                        if (listusing == "")
                                        {
                                            listusing = "using System.Collections.Generic;";
                                        }
                                    }
                                    if (Global.IsCustomType(message.items[i].classType) && !message.items[i].isHavePrefix && importBean == "")
                                    {
                                        importBean = "using " + msg.import + ".bean;";
                                    }
                                }
                            }
                            if (message.items[message.items.Count - 1] != null)
                            {
                                if (!message.items[message.items.Count - 1].isList)
                                {
                                    if (message.items[message.items.Count - 1].classType == "String")
                                    {
                                        sb.Append("string " +
                                                  message.items[message.items.Count - 1].name);
                                    }
                                    else
                                    {
                                        sb.Append(message.items[message.items.Count - 1].classType + " " +
                                                  message.items[message.items.Count - 1].name);
                                    }
                                }
                                else
                                {
                                    if (message.items[message.items.Count - 1].classType == "String")
                                    {
                                        sb.Append("List<string>" + " " +
                                                  message.items[message.items.Count - 1].name);
                                    }
                                    else
                                    {
                                        sb.Append("List<" + message.items[message.items.Count - 1].classType + ">" + " " +
                                                  message.items[message.items.Count - 1].name);
                                    }
                                    if (listusing == "")
                                    {
                                        listusing = "using System.Collections.Generic;";
                                    }
                                }
                                if (Global.IsCustomType(message.items[message.items.Count - 1].classType) && importBean == "")
                                {
                                    importBean = "using " + msg.import + ".bean;";
                                }
                            }
                        }
                        sb.Append(")\n        {\n            ");
                        sb.Append(message.name + "Message message = new " + message.name + "Message();\n            ");
                        if (message.items != null && message.items.Count > 0)
                        {
                            for (int i = 0; i < message.items.Count; i++)
                            {
                                sb.Append("message." + message.items[i].name + "=" + message.items[i].name + ";\n            ");
                            }
                        }
                        sb.Append("ClientNetwork.Instance.SendMessage (message);\n        }\n");
                    }
                }
            }
            vltCtx.Put("FunList", sb);
            List <string> usList = new List <string>();

            if (listusing != "")
            {
                usList.Add(listusing);
            }
            if (importBean != "")
            {
                usList.Add(importBean);
            }
            vltCtx.Put("usList", usList);
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            temp.Merge(vltCtx, vltWriter);

            sw.Write(vltWriter.ToString());
            sw.Close();
            fs.Close();
            Debug.Log(name + "Handler.cs生成成功");
        }
예제 #19
0
        /// <summary>
        /// 生成CS下的Bean文件
        /// </summary>
        /// <param name="csMessages"></param>
        /// <param name="funMap"></param>
        /// <param name="label1"></param>
        private static void CreateBeans(CMessages msg, string path)
        {
            //Thread myThread=new Thread(new ThreadStart(CreateBeanThread(msg,path,LogText)));
            foreach (var bean in msg.beans)
            {
                if (bean.name != "")
                {
                    Template        temp   = CNVelociryHelp.GetTemplate(@".\Templates\CS\" + Global.CsBeanTemplatePath.Substring(Global.CsBeanTemplatePath.LastIndexOf(@"\")));
                    VelocityContext vltCtx = new VelocityContext();
                    vltCtx.Put("ImportString", msg.import);
                    vltCtx.Put("BeanExplain", bean.explain);
                    vltCtx.Put("BeanName", bean.name);
                    //if (bean.fileds != null && bean.fileds.Length > 0)
                    //{
                    //    List<BeanVar> beanVarList = new List<BeanVar>();
                    //    //List<CField> beanWriteList = new List<CField>();
                    //    foreach (var field in bean.fileds)
                    //    {
                    //        BeanVar var = new BeanVar(field);
                    //        beanVarList.Add(var);
                    //    }
                    //    vltCtx.Put("fieldList", beanVarList);
                    //}
                    //if (bean.lists != null && bean.lists.Length > 0)
                    //{
                    //    List<BeanVar> beanVarList = new List<BeanVar>();
                    //    foreach (var list in bean.lists)
                    //    {
                    //        BeanVar var = new BeanVar(list);
                    //        beanVarList.Add(var);
                    //    }
                    //    vltCtx.Put("listList", beanVarList);
                    //}
                    List <string> usList = new List <string>();
                    if (bean.lists != null && bean.lists.Length > 0)
                    {
                        usList.Add("using System.Collections.Generic;");
                    }
                    vltCtx.Put("usList", usList);
                    if (bean.items != null && bean.items.Count > 0)
                    {
                        List <CMessageFieldAndList> list = new List <CMessageFieldAndList>();
                        foreach (var item in bean.items)
                        {
                            if (item != null)
                            {
                                CMessageFieldAndList fl = new CMessageFieldAndList(item);
                                list.Add(fl);
                            }
                        }
                        vltCtx.Put("flList", list);
                    }
                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    temp.Merge(vltCtx, vltWriter);

                    FileStream fs = new FileStream(path + @"\" + bean.name + ".cs",
                                                   FileMode.Create, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(vltWriter.ToString());
                    sw.Close();
                    fs.Close();
                    Debug.Log(bean.name + ".cs生成成功");
                }
                else
                {
                    Debug.Log("Bean名称为空,不能生成文件", 3);
                }
            }
        }
예제 #20
0
        /// <summary>
        /// 生成CS下的Message.cs文件
        /// </summary>
        /// <param name="csMessages"></param>
        /// <param name="funMap"></param>
        private static void CreateMessage(CMessages msg, string path)
        {
            foreach (var message in msg.messages)
            {
                if (message.name != "")
                {
                    FileStream fs = new FileStream(path + @"\" + message.name + "Message.cs",
                                                   FileMode.Create, FileAccess.Write);
                    StreamWriter sw       = new StreamWriter(fs);
                    string       tempPath = @".\Templates\CS\" +
                                            Global.CsMessageTemplatePath.Substring(
                        Global.CsMessageTemplatePath.LastIndexOf(@"\") + 1);
                    Template        temp         = CNVelociryHelp.GetTemplate(tempPath);
                    VelocityContext vltCtx       = new VelocityContext();
                    string          importString = "";
                    vltCtx.Put("MessageExplain", message.explain);
                    vltCtx.Put("MessageName", message.name + "Message");
                    vltCtx.Put("MessageID", msg.ID + message.ID);
                    if (message.lists != null && message.lists.Length > 0)
                    {
                        vltCtx.Put("Length", "int length=0;");
                    }
                    else
                    {
                        vltCtx.Put("Length", "");
                    }
                    List <string> usList = new List <string>();
                    if (message.lists != null && message.lists.Length > 0)
                    {
                        usList.Add("using System.Collections.Generic;");
                    }

                    if (message.items != null && message.items.Count > 0)
                    {
                        List <CMessageFieldAndList> list = new List <CMessageFieldAndList>();
                        foreach (var item in message.items)
                        {
                            if (item != null)
                            {
                                CMessageFieldAndList fl = new CMessageFieldAndList(item);

                                if (Global.IsCustomType(fl.className) && fl.isPrefix == "0" && importString == "")
                                {
                                    importString = msg.import;
                                }
                                list.Add(fl);
                                if (item.classType == "Position")
                                {
                                    usList.Add("using com.game.structs;");
                                }
                            }
                        }
                        vltCtx.Put("flList", list);
                    }
                    vltCtx.Put("usList", usList);
                    vltCtx.Put("ImportString", importString);
                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    temp.Merge(vltCtx, vltWriter);

                    sw.Write(vltWriter.ToString());
                    sw.Close();
                    fs.Close();
                    Debug.Log(message.name + "Message.cs生成成功");
                }
                else
                {
                    Debug.Log("Message文件名称为空", 3);
                }
            }
        }