using WingCloudServer.GeneralDocTools.Service; using WingCloudServer.GeneralDocTools.Model.Parameters; using WingCloudServer.GeneralDocTools.Helper; using Newtonsoft.Json; using System; using System.IO; namespace WingCloudServer.GeneralDocTools { class Program { //初始化最近文档更新时间 private static string InterfaceDllVersion = string.Empty; static void Main(string[] args) { Console.WriteLine("******DocHtml文档生成工具启动******"); GeneralDocHtml(); Console.ReadLine(); } /// /// 生成doc文件 /// private static void GeneralDocHtml() { //读取配置 var dllDirect = ConfigurationManager.GetParammeter("InterfaceService", "DLLPath").Value; var dllPath = dllDirect + "WingInterfaceLibrary.dll"; var xmlPath = dllDirect + "WingInterfaceLibrary.xml"; System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(dllPath); //初始化或者版本不一致时,更新文档 if (string.IsNullOrEmpty(InterfaceDllVersion) || fvi.FileVersion != InterfaceDllVersion) { InterfaceDllVersion = fvi.FileVersion ?? CommonHelper.DateTimeToUnixTime().ToString(); var destDirect = AppDomain.CurrentDomain.BaseDirectory + "\\DLLFolder\\"; if (!Directory.Exists(destDirect)) { Directory.CreateDirectory(destDirect); } var destDllPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.dll"; var destXmlPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.xml"; File.Copy(dllPath, destDllPath, true); File.Copy(xmlPath, destXmlPath, true); LoadData.SetInterfaceConfigToCache(destDirect, $"_{InterfaceDllVersion}"); CreateReleaseNoteAndDocHtml(InterfaceDllVersion); File.Copy(dllPath, $"{AppDomain.CurrentDomain.BaseDirectory}\\ReleaseNotes\\WingInterfaceLibrary.dll", true); Console.WriteLine($"系统于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}生成DocHtml文档成功,DLL版本:{InterfaceDllVersion}"); } } /// /// 创建releaseNotes并生成doc文件 /// private static void CreateReleaseNoteAndDocHtml(string InterfaceDllVersion) { CreateDocHtml doc = new CreateDocHtml(); var resPath = ConfigurationManager.GetParammeter("ReponseService", "DocHtmlPath").Value; if (string.IsNullOrEmpty(resPath)) { resPath = AppDomain.CurrentDomain.BaseDirectory + "ReleaseNotes\\"; } if (!Directory.Exists(resPath)) { Directory.CreateDirectory(resPath); } var secondService = ConfigurationManager.GetParammeter("ReponseService", "SecondService").Value; var fileName = secondService + "DocHtml.html"; var resEntity = doc.CreateDocProjectString(InterfaceDllVersion, fileName); var json = JsonConvert.SerializeObject(resEntity.Item1).Replace("\"Event\":", "\"event\":"); var dataSourceJson = JsonConvert.SerializeObject(resEntity.Item2); var baseDirect = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug\\net6.0", ""); //copy文件到releaseNotes目录 CopyReleaseNotesFile(baseDirect, resPath); //生成dochtml var readXMLPath = baseDirect + "XML.htm"; var htmlContent = File.ReadAllText(readXMLPath); var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json).Replace("$GetDocDataSources()", dataSourceJson); resPath += "DocHtml.html"; if (File.Exists(resPath)) { File.Delete(resPath); } byte[] myByte = System.Text.Encoding.UTF8.GetBytes(resultHtml); using (FileStream fsWrite = new FileStream(resPath, FileMode.Append)) { fsWrite.Write(myByte, 0, myByte.Length); }; } /// /// 复制releaseNotes /// private static void CopyReleaseNotesFile(string baseDirect, string resPath) { var rnHtmlSource = baseDirect + "ReleaseNoteDetail.html"; var rnHtmlCopyPath = resPath + "ReleaseNoteDetail.html"; File.Copy(rnHtmlSource, rnHtmlCopyPath, true); // var rnXlsxSource = baseDirect + "新版杏聆荟ReleaseNotes.xlsx"; // var rnXlsxCopyPath = resPath + "新版杏聆荟ReleaseNotes.xlsx"; // File.Copy(rnXlsxSource, rnXlsxCopyPath, true); var rnResPath = resPath + "ReleaseNoteStyle\\"; if (!Directory.Exists(rnResPath)) { Directory.CreateDirectory(rnResPath); } var rnSourcePath = baseDirect + "ReleaseNoteStyle\\"; if (!Directory.Exists(rnSourcePath)) { Directory.CreateDirectory(rnSourcePath); } string[] folders = Directory.GetFiles(rnSourcePath); if (folders?.Length > 0) { foreach (string folder in folders) { string name = System.IO.Path.GetFileName(folder); string dest = System.IO.Path.Combine(rnResPath, name); File.Copy(folder, dest, true); } } } } }