示例#1
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生成成功");
                }
            }
        }
示例#2
0
        public void CreateAsMessage()
        {
            if (string.IsNullOrEmpty(Global.AsMessageFilePath) || !File.Exists(Global.AsMessageFilePath))
            {
                MessageBox.Show("请选择消息文件", "消息文件为空", MessageBoxButtons.OK);
                return;
            }
            CMessages msg = Global.CsMessages;

            if (!Directory.Exists(Global.ResFolder + @"\AS"))
            {
                Directory.CreateDirectory(Global.ResFolder + @"\AS");
            }
            FileInfo info     = new FileInfo(Global.AsMessageFilePath);
            string   fileName = info.Name;
            int      index    = fileName.IndexOf("_");
            string   name     = fileName.Substring(0, index);

            if (msg.beans.Length > 0)
            {
                if (string.IsNullOrEmpty(Global.AsBeanTemplatePath) || !File.Exists(Global.AsBeanTemplatePath))
                {
                    MessageBox.Show("请设置Bean模板文件", "Bean模板文件为空", MessageBoxButtons.OK);
                    return;
                }

                string path = Global.ResFolder + @"\AS\NetWork\" + name + @"\bean";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateAsBeans(msg, path);
            }
            if (msg.messages.Length > 0)
            {
                if (string.IsNullOrEmpty(Global.AsMessageTemplatePath) || !File.Exists(Global.AsMessageTemplatePath))
                {
                    MessageBox.Show("请设置Message模板文件", "Message模板文件为空", MessageBoxButtons.OK);
                    return;
                }
                string path = Global.ResFolder + @"\AS\NetWork\" + name + @"\message";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateAsMessages(msg, path);
                if (string.IsNullOrEmpty(Global.AsHandleTemplatePath) || !File.Exists(Global.AsHandleTemplatePath))
                {
                    MessageBox.Show("请设置Handle模板文件", "Handle模板文件为空", MessageBoxButtons.OK);
                    return;
                }
                string path1 = Global.ResFolder + @"\AS\NetWork\" + name + @"\handler";
                if (!Directory.Exists(path1))
                {
                    Directory.CreateDirectory(path1);
                }
                CreateAsHandler(msg, path1);
            }
        }
示例#3
0
 private void UpdateMsgPool(CMessages messages, string path)
 {
     //foreach (var cMes in messages.messages)
     {
         string filePath = path + @"\MessagePool.java";
         if (File.Exists(filePath))
         {
             FileStream   stream  = new FileStream(filePath, FileMode.Open, FileAccess.Read);
             StreamReader reader  = new StreamReader(stream);
             string       content = reader.ReadToEnd();
             reader.Close();
             stream.Close();
             string[]            cts    = content.Split('\n');
             List <string>       names  = new List <string>();
             List <string>       ids    = new List <string>();
             List <MessgaeField> mfList = new List <MessgaeField>();
             foreach (var ct in cts)
             {
                 if (ct.Contains("import") && ct.Contains("com"))
                 {
                     int beginIndex = ct.LastIndexOf(".");
                     int endIndex   = ct.IndexOf("Buff");
                     names.Add(ct.Trim().Substring(beginIndex + 1, endIndex - beginIndex - 1));
                 }
                 if (ct.Contains("register(") && ct.Contains(");"))
                 {
                     ids.Add(ct.Trim().Substring(9, 6));
                 }
             }
             if (names.Count > 0 && ids.Count > 0)
             {
                 for (int i = 0; i < ids.Count; i++)
                 {
                     MessgaeField mf = new MessgaeField();
                     mf.name = names[i * 2];
                     mf.id   = ids[i];
                     mfList.Add(mf);
                 }
             }
             if (mfList.Count > 0)
             {
                 WriteToMsgPool(messages, filePath, mfList);
                 Debug.Log("MessagePool.java文件更新完毕");
             }
             else
             {
                 WriteToMsgPool(messages, filePath, null);
                 Debug.Log("MessagePool.java文件更新完毕");
             }
         }
         else
         {
             WriteToMsgPool(messages, filePath, null);
             Debug.Log("MessagePool.java文件更新完毕");
         }
     }
 }
示例#4
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文件生成完毕");
     }
 }
