Ejemplo n.º 1
0
        /// <summary>
        /// 将 .proto 文件转成 .cs 文件
        /// <para>用于项目非ProtoBuf-net类型协议,以后用PB协议的话这里就没有用了</para>
        /// </summary>
        /// <param name="inPath"></param>
        /// <param name="inFolderName"></param>
        /// <returns></returns>
        public bool Proto2CSharp(string inPath, string inFolderName)
        {
            Assist.CheckFolderExist(inFolderName);
            Assist.DeleteFilesInFolder("ProtoItem");

            Assist.GetObjPaths(".proto", inPath).ForEach(delegate(string path)
            {
                FileInfo targetFileInfo = new FileInfo(path);
                bool bCommonClass       = path.EndsWith("_comm.proto");

                // 类名 -> 成员列表<成员名, 成员类型>
                Dictionary <string, Dictionary <string, string> > nClasses = null;
                if (targetFileInfo != null)
                {
                    Queue <string> sq = new Queue <string>();
                    StreamReader sr   = new StreamReader(path, System.Text.Encoding.Default);
                    string line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine().Trim();
                        line = Regex.Replace(line, @"/{2}.+", "");// 去掉“//”行
                        line = Regex.Replace(line, @"{\s*", "");
                        sq.Enqueue(line);
                    }
                    sr.Close();
                    sr.Dispose();

                    string curNameSpace = sq.Dequeue().Remove(0, 8).Replace(";", "");

                    nClasses = HanldQueue(sq);

                    foreach (KeyValuePair <string, Dictionary <string, string> > fieldStr in nClasses)
                    {
                        if (fieldStr.Key != "")
                        {
                            ProtoToCSharp ptcs = new ProtoToCSharp(curNameSpace, fieldStr.Key, "ProtoItem");
                            try
                            {
                                ptcs.Create(fieldStr.Value, bCommonClass);
                            }
                            catch (Exception exp)
                            {
                                throw new Exception(exp.ToString() + ", Class" + fieldStr);
                            }
                        }
                    }
                }
                if (bCommonClass)
                {
                    AutoCSharp.Do.Creator.TypeMapper.InitProtoAssembly();
                }
            });
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将 .proto 文件转成 .cs 文件
        /// <para>用于项目非ProtoBuf-net类型协议,以后用PB协议的话这里就没有用了</para>
        /// </summary>
        /// <param name="inPath"></param>
        /// <param name="inFolderName"></param>
        /// <returns></returns>
        public bool Proto2CSharp(string inPath, string inFolderName)
        {
            Assist.CheckFolderExist(inFolderName);
            Assist.GetObjPaths(".proto", inPath).ForEach(delegate(string path)
            {
                FileInfo targetFileInfo = new FileInfo(path);
                if (targetFileInfo != null)
                {
                    Queue <string> sq = new Queue <string>();
                    StreamReader sr   = new StreamReader(path, System.Text.Encoding.Default);
                    String line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine().Trim();
                        line = Regex.Replace(line, @"/{2}.+", "");
                        line = Regex.Replace(line, @"{\s*", "");
                        if (line != "")
                        {
                            sq.Enqueue(line);
                        }
                    }
                    sr.Close();
                    sr.Dispose();

                    string curNameSpace = sq.Dequeue().Remove(0, 8).Replace(";", "");

                    // 类名 -> 成员列表<成员名, 成员类型>
                    Dictionary <string, Dictionary <string, string> > nClasses = HanldQueue(sq);

                    foreach (KeyValuePair <string, Dictionary <string, string> > item in nClasses)
                    {
                        if (item.Key != "")
                        {
                            ProtoToCSharp ptcs = new ProtoToCSharp(curNameSpace, item.Key, "ProtoItem");
                            ptcs.Create(item.Value);
                        }
                    }
                }
            });
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将 .proto 文件转成 .cs 文件
        /// <para>用于项目非ProtoBuf-net类型协议,以后用PB协议的话这里就没有用了</para>
        /// </summary>
        /// <param name="inPath"></param>
        /// <param name="inFolderName"></param>
        /// <returns></returns>
        public bool Proto2CSharp(string inPath, string inFolderName)
        {
            Assist.CheckFolderExist(inFolderName);
            Assist.GetObjPaths(".proto", inPath).ForEach(delegate(string path)
            {
                FileInfo targetFileInfo = new FileInfo(path);
                if (targetFileInfo != null)
                {
                    Queue<string> sq = new Queue<string>();
                    StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
                    String line;
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine().Trim();
                        line = Regex.Replace(line, @"/{2}.+", "");
                        line = Regex.Replace(line, @"{\s*", "");
                        if (line != "")
                            sq.Enqueue(line);
                    }
                    sr.Close();
                    sr.Dispose();

                    string curNameSpace = sq.Dequeue().Remove(0, 8).Replace(";", "");

                    // 类名 -> 成员列表<成员名, 成员类型>
                    Dictionary<string, Dictionary<string, string>> nClasses = HanldQueue(sq);

                    foreach (KeyValuePair<string, Dictionary<string, string>> item in nClasses)
                    {
                        if (item.Key != "")
                        {
                            ProtoToCSharp ptcs = new ProtoToCSharp(curNameSpace, item.Key, "ProtoItem");
                            ptcs.Create(item.Value);
                        }
                    }
                }
            });
            return true;
        }