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.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Runtime.Serialization; using System.Collections.Concurrent; using System.ServiceModel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Net; using NLog; using NLog.Config; using NLog.Targets; using GZ.DB.Map.OIDATABASE; using GZ.DB.App.OIDATABASE; using GZ.DB.Repository.OIDATABASE; using GZ.DB.IRepository.OIDATABASE; using GZ.DB.Entity.OIDATABASE; namespace GZ.Projects.S7 { /// /// 事件 /// public partial class ViewModel : System.ComponentModel.INotifyPropertyChanged { bool IsExitApp = false; ConcurrentStack ExitJudgeStack = new ConcurrentStack(); System.Net.HttpListener HttpSvcHost = null; #region View1事件 /// /// View1打开事件 /// /// /// public void View1_LoadEvent(object sender, RoutedEventArgs e) { try { HttpSvcHost = new System.Net.HttpListener(); HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; HttpSvcHost.Prefixes.Add("http://127.0.0.1:8808/"); HttpSvcHost.Start(); HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } View1_Init(sender, e); /// /// 程序片段:Program1 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250312161912180][业务逻辑.Program1] if(Tag.PLC1.Param111111){ var msg = ""; GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity(); group.groupName = "PLC1.jss1捷瞬输送1"; group.queueStatus = 1; group.queueTime = DateTime.Now; group.writeList = new List(); GZ.Modular.Redis.ParamData barcodeData = new GZ.Modular.Redis.ParamData(); barcodeData.paramName = "PLC1.Param2"; barcodeData.paramValue = "false"; GZ.Modular.Redis.ParamData sendData = new GZ.Modular.Redis.ParamData(); sendData.paramName = "PLC1.Param3"; sendData.paramValue = "false"; group.writeList.Add(barcodeData); group.writeList.Add(sendData); msg += $"\r\n\t[WriteSend][{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff")}]写PLC:"; msg += Conn.默认Redis.SetQueue(group, "PLC1Queue","PLC1.Param1_LAST", "0") ? "--成功" : "--失败"; Console.WriteLine( msg); ITaskRepository MainMissionService = new TaskRepository(); var vv = MainMissionService.FindList(x => string.IsNullOrEmpty(x.S_END_LOC)); if (!vv.Any()) { TaskEntity t = new TaskEntity() { S_ID = Guid.NewGuid().ToString(), S_STATE = "", S_TASK_NO = "1111", T_CREATE = DateTime.Now, T_MODIFY = DateTime.Now, }; MainMissionService.Insert(t); } else { //MainMissionService.dbcontext.Database.BeginTransaction(); var v = vv.FirstOrDefault(); v.T_MODIFY = DateTime.Now; MainMissionService.Update(v); } } #endregion [脚本][20250312161912180][业务逻辑.Program1] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:Program2 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250313134354359][业务逻辑.Program2] if(Tag.PLC1.Param111111){ var msg = ""; GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity(); group.groupName = "PLC1.ssx2Xplc"; group.queueStatus = 1; group.queueTime = DateTime.Now; group.writeList = new List(); GZ.Modular.Redis.ParamData barcodeData = new GZ.Modular.Redis.ParamData(); barcodeData.paramName = "PLC1.Param4"; barcodeData.paramValue = Tag.PLC1.Param4+1+""; GZ.Modular.Redis.ParamData sendData = new GZ.Modular.Redis.ParamData(); sendData.paramName = "PLC1.Param5"; sendData.paramValue = Tag.PLC1.Param5+2+""; group.writeList.Add(barcodeData); group.writeList.Add(sendData); msg += $"\r\n\t[WriteSend][{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff")}]写PLC:"; msg += Conn.默认Redis.SetQueue(group, "PLC1Queue", "PLC1.Param1_LAST", "1") ? "--成功" : "--失败"; Console.WriteLine( msg); } #endregion [脚本][20250313134354359][业务逻辑.Program2] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:初始化配置 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250323111613779][业务逻辑.初始化配置] SettingInit(); #endregion [脚本][20250323111613779][业务逻辑.初始化配置] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(10000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:维希尔抓臂1 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325083149366][业务逻辑.第三标段.维希尔抓臂1] //vrx1 var VERX = Settings.deviceInfos.Find(x => x.deviceName == "vxr1"); LocRepository locservice = new LocRepository(); LocEntity startLoc = null; { startLoc = locservice.FindEntity(x => x.S_LOC_CODE == "VXR1L"); if (startLoc == null) { startLoc = new LocEntity { S_ID = Guid.NewGuid().ToString(), S_LOC_CODE = "VXR1", S_STATE="编辑", N_ROW = 1, N_COL = 1, S_TYPE="货位", S_AGV_SITE = "9,1", T_EMPTY_TIME = null, T_FULL_TIME = null, S_LOCK_STATE="无", S_DEEP="BB", T_CREATE = DateTime.Now, T_MODIFY = DateTime.Now, }; locservice.Insert(startLoc); startLoc = null; } } if (Tag.wxr1.R44 && !string.IsNullOrEmpty(VERX.location[0])) { startLoc = locservice.FindEntity(x => x.S_LOC_CODE == VERX.location[0]); //if (startLoc == null && startLoc.S_LOCK_STATE == "无") } if (Tag.wxr1.R46 && !string.IsNullOrEmpty(VERX.location[0])) { startLoc = locservice.FindEntity(x => x.S_LOC_CODE == VERX.location[0]); } if (startLoc != null && startLoc.N_CURRENT_NUM == 1) { if (startLoc.T_FULL_TIME == null) { locservice.dbcontext.Set().Attach(startLoc); startLoc.T_FULL_TIME = DateTime.Now; //locservice.Update(startLoc); locservice.dbcontext.Entry(startLoc).Property(x => x.T_FULL_TIME).IsModified = true; locservice.dbcontext.SaveChanges(); } if (startLoc.T_FULL_TIME != null && DateTime.Now.Subtract(startLoc.T_FULL_TIME ?? DateTime.Now).TotalSeconds > 30) { } } #endregion [脚本][20250325083149366][业务逻辑.第三标段.维希尔抓臂1] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:维希尔抓臂2 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325083315503][业务逻辑.第三标段.维希尔抓臂2] //vrx2维希尔抓臂2 #endregion [脚本][20250325083315503][业务逻辑.第三标段.维希尔抓臂2] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:捷瞬输送2 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); try { #region [脚本][20250325083324489][业务逻辑.第三标段.捷瞬输送2] //jss2捷瞬输送2 #endregion [脚本][20250325083324489][业务逻辑.第三标段.捷瞬输送2] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:捷瞬抓臂1 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1] //jsz1捷瞬抓臂1 #endregion [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:捷瞬抓臂2 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2] //jsz2捷瞬抓臂2 #endregion [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:自流转流程 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325085810885][业务逻辑.第三标段.自流转流程] foreach(var di in Settings.deviceInfos) RunafterMac(di,true); #endregion [脚本][20250325085810885][业务逻辑.第三标段.自流转流程] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:捷瞬输送1 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); try { #region [脚本][20250325083323322][业务逻辑.第三标段.捷瞬输送1] //jss1捷瞬输送1Tag.vrx2维希尔抓臂2 #endregion [脚本][20250325083323322][业务逻辑.第三标段.捷瞬输送1] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P3005部件下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407134010436][业务逻辑.第一标段.P3005部件下线] #endregion [脚本][20250407134010436][业务逻辑.第一标段.P3005部件下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P3010部件下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407134052636][业务逻辑.第一标段.P3010部件下线] #endregion [脚本][20250407134052636][业务逻辑.第一标段.P3010部件下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1023定空下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135423962][业务逻辑.第一标段.P1023定空下线] #endregion [脚本][20250407135423962][业务逻辑.第一标段.P1023定空下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1020转空下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135424914][业务逻辑.第一标段.P1020转空下线] #endregion [脚本][20250407135424914][业务逻辑.第一标段.P1020转空下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1010定满下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135527834][业务逻辑.第一标段.P1010定满下线] #endregion [脚本][20250407135527834][业务逻辑.第一标段.P1010定满下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1016定满下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135528735][业务逻辑.第一标段.P1016定满下线] #endregion [脚本][20250407135528735][业务逻辑.第一标段.P1016定满下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1002转满下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135612507][业务逻辑.第一标段.P1002转满下线] #endregion [脚本][20250407135612507][业务逻辑.第一标段.P1002转满下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:P1008转满下线 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250407135613444][业务逻辑.第一标段.P1008转满下线] #endregion [脚本][20250407135613444][业务逻辑.第一标段.P1008转满下线] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); /// /// 程序片段:任务下发 /// 描述: /// System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.CurrentThread.IsBackground = true; ExitJudgeStack.Push(0); //一直执行,直到满足结束条件 while(true) { if (IsExitApp) { break; } try { #region [脚本][20250325085542733][业务逻辑.任务下发] ITaskRepository taskservice = new TaskRepository(); var tklist = taskservice.FindList(x => x.S_B_STATE == "未执行"); foreach (var tk in tklist.GroupBy(item => { var ticks = item.T_CREATE.Ticks; return new DateTime(ticks - ticks % (10 * TimeSpan.TicksPerMinute)); }).OrderBy(x => x.Key)) { var ts = tk.OrderByDescending(x => x.N_PRIORITY).ToList(); foreach (var t in ts) { var b = RunTask(t); if (b) { t.S_B_STATE = "已推送"; taskservice.Update(t); } } break; } #endregion [脚本][20250325085542733][业务逻辑.任务下发] } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { System.Threading.Thread.Sleep(3000); } } ExitJudgeStack.TryPop(out int exitJudgeVal); }); } /// /// View1关闭事件 /// /// /// public void View1_CloseEvent(object sender, System.ComponentModel.CancelEventArgs e) { try { System.Threading.Tasks.Task.Factory.StartNew(() => { MessageBox.Show("程序正在关闭,请等待..."); }); } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } try { Conn.默认日志.Debug("[关闭处理][Start]关闭Http服务"); if(HttpSvcHost!=null) { HttpSvcHost.Stop(); } } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { Conn.默认日志.Debug("[关闭处理][End]关闭Http服务"); } try { Conn.默认日志.Debug("[关闭处理][Start]判断业务处理状态"); IsExitApp = true; //int exitCnt = 0; while ( ExitJudgeStack.Count > 0 ) { System.Threading.Thread.Sleep(100); //++exitCnt; //10秒未结束则强制关闭 //if (exitCnt >= 100) //{ // break; //} } } catch (Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { Conn.默认日志.Debug("[关闭处理][End]判断业务处理状态"); } e.Cancel = true; System.Threading.Tasks.Task.Factory.StartNew(() => { try { Conn.默认日志.Debug("[关闭处理][Start]关闭PLC"); Device.PLC1?.Stop(); Device.西门子2?.Stop(); Device.wxwp?.Stop(); Device.wxrp?.Stop(); Device.warp?.Stop(); Device.ssx2xPlcRead?.Stop(); Device.ssx1xPlcRead?.Stop(); Device.ssx3xPlcRead?.Stop(); Device.维希尔抓臂1?.Stop(); Device.维希尔抓臂2?.Stop(); Device.捷瞬抓臂1?.Stop(); Device.捷瞬抓臂2?.Stop(); } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { Conn.默认日志.Debug("[关闭处理][End]关闭PLC"); } try { Conn.默认日志.Debug("[关闭处理][Start]判断PLC状态"); //int exitCnt = 0; while ( false || (Device.PLC1 == null ? false : Device.PLC1.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.西门子2 == null ? false : Device.西门子2.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.wxwp == null ? false : Device.wxwp.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.wxrp == null ? false : Device.wxrp.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.warp == null ? false : Device.warp.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.ssx2xPlcRead == null ? false : Device.ssx2xPlcRead.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.ssx1xPlcRead == null ? false : Device.ssx1xPlcRead.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.ssx3xPlcRead == null ? false : Device.ssx3xPlcRead.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.维希尔抓臂1 == null ? false : Device.维希尔抓臂1.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.维希尔抓臂2 == null ? false : Device.维希尔抓臂2.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.捷瞬抓臂1 == null ? false : Device.捷瞬抓臂1.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.捷瞬抓臂2 == null ? false : Device.捷瞬抓臂2.State != GZ.Device.PLC.PlcRunState.Stoped) ) { System.Threading.Thread.Sleep(1000); //++exitCnt; //10秒未结束则强制关闭 //if (exitCnt >= 100) //{ // break; //} } } catch (Exception ex) { Conn.默认日志.Error(ex.ToString()); } finally { Conn.默认日志.Debug("[关闭处理][End]判断PLC状态"); } Application.Current.Dispatcher.Invoke(() => { Environment.Exit(0); }); }); //System.Windows.Application.Current.Shutdown(); } /// /// View1初始化 /// /// /// public void View1_Init(object sender, RoutedEventArgs e) { } #endregion #region 切换tab页 public void tab_SelectionChanged(object sender, EventArgs e) { //TabItem ti = (sender as TabControl).SelectedItem as TabItem; //MessageBox.Show(ti.Name); } #endregion #region Http服务监听 private void HttpSvcListenerCallback(IAsyncResult ar) { try { HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar); System.Net.HttpListenerRequest request = context.Request; System.Net.HttpListenerResponse response = context.Response; switch(request.LocalEndPoint.ToString()) { case "127.0.0.1:8808": { 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); string logContent=""; logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}"; logContent += $"\r\n[request]{requestJson}"; logContent += $"\r\n[response]{respstr}"; 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(); } break; } } } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); } } private System.String HttpSvcListenerCallback_he(System.String method,System.String path,System.String requestJson,out System.Net.HttpStatusCode statusCode) { try { switch(method) { case "POST": { switch(path) { case "/agv/agvCallbackService/agvCallback": { statusCode = System.Net.HttpStatusCode.OK; var model = JsonConvert.DeserializeObject(requestJson); LogHelper.Info("ExecuteState Request-haikang:" + JsonConvert.SerializeObject(model), "agv杭叉交互日志"); OperateHKTaskStatus(model); return JsonConvert.SerializeObject(new HkReturnResult { reqCode = model.reqCode }); } } break; } case "GET": { switch(path) { case "/inddddddddddddddddd": { statusCode = System.Net.HttpStatusCode.OK; // 复制到case 上 //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)); return File.ReadAllText(filePath); } } break; } } statusCode = System.Net.HttpStatusCode.NotFound; return ""; } catch(Exception ex) { Conn.默认日志.Error(ex.ToString()); statusCode = System.Net.HttpStatusCode.InternalServerError; return ""; } } #endregion } }