This commit is contained in:
jl
2023-04-21 11:44:47 +08:00
parent 3a08c033ba
commit 8c07d147d5
4 changed files with 75 additions and 48 deletions

View File

@ -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<LightcontrolModel> 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<LightcontrolModel> 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<LightcontrolModel> { 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<LightcontrolModel> { 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<LightcontrolModel> 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 = "断开连接成功!";
}
}
}