示例#5
0
        public void CreateJavaMessageSeries(string messageFilePath)
        {
            CMessages messages          = ConfigControl.ReadMessageXml(messageFilePath);
            string    messageCreatePath = Global.ResFolder + @"\Java\NetWork\" + messages.name;

            if (messages.beans != null && messages.beans.Length > 0)
            {
                CreateJavaMsBean(messages, messageCreatePath);
            }
            if (messages.messages != null && messages.messages.Length > 0)
            {
                CreateJavaMsMessage(messages, messageCreatePath);
                CreateJavaMsHandler(messages, messageCreatePath);
                UpdateMsgPool(messages, Global.ResFolder + @"\Java\NetWork\");
            }
        }
示例#6
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生成成功");
            }
        }
示例#7
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);
        }
示例#8
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文件生成完毕");
     }
 }
示例#9
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);
         }
     }
 }
示例#10
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" + "生成成功");
            }
        }
示例#11
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生成成功");
        }
示例#12
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);
                }
            }
        }
示例#13
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);
                }
            }
        }
示例#14
0
        /// <summary>
        /// 生成CS消息相关文件
        /// </summary>
        public static void CreateCSMessage(bool isBean, bool ismessage, bool isHandler, bool isCservice, bool isMessagePool, string outpath)
        {
            if (Global.CsMessages == null)
            {
                MessageBox.Show("请先选择消息配置表", "配置表为空", MessageBoxButtons.OK);
                return;
            }
            if (string.IsNullOrEmpty(Global.CsBeanTemplatePath) || string.IsNullOrEmpty(Global.CsMessageTemplatePath) ||
                string.IsNullOrEmpty(Global.CsFunMapFilePath) || string.IsNullOrEmpty(Global.CsMessageTypeTemplatePath))
            {
                MessageBox.Show("请先设置CS消息配置", "CS消息配置不正确", MessageBoxButtons.OK);
                return;
            }
            CMessages msg = Global.CsMessages;
            string    conflictSheetPath = @".\Templates\CS\ClassNameConflict.xlsx";

            string[,] conflictStrings = Global.GetSheetFromExcel(conflictSheetPath, "Conflict$");
            if (conflictStrings.GetLength(0) > 1)
            {
                if (msg.beans != null && msg.beans.Length > 0)//bean
                {
                    for (int k = 0; k < msg.beans.Length; k++)
                    {
                        //if (msg.beans[k].fileds!=null &&msg.beans[k].fileds.Length > 0)
                        //{
                        //    for (int j = 0; j < msg.beans[k].fileds.Length; j++)
                        //    {
                        //        for (int i = 0; i < conflictStrings.GetLength(0); i++)
                        //        {
                        //            if (msg.beans[k].fileds[j].fieldType.Contains(conflictStrings[i,0]))
                        //            {
                        //                msg.beans[k].fileds[j].fieldType=msg.beans[k].fileds[j].fieldType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                        //            }
                        //        }
                        //    }
                        //}
                        //if (msg.beans[k].lists!=null &&msg.beans[k].lists.Length > 0)
                        //{
                        //    for (int j = 0; j < msg.beans[k].lists.Length; j++)
                        //    {
                        //        for (int i = 0; i < conflictStrings.GetLength(0); i++)
                        //        {
                        //            if (msg.beans[k].lists[j].listType.Contains(conflictStrings[i, 0]))
                        //            {
                        //                msg.beans[k].lists[j].listType=msg.beans[k].lists[j].listType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                        //            }
                        //        }
                        //    }
                        //}
                        if (msg.beans[k].items != null && msg.beans[k].items.Count > 0)
                        {
                            for (int i = 0; i < conflictStrings.GetLength(0); i++)
                            {
                                if (msg.beans[k].name == conflictStrings[i, 0])
                                {
                                    msg.beans[k].name = conflictStrings[i, 1];
                                }
                            }
                            for (int j = 0; j < msg.beans[k].items.Count; j++)
                            {
                                for (int i = 0; i < conflictStrings.GetLength(0); i++)
                                {
                                    if (msg.beans[k].items[j].realClassType == conflictStrings[i, 0])
                                    {
                                        msg.beans[k].items[j].classType     = msg.beans[k].items[j].classType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                                        msg.beans[k].items[j].realClassType = conflictStrings[i, 1];
                                    }
                                }
                            }
                        }
                    }
                }
                if (msg.messages != null && msg.messages.Length > 0)//message
                {
                    for (int k = 0; k < msg.messages.Length; k++)
                    {
                        //    if (msg.messages[k].fields!=null &&msg.messages[k].fields.Length > 0)
                        //    {
                        //        for (int j = 0; j < msg.messages[k].fields.Length; j++)
                        //        {
                        //            for (int i = 0; i < conflictStrings.GetLength(0); i++)
                        //            {
                        //                if (msg.messages[k].fields[j].fieldType.Contains(conflictStrings[i, 0]))
                        //                {
                        //                    msg.messages[k].fields[j].fieldType=msg.messages[k].fields[j].fieldType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                        //                }
                        //            }
                        //        }
                        //    }
                        //    if (msg.messages[k].lists!=null&&msg.messages[k].lists.Length > 0)
                        //    {
                        //        for (int j = 0; j < msg.messages[k].lists.Length; j++)
                        //        {
                        //            for (int i = 0; i < conflictStrings.GetLength(0); i++)
                        //            {
                        //                if (msg.messages[k].lists[j].listType.Contains(conflictStrings[i, 0]))
                        //                {
                        //                    msg.messages[k].lists[j].listType=msg.messages[k].lists[j].listType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                        //                }
                        //            }
                        //        }
                        //    }
                        if (msg.messages[k].items != null && msg.messages[k].items.Count > 0)
                        {
                            for (int j = 0; j < msg.messages[k].items.Count; j++)
                            {
                                for (int i = 0; i < conflictStrings.GetLength(0); i++)
                                {
                                    if (msg.messages[k].items[j].realClassType == conflictStrings[i, 0])
                                    {
                                        msg.messages[k].items[j].classType     = msg.messages[k].items[j].classType.Replace(conflictStrings[i, 0], conflictStrings[i, 1]);
                                        msg.messages[k].items[j].realClassType = conflictStrings[i, 1];
                                    }
                                }
                            }
                        }
                    }
                }
            }


            FileInfo info     = new FileInfo(Global.CsMessageFilePath);
            string   fileName = info.Name;
            string   name     = msg.name;

            if (isBean && msg.beans != null && msg.beans.Length > 0)
            {
                //if (string.IsNullOrEmpty(Global.CsBeanTemplatePath) || !File.Exists(Global.CsBeanTemplatePath))
                //{
                //    MessageBox.Show("请设置Bean模板文件", "Bean模板文件为空", MessageBoxButtons.OK);
                //    return;
                //}

                string path = outpath + @"\" + name + @"\bean";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateBeans(msg, path);
            }
            if (ismessage && msg.messages.Length > 0)
            {
                //if (string.IsNullOrEmpty(Global.CsMessageTemplatePath) || !File.Exists(Global.CsMessageTemplatePath))
                //{
                //    MessageBox.Show("请设置Message模板文件", "Message模板文件为空", MessageBoxButtons.OK);
                //    return;
                //}
                string path = outpath + @"\" + name + @"\message";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateMessage(msg, path);
            }
            if (isHandler && msg.messages.Length > 0)
            {
                string path = outpath + @"\" + name + @"\handler";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateHandler(msg, path);
            }
            if (isCservice && msg.messages.Length > 0)
            {
                string path = outpath + @"\" + name;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                CreateServices(msg, path);
            }
            if (isMessagePool && msg.messages.Length > 0)
            {
                CreateMessageTypeEnum(outpath, msg);
            }
        }
