diff --git a/Epost.DAL/Cache/LightControlCacheDAL.cs b/Epost.DAL/Cache/LightControlCacheDAL.cs index d0e596b..3541b5b 100644 --- a/Epost.DAL/Cache/LightControlCacheDAL.cs +++ b/Epost.DAL/Cache/LightControlCacheDAL.cs @@ -54,7 +54,10 @@ namespace Epost.DAL.Cache else if (CommendType.Equals(EcontrolCommend.Execute)) { - JobParam.ForEach(m => MainControlList.Remove(m)); + foreach (var planitem in MainControlList.ToArray()) + { + MainControlList.Remove(planitem); + } } @@ -86,9 +89,11 @@ namespace Epost.DAL.Cache public class LightcontrolModel { private string _controlip = string.Empty; + private int _port ; MainControl _maincontrol = new MainControl(); public MainControl maincontrol { get => _maincontrol; set => _maincontrol = value; } public string controlip { get => _controlip; set => _controlip = value; } + public int port { get => _port; set => _port = value; } } } diff --git a/Epost.Model/ResultModel.cs b/Epost.Model/ResultModel.cs index 995630a..c9629df 100644 --- a/Epost.Model/ResultModel.cs +++ b/Epost.Model/ResultModel.cs @@ -110,6 +110,7 @@ namespace Epost.Model public string wallNo { get; set; } public string lightType { get; set; } public string lightColor { get; set; } + public string status { get; set; } } diff --git a/Epost.TestToolsWeb/Controllers/ServerController.cs b/Epost.TestToolsWeb/Controllers/ServerController.cs index 7aa0401..7990d90 100644 --- a/Epost.TestToolsWeb/Controllers/ServerController.cs +++ b/Epost.TestToolsWeb/Controllers/ServerController.cs @@ -11,6 +11,7 @@ using LightContrl; using Epost.DAL.Cache; using System.Net; +using Microsoft.Owin.BuilderProperties; namespace Epost.DPS.Controllers { @@ -32,52 +33,72 @@ namespace Epost.DPS.Controllers { foreach (var item in data) { - DataTable dt = addrbll.QueryControlList(" and waveno ='" + item.wallNo + "'"); - if (dt != null && dt.Rows.Count > 0) + if (item.status == "1")//连接 { - foreach (DataRow rowitem in dt.Rows) + DataTable dt = addrbll.QueryControlList(" and waveno ='" + item.wallNo + "'"); + if (dt != null && dt.Rows.Count > 0) { + foreach (DataRow rowitem in dt.Rows) + { - string ipaddress = rowitem["controlip"].ToString().Trim(); - List conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress); - if (conlist != null && conlist.Count > 0) - { - LogHelper.WriteLogInfo(ipaddress + "已连接!"); - } - else - { - int port = Convert.ToInt32(rowitem["port"].ToString().Trim()); - int timeout = 2000; - bool bo = lig.Connect(ipaddress, port, timeout);//timeout 毫秒 - if (bo) + string ipaddress = rowitem["controlip"].ToString().Trim(); + List conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress); + if (conlist != null && conlist.Count > 0) { - LightcontrolModel model = new LightcontrolModel(); - model.controlip = ipaddress; - model.maincontrol = lig; - cachedal.UpdateControlList(new List { model }, EcontrolCommend.Create); - res.resultCode = "0"; - res.resultMsg = "成功!"; + LogHelper.WriteLogInfo(ipaddress + "已连接!"); } else { - res.resultCode = "-1"; - res.resultMsg = "连接失败" + ipaddress; - return res; + int port = Convert.ToInt32(rowitem["port"].ToString().Trim()); + int timeout = 2000; + bool bo = lig.Connect(ipaddress, port, timeout);//timeout 毫秒 + if (bo) + { + LightcontrolModel model = new LightcontrolModel(); + model.controlip = ipaddress; + model.maincontrol = lig; + model.port = port; + cachedal.UpdateControlList(new List { model }, EcontrolCommend.Create); + res.resultCode = "0"; + res.resultMsg = "成功!"; + } + else + { + res.resultCode = "-1"; + res.resultMsg = "连接失败" + ipaddress; + return res; + } } } + + + + + + + + } + else + { + res.resultCode = "-1"; + res.resultMsg = "播种墙号错误"; + return res; } - - - - - - - } else { - res.resultCode = "-1"; - res.resultMsg = "播种墙号错误"; - return res; + LogHelper.WriteLogInfo("断开连接"); + List conlist = cachedal.GetControlList(); + if (conlist.Any() && conlist.Count > 0) + { + foreach (LightcontrolModel con in conlist) + { + bool b= con.maincontrol.DisConnect(con.controlip,con.port); + LogHelper.WriteLogInfo(b+"断开连接"+ con.controlip+"=="+con.port); + } + } + cachedal.ClearControlList(); + res.resultCode = "0"; + res.resultMsg = "断开连接成功!"; } } } diff --git a/Epost.TestToolsWeb/Properties/PublishProfiles/Toolsweb.pubxml.user b/Epost.TestToolsWeb/Properties/PublishProfiles/Toolsweb.pubxml.user index 41a833a..e39dce1 100644 --- a/Epost.TestToolsWeb/Properties/PublishProfiles/Toolsweb.pubxml.user +++ b/Epost.TestToolsWeb/Properties/PublishProfiles/Toolsweb.pubxml.user @@ -33,19 +33,19 @@ 04/04/2018 15:45:12 - 04/20/2023 10:35:48 + 04/20/2023 18:07:45 - 04/20/2023 10:35:48 + 04/20/2023 18:07:45 02/24/2020 15:29:24 - 04/20/2023 10:35:36 + 04/20/2023 18:07:34 - 04/20/2023 10:35:36 + 04/20/2023 18:07:34 04/29/2020 16:50:14 @@ -63,31 +63,31 @@ 10/23/2017 13:15:20 - 04/20/2023 10:35:37 + 04/20/2023 18:07:35 - 04/20/2023 10:35:37 + 04/20/2023 18:07:35 08/26/2020 18:09:48 - 04/20/2023 10:35:36 + 04/20/2023 18:07:35 - 04/20/2023 10:35:36 + 04/20/2023 18:07:35 - 04/20/2023 10:35:39 + 04/20/2023 18:07:38 - 04/20/2023 10:35:39 + 04/20/2023 18:07:38 - 04/20/2023 10:35:36 + 04/20/2023 18:07:34 - 04/20/2023 10:35:36 + 04/20/2023 18:07:34 09/06/2018 11:57:11 @@ -5658,7 +5658,7 @@ 05/30/2022 16:58:47 - 04/20/2023 10:35:44 + 04/20/2023 18:07:40 04/04/2018 15:45:12