private void GenerateCode_FlatTableManager(ExcelData excelData)
        {
            string flatBufferManagerCode = string.Format(Template.Template_FlatBufferTableManager, FlatBufferTableManagerCode_Content1, FlatBufferTableManagerCode_Content2);
            string path = System.IO.Path.Combine(Setting.GenerateFlatCodePath, "FlatBufferTableManager.cs");

            Tools.GenerateFile(flatBufferManagerCode, path);
            Debug.Log("[Generate]=>" + path + " Sucess!");
        }
        public bool Procedure_ChangeFlatBufferCode(ExcelData excelData)
        {
            string codePath = System.IO.Path.Combine(Setting.GenerateFlatCodePath, "Table_" + excelData.Name + ".cs");
            bool   result   = ChangeCSharpCode(excelData, codePath);

            Debug.Log("[ChangeCode]=>" + codePath + " Surcess!");
            AddDelayRun(() =>
            {
                Procedure_GenerateBuildFlatBufferCode(excelData);
            });

            return(result);
        }
        public bool Procedure_GenerateFlatBufferCode(ExcelData excelData)
        {
            string arguments = string.Format("{0} --csharp -o {1} {2} --gen-onefile", Setting.FlatcPath, Setting.GenerateFlatCodePath, excelData.FbsPath);

            Console.WriteLine(arguments);
            ProcCmd(false, arguments);
            string codePath = System.IO.Path.Combine(Setting.GenerateFlatCodePath, "Table_" + excelData.Name + ".cs");

            Debug.Log("[Generate]=>" + codePath + " Sucess!");
            AddDelayRun(() => {
                Procedure_ChangeFlatBufferCode(excelData);
            });
            return(true);
        }
        public override void Execute(List <ExcelData> excelList, System.Action <bool> onFinished)
        {
            int    count = excelList.Count;
            string template_manager_content1 = "";
            string template_manager_content2 = "";

            for (int i = 0; i < count; i++)
            {
                ExcelData excelData = excelList[i];
                string    content1  = string.Format(Template_Server_Java_Json.Template_ManagerSingleTableCode,
                                                    excelData.Name, excelData.Name, excelData.Name, excelData.Name, excelData.Name,
                                                    excelData.Name, excelData.Name, excelData.Name, excelData.Name, excelData.Name,
                                                    excelData.Name, excelData.Name, excelData.Name, excelData.Name, excelData.Name,
                                                    excelData.Name, excelData.Name, excelData.Name, excelData.Name, excelData.Name,
                                                    excelData.Name, excelData.Name, excelData.Name);

                template_manager_content1 += content1;

                string content2 = string.Format(Template_Server_Java_Json.Template_ManagerSingleTableCodeInit,
                                                excelData.Name, excelData.Name);

                template_manager_content2 += content2;
            }
            string fileContent = string.Format(Template_Server_Java_Json.Template_Manager,
                                               template_manager_content1, template_manager_content2);

            string JsonManagerFilePath = System.IO.Path.Combine(Setting.GenJavaServerJsonCodePath, "TableManager.java");

            if (Tools.GenerateFile(fileContent, JsonManagerFilePath))
            {
                Debug.Log("[Generate Sucess]:" + JsonManagerFilePath);
                if (onFinished != null)
                {
                    onFinished(true);
                }
            }
            else
            {
                if (onFinished != null)
                {
                    onFinished(false);
                }
            }

            Debug.LogError("生成管理器" + excelList.Count);
            if (onFinished != null)
            {
                onFinished(true);
            }
        }
        public override void Execute(ExcelData excelData, System.Action <ExcelData, bool> onFinished)
        {
            string fileContent = string.Format(Template_Server_Java_Json.Template_Json, jsonContentStr);
            //Console.WriteLine(fileContent);
            string JsonFilePath = System.IO.Path.Combine(Setting.GenServerJavaJsonFilePath, excelData.Name + ".json");

            if (Tools.GenerateFile(fileContent, JsonFilePath))
            {
                Debug.Log("[Generate Sucess]:" + JsonFilePath);
                if (onFinished != null)
                {
                    onFinished(excelData, true);
                }
            }
        }
        private void OnCodeGenerateFinish(ExcelData excelData)
        {
            //string path = System.IO.Path.Combine(Setting.GenerateFlatCodePath, "ITable.cs");
            //GenerateFile(Template.Template_CSharp_Interface, path);
            //Debug.Log("[Generate]=>" + path + " Sucess!");

            string scriptCode = string.Format(Template.Template_GenerateManager, GenerateManagerCode);
            string path       = System.IO.Path.Combine(Setting.GenerateBuildFlatCodePath, "GenerateManager.cs");

            Tools.GenerateFile(scriptCode, System.IO.Path.Combine(Setting.GenerateBuildFlatCodePath, "GenerateManager.cs"));
            Debug.Log("[Generate]=>" + path + " Sucess!");

            AddDelayRun(() =>
            {
                Debug.Log("所有的代码都生成完毕!");
                //Console.WriteLine(GenerateManagerCode);
                Procedure_CompileCode();
            });
        }
        public void Procedure_OnDealSingleExcel(ExcelData excelData)
        {
            PreDealExcelIndex++;

            IDealSingleExcel generateCode = new Generate_Server_Java_JsonCode();
            IDealSingleExcel generateRes  = new Generate_Server_Java_JsonFile();


            List <List <string> > allRows = excelData.GetAllRows();
            int rowCount = allRows.Count;

            for (int i = 0; i < rowCount; i++)
            {
                generateRes.DealRow(excelData, i);
            }

            generateCode.Execute(excelData, (ExcelData d1, bool r1) =>
            {
                if (r1)
                {
                    AddDelayRun(() =>
                    {
                        generateRes.Execute(excelData, (ExcelData d2, bool r2) =>
                        {
                            if (r2)
                            {
                                m_ExcelDataList.Add(excelData);
                                DealExcelIndex++;
                                if (PreDealExcelIndex == DealExcelIndex) //如果所有的Excel都处理完了,切到下一个流程(整体处理)
                                {
                                    Console.WriteLine("PreDealExcelIndex:" + PreDealExcelIndex.ToString());
                                    AddDelayRun(() =>
                                    {
                                        Procedure_OnAllExcelDealFinish(m_ExcelDataList);
                                    });
                                }
                            }
                        });
                    });
                }
            });
        }
        private bool ChangeCSharpCode(ExcelData excelData, string codePath)
        {
            bool executeResult = false;

            try
            {
                string[] lineArry = File.ReadAllLines(codePath);
                int      length   = lineArry.Length;
                string   findStr  = string.Format(Template.Template_ChangeCode_CSharp, excelData.Name);
                string   findStr2 = string.Format(Template.Template_ChangeCode_CSharp2, excelData.Name);
                for (int i = 0; i < length; i++)
                {
                    string line = lineArry[i].Trim();
                    if (line.Equals(findStr))
                    {
                        lineArry[i]     = string.Format(Template.Template_ChangeTarget_CSharp, excelData.Name, excelData.KeyValueString, excelData.Name);
                        lineArry[i + 1] = "{\n  private Dictionary<int, int> IntKeys;";
                        executeResult   = true;
                        continue;
                    }

                    if (line.Equals(findStr2))
                    {
                        lineArry[i] = string.Format(Template.Template_ChangeTarget_CSharp2, excelData.Name);
                        break;
                    }
                }
                File.WriteAllLines(codePath, lineArry);
            }
            catch (Exception error)
            {
                executeResult = false;
                Debug.LogError(error.ToString());
            }

            return(executeResult);
        }
        public override void Execute(ExcelData excelData, System.Action <ExcelData, bool> onFinished)
        {
            string        singleCode1  = "";
            string        singleCode2  = "";
            List <string> rowList      = excelData.GetRowData(0);
            List <string> desList      = excelData.GetRowData(2);
            string        lastWordName = "";

            for (int i = 0; i < rowList.Count; i++)
            {
                string typeName = excelData.GetTypeName(i);
                string wordName = excelData.GetWordName(i);
                string desStr   = desList[i];
                if (string.IsNullOrEmpty(desStr))
                {
                    desStr = "该字段未添加注释";
                }

                bool isArray = false;
                if (wordName.Contains(":"))
                {
                    wordName = wordName.Split(':')[0];
                    isArray  = true;
                }
                if (!lastWordName.Equals(wordName))
                {
                    if (typeName == "string")
                    {
                        typeName = "String";
                    }
                    if (typeName == "bool")
                    {
                        typeName = "boolean";
                    }
                    if (isArray)
                    {
                        if (typeName == "int")
                        {
                            typeName = "List<Integer>";
                        }
                        else
                        {
                            typeName = string.Format(@"List<{0}>", typeName);
                        }
                    }
                    singleCode1 += string.Format(Template_Server_Java_Json.Template_SingleTableCodeWord, wordName, typeName, wordName);
                    singleCode2 += string.Format(Template_Server_Java_Json.Template_SingleTableCodeWordGet, desStr, typeName, wordName, wordName);
                    lastWordName = wordName;
                }
            }
            string codeFileContent = string.Format(Template_Server_Java_Json.Template_SingleTableCode, excelData.Name, singleCode1, singleCode2);
            string JsonFilePath    = System.IO.Path.Combine(Setting.GenJavaServerJsonCodePath, "Table" + excelData.Name + ".java");

            if (Tools.GenerateFile(codeFileContent, JsonFilePath))
            {
                Debug.Log("[Generate Sucess]:" + JsonFilePath);
                if (onFinished != null)
                {
                    onFinished(excelData, true);
                }
            }

            if (onFinished != null)
            {
                onFinished(excelData, true);
            }
        }
예제 #10
0
        private bool Read_Single_Excel(string path)
        {
            try
            {
                ExcelData    excelData   = new ExcelData(path);
                FileInfo     fileInfo    = new System.IO.FileInfo(path);
                XSSFWorkbook workbook    = new XSSFWorkbook(fileInfo);
                ISheet       sheet       = workbook.GetSheetAt(0);
                int          columnCount = 0; //列数
                for (int i = 0; i < 10000; i++)
                {
                    IRow row = sheet.GetRow(i);
                    if (row != null)
                    {
                        List <string> rowList = new List <string>();
                        for (int j = 0; j < 100; j++)
                        {
                            ICell  cell    = row.GetCell(j);
                            string cellStr = "";
                            if (cell == null)
                            {
                                if (columnCount == 0)
                                {
                                    columnCount = rowList.Count;
                                    break;
                                }
                                else if (j < columnCount)
                                {
                                    if (i > 2)//策划没有配置,给预一个默认值
                                    {
                                        string cellType = excelData.GetTypeName(j);
                                        if (cellType == "string")
                                        {
                                            cellStr = "";
                                        }
                                        else if (cellType == "bool")
                                        {
                                            cellStr = "FLASE";
                                        }
                                        else
                                        {
                                            cellStr = "0";
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (string.IsNullOrEmpty(cellStr) && cell != null)
                            {
                                if (cell.CellType != CellType.Formula)  //如果不是公式
                                {
                                    cellStr = cell.ToString().Trim();
                                }
                                else
                                {
                                    if (cell.CachedFormulaResultType == CellType.Numeric)
                                    {
                                        cellStr = cell.NumericCellValue.ToString();
                                    }
                                    else if (cell.CachedFormulaResultType == CellType.String)
                                    {
                                        cellStr = cell.StringCellValue.Trim();
                                    }
                                    else if (cell.CachedFormulaResultType == CellType.Boolean)
                                    {
                                        cellStr = cell.BooleanCellValue.ToString();
                                    }
                                }
                            }

                            if (i == 0)
                            {
                                cellStr = cellStr[0].ToString().ToUpper() + cellStr.Substring(1); //字段首字母必须大写,应该flat会解析成首字母大写
                            }
                            if (i > 2 && j == 0 && cellStr.StartsWith("#"))                       //如果从第三行开始第一个单元格里的是#,则本行不读
                            {
                                break;
                            }
                            else
                            {
                                rowList.Add(cellStr);
                            }
                        }
                        if (rowList.Count > 0)
                        {
                            excelData.AddRowData(rowList);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                AddDelayRun(() =>
                {
                    SchemeType scheme = Setting.GetCurSchemeType();
                    if (scheme == SchemeType.Client_CSharp_To_FlatBuffer)
                    {
                        Proceduree_GenerateFbs(excelData);
                    }
                    else if (scheme == SchemeType.Server_Java_To_Json)
                    {
                        Procedure_OnDealSingleExcel(excelData);
                    }
                });
            }
            catch (Exception error)
            {
                Debug.Log(error);
                return(true);
            }
            return(true);
        }
 private void GenerateCode_FlatTableManager_Content(ExcelData excelData)
 {
     FlatBufferTableManagerCode_Content1 += string.Format(Template.Template_FlatBufferTableManager_Content1, excelData.Name);
     FlatBufferTableManagerCode_Content2 += string.Format(Template.Template_FlatBufferTableManager_Content2, excelData.Name, excelData.Name, excelData.Name);
 }
        public bool Procedure_GenerateBuildFlatBufferCode(ExcelData excelData)
        {
            List <List <string> > allRows          = excelData.GetAllRows();
            int           rowCount                 = allRows.Count;
            List <string> typeList                 = allRows[1];
            string        scriptline               = "";
            int           arrayStart               = 0;                                  //当遇到数组的时候会变成1; 遇到最后一个数组元素的时候变成 2
            List <TableArrayElementInfo> arrayList = new List <TableArrayElementInfo>(); //记录所有的数组单元格数据(必须是连贯的)

            for (int i = 3; i < rowCount; i++)
            {
                //offsets[{0}] = DR{1}.CreateDR{2}(fbb, {3});
                List <string> cellList = allRows[i];
                string        strParam = "";
                for (int j = 0; j < cellList.Count; j++)
                {
                    string cellName = allRows[0][j]; //字段名称
                    string wordType = typeList[j].ToLower();
                    string cellStr  = cellList[j];

                    string wordArrayName = null;
                    if (cellName.Contains(":"))
                    {
                        wordArrayName = cellName.Split(':')[0];
                        if (arrayStart == 0)
                        {
                            arrayStart = 1;
                            arrayList.Clear();
                            //arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name));
                        }
                    }

                    if (j + 1 < cellList.Count)                  //预判下一个值(如果不是最后一个)
                    {
                        string nextCellName = allRows[0][j + 1]; //字段名称
                        if (nextCellName.Contains(":"))
                        {
                            string nextWordArrayName = nextCellName.Split(':')[0];
                            if (!nextWordArrayName.Equals(wordArrayName)) //如果下一个单元格和当前单元格不是一个数组里的
                            {
                                if (arrayStart == 1)
                                {
                                    arrayStart = 2;
                                }
                            }
                        }
                        else
                        {
                            if (arrayStart == 1)
                            {
                                arrayStart = 2;
                            }
                        }
                    }
                    else
                    {
                        //如果已经是最后一个了
                        if (arrayStart == 1)
                        {
                            arrayStart = 2;
                        }
                    }

                    string cellParam = "";
                    if (arrayStart == 0)                                  //普通单元格
                    {
                        cellParam = GetCellCodeString(wordType, cellStr); //添加单个元素
                        strParam  = strParam + cellParam + ",";
                    }
                    else if (arrayStart == 1) //同一数组添加
                    {
                        arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name));
                    }
                    else if (arrayStart == 2) //整个数组解析成代码
                    {
                        arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name));
                        cellParam  = GetCellArrayCodeString(arrayList);
                        strParam   = strParam + cellParam + ",";
                        arrayStart = 0;
                    }
                }
                strParam = strParam.Substring(0, strParam.Length - 1);

                string addline = string.Format(Template.Template_GenerateBytesLine, i - 3, excelData.Name, excelData.Name, strParam);

                scriptline = scriptline + addline;
            }

            string generateByteFilePath = System.IO.Path.Combine(Setting.GenerateByteFilePath, string.Format("Table_{0}.bytes", excelData.Name));

            generateByteFilePath = generateByteFilePath.Replace(@"\", @"/");
            string script = string.Format(Template.Template_CSharp_GenearteBytes,
                                          excelData.Name, generateByteFilePath, excelData.Name, excelData.Name, rowCount - 3, scriptline, excelData.Name,
                                          excelData.Name, excelData.Name, excelData.Name, excelData.Name);
            //Console.WriteLine(script);

            string codePath = System.IO.Path.Combine(Setting.GenerateBuildFlatCodePath, "GenerateByte_" + excelData.Name + ".cs");

            if (Tools.GenerateFile(script, codePath))
            {
                Debug.Log("创建生成二进制代码" + codePath + "成功!");
            }

            //添加到管理器的代码
            GenerateManagerCode = GenerateManagerCode + string.Format(Template.Template_AddToGenerateManager, excelData.Name, excelData.Name);

            SetGenerateCodeFinish(excelData.FileName);

            //添加到FlatBufferTableManager(项目中使用)
            GenerateCode_FlatTableManager_Content(excelData);

            if (IsAllCodeGenerateFinish)
            {
                GenerateCode_FlatTableManager(excelData);
                OnCodeGenerateFinish(excelData);
            }
            return(true);
        }
 public override bool DealRow(ExcelData excelData, int rowIndex)
 {
     return(true);
 }
        public override bool DealRow(ExcelData excelData, int rowIndex)
        {
            if (rowIndex > 2)
            {
                string        JsonLine                 = "{"; //一行的json数据
                List <string> rowList                  = excelData.GetRowData(rowIndex);
                int           rowListCount             = rowList.Count;
                int           arrayMark                = 0;
                List <TableArrayElementInfo> arrayList = new List <TableArrayElementInfo>();
                for (int i = 0; i < rowListCount; i++)
                {
                    string wordName = excelData.GetWordName(i);
                    string wordType = excelData.GetTypeName(i);
                    string cellStr  = rowList[i];

                    //string wordArrayName = null;
                    if (wordName.Contains(":"))
                    {
                        wordName = wordName.Split(':')[0];
                        if (arrayMark == 0)
                        {
                            arrayMark = 1;
                            arrayList.Clear();
                        }
                    }

                    if (i + 1 < rowListCount)                                   //预判下一个值(如果不是最后一个)
                    {
                        string nextCellWordName = excelData.GetWordName(i + 1); //字段名称
                        if (nextCellWordName.Contains(":"))
                        {
                            string nextWordArrayName = nextCellWordName.Split(':')[0];
                            if (!nextWordArrayName.Equals(wordName)) //如果下一个单元格和当前单元格不是一个数组里的
                            {
                                if (arrayMark == 1)
                                {
                                    arrayMark = 2;
                                }
                            }
                        }
                        else
                        {
                            if (arrayMark == 1)
                            {
                                arrayMark = 2;
                            }
                        }
                    }
                    else
                    {
                        //如果已经是最后一个了
                        if (arrayMark == 1)
                        {
                            arrayMark = 2;
                        }
                    }

                    if (arrayMark == 0)  //普通单元格
                    {
                        cellStr = GetSingleCellString(wordType, cellStr);
                        string jsonCellStr = string.Format(Template_Server_Java_Json.Template_JsonCell, wordName, cellStr);
                        JsonLine += jsonCellStr;
                        if (i + 1 < rowListCount)
                        {
                            JsonLine += ",";
                        }
                    }
                    else if (arrayMark == 1) //同一数组添加
                    {
                        arrayList.Add(new TableArrayElementInfo(wordName, wordType, cellStr, excelData.Name));
                    }
                    else if (arrayMark == 2) //整个数组解析成代码
                    {
                        arrayList.Add(new TableArrayElementInfo(wordName, wordType, cellStr, excelData.Name));
                        string cellParam   = GetCellArrayString(arrayList);
                        string jsonCellStr = string.Format(Template_Server_Java_Json.Template_JsonCell, wordName, cellParam);

                        JsonLine = JsonLine + jsonCellStr;
                        if (i + 1 < rowListCount)
                        {
                            JsonLine += ",";
                        }
                        arrayMark = 0;
                    }
                }


                //Console.WriteLine(excelData.GetAllRowCount().ToString() + "   " + (rowIndex + 1).ToString());
                if (excelData.GetAllRowCount() == rowIndex + 1)
                {
                    JsonLine       += "}";
                    jsonContentStr += JsonLine;
                }
                else
                {
                    JsonLine       += "},";
                    jsonContentStr += JsonLine + "\n";
                }
            }
            return(true);
        }
예제 #15
0
 public abstract bool DealRow(ExcelData excelData, int rowIndex);
예제 #16
0
 public abstract void Execute(ExcelData excelData, System.Action <ExcelData, bool> onFinished);
예제 #17
0
        public bool Proceduree_GenerateFbs(ExcelData excelData)
        {
            List <string> dataList0 = excelData.GetRowData(0);   //字段
            List <string> dataList1 = excelData.GetRowData(1);   //类型
            List <string> dataList2 = excelData.GetRowData(2);   //说明

            if (dataList0 == null)
            {
                Debug.LogError("获取" + excelData.FileName + "第0行失败!");
                return(false);
            }
            if (dataList1 == null)
            {
                Debug.LogError("获取" + excelData.FileName + "第1行失败!");
                return(false);
            }
            if (dataList2 == null)
            {
                Debug.LogError("获取" + excelData.FileName + "第2行失败!");
                return(false);
            }

            int    count              = dataList0.Count;
            string generateScript     = "";
            string lastArrayWorldName = "";

            for (int i = 0; i < count; i++)
            {
                string cell_world = dataList0[i];
                string cell_type  = dataList1[i];
                string cell_des   = "该字段无备注";
                if (i < dataList2.Count)
                {
                    cell_des = dataList2[i];
                }

                if (i == 0)
                {
                    if (cell_world.StartsWith("#"))
                    {
                        cell_world = cell_world.Replace("#", "");
                    }
                    if (cell_type.StartsWith("#"))
                    {
                        cell_type = cell_type.Replace("#", "");
                    }
                    if (cell_des.StartsWith("#"))
                    {
                        cell_des = cell_des.Replace("#", "");
                    }
                }

                bool needAdd = true;
                if (cell_world.Contains(":"))
                {
                    string[] temp = cell_world.Split(':');
                    if (temp.Length > 0)
                    {
                        needAdd = string.IsNullOrEmpty(lastArrayWorldName) || temp[0] != lastArrayWorldName;
                        if (needAdd)
                        {
                            lastArrayWorldName = temp[0];
                            cell_type          = string.Format("[{0}]", cell_type);
                            cell_world         = lastArrayWorldName;
                        }
                    }
                }

                if (needAdd)
                {
                    generateScript = generateScript + string.Format(Template.Template_FbsLine, cell_des, cell_world, cell_type.ToLower());
                }
            }

            string fbs = string.Format(Template.Template_Fbs, excelData.Name, excelData.Name, excelData.Name, generateScript, excelData.Name);

            if (Tools.GenerateFile(fbs, excelData.FbsPath))
            {
                Debug.Log("[Generate]=> " + excelData.FbsPath + " Sucess!");

                AddDelayRun(() =>
                {
                    Procedure_GenerateFlatBufferCode(excelData);
                });
            }

            return(true);
        }