Ver Fonte

添加了一个测试eml解析的示例代码
修正winform调用登录接口卡住的问题

luocaiyang há 9 meses atrás
pai
commit
b43ccf1486

+ 26 - 20
wispro.sp.utility/IPEasyUtility.cs

@@ -713,28 +713,34 @@ namespace wispro.sp.utility
 
         private static OpenQA.Selenium.Chrome.ChromeDriver CreateChromeDriver()
         {
-            bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
-            
-            var options = new OpenQA.Selenium.Chrome.ChromeOptions();
-
-            options.AddUserProfilePreference("profile.default_content_settings.popups", 0);
-            options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
-            options.AddUserProfilePreference("download.prompt_for_download", false); // 禁止下载提示
-            options.AddUserProfilePreference("download.default_directory", strFileSavePath);
-            options.AddUserProfilePreference("intl.accept_languages", "nl");
-            options.AddUserProfilePreference("disable-popup-blocking", "true");
-            options.AddUserProfilePreference("safebrowsing.enabled", true);
-            options.AddArgument($"--unsafely-treat-insecure-origin-as-secure={ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb").Replace("/Login.aspx", "")}");//替换自己的域名,多域名可用逗号分隔。
-            if (isheadless)
+            try
             {
-                options.AddArgument("headless");
+                bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
+
+                var options = new OpenQA.Selenium.Chrome.ChromeOptions();
+
+                options.AddUserProfilePreference("profile.default_content_settings.popups", 0);
+                options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
+                options.AddUserProfilePreference("download.prompt_for_download", false); // 禁止下载提示
+                options.AddUserProfilePreference("download.default_directory", strFileSavePath);
+                options.AddUserProfilePreference("intl.accept_languages", "nl");
+                options.AddUserProfilePreference("disable-popup-blocking", "true");
+                options.AddUserProfilePreference("safebrowsing.enabled", true);
+                options.AddArgument($"--unsafely-treat-insecure-origin-as-secure={ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb").Replace("/Login.aspx", "")}");//替换自己的域名,多域名可用逗号分隔。
+                if (isheadless)
+                {
+                    options.AddArgument("headless");
+                }
+                var driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options);
+                driver.Manage().Window.Maximize();
+                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
+                driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
+
+                return driver;
+            }
+            catch(Exception ex) {
+                throw new Exception("创建chrome driver 出错!",ex);
             }
-            var driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options);
-            driver.Manage().Window.Maximize();
-            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
-            driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
-            
-            return driver;
         }
 
         /// <summary>

+ 2 - 2
wispro.sp.winClient/appsettings.json

@@ -4,7 +4,7 @@
     "isHeadless": "false",
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
-    "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\130.0.6723.69",
+    "ChormeDriverPath": "e:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\131.0.6778.108",
     "ScheduleSetting": "00 55 10 3 * ? *",
     "IPEasyWeb": "http://47.106.94.35/Login.aspx"
   },
@@ -17,6 +17,6 @@
 
   },
   "InvalidDataMessageMails": "罗才洋|luocaiyang@china-wispro.com,何青瓦|heqingwa@china-wispro.com,钟子敏|zhongzimin@china-wispro.com,吴芳|wufang@china-wispro.com,邢丽霞|xinglixia@china-wispro.com,田婵玉|tianchanyu@china-wispro.com,周珊珊|zhoushanshan@china-wispro.com",
-  "APIBaseUri": "http://1.116.113.26:81"
+  "APIBaseUri": "http://localhost:39476"
 
 }

+ 40 - 0
wispro.sp.winClient/emlFileReader.cs

@@ -0,0 +1,40 @@
+using MimeKit;
+using System;
+using System.IO;
+
+
+namespace wispro.sp.winClient
+{
+    public class emlFileReader
+    {
+        private string _filePath;
+
+        public emlFileReader(string filePath) { 
+            _filePath = filePath;
+
+            using (var stream = File.OpenRead(_filePath))
+            {
+                var message = MimeMessage.Load(stream);
+
+                // 遍历所有附件
+                foreach (var attachment in message.Attachments)
+                {
+                    if (attachment is MimePart part && part.IsAttachment)
+                    {
+                        string fileName = part.FileName;
+                        string contentType = part.ContentType.ToString();
+
+                        // 保存附件到文件系统
+                        string savePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
+                        using (var output = File.Create(savePath))
+                        {
+                            part.Content.DecodeTo(output);
+                        }
+
+                        Console.WriteLine($"附件 '{fileName}' 已保存,类型: {contentType}");
+                    }
+                }
+            }
+        }
+    }
+}

Diff do ficheiro suprimidas por serem muito extensas
+ 38 - 16
wispro.sp.winClient/frmCaseFileCompare.Designer.cs


+ 28 - 28
wispro.sp.winClient/frmCaseFileCompare.cs

@@ -38,9 +38,9 @@ namespace wispro.sp.winClient
         {
 
         }
-        
 
-        private CaseInfo getCaseInfo_files(string caseNo,out string draftFile,out string returnFile,out string finalFile)
+
+        private CaseInfo getCaseInfo_files(string caseNo, out string draftFile, out string returnFile, out string finalFile)
         {
             draftFile = null;
             returnFile = null;
@@ -115,7 +115,7 @@ namespace wispro.sp.winClient
                 return null;
             }
 
-            
+
 
         }
 
@@ -133,22 +133,22 @@ namespace wispro.sp.winClient
                     }
 
                     string draftFile = string.Empty;
-                    string returnFile =string.Empty;
-                    string finalFile =string.Empty;
+                    string returnFile = string.Empty;
+                    string finalFile = string.Empty;
 
                     string CaseNo = row["我方文号"].ToString();
 
-                    var isExistResp = new APIService().CaseExist(CaseNo);
+                    var isExistResp = await new APIService().CaseExist(CaseNo);
 
-                    isExistResp.Wait();
+                    //isExistResp.Wait();
 
-                    if (isExistResp.Result)
+                    if (isExistResp)
                     {
                         continue;
                     }
 
-                    CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile,out returnFile, out finalFile);
-                    
+                    CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile, out returnFile, out finalFile);
+
 
                     int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
                         (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
@@ -167,10 +167,10 @@ namespace wispro.sp.winClient
             }
         }
 
-        private  void CompareFiles(string draftFile, string returnFile, string finalFile, CaseInfo caseInfo)
+        private void CompareFiles(string draftFile, string returnFile, string finalFile, CaseInfo caseInfo)
         {
             string strExtractPath = @"c:\temp";
-            string  tmpdraftFile = ExtractFile(draftFile,0,strExtractPath);
+            string tmpdraftFile = ExtractFile(draftFile, 0, strExtractPath);
             string tmpreturnFile = ExtractFile(returnFile, 1, strExtractPath);
             string tmpfinalFile = ExtractFile(finalFile, 2, strExtractPath);
 
@@ -178,7 +178,7 @@ namespace wispro.sp.winClient
             {
                 CompareDocx docx = new CompareDocx();
                 docx.Compare(tmpdraftFile, tmpreturnFile);
-                if(docx.FulltextResult.oldWordCount > 0)
+                if (docx.FulltextResult.oldWordCount > 0)
                 {
                     caseInfo.DRRFulltext = docx.FulltextResult;
                 }
@@ -241,24 +241,24 @@ namespace wispro.sp.winClient
                 System.IO.File.Delete(finalFile);
             }
 
-            if (System.IO.Directory.Exists(Path.Combine(strExtractPath,returnFile.Substring(0,returnFile.Length -4))))
+            if (System.IO.Directory.Exists(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4))))
             {
                 System.IO.Directory.Delete(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4)), true);
             }
 
             if (System.IO.Directory.Exists(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4))))
             {
-                System.IO.Directory.Delete(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4)),true);
+                System.IO.Directory.Delete(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4)), true);
             }
             if (System.IO.Directory.Exists(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4))))
             {
-                System.IO.Directory.Delete(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4)),true);
+                System.IO.Directory.Delete(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4)), true);
             }
             #endregion
 
         }
 
-        
+
         CaseInfo caseInfo;
         private void button1_Click(object sender, EventArgs e)
         {
@@ -291,12 +291,7 @@ namespace wispro.sp.winClient
                 if (i > 1)
                 {
                     CompareFiles(draftFile, returnFile, finalFile, caseInfo);
-
-                    for (int k = 0; k < 1; k++)
-                    {
-                        new APIService().SaveCompareResult(caseInfo);
-                    }
-
+                    new APIService().SaveCompareResult(caseInfo);
                 }
 
                 comboBox1.SelectedIndex = 0;
@@ -356,7 +351,7 @@ namespace wispro.sp.winClient
 
         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
         {
-            if (caseInfo != null )
+            if (caseInfo != null)
             {
                 richTextBox1.Clear();
 
@@ -366,12 +361,12 @@ namespace wispro.sp.winClient
                     case 0:
                         if (caseInfo.DRRAll != null)
                         {
-                            strHtml = $"<b>所有文字比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRAll.InsertCount}</p><p>修改比率:{(caseInfo.DRRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.DRRAll.TextSimilarity*100).ToString("0.0000")}%</p>";
+                            strHtml = $"<b>所有文字比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRAll.InsertCount}</p><p>修改比率:{(caseInfo.DRRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.DRRAll.TextSimilarity * 100).ToString("0.0000")}%</p>";
                         }
 
                         if (caseInfo.RFRAll != null)
                         {
-                            strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{ caseInfo.RFRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRAll.InsertCount}</p><p>修改比率:{(caseInfo.RFRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.RFRAll.TextSimilarity * 100).ToString("0.0000")}%</p>";
+                            strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{caseInfo.RFRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRAll.InsertCount}</p><p>修改比率:{(caseInfo.RFRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.RFRAll.TextSimilarity * 100).ToString("0.0000")}%</p>";
                         }
 
 
@@ -483,7 +478,7 @@ namespace wispro.sp.winClient
         private void button2_Click(object sender, EventArgs e)
         {
             new Form1().ShowDialog();
-            
+
             #region 选择文档比较
             //OpenFileDialog openFileDialog = new OpenFileDialog();
 
@@ -519,7 +514,7 @@ namespace wispro.sp.winClient
 
         }
 
-        private void SaveResult(string strPath,CompareDocx draft_fristReturn)
+        private void SaveResult(string strPath, CompareDocx draft_fristReturn)
         {
             string strHtml = @"<!DOCTYPE html>
 <html lang=""en"">
@@ -716,5 +711,10 @@ namespace wispro.sp.winClient
 
             }
         }
+
+        private void button3_Click(object sender, EventArgs e)
+        {
+            emlFileReader reader = new emlFileReader(@"D:\Users\luowen\Downloads\2f7e92c1-e009-4b19-ba8d-332e8f6f2ffc.eml");
+        }
     }
 }

+ 1 - 0
wispro.sp.winClient/wispro.sp.winClient.csproj

@@ -8,6 +8,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="MimeKit" Version="4.9.0" />
     <PackageReference Include="Quartz" Version="3.13.1" />
     <PackageReference Include="SharpCompress" Version="0.38.0" />
   </ItemGroup>