123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
-
- 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();
- }
- /// <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 ?? 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}");
- }
- }
- /// <summary>
- /// 创建releaseNotes并生成doc文件
- /// </summary>
- private static void CreateReleaseNoteAndDocHtml(string InterfaceDllVersion)
- {
- CreateDocHtml doc = new CreateDocHtml();
- var resPath = ConfigurationManager.GetParammeter<StringParameter>("ReponseService", "DocHtmlPath").Value;
- if (string.IsNullOrEmpty(resPath))
- {
- resPath = AppDomain.CurrentDomain.BaseDirectory + "ReleaseNotes\\";
- }
- if (!Directory.Exists(resPath))
- {
- Directory.CreateDirectory(resPath);
- }
- var secondService = ConfigurationManager.GetParammeter<StringParameter>("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);
- };
- }
- /// <summary>
- /// 复制releaseNotes
- /// </summary>
- 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);
- }
- }
- }
- }
- }
|