private static void SecondTask(ref int iLastSecond, DateTime oDateTime) { if (iLastSecond == oDateTime.Second) { return; } iLastSecond = oDateTime.Second; if (oDateTime.Second % 3 == 0) { NICSServerProgram.TellAPIByTimeout(); } }
/// <summary> /// 发送单独控制 /// </summary> /// <param name="info"></param> /// <returns></returns> public Result SendSingleCtrl(SingleCtrlInfo info) { Result oResult = new Result(); if ((info.analogue > 99) || (info.analogue < 0)) { oResult.message = "analogue参数错误"; return(oResult); } if ((info.device_port > 24) || (info.device_port < 1)) { oResult.message = "device_port参数错误"; return(oResult); } try { CmdSingleCtrl oCmdSingleCtrl = new CmdSingleCtrl(info); string strCmd = oCmdSingleCtrl.GetPkg(); lock (NICSServerProgram.mMyServer) { var allSessions = NICSServerProgram.mMyServer.GetAllSessions(); int iCounter = allSessions.Count(p => p.ClientID == info.client_id); if (iCounter == 1) { MySession oMySession = allSessions.First(p => p.ClientID == info.client_id); oMySession.MySend(strCmd); NICSServerProgram.AddBypssMap(strCmd, DateTime.Now); oResult.message = "命令下发成功"; } else { oResult.message = "离线"; } } } catch (System.Exception ex) { oResult.message = ex.Message; } return(oResult); }
/// <summary> /// 高级参数下发 /// </summary> /// <param name="info"></param> /// <returns></returns> public Result SendAdvancedPara(AdvancedParaInfo info) { Result oResult = new Result(); byte[] arrbType = { 0x01, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E }; if (arrbType.ToList().Contains(info.type)) { //正确执行后面的代码 } else { oResult.message = "type参数错误"; return(oResult); } try { CmdAdvancedPara oCmdAdvancedPara = new CmdAdvancedPara(info); string strCmd = oCmdAdvancedPara.GetPkg(); lock (NICSServerProgram.mMyServer) { var allSessions = NICSServerProgram.mMyServer.GetAllSessions(); int iCounter = allSessions.Count(p => p.ClientID == info.client_id); if (iCounter == 1) { MySession oMySession = allSessions.First(p => p.ClientID == info.client_id); oMySession.MySend(strCmd); NICSServerProgram.AddBypssMap(strCmd, DateTime.Now); oResult.message = "命令下发成功"; } else { oResult.message = "离线"; } } } catch (System.Exception ex) { oResult.message = ex.Message; } return(oResult); }
/// <summary> /// 开始 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonXStart_Click(object sender, EventArgs e) { SaveFrmCfg(); //nics 服务器端程序,处理nics客户端 NICSServerProgram oNICSServerProgram = new NICSServerProgram(); oNICSServerProgram.ServerSvrStart(mServerXml); //API服务程序启动 RestFulServiceProgram oRestFulServiceProgram = new RestFulServiceProgram(); RestFulServiceProgram.m_ServerXml = mServerXml; oRestFulServiceProgram.ApiSvrStart(); LoadFrmCfg(); this.buttonXStart.Enabled = false; this.buttonXStop.Enabled = true; this.integerInputPort.Enabled = false; this.integerInputAPIPort.Enabled = false; }
public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo) { if (requestInfo.IsCorrectPkg) { if ((requestInfo.BodyKey == "LOGIN") || (requestInfo.BodyKey == "LOGIN2")) { string strClientID = requestInfo.ClientID; if (requestInfo.BodyKey == "LOGIN2") { //根据验证码查询客户端ID,并返回给客户端 nics_clientBLL oNics_clientBLL = new nics_clientBLL(); strClientID = oNics_clientBLL.GetClientID(strClientID); } //根据站点号,查询相应的配置信息 nics_regulatorBLL oNics_regulatorBLL = new nics_regulatorBLL(); List <ControllersInfo> lst = oNics_regulatorBLL.GetModelsByClientID(strClientID); string strJson = JsonConvert.SerializeObject(lst); ControllerInfo oControllerInfo = new ControllerInfo(strClientID, strJson); lock (NICSServerProgram.mMyServer) { var allSessions = NICSServerProgram.mMyServer.GetAllSessions(); int iCounter = allSessions.Count(p => p.ClientID == strClientID); if (iCounter == 0) { session.ClientID = strClientID; string strString = oControllerInfo.GetPkg(); session.Send(strString); } else { //关闭老连接 List <MySession> lstMySession = allSessions.Where(p => p.ClientID == strClientID).ToList(); foreach (var o in lstMySession) { if (o.SessionID != session.SessionID) { LogHelp.Info("断开的客户端ID:" + o.ClientID + " IP:" + o.RemoteEndPoint); o.Close(); } } //给新的发送注册信息 session.ClientID = strClientID; string strString = oControllerInfo.GetPkg(); session.Send(strString); LogHelp.Info("重复的客户端ID:" + strClientID + " IP:" + session.RemoteEndPoint); } } } else if (requestInfo.BodyKey == "BYPASS") { NICSServerProgram.TellAPIByRsp(requestInfo.OnePkg); } else { } } //session.Send(requestInfo.Parameters.Select(p => int.Parse(p)).Sum().ToString()); }