示例#15
0
        public static CMessages ReadMessageXml(string path)
        {
            CMessages   messages = new CMessages();
            XmlDocument doc      = GetXmlDocument(path);
            XmlElement  root     = GetXmlRootAsElement(doc, "messages");

            if (root != null)
            {
                messages.ID = root.GetAttribute("id");
                FileInfo fi           = new FileInfo(path);
                string   fileFullName = fi.Name;
                if (fileFullName.Contains("_"))
                {
                    messages.name = fileFullName.Substring(0, fileFullName.LastIndexOf("_"));
                }
                else
                {
                    messages.name = fileFullName.Substring(0, fileFullName.IndexOf(".xml"));
                }
                messages.explain   = root.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                messages.import    = root.GetAttribute("package");
                messages.beanSuper = root.GetAttribute("beansuper");
                messages.handler   = root.GetAttribute("handler");
                XmlNodeList beanList = root.SelectNodes("bean");
                if (beanList.Count > 0)
                {
                    messages.beans = new CBean[beanList.Count];
                    for (int i = 0; i < beanList.Count; i++)
                    {
                        XmlElement element = (XmlElement)beanList[i];
                        messages.beans[i]         = new CBean();
                        messages.beans[i].name    = element.GetAttribute("name");
                        messages.beans[i].explain = element.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                        XmlNodeList classItemList = element.ChildNodes;
                        if (classItemList != null && classItemList.Count > 0)
                        {
                            messages.beans[i].items = new List <CMessgaeItem>();
                            foreach (XmlNode item in classItemList)
                            {
                                if (item.LocalName == "field" || item.LocalName == "list")
                                {
                                    messages.beans[i].items.Add(new CMessgaeItem((XmlElement)item));
                                }
                            }
                        }
                        XmlNodeList fieldList = element.SelectNodes("field");
                        if (fieldList.Count > 0)
                        {
                            messages.beans[i].fileds = new CField[fieldList.Count];
                            for (int j = 0; j < fieldList.Count; j++)
                            {
                                XmlElement fieldElement = (XmlElement)fieldList[j];
                                messages.beans[i].fileds[j]           = new CField();
                                messages.beans[i].fileds[j].name      = fieldElement.GetAttribute("name");
                                messages.beans[i].fileds[j].explain   = fieldElement.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                                messages.beans[i].fileds[j].fieldType = fieldElement.GetAttribute("class");
                            }
                        }
                        XmlNodeList listList = element.SelectNodes("list");
                        if (listList.Count > 0)
                        {
                            messages.beans[i].lists = new CList[listList.Count];
                            for (int j = 0; j < listList.Count; j++)
                            {
                                XmlElement fieldElement = (XmlElement)listList[j];
                                messages.beans[i].lists[j]          = new CList();
                                messages.beans[i].lists[j].name     = fieldElement.GetAttribute("name");
                                messages.beans[i].lists[j].explain  = fieldElement.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                                messages.beans[i].lists[j].listType = fieldElement.GetAttribute("class");
                            }
                        }
                    }
                }
                XmlNodeList messageList = root.SelectNodes("message");
                if (messageList.Count > 0)
                {
                    messages.messages = new CMessage[messageList.Count];
                    for (int i = 0; i < messageList.Count; i++)
                    {
                        XmlElement messageElement = (XmlElement)messageList[i];
                        messages.messages[i]         = new CMessage();
                        messages.messages[i].name    = messageElement.GetAttribute("name");
                        messages.messages[i].ID      = messageElement.GetAttribute("id");
                        messages.messages[i].explain = messageElement.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                        messages.messages[i].msType  = messageElement.GetAttribute("type");
                        XmlNodeList classItemList = messageElement.ChildNodes;
                        if (classItemList.Count > 0)
                        {
                            messages.messages[i].items = new List <CMessgaeItem>();
                            int j = 0;
                            foreach (XmlNode item in classItemList)
                            {
                                if (item.LocalName == "field" || item.LocalName == "list")
                                {
                                    messages.messages[i].items.Add(new CMessgaeItem((XmlElement)item));
                                    j++;
                                }
                            }
                        }
                        XmlNodeList fieleList = messageElement.SelectNodes("field");
                        if (fieleList.Count > 0)
                        {
                            messages.messages[i].fields = new CField[fieleList.Count];
                            for (int j = 0; j < fieleList.Count; j++)
                            {
                                XmlElement fieldElement = (XmlElement)fieleList[j];
                                messages.messages[i].fields[j]           = new CField();
                                messages.messages[i].fields[j].fieldType = fieldElement.GetAttribute("class");
                                messages.messages[i].fields[j].name      = fieldElement.GetAttribute("name");
                                messages.messages[i].fields[j].explain   = fieldElement.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                            }
                        }
                        XmlNodeList listList = messageElement.SelectNodes("list");
                        if (listList.Count > 0)
                        {
                            messages.messages[i].lists = new CList[listList.Count];
                            for (int j = 0; j < listList.Count; j++)
                            {
                                XmlElement fieldElement = (XmlElement)listList[j];
                                messages.messages[i].lists[j]          = new CList();
                                messages.messages[i].lists[j].name     = fieldElement.GetAttribute("name");
                                messages.messages[i].lists[j].explain  = fieldElement.GetAttribute("explain").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                                messages.messages[i].lists[j].listType = fieldElement.GetAttribute("class");
                            }
                        }
                    }
                }
            }
            return(messages);
        }