12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using DocTools;
- using DocTools.Entity.Parameters;
- using DocTools.Helper;
- using Newtonsoft.Json;
- using System;
- using System.IO;
- using System.Threading.Tasks;
- namespace DocHtml
- {
- class Program
- {
- //初始化最近文档更新时间
- private static string InterfaceDllVersion = string.Empty;
- /// <summary>
- /// 启动项
- /// </summary>
- /// <param name="args"></param>
- static void Main(string[] args)
- {
- Console.WriteLine("DocHtml文档生成工具启动");
- while (true)
- {
- GeneralDocHtml();
- System.Threading.Thread.Sleep(1000 * 60 * 1);
- }
- }
- /// <summary>
- /// 生成doc文件
- /// </summary>
- private static void GeneralDocHtml()
- {
- //读取配置
- var dllDirect = ConfigurationManager.GetParammeter<StringParameter>("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;
- 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}");
- CreateDocHtml doc = new CreateDocHtml();
- var resPath = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "DocHtmlPath").Value;
- var secondService = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "SecondService").Value;
- var fileName = secondService + Path.GetFileName(resPath);
- var resEntity = doc.CreateDocProjectString(InterfaceDllVersion, fileName);
- var json = JsonConvert.SerializeObject(resEntity).Replace("\"Event\":", "\"event\":");
- var readXMLPath = AppDomain.CurrentDomain.BaseDirectory + "\\XML.htm";
- var htmlContent = File.ReadAllText(readXMLPath);
- var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json);
- 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);
- };
- Console.WriteLine($"系统于{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }生成DocHtml文档成功,DLL版本:{InterfaceDllVersion}");
- }
- }
- }
- }
|