Program.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using DocTools;
  2. using DocTools.Entity.Parameters;
  3. using DocTools.Helper;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.IO;
  7. using System.Threading.Tasks;
  8. namespace DocHtml
  9. {
  10. class Program
  11. {
  12. //初始化最近文档更新时间
  13. private static string InterfaceDllVersion = string.Empty;
  14. /// <summary>
  15. /// 启动项
  16. /// </summary>
  17. /// <param name="args"></param>
  18. static void Main(string[] args)
  19. {
  20. Console.WriteLine("DocHtml文档生成工具启动");
  21. while (true)
  22. {
  23. GeneralDocHtml();
  24. System.Threading.Thread.Sleep(1000 * 60 * 1);
  25. }
  26. }
  27. /// <summary>
  28. /// 生成doc文件
  29. /// </summary>
  30. private static void GeneralDocHtml()
  31. {
  32. //读取配置
  33. var dllDirect = ConfigurationManager.GetParammeter<StringParameter>("InterfaceService", "DLLPath").Value;
  34. var dllPath = dllDirect + "WingInterfaceLibrary.dll";
  35. var xmlPath = dllDirect + "WingInterfaceLibrary.xml";
  36. System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(dllPath);
  37. //初始化或者版本不一致时,更新文档
  38. if (string.IsNullOrEmpty(InterfaceDllVersion) || fvi.FileVersion != InterfaceDllVersion)
  39. {
  40. InterfaceDllVersion = fvi.FileVersion;
  41. var destDirect = AppDomain.CurrentDomain.BaseDirectory + "\\DLLFolder\\";
  42. if (!Directory.Exists(destDirect))
  43. {
  44. Directory.CreateDirectory(destDirect);
  45. }
  46. var destDllPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.dll";
  47. var destXmlPath = destDirect + $"WingInterfaceLibrary_{InterfaceDllVersion}.xml";
  48. File.Copy(dllPath, destDllPath, true);
  49. File.Copy(xmlPath, destXmlPath, true);
  50. LoadData.SetInterfaceConfigToCache(destDirect, $"_{InterfaceDllVersion}");
  51. CreateDocHtml doc = new CreateDocHtml();
  52. var resPath = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "DocHtmlPath").Value;
  53. var secondService = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "SecondService").Value;
  54. var fileName = secondService + Path.GetFileName(resPath);
  55. var resEntity = doc.CreateDocProjectString(InterfaceDllVersion, fileName);
  56. var json = JsonConvert.SerializeObject(resEntity).Replace("\"Event\":", "\"event\":");
  57. var readXMLPath = AppDomain.CurrentDomain.BaseDirectory + "\\XML.htm";
  58. var htmlContent = File.ReadAllText(readXMLPath);
  59. var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json);
  60. if (File.Exists(resPath))
  61. {
  62. File.Delete(resPath);
  63. }
  64. byte[] myByte = System.Text.Encoding.UTF8.GetBytes(resultHtml);
  65. using (FileStream fsWrite = new FileStream(resPath, FileMode.Append))
  66. {
  67. fsWrite.Write(myByte, 0, myByte.Length);
  68. };
  69. Console.WriteLine($"系统于{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }生成DocHtml文档成功,DLL版本:{InterfaceDllVersion}");
  70. }
  71. }
  72. }
  73. }