From 1cf00bcc4e6869b356dd15310648bb93c9b1bbde Mon Sep 17 00:00:00 2001
From: czw <selecti@yeah.net>
Date: 星期三, 23 七月 2025 09:10:15 +0800
Subject: [PATCH] init_内存泄漏测试- 增加全部释放

---
 2025年6月12日/AuxAllWCS/Build/Project/代码/自定义类.cs |   78 ++++++++++++++++++++++++++------------
 1 files changed, 53 insertions(+), 25 deletions(-)

diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\350\207\252\345\256\232\344\271\211\347\261\273.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\350\207\252\345\256\232\344\271\211\347\261\273.cs"
index 9159ff1..9f66096 100644
--- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\350\207\252\345\256\232\344\271\211\347\261\273.cs"
+++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\350\207\252\345\256\232\344\271\211\347\261\273.cs"
@@ -50,6 +50,29 @@
         }
         #endregion [鑷畾涔夌被][20250323144531864][Settings]
     }
+    public static class ExtendClass
+    {
+        public static void Disnull(this TaskRepository repository)
+        {
+            repository.dbcontext.Dispose();
+            repository = null;
+        }
+        public static void Disnull(this LocRepository repository)
+        {
+            repository.dbcontext.Dispose();
+            repository = null;
+        }
+        public static void Disnull(this TaskActRepository repository)
+        {
+            repository.dbcontext.Dispose();
+            repository = null;
+        }
+        public static void Disnull(this SYSRepository repository)
+        {
+            repository.dbcontext.Dispose();
+            repository = null;
+        }
+    }
     public class LogHelper
     {
         #region    [鑷畾涔夌被][20250323145442478][LogHelper]
@@ -143,7 +166,7 @@
         /// </summary>
         static LogFactory()
         {
-            var loggerNames = new List<string>() { "HosttoagvTask", "HosttoagvCar", "NDC", "鏉ゥ" };
+            var loggerNames = new List<string>() { "HosttoagvTask", "HosttoagvCar", "NDC", "鏉ゥ", "IP鍦ㄧ嚎妫�祴" };
             LogManager.Configuration = DefaultConfig(loggerNames);
         }
         public static ILogger CreateLogger(string name)
@@ -449,7 +472,8 @@
         #region    [鑷畾涔夌被][20250325095622918][HttpHelper]
         public string Post(string url, string postData, string contentType = "application/json", string sessionId = "")
         {
-            LogHelper.Info(url + "+" + postData);
+            var SendPRO = TaskProcess.GenerateTaskNo("鏃ュ織娴佹按鍙�, "LOG");
+            LogHelper.Info($"娴佹按鍙枫�{SendPRO}銆� + url + "+" + postData);
             WebRequest request = WebRequest.Create(url);
             request.Method = "POST";
             byte[] byteArray = Encoding.UTF8.GetBytes(postData);
@@ -475,12 +499,12 @@
                 stream = rsp.GetResponseStream();
                 reader = new StreamReader(stream);
                 string rrend = reader.ReadToEnd();
-                LogHelper.Info($"{url} response={rrend}");
+                LogHelper.Info($"娴佹按鍙枫�{SendPRO}銆�response={rrend}");
                 return rrend;
             }
             catch (Exception ex)
             {
-                LogHelper.Info($"{url} err={ex.Message}");
+                LogHelper.Info($"娴佹按鍙枫�{SendPRO}銆�err={ex.Message}");
                 return "";
             }
             finally
@@ -522,15 +546,13 @@
     {
         #region    [鑷畾涔夌被][20250325131633664][SYSHelper]
         private static object locker = new object();
-        internal static int GetSerialNumber(string snType, string prefix, string Vend = "0")
+        internal static int GetSerialNumber(string snType, string prefix)
         {
-            if (Vend == "1")
-                Vend = DateTime.Now.ToString("yyMMdd");
             int result = 0;
             lock (locker)
             {
                 SYSRepository sysservice = new SYSRepository();
-                var sId = sysservice.FindEntity(a => a.CN_S_TYPE.Trim() == snType && a.CN_S_PRE.Trim() == prefix + Vend);
+                var sId = sysservice.FindEntity(a => a.CN_S_TYPE.Trim() == snType && a.CN_S_PRE.Trim() == prefix);
 
                 if (sId != null)
                 {
@@ -552,9 +574,10 @@
                 }
                 else
                 {
-                    sId = new SYSEntity { CN_S_TYPE = snType, CN_T_LAST = DateTime.Now, CN_S_PRE = prefix + Vend, CN_N_MAX = 0, CN_S_APP_TYPE = "WCS" };
+                    sId = new SYSEntity { CN_S_TYPE = snType, CN_T_LAST = DateTime.Now, CN_S_PRE = prefix, CN_N_MAX = 0, CN_S_APP_TYPE = "WCS" };
                     sysservice.Insert(sId);
                 }
+                sysservice.Disnull();
             }
             return result;
         }
@@ -563,24 +586,25 @@
     public class TaskProcess
     {
         #region    [鑷畾涔夌被][20250325152141671][TaskProcess]
-        internal static bool CreateTask(string no, string from, string to, string taskType, int pri, List<string> cntrs, string workMode = "AGV", int cntrCount = 1, int startLayer = 1, int endLayer = 1)
+        internal static bool CreateTask(string no, string from, string to, string taskType, int pri, List<string> cntrs, string workMode = "AGV", string S_INDEX = "", int cntrCount = 1, int startLayer = 1, int endLayer = 1)
         {
 
             LogHelper.Info($"鍒涘缓浠诲姟 from:{from}>to {to}寮�鍒涘缓>");
             var cntrInfo = string.Join(",", cntrs);
-            ILocRepository locc = new LocRepository();
+            LocRepository locc = new LocRepository();
             var fromLoc = locc.FindEntity(x => x.S_LOC_CODE == from);
             var endLoc = locc.FindEntity(x => x.S_LOC_CODE == to);
 
-            var s = Settings.deviceInfos.Find(x => x.location.Contains(from)) != null;
-            var e = Settings.deviceInfos.Find(x => x.location.Contains(to)) != null;
-            string t = "";
-            if (workMode == "AGV")
+            //string t = "";
+            if (workMode == "AGV" && string.IsNullOrEmpty(S_INDEX))
             {
-                t = "F01";
-                if (s && !e) t = "A002";
-                if (!s && e) t = "A003";
-                if (s && e) t = "A004";
+                var s = Settings.deviceInfos.Find(x => x.location.Contains(from)) != null;
+                var e = Settings.deviceInfos.Find(x => x.location.Contains(to)) != null;
+
+                S_INDEX = "F01";
+                if (s && !e) S_INDEX = "A002";
+                if (!s && e) S_INDEX = "A003";
+                if (s && e) S_INDEX = "A004";
             }
             try
             {
@@ -607,9 +631,9 @@
                     N_START_LAYER = startLayer,
                     N_END_LAYER = endLayer,
                     N_CNTR_COUNT = cntrCount,
-                    S_INDEX = t,
+                    S_INDEX = S_INDEX,
                 };
-                ITaskRepository taskserice = new TaskRepository();
+                TaskRepository taskserice = new TaskRepository();
                 taskserice.Insert(wmsTask);
 
                 if (workMode == "AGV")
@@ -619,6 +643,9 @@
                     locc.Update(fromLoc);
                     locc.Update(endLoc);
                 }
+
+                locc.Disnull();
+                taskserice.Disnull();
 
                 LogHelper.Info($"鍒涘缓浠诲姟 from:{from}>to {to} 鍒涘缓{wmsTask.S_TASK_NO}鎴愬姛");
                 return true;
@@ -649,14 +676,15 @@
                 N_CREATEMETHOD = 0
             };
             TaskActRepository taskserice = new TaskActRepository();
-            taskserice.Insert(action);
+
+            taskserice.Disnull();
         }
 
-        public static System.String GenerateTaskNo()
+        public static System.String GenerateTaskNo(string snType = "浠诲姟鍙�, string Snt = "TN")
         {
-            var id = SYSHelper.GetSerialNumber("浠诲姟鍙�, "TN", "1");
             var date = DateTime.Now.ToString("yyMMdd");
-            return $"TN{date}{id.ToString().PadLeft(4, '0')}";
+            var id = SYSHelper.GetSerialNumber(snType, date);
+            return $"{Snt}{date}{id.ToString().PadLeft(4, '0')}";
         }
         #endregion [鑷畾涔夌被][20250325152141671][TaskProcess]
     }

--
Gitblit v1.9.1