// 实时表是否在线字段实时维护 private void InitSensorRealData() { StaionDataOper.Instance.InitSCADASensorRealTime(out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForProject.AppendErrMsg(errMsg); } }
public override void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } WEBSoapCommand.CreateInitSensorRealData(param).Execute(); //初始化实时表 timer = new System.Timers.Timer(); timer.Interval = this.param.collectInterval * 1000; timer.Elapsed += (o, e) => { try { Excute(); } catch (Exception ee) { TraceManagerForProject.AppendErrMsg("WEB-SOAP-兴国定时任务执行失败:" + ee.Message); } }; timer.Enabled = true; // 控制器服务 if (commandCustomer != null) { commandCustomer.Stop(); } commandCustomer = new CommandConsumer(ConsumerCommand); commandCustomer.Start(); if (commandCustomer.IsRuning) { TraceManagerForProject.AppendDebug("WEB-SOAP-兴国控制器服务已经打开"); } else { TraceManagerForProject.AppendErrMsg("WEB-SOAP-兴国控制器服务打开失败"); Stop(); return; } IsRuning = true; // 开始异步执行一次-防止启动卡死 Action action = Excute; action.BeginInvoke(null, null); }
public void Execute() { try { lock (this) //会被多线程调用注意安全 { switch (Type) { case WEBSoapCommandType.CollectAndSaveScadaSensors: CollectAndSaveSnesors(); break; case WEBSoapCommandType.InitSensorRealData: InitSensorRealData(); break; } } } catch (Exception e) { TraceManagerForProject.AppendErrMsg("执行 WEB-SOAP-兴国 数据库工作器失败:" + e.Message); } }
private List <SoapData> GetSoapData() { string url = "http://120.77.66.89:90/WebService1.asmx"; HttpRequestUtil requestUtil = new HttpRequestUtil(ContentType.textXml); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(new Param().request); List <SoapData> data = new List <SoapData>(); requestUtil.CreateSyncPostHttpRequest(url, stringBuilder, (successData) => { data = GetSoapDataFromXML(successData); if (data.Count == 0) { TraceManagerForProject.AppendErrMsg("获取WEB-SOAP-兴国数据接口失败:" + "返回的数据格式不正确"); data = null; return; } else { TraceManagerForProject.AppendDebug("获取WEB-SOAP-兴国数据接口成功"); } }, (failData) => { data = null; TraceManagerForProject.AppendErrMsg("获取WEB-SOAP-兴国数据接口失败" + failData); }, (doErrorData) => { data = null; TraceManagerForProject.AppendErrMsg("处理WEB-SOAP-兴国数据接口失败" + doErrorData); }); if (data == null) { return(null); } return(data); }
public override void Stop() { if (!IsRuning) { return; } try { // 控制器服务 if (commandCustomer != null) { commandCustomer.Stop(); if (!commandCustomer.IsRuning) { TraceManagerForProject.AppendDebug("WEB-SOAP-兴国控制器服务已停止"); this.commandCustomer = null; } else { TraceManagerForProject.AppendErrMsg("WEB-SOAP-兴国控制器服务停止失败"); } } } catch { } // 关闭定时器 if (timer != null) { timer.Enabled = false; timer.Close(); timer = null; } IsRuning = false; }
public void Start(out string errMsg) { // 子服务启动失败,应该不影响其他子服务 errMsg = ""; try { // Pump-OPC通信子服务 if (Config.configInfo.confSonOPCPumpDataService != null && Config.configInfo.confSonOPCPumpDataService.IsNeedRun) { opcPumpService = new OPCPumpService(Config.configInfo.confSonOPCPumpDataService); opcPumpService.Start(out errMsg); if (opcPumpService.IsRuning) { TraceManagerForOPC.AppendInfo("Pump-OPC通信子服务已经启动"); } else { errMsg = "Pump-OPC通信子服务启动失败:" + errMsg; TraceManagerForOPC.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // Scada-OPC通信子服务 if (Config.configInfo.confSonOPCScadaDataService != null && Config.configInfo.confSonOPCScadaDataService.IsNeedRun) { opcScadaService = new OPCScadaService(Config.configInfo.confSonOPCScadaDataService); opcScadaService.Start(out errMsg); if (opcScadaService.IsRuning) { TraceManagerForOPC.AppendInfo("Scada-OPC通信子服务已经启动"); } else { errMsg = "Scada-OPC通信子服务启动失败:" + errMsg; TraceManagerForOPC.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 二供WEB-pump通信子服务 if (Config.configInfo.confSonWebPandaPumpDataService != null && Config.configInfo.confSonWebPandaPumpDataService.IsNeedRun) { webPandaPumpService = new WEBPandaPumpService(Config.configInfo.confSonWebPandaPumpDataService); webPandaPumpService.Start(out errMsg); if (webPandaPumpService.IsRuning) { TraceManagerForWeb.AppendInfo("二供WEB通信子服务已经启动"); } else { errMsg = "二供WEB通信子服务启动失败:" + errMsg; TraceManagerForWeb.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // WEB-pump-Scada 通信子服务 if (Config.configInfo.confSonWebPandaPumpScadaDataService != null && Config.configInfo.confSonWebPandaPumpScadaDataService.IsNeedRun) { webPandaPumpScadaService = new WEBPandaPumpSCADAService(Config.configInfo.confSonWebPandaPumpScadaDataService); webPandaPumpScadaService.Start(out errMsg); if (webPandaPumpScadaService.IsRuning) { TraceManagerForWeb.AppendInfo("WEB-pandaPump_Scada 通信子服务已经启动"); } else { errMsg = "WEB-pandaPump_Scada 通信子服务启动失败:" + errMsg; TraceManagerForWeb.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("WEB-pandaPump_Scada 通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // SACADA—WEB-监测点通信子服务 if (Config.configInfo.confSonWebPandaYLDataService != null && Config.configInfo.confSonWebPandaYLDataService.IsNeedRun) { webPandaYLScadaService = new WEBPandaYLSacdaService(Config.configInfo.confSonWebPandaYLDataService); webPandaYLScadaService.Start(out errMsg); if (webPandaYLScadaService.IsRuning) { TraceManagerForWeb.AppendInfo("SACADA—WEB-监测点通信子服务已经启动"); } else { errMsg = "SACADA—WEB-监测点通信子服务启动失败:" + errMsg; TraceManagerForWeb.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // SACADA—WEB-综合测点通信子服务 if (Config.configInfo.confSonWebPandaZHCDDataService != null && Config.configInfo.confSonWebPandaZHCDDataService.IsNeedRun) { webPandaZHCDScadaServcice = new WEBPandaZHCDSacdaService(Config.configInfo.confSonWebPandaZHCDDataService); webPandaZHCDScadaServcice.Start(out errMsg); if (webPandaZHCDScadaServcice.IsRuning) { TraceManagerForWeb.AppendInfo("SACADA—WEB-综合测点通信子服务已经启动"); } else { errMsg = "SACADA—WEB-综合测点通信子服务启动失败:" + errMsg; TraceManagerForWeb.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-综合测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 二供报警服务 if (Config.configInfo.confSonCityIoTPumpAlarm != null && Config.configInfo.confSonCityIoTPumpAlarm.IsNeedRun) { pumpAlarmService = new PumpAlarmService(Config.configInfo.confSonCityIoTPumpAlarm); pumpAlarmService.Start(out errMsg); if (pumpAlarmService.IsRuning) { TraceManagerForPumpAlarm.AppendInfo("二供报警服务已经启动"); } else { errMsg = "二供报警服务启动失败:" + errMsg; TraceManagerForPumpAlarm.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 历史抽稀服务 if (Config.configInfo.confSonHisVacuateService != null && Config.configInfo.confSonHisVacuateService.IsNeedRun) { hisVacuate = new HisVacuate(Config.configInfo.confSonHisVacuateService); hisVacuate.Start(out errMsg); if (hisVacuate.IsRuning) { TraceManagerForHisVacuate.AppendInfo("历史抽稀服务已经启动"); } else { errMsg = "历史抽稀服务启动失败:" + errMsg; TraceManagerForHisVacuate.AppendErrMsg(errMsg); } } } catch (Exception e) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 特殊项目子服务 if (Config.configInfo.confSonProjectDataService != null && Config.configInfo.confSonProjectDataService.IsNeedRun) { if (!Config.configInfo.confSonProjectDataService.EnvIsOkay) { TraceManagerForProject.AppendErrMsg("特殊项目动态库环境配置异常:" + Config.configInfo.confSonProjectDataService.ErrMsg); } else { caseManagerInjection = Interface.GetInjection(Config.configInfo.confSonProjectDataService.DllPath); caseManagerInjection.Start(out errMsg); if (caseManagerInjection.IsRuning) { TraceManagerForProject.AppendInfo(Config.configInfo.confSonProjectDataService.ProjectName + "服务已经启动"); } else { errMsg = Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + errMsg; TraceManagerForProject.AppendErrMsg(errMsg); } } } } catch (Exception e) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); } IsRuning = true; }
public void Stop() { try { // 特殊项目子服务 if (this.caseManagerInjection != null) { this.caseManagerInjection.Stop(); if (this.caseManagerInjection.IsRuning) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务停止失败"); } else { TraceManagerForProject.AppendInfo(Config.configInfo.confSonProjectDataService.ProjectName + "服务已经全部停止"); } this.caseManagerInjection = null; } } catch (Exception e) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 历史抽稀服务 if (this.hisVacuate != null) { this.hisVacuate.Stop(); if (this.hisVacuate.IsRuning) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务停止失败"); } else { TraceManagerForHisVacuate.AppendInfo("历史抽稀服务已经全部停止"); } this.hisVacuate = null; } } catch (Exception e) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 二供报警服务 if (this.pumpAlarmService != null) { this.pumpAlarmService.Stop(); if (this.pumpAlarmService.IsRuning) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("二供报警服务已经全部停止"); } this.pumpAlarmService = null; } } catch (Exception e) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // SACADA—WEB-综合测点通信子服务 if (this.webPandaZHCDScadaServcice != null) { this.webPandaZHCDScadaServcice.Stop(); if (this.webPandaZHCDScadaServcice.IsRuning) { TraceManagerForWeb.AppendErrMsg("SACADA-WEB-综合测点通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("SACADA—WEB-综合测点通信子服务已经全部停止"); } this.webPandaZHCDScadaServcice = null; } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-综合测点通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // SACADA—WEB-监测点通信子服务 if (this.webPandaYLScadaService != null) { this.webPandaYLScadaService.Stop(); if (this.webPandaYLScadaService.IsRuning) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("SACADA—WEB-监测点通信子服务已经全部停止"); } this.webPandaYLScadaService = null; } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // WEB-pandaPump_Scada 通信子服务 if (this.webPandaPumpScadaService != null) { this.webPandaPumpScadaService.Stop(); if (this.webPandaPumpScadaService.IsRuning) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("二供WEB通信子服务已经全部停止"); } this.webPandaPumpScadaService = null; } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // 二供WEB通信子服务 if (this.webPandaPumpService != null) { this.webPandaPumpService.Stop(); if (this.webPandaPumpService.IsRuning) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("二供WEB通信子服务已经全部停止"); } this.webPandaPumpService = null; } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // Scada-OPC通信子服务 if (this.opcScadaService != null) { this.opcScadaService.Stop(); if (this.opcScadaService.IsRuning) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("Scada-OPC通信子服务已经全部停止"); } this.opcScadaService = null; } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } try { // Pump-OPC通信子服务 if (this.opcPumpService != null) { this.opcPumpService.Stop(); if (this.opcPumpService.IsRuning) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务停止失败"); } else { TraceManagerForPumpAlarm.AppendInfo("Pump-OPC通信子服务已经全部停止"); } this.opcPumpService = null; } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } IsRuning = false; }
private void CollectAndSaveSnesors() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 Dictionary <int, Station> dicStations = new Dictionary <int, Station>(); #region 查询sensor表 string sqlSensors = @" select t.ID stationID, t.GUID as stationCode,t.Name stationName,t1.ID sensorID,t1.Name sensorName from SCADA_Station t ,SCADA_Sensor t1 where t.ID=t1.StationID and t.ReadMode='WEB_SOAP_XINGGUO' and IsNull(t1.是否删除,0)=0;"; DataTable dtSensors = DBUtil.ExecuteDataTable(sqlSensors, out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForProject.AppendErrMsg("查询sensor列表失败:" + errMsg); return; } foreach (DataRow dr in dtSensors.Rows) { Station station = new Station() { _ID = DataUtil.ToInt(dr["stationID"]), _GUID = DataUtil.ToString(dr["stationCode"]), _Name = DataUtil.ToString(dr["stationName"]), sensors = new List <Sensor>() }; Sensor sensor = new Sensor() { sensorID = DataUtil.ToString(dr["sensorID"]), sensorName = DataUtil.ToString(dr["sensorName"]) }; if (dicStations.Keys.Contains(station._ID)) { dicStations[station._ID].sensors.Add(sensor); } else { station.sensors.Add(sensor); dicStations.Add(station._ID, station); } } if (dicStations.Keys.Count == 0) { TraceManagerForProject.AppendWarning("站点表没有读取模式:WEB_SOAP_XINGGUO的站点表"); return; } #endregion #region 请求监测点数据并存入 List <SoapData> list = GetSoapData(); Collect(list, ref dicStations); string saveSQL = GetSaveSensorsSQL(dicStations); if (string.IsNullOrWhiteSpace(saveSQL)) { TraceManagerForProject.AppendWarning(string.Format(@"采集WEB-SOAP-兴国 数量{0}获取存入数据库SQL失败,可能原因没有在线的站点", dicStations.Keys.Count)); return; } DBUtil.ExecuteNonQuery(saveSQL, out string err); stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 if (!string.IsNullOrWhiteSpace(err)) { TraceManagerForProject.AppendErrMsg("更新WEB-SOAP-兴国实时数据失败" + ",耗时:" + milliseconds.ToString() + "毫秒," + err); } else { TraceManagerForProject.AppendDebug("更新WEB-SOAP-兴国实时数据成功" + ",耗时:" + milliseconds.ToString() + "毫秒"); } #endregion }
private void Collect(List <SoapData> soapDatas, ref Dictionary <int, Station> dicStations) { if (soapDatas == null) { return; } if (dicStations == null) { return; } foreach (int key in dicStations.Keys) { Station station = dicStations[key]; int errorTimes = 0; // 三个离线就认为其离线了 foreach (Sensor sensor in dicStations[key].sensors) { // 防止采集的点多了,错误消息炸了,每个都报出来了---直接让其离线 if (errorTimes >= 3) { TraceManagerForProject.AppendErrMsg("StationName:" + station._Name + "三个条目采集失败,已跳过该站点采集,请检查点表和数据源"); dicStations[key].IsOnline = false; break; } // 拿到数据源 SoapData[] curSoapDatas = soapDatas.Where(y => y.称 == station._Name.ToUpper()).ToArray(); // 注意转换大写在比较 if (curSoapDatas.Length == 0) { sensor.MakeFail("未在WEB-SOAP-兴国数据源中找到配置站点信息,站点编码:" + station._GUID); TraceManagerForProject.AppendErrMsg("未在WEB-SOAP-兴国数据源中找到配置站点信息,站点编码:" + station._GUID); errorTimes++; continue; } object pointDataSource; try { SoapData curSoapData = curSoapDatas[0]; // 在拿到值 Type type = curSoapData.GetType(); //获取类型 System.Reflection.PropertyInfo propertyInfo = type.GetProperty(sensor.sensorName); //获取指定名称的属性 pointDataSource = propertyInfo.GetValue(curSoapData, null); //获取属性值 } catch (Exception e) { string er = string.Format("未在WEB监测点数据源中找到配置站点信息:{0}找到点地址为:{1}的点,错误原因:{2}" + station._Name, sensor.sensorName, e.Message); sensor.MakeFail(er); TraceManagerForProject.AppendErrMsg(er); errorTimes++; continue; } // 根据数据源获取数据 sensor.ReadWEBSoap(pointDataSource); //sensor.LastTime = tempTime;// 使用采集时间,不要用当前时间 //sensor.State = ValueState.Success; station.IsOnline = true; if (sensor.State == ValueState.Fail) { string er = string.Format("站点名称:{0},sensorName:{1},取值错误:{2}", station._Name, sensor.sensorName, sensor.Mess); TraceManagerForProject.AppendErrMsg(er); errorTimes++; continue; } } } }