예제 #1
0
        /// <summary>
        /// 生成指定文件
        /// </summary>
        /// <param name="fileRelaticePathList"></param>
        /// <param name="resultCallback"></param>
        /// <param name="progressCallback"></param>
        public static void GenFile(List <string> fileRelaticePathList, Action <bool> resultCallback, Action <float> progressCallback)
        {
            ConfigData configData = ConfigData.GetSingle();

            foreach (var item in configData.CodeConfigDataMap)
            {
                if (item.Value.NeedExport)
                {
                    if (!Directory.Exists(item.Value.ExportXmlAbsolutePath))
                    {
                        Log(false, $"xml配置文件根路径:{item.Value.ExportXmlAbsolutePath}不存在!");
                        resultCallback?.Invoke(false);
                        return;
                    }
                    if (!Directory.Exists(item.Value.ExportCodeAbsolutePath))
                    {
                        Log(false, $"{item.Key}代码文件根路径:{item.Value.ExportCodeAbsolutePath}不存在!");
                        resultCallback?.Invoke(false);
                        return;
                    }
                }
            }
            progressCallback?.Invoke(0);
            int    finishFileNumber    = 0;
            string currentXlsxFilePath = "";

            try
            {
                Task.Run(() =>
                {
                    Log(true, $"开始生成文件!");
                    foreach (string xlsxFileRelativePath in fileRelaticePathList)
                    {
                        string xlsxFilePath = GetImportXlsxAbsolutePath() + "/" + xlsxFileRelativePath;
                        currentXlsxFilePath = xlsxFilePath;

                        XlsxFile xlsxFile = new XlsxFile(xlsxFilePath);
                        foreach (var item in configData.CodeConfigDataMap)
                        {
                            if (item.Value.NeedExport)
                            {
                                xlsxFile.Export(item.Key, xlsxFileRelativePath);
                            }
                        }
                        finishFileNumber++;
                        progressCallback?.Invoke((float)finishFileNumber / fileRelaticePathList.Count);
                    }
                    Log(true, $"生成文件结束!");
                    resultCallback?.Invoke(true);
                });
            }
            catch (CustomException customException)
            {
                Log(false, $"生成文件失败!{currentXlsxFilePath}");
                Log(false, $"{customException.customMessage}");
                resultCallback?.Invoke(false);
            }
            catch (Exception exception)
            {
                Log(false, $"生成文件失败!{currentXlsxFilePath}");
                Log(false, exception);
                resultCallback?.Invoke(false);
            }
        }