Program.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 
  2. using WingCloudServer.GeneralDocTools.Service;
  3. using WingCloudServer.GeneralDocTools.Model.Parameters;
  4. using WingCloudServer.GeneralDocTools.Helper;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.IO;
  8. namespace WingCloudServer.GeneralDocTools
  9. {
  10. class Program
  11. {
  12. //初始化最近文档更新时间
  13. private static string InterfaceDllVersion = string.Empty;
  14. static void Main(string[] args)
  15. {
  16. Console.WriteLine("******DocHtml文档生成工具启动******");
  17. GeneralDocHtml();
  18. Console.ReadLine();
  19. }
  20. /// <summary>
  21. /// 生成doc文件
  22. /// </summary>
  23. private static void GeneralDocHtml()
  24. {
  25. //读取配置
  26. var dllDirect = ConfigurationManager.GetParammeter<StringParameter>("InterfaceService", "DLLPath").Value;
  27. var dllPath = dllDirect + "WingInterfaceLibrary.dll";
  28. var xmlPath = dllDirect + "WingInterfaceLibrary.xml";
  29. System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(dllPath);
  30. //初始化或者版本不一致时,更新文档
  31. if (string.IsNullOrEmpty(InterfaceDllVersion) || fvi.FileVersion != InterfaceDllVersion)
  32. {
  33. InterfaceDllVersion = fvi.FileVersion ?? CommonHelper.DateTimeToUnixTime().ToString();
  34. var destDirect = AppDomain.CurrentDomain.BaseDirectory + "\\DLLFolder\\";
  35. if (!Directory.Exists(destDirect))
  36. {
  37. Directory.CreateDirectory(destDirect);
  38. }
  39. var destDllPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.dll";
  40. var destXmlPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.xml";
  41. File.Copy(dllPath, destDllPath, true);
  42. File.Copy(xmlPath, destXmlPath, true);
  43. LoadData.SetInterfaceConfigToCache(destDirect, $"_{InterfaceDllVersion}");
  44. CreateReleaseNoteAndDocHtml(InterfaceDllVersion);
  45. File.Copy(dllPath, $"{AppDomain.CurrentDomain.BaseDirectory}\\ReleaseNotes\\WingInterfaceLibrary.dll", true);
  46. Console.WriteLine($"系统于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}生成DocHtml文档成功,DLL版本:{InterfaceDllVersion}");
  47. }
  48. }
  49. /// <summary>
  50. /// 创建releaseNotes并生成doc文件
  51. /// </summary>
  52. private static void CreateReleaseNoteAndDocHtml(string InterfaceDllVersion)
  53. {
  54. CreateDocHtml doc = new CreateDocHtml();
  55. var resPath = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "DocHtmlPath").Value;
  56. if (string.IsNullOrEmpty(resPath))
  57. {
  58. resPath = AppDomain.CurrentDomain.BaseDirectory + "ReleaseNotes\\";
  59. }
  60. if (!Directory.Exists(resPath))
  61. {
  62. Directory.CreateDirectory(resPath);
  63. }
  64. var secondService = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "SecondService").Value;
  65. var fileName = secondService + "DocHtml.html";
  66. var resEntity = doc.CreateDocProjectString(InterfaceDllVersion, fileName);
  67. var json = JsonConvert.SerializeObject(resEntity.Item1).Replace("\"Event\":", "\"event\":");
  68. var dataSourceJson = JsonConvert.SerializeObject(resEntity.Item2);
  69. var baseDirect = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug\\net6.0", "");
  70. //copy文件到releaseNotes目录
  71. CopyReleaseNotesFile(baseDirect, resPath);
  72. //生成dochtml
  73. var readXMLPath = baseDirect + "XML.htm";
  74. var htmlContent = File.ReadAllText(readXMLPath);
  75. var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json).Replace("$GetDocDataSources()", dataSourceJson);
  76. resPath += "DocHtml.html";
  77. if (File.Exists(resPath))
  78. {
  79. File.Delete(resPath);
  80. }
  81. byte[] myByte = System.Text.Encoding.UTF8.GetBytes(resultHtml);
  82. using (FileStream fsWrite = new FileStream(resPath, FileMode.Append))
  83. {
  84. fsWrite.Write(myByte, 0, myByte.Length);
  85. };
  86. }
  87. /// <summary>
  88. /// 复制releaseNotes
  89. /// </summary>
  90. private static void CopyReleaseNotesFile(string baseDirect, string resPath)
  91. {
  92. var rnHtmlSource = baseDirect + "ReleaseNoteDetail.html";
  93. var rnHtmlCopyPath = resPath + "ReleaseNoteDetail.html";
  94. File.Copy(rnHtmlSource, rnHtmlCopyPath, true);
  95. // var rnXlsxSource = baseDirect + "新版杏聆荟ReleaseNotes.xlsx";
  96. // var rnXlsxCopyPath = resPath + "新版杏聆荟ReleaseNotes.xlsx";
  97. // File.Copy(rnXlsxSource, rnXlsxCopyPath, true);
  98. var rnResPath = resPath + "ReleaseNoteStyle\\";
  99. if (!Directory.Exists(rnResPath))
  100. {
  101. Directory.CreateDirectory(rnResPath);
  102. }
  103. var rnSourcePath = baseDirect + "ReleaseNoteStyle\\";
  104. if (!Directory.Exists(rnSourcePath))
  105. {
  106. Directory.CreateDirectory(rnSourcePath);
  107. }
  108. string[] folders = Directory.GetFiles(rnSourcePath);
  109. if (folders?.Length > 0)
  110. {
  111. foreach (string folder in folders)
  112. {
  113. string name = System.IO.Path.GetFileName(folder);
  114. string dest = System.IO.Path.Combine(rnResPath, name);
  115. File.Copy(folder, dest, true);
  116. }
  117. }
  118. }
  119. }
  120. }