From 31beeb3d23e658e5aa2bbb9f251b006095eef15a Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期一, 07 七月 2025 11:05:04 +0800 Subject: [PATCH] 1 --- 2025年6月12日/AuxAllWCS/Build/Project/代码/界面事件.cs | 77 ++++++++++++++++++++------------------ 1 files changed, 41 insertions(+), 36 deletions(-) diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" index 023f0d4..b0ec9b5 100644 --- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" +++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" @@ -50,11 +50,11 @@ try { - HttpSvcHost = new System.Net.HttpListener(); - HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; - HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); - HttpSvcHost.Start(); - HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); + //HttpSvcHost = new System.Net.HttpListener(); + //HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; + //HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); + //HttpSvcHost.Start(); + //HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); } catch (Exception ex) { @@ -173,21 +173,21 @@ // RunafterMac(di,true); /// TODO mes 涓嬪彂銆� 鏀规垚鏈烘鑷傜洃鎺�- 鐩戞帶绌虹殑杩樻槸婊$殑 - 鑱斿姩mes 浠诲姟銆� - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.State:{Device.缁村笇灏旀姄鑷�.State} "); - Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out object value); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.R50:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.State:{Device.缁村笇灏旀姄鑷�.State} "); + //Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out object value); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.R50:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.State:{Device.缁村笇灏旀姄鑷�.State} "); - Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out value); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.R50:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.State:{Device.缁村笇灏旀姄鑷�.State} "); + //Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out value); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.R50:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『1.State:{Device.Js鎹烽『1.State} "); - Device.Js鎹烽『1.ReadPLC("Js鎹烽『1.D1202", out value); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『1.D1202:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『1.State:{Device.Js鎹烽『1.State} "); + //Device.Js鎹烽『1.ReadPLC("Js鎹烽『1.D1202", out value); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『1.D1202:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『2.State:{Device.Js鎹烽『2.State} "); - Device.Js鎹烽『2.ReadPLC("Js鎹烽『2.D1202", out value); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『2.D1202:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『2.State:{Device.Js鎹烽『2.State} "); + //Device.Js鎹烽『2.ReadPLC("Js鎹烽『2.D1202", out value); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『2.D1202:{value?.ToString()} "); #endregion [鑴氭湰][20250325085810885][涓氬姟閫昏緫.绗笁鏍囨.鑷祦杞祦绋媇 @@ -370,7 +370,7 @@ { #region [鑴氭湰][20250531163716255][涓氬姟閫昏緫.澶勭悊MES浠诲姟绾跨▼.ResolveMesTask] //mes 浠诲姟鎷嗗垎銆備竴娈典换鍔″拰 澶氭浠诲姟銆�- ToWMSMES.ResMesTask(); + ToWMSMES.ResMesTask(tag); #endregion [鑴氭湰][20250531163716255][涓氬姟閫昏緫.澶勭悊MES浠诲姟绾跨▼.ResolveMesTask] } catch (Exception ex) @@ -387,15 +387,7 @@ try { #region [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] - var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); - foreach (var ip in host.AddressList) - { - if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) - { - Console.WriteLine($"ip= {ip.ToString()}"); - new TcpServer(ip.ToString()); - } - } + AutoThread.InvokeMethod(AutoThread.Instance, "TaskEverythingRun"); #endregion [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] } catch (Exception ex) @@ -771,6 +763,7 @@ } ExitJudgeStack.TryPop(out int exitJudgeVal); }); + /// <summary> /// 绋嬪簭鐗囨:Program1 /// 鎻忚堪: @@ -1061,12 +1054,13 @@ #endregion #region Http鏈嶅姟鐩戝惉 - private void HttpSvcListenerCallback(IAsyncResult ar) + private async void HttpSvcListenerCallback(IAsyncResult ar) { + System.Net.HttpListenerContext context = null; try { HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); - System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar); + context = HttpSvcHost.EndGetContext(ar); System.Net.HttpListenerRequest request = context.Request; System.Net.HttpListenerResponse response = context.Response; switch (request.LocalEndPoint.ToString()) @@ -1076,21 +1070,28 @@ using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8)) { string requestJson = reader.ReadToEnd(); - - string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out System.Net.HttpStatusCode statusCode); - + System.Net.HttpStatusCode statusCode = 0; + string respstr = await Task.Run(() => + { + return HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out statusCode); + }); string logContent = ""; logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}"; logContent += $"\r\n[request]{requestJson}"; logContent += $"\r\n[response]{respstr}"; - Conn.榛樿鏃ュ織?.Info(logContent); + _ = Task.Run(() => + { + Conn.榛樿鏃ュ織?.Info(logContent); + }); byte[] bytstr = Encoding.UTF8.GetBytes(respstr); response.StatusCode = (int)statusCode; response.SendChunked = false; response.ContentLength64 = bytstr.Length; response.OutputStream.Write(bytstr, 0, bytstr.Length); - response.Close(); + // 寮傛鍐欏叆鍝嶅簲 + await response.OutputStream.WriteAsync(bytstr, 0, bytstr.Length); + } break; } @@ -1099,6 +1100,10 @@ catch (Exception ex) { Conn.榛樿鏃ュ織.Error(ex.ToString()); + } + finally + { + context?.Response.Close(); } } private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode) @@ -1167,12 +1172,12 @@ { switch (path) { - case "/inddddddddddddddddd": + case var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase): { statusCode = System.Net.HttpStatusCode.OK; // 澶嶅埗鍒癱ase 涓� //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase) - var filePath = System.IO.Path.Combine("Static", path.Substring(1)); + var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1)); return File.ReadAllText(filePath); } } -- Gitblit v1.9.1