Program.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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;
  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. CreateDocHtml doc = new CreateDocHtml();
  45. var resPath = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "DocHtmlPath").Value;
  46. var secondService = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "SecondService").Value;
  47. var fileName = secondService + Path.GetFileName(resPath);
  48. var resEntity = doc.CreateDocProjectString(InterfaceDllVersion, fileName);
  49. var json = JsonConvert.SerializeObject(resEntity).Replace("\"Event\":", "\"event\":");
  50. var readXMLPath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug\\net6.0", "") + "XML.htm";
  51. var htmlContent = File.ReadAllText(readXMLPath);
  52. var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json);
  53. if (File.Exists(resPath))
  54. {
  55. File.Delete(resPath);
  56. }
  57. byte[] myByte = System.Text.Encoding.UTF8.GetBytes(resultHtml);
  58. using (FileStream fsWrite = new FileStream(resPath, FileMode.Append))
  59. {
  60. fsWrite.Write(myByte, 0, myByte.Length);
  61. };
  62. Console.WriteLine($"系统于{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }生成DocHtml文档成功,DLL版本:{InterfaceDllVersion}");
  63. }
  64. }
  65. }
  66. }