Selaa lähdekoodia

【软件版本】
V 3.0.6.4 未发布
【模块名称】
路由跟踪功能,执行批处理;
【问题原因】
在http通信出现404之类的错误时,如果配置开启Tracert功能则进行批处理执行。
【修改描述】

【测试结果】

sat23 3 vuotta sitten
vanhempi
commit
93b38371f4

+ 87 - 0
SCBC Factory Tools/Http/HttpHelper.cs

@@ -14,6 +14,7 @@ using System.Linq;
 using System.Net.Cache;
 using System.Diagnostics;
 using SXLibrary;
+using System.Threading;
 
 namespace SufeiUtil
 {
@@ -22,6 +23,75 @@ namespace SufeiUtil
     /// </summary>
     public class HttpHelper
     {
+        #region 后台进程;
+        static int ms_ProcessID = -1;
+        static int ms_ProcessID2= -1;
+        private static readonly object ms_Lock = new object();
+        public static bool Tracert = false;
+        private void CallTracertBat()
+        {
+            Monitor.Enter(ms_Lock);
+            //是否已有批处理在执行;
+            if (ms_ProcessID != -1)
+            {
+                try
+                {   // 查找该进程ID是否存在;
+                    System.Diagnostics.Process bat = System.Diagnostics.Process.GetProcessById(ms_ProcessID);
+                    // nothing to do;
+                }
+                catch (Exception ex)
+                {
+                    ms_ProcessID = -1;
+                    //if ((uint)ex.HResult == 0x80070057) {ms_ProcessID = -1;}
+                }
+            }
+
+            if ( ms_ProcessID == -1 )
+            {
+                Process bat = new Process();
+                bat.StartInfo.FileName = "route-tracert.bat";
+                // 隐藏窗口;
+                bat.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+                bat.Start();
+                // 记录进程id;
+                ms_ProcessID = bat.Id;
+            }
+            
+            Monitor.Exit(ms_Lock);
+        }
+        private void CallPingBat()
+        {
+            Monitor.Enter(ms_Lock);
+            //是否已有批处理在执行;
+            if (ms_ProcessID2 != -1)
+            {
+                try
+                {   // 查找该进程ID是否存在;
+                    System.Diagnostics.Process bat = System.Diagnostics.Process.GetProcessById(ms_ProcessID2);
+                    // nothing to do;
+                }
+                catch (Exception ex)
+                {
+                    ms_ProcessID2 = -1;
+                    //if ((uint)ex.HResult == 0x80070057) {ms_ProcessID = -1;}
+                }
+            }
+
+            if (ms_ProcessID2 == -1)
+            {
+                Process bat = new Process();
+                bat.StartInfo.FileName = "route-ping.bat";
+                // 隐藏窗口;
+                bat.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+                bat.Start();
+                // 记录进程id;
+                ms_ProcessID2 = bat.Id;
+            }
+
+            Monitor.Exit(ms_Lock);
+        }
+        #endregion
+
         #region 预定义方变量
         //默认的编码
         private Encoding encoding = Encoding.Default;
@@ -101,6 +171,23 @@ namespace SufeiUtil
             Log.WriteTimesdLog(string.Format("\r\nurl={0}\r\nPostdata={1}\r\nResult={2}\r\nStatus={3}\r\nElapsed={4}ms\r\n", 
                 item.URL, item.Postdata, result.Html, result.StatusDescription, stopwatch.ElapsedMilliseconds.ToString()));
             stopwatch.Reset();
+
+            switch ( result.StatusCode )
+            {
+                case HttpStatusCode.BadRequest:
+                case HttpStatusCode.NotFound:
+                case HttpStatusCode.GatewayTimeout:
+                case HttpStatusCode.BadGateway:
+                    if (Tracert)
+                    {
+                        CallPingBat();
+                        CallTracertBat();
+                    }
+                    break;
+                default:
+                    break;
+            }
+
             return result;
         }
         #endregion

+ 2 - 0
SCBC Factory Tools/Views/Login.cs

@@ -1,6 +1,7 @@
 using CCWin;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
+using SufeiUtil;
 using System;
 using System.Collections.Generic;
 using System.Data.SQLite;
@@ -240,6 +241,7 @@ namespace MOKA_Factory_Tools
                     AccountText.Text = jObject["FactoryName"] == null ? (!CommonMethod.AddJsonConfig("FactoryName", null) ? "" : "") : jObject["FactoryName"].Value<string>();
                     loginOutput1.factoryname = jObject["FactoryName"] == null ? "" : jObject["FactoryName"].Value<string>();
                     loginOutput1.factorynum=jObject["FactoryNum"] == null ? "" : jObject["FactoryNum"].Value<string>();
+                    HttpHelper.Tracert = jObject["Tracert"] == null ? false : jObject["Tracert"].Value<bool>();
                     #region G客户NTF功能开启;
                     if (jObject["NTF"] != null)
                     {

+ 15 - 2
SCBC Factory Tools/路由跟踪.bat

@@ -2,7 +2,20 @@
 @set datetime=%date:~0,4% %date:~5,2% %date:~8,2%-%time:~0,2% %time:~3,2% %time:~6,2%
 ::去除所有空格;
 @set datetime=%datetime: =%
+:: 判断文件夹是否存在,不存在创建;
+set logpath=.\log\tracert
+if not exist %logpath% (@md .\log\tracert)
 :: -h表示跟踪的最大跃点数;
 :: -w表示等待每个回复的超时值,毫秒;
-@md tracertlog
-tracert -h 50 -w 3000 huizhou.idmanage.qhmoka.com > .\tracertlog\%datetime%.log
+tracert -h 50 -w 3000 huizhou.idmanage.qhmoka.com > .\log\tracert\%datetime%.log
+
+
+::获取系统时间;
+@set datetime=%date:~0,4% %date:~5,2% %date:~8,2%-%time:~0,2% %time:~3,2% %time:~6,2%
+::去除所有空格;
+@set datetime=%datetime: =%
+:: 判断文件夹是否存在,不存在创建;
+set logpath=.\log\ping
+if not exist %logpath% (@md .\log\ping)
+:: -n 表示要ping的次数;
+ping huizhou.idmanage.qhmoka.com -n 60 > .\log\ping\%datetime%.log