123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace DocTools.WPF
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
-
- /// <summary>
- /// 文档工具生成
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GeneralDoc_Button_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- this.GeneralDoc_Button.IsEnabled = false;
- var tuple = ValidateDirectory();
- if (!tuple.Item1)
- {
- MessageBox.Show(tuple.Item2);
- return;
- }
- tuple = ValidateFile();
- if (!tuple.Item1)
- {
- MessageBox.Show(tuple.Item2);
- return;
- }
- //先copy文件到自己目录
- this.Logs_Text.Text += "开始Copy RPC服务文件 到 DOCS文档工具目录" + Environment.NewLine;
- var rpcDLLPath = RPCFilePath_Text.Text + "\\WingInterfaceLibrary.dll";
- var rpcXMLPath = RPCFilePath_Text.Text + "\\WingInterfaceLibrary.xml";
- string destinationDLLPath = FilePath_Text.Text + "\\WingInterfaceLibrary.dll";
- string destinationXMLPath = FilePath_Text.Text + "\\WingInterfaceLibrary.xml";
- File.Copy(rpcDLLPath, destinationDLLPath, true);
- File.Copy(rpcXMLPath, destinationXMLPath, true);
- this.Logs_Text.Text += "RPC服务文件 Copy 成功" + Environment.NewLine;
- this.Logs_Text.Text += "文档工具开始读取 RPC服务文件内容" + Environment.NewLine;
- LoadData.SetInterfaceConfigToCache(FilePath_Text.Text + "\\");
- this.Logs_Text.Text += "RPC服务文件内容成功读取到内存" + Environment.NewLine;
- this.Logs_Text.Text += "文档工具开始生成文档JSON数据" + Environment.NewLine;
- CreateDocHtml doc = new CreateDocHtml();
- var resEntity = doc.CreateDocProjectString();
- var json = JsonConvert.SerializeObject(resEntity).Replace("\"Event\":", "\"event\":");
- this.Logs_Text.Text += "文档工具生成JSON数据成功" + Environment.NewLine;
- this.Logs_Text.Text += "文档工具开始生成HTML文档" + Environment.NewLine;
- var readXMLPath = FilePath_Text.Text + "\\XML.htm";
- var htmlContent = File.ReadAllText(readXMLPath);
- var resultHtml = htmlContent.Replace("$GetExportDocHtml()", json);
- var resPath = Description_Text.Text + "\\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);
- };
- this.Logs_Text.Text += "文档工具生成HTML文档成功,并写入到指定目录" + Environment.NewLine;
- this.GeneralDoc_Button.IsEnabled = true;
- MessageBox.Show("生成成功");
- }
- catch (Exception ex)
- {
- this.Logs_Text.Text += ex.InnerException?.ToString() + Environment.NewLine;
- }
- }
- /// <summary>
- /// 验证输入
- /// </summary>
- /// <returns></returns>
- private Tuple<bool,string> ValidateDirectory()
- {
- bool res = false;
- var msg = "";
- if (string.IsNullOrEmpty(RPCFilePath_Text.Text) || !Directory.Exists(RPCFilePath_Text.Text))
- {
- msg = "杏聆荟RPC服务目录无效";
- }
- else if (string.IsNullOrEmpty(FilePath_Text.Text) || !Directory.Exists(FilePath_Text.Text))
- {
- msg = "DOCS文档工具目录无效";
- }
- else if (string.IsNullOrEmpty(Description_Text.Text) || !Directory.Exists(Description_Text.Text))
- {
- msg = "HTML文档输出目录无效";
- }
- else
- {
- res = true;
- }
- return Tuple.Create(res, msg);
- }
- /// <summary>
- /// 验证输入文件
- /// </summary>
- /// <returns></returns>
- private Tuple<bool, string> ValidateFile()
- {
- bool res = false;
- var msg = "";
- var rpcDLLPath = RPCFilePath_Text.Text + "\\WingInterfaceLibrary.dll";
- var rpcXMLPath = RPCFilePath_Text.Text + "\\WingInterfaceLibrary.xml";
- var templateXMLPath = FilePath_Text.Text + "\\XML.htm";
- if (!File.Exists(rpcDLLPath) || !File.Exists(rpcXMLPath))
- {
- msg = "杏聆荟指定RPC服务DLL和XML文件不存在";
- }
- else if (!File.Exists(templateXMLPath))
- {
- msg = "HTML系统模板文件不存在";
- }
- else
- {
- res = true;
- }
- return Tuple.Create(res, msg);
- }
- }
- }
|