public void Stop() { if (!IsRuning) { return; } try { // Scada-OPC通信服务 if (opcScadaService != null) { opcScadaService.Stop(); if (!opcScadaService.IsRuning) { TraceManagerForWeb.AppendDebug("Scada-OPC通信服务停止成功"); this.opcScadaService = null; } else { TraceManagerForWeb.AppendErrMsg("Scada-OPC通信服务停止失败"); } } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信服务停止失败:" + e.Message); } IsRuning = false; }
public void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } LoadConfig(); WebPandaZHCDScadaCommand.CreateInitSensorRealData(Config.yaLiParam).Execute(); //初始化实时表 timer = new System.Timers.Timer(); timer.Interval = collectInterval * 60 * 1000; timer.Elapsed += (o, e) => { try { ReceiveCommand(new ReciveData()); } catch (Exception ee) { TraceManagerForWeb.AppendErrMsg("Scada-WEB-综合监测点定时任务执行失败:" + ee.Message); } }; timer.Enabled = true; IsRuning = true; // 开始异步执行一次-防止启动卡死 Action <ReciveData> action = ReceiveCommand; action.BeginInvoke(new ReciveData(), null, null); }
public void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } LoadConfig(); WebPandaPumpCommand.CreateInitPumpRealData(Config.pumpParam).Execute(); //初始化实时表 timer = new System.Timers.Timer(); timer.Interval = collectInterval * 60 * 1000; timer.Elapsed += (o, e) => { try { Excute(); } catch (Exception ee) { TraceManagerForWeb.AppendErrMsg("二供-WEB 定时任务执行失败:" + ee.Message); } }; timer.Enabled = true; IsRuning = true; // 开始异步执行一次-防止启动卡死 Action action = Excute; action.BeginInvoke(null, null); }
// 二供执行体辅助工具 private PandaToken GetToken() { PandaToken token = null; string AppKey = param.appKey; string appSecret = param.appSecret; string url = param.getTokenUrl; IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("AppKey", AppKey); parameters.Add("appSecret", appSecret); HttpRequestUtil requestUtil = new HttpRequestUtil(ContentType.XWwwFromUrlencoded); requestUtil.CreateSyncPostHttpRequest(url, parameters, (successData) => { token = ByteUtil.ToDeserializeObject <PandaToken>(successData); if (token == null) { TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "返回的数据格式不正确"); return; } if (token.code == "200") { TraceManagerForWeb.AppendDebug("获取熊猫二供接口token成功"); return; } else if (token.code == "10005") { TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "参数为空或格式不正确,确认appKey是否正确"); token = null; return; } else if (token.code == "10006") { TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "Appkey和AppSecret不匹配"); token = null; return; } else if (token.code == "49999") { TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "接口调用异常"); token = null; return; } else { TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "错误的返回码"); token = null; return; } }, (failData) => { token = null; TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败" + failData); }, (doErrorData) => { token = null; TraceManagerForWeb.AppendErrMsg("处理熊猫二供接口token数据失败" + doErrorData); }); return(token); }
// 实时表是否在线字段实时维护 private void InitPumpRealData() { PumpJZDataOper.Instance.InitPumpRealData(out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.AppendErrMsg(errMsg); } }
// 实时表是否在线字段实时维护 private void InitSensorRealData() { StaionDataOper.Instance.InitSCADASensorRealTime(out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.AppendErrMsg(errMsg); } }
public void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } // 环境检查 if (!EnvChecker.CheckPandaYaLiWEB(out errMsg)) { return; } TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点环境检查通过"); this.param = Config.pandaYaLiParam; WebPandaYLScadaCommand.CreateInitSensorRealData(param).Execute(); //初始化实时表 timer = new System.Timers.Timer(); timer.Interval = this.param.collectInterval * 60 * 1000; timer.Elapsed += (o, e) => { try { Excute(); } catch (Exception ee) { TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点定时任务执行失败:" + ee.Message); } }; timer.Enabled = true; // 控制器服务 if (commandCustomer != null) { commandCustomer.Stop(); } commandCustomer = new CommandConsumer(ConsumerCommand); commandCustomer.Start(); if (commandCustomer.IsRuning) { TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点控制器服务已经打开"); } else { TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点控制器服务打开失败"); Stop(); return; } IsRuning = true; // 开始异步执行一次-防止启动卡死 Action action = Excute; action.BeginInvoke(null, null); }
private List <PandaPumpJZ> GetWebPumpData() { PandaWEBData pandaPumpData = new PandaWEBData(); string url = param.getDataUrl; IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("accessToken", tokenCache.data.accessToken); parameters.Add("useName", param.useName); HttpRequestUtil requestUtil = new HttpRequestUtil(ContentType.XWwwFromUrlencoded); List <PandaPumpJZ> data = new List <PandaPumpJZ>(); requestUtil.CreateSyncPostHttpRequest(url, parameters, (successData) => { pandaPumpData = ByteUtil.ToDeserializeObject <PandaWEBData>(successData); if (pandaPumpData == null) { TraceManagerForWeb.AppendErrMsg("获取熊猫二供数据接口失败:" + "返回的数据格式不正确"); data = null; return; } if (pandaPumpData.code == "200") { TraceManagerForWeb.AppendDebug("获取熊猫二供数据接口成功"); try { data = ByteUtil.ToDeserializeObject <List <PandaPumpJZ> >(pandaPumpData.data.ToString()); } catch (Exception e) { data = null; TraceManagerForWeb.AppendErrMsg("反序列化熊猫二供数据接口数据失败:" + e.Message); } return; } else { TraceManagerForWeb.AppendErrMsg("获取熊猫二供数据接口失败:" + pandaPumpData.msg); data = null; return; } }, (failData) => { data = null; TraceManagerForWeb.AppendErrMsg("获取熊猫二供数据接口失败" + failData); }, (doErrorData) => { data = null; TraceManagerForWeb.AppendErrMsg("处理熊猫二供数据接口失败" + doErrorData); }); if (data == null) { return(null); } return(data); }
public void Start(out string errMsg) { // 子服务启动失败,应该不影响其他子服务 errMsg = ""; string err = ""; if (!LoadConfig(out errMsg)) { return; } try { // web接入服务 if (this.runWebDataService == 1) { webDataService = new WEBDataService(); webDataService.Start(out err); if (webDataService.IsRuning) { TraceManagerForWeb.AppendDebug("web接入服务已经全部启动"); } else { errMsg = "二供web接入服务启动失败:" + err; } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("web接入服务启动失败:" + e.Message); } try { // 二供报警服务 if (this.runPumpAlarmService == 1) { pumpAlarmService = new PumpAlarmService(Config.projectConfigPath); pumpAlarmService.Start(out err); if (pumpAlarmService.IsRuning) { LogManager.AppendInfo(ServerTypeName.PumpAlarm, "二供报警服务已经全部启动"); } else { errMsg = "二供报警服务启动失败:" + err; } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供报警服务启动失败:" + e.Message); } IsRuning = true; }
public void Stop() { try { // 二供WEB通信服务 if (webPumpManager != null) { webPumpManager.Stop(); if (!webPumpManager.IsRuning) { TraceManagerForWeb.AppendDebug("二供—WEB通信服务管理器停止成功"); this.webPumpManager = null; } else { TraceManagerForWeb.AppendErrMsg("二供—WEB通信服务管理器停止失败"); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供—WEB通信服务管理器停止失败:" + e.Message); } IsRuning = false; }
// 执行体 public void Execute() { try { lock (this) //会被多线程调用注意安全 { switch (Type) { case WebPandaPumpCommandType.CollectAndSavePumpPoints: CollectAndSavePoints(); break; case WebPandaPumpCommandType.InitPumpRealData: InitPumpRealData(); break; } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("执行数据库工作器失败:" + e.Message); } }
// 执行体 public void Execute() { try { lock (this) //会被多线程调用注意安全 { switch (Type) { case WebPandaZHCDScadaCommandType.CollectAndSaveScadaSensors: CollectAndSaveSnesors(); break; case WebPandaZHCDScadaCommandType.InitSensorRealData: InitSensorRealData(); break; } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("执行SCADA-综合测点-web接入数据库工作器失败:" + e.Message); } }
public void Stop() { try { // Scada-OPC通信服务 if (opcScadaManager != null) { opcScadaManager.Stop(); if (!opcScadaManager.IsRuning) { TraceManagerForWeb.AppendDebug("Scada-OPC通信服务管理器停止成功"); this.opcScadaManager = null; } else { TraceManagerForWeb.AppendErrMsg("Scada-OPC通信服务管理器停止失败"); } } } catch (Exception e) { TraceManagerForWeb.AppendErrMsg("Scada-OPC通信服务管理器停止失败:" + e.Message); } IsRuning = false; }
public void Stop() { if (!IsRuning) { return; } try { // 控制器服务 if (commandCustomer != null) { commandCustomer.Stop(); if (!commandCustomer.IsRuning) { TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点控制器服务已停止"); this.commandCustomer = null; } else { TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点控制器服务停止失败"); } } } catch { } // 关闭定时器 if (timer != null) { timer.Enabled = false; timer.Close(); timer = null; } IsRuning = false; }
private void CollectAndSavePoints() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 #region 查询点表 string sqlPoints = @"select t.*,t1.数据业务地址,t1.名称 from PointAddressEntry t,PumpPointAddressDetail t1 where t.点明细ID=t1.ID and t.版本ID in(select distinct PointAddressID from PumpJZ x,pump x1 where PumpJZReadMode='WEB-PUMP' and (x.是否删除=0 or x.是否删除 is null) and (x1.是否删除=0 or x1.是否删除 is null));"; DataTable dtPoints = DBUtil.ExecuteDataTable(sqlPoints, out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.AppendErrMsg("查询二供点表版本失败:" + errMsg); return; } pointsCache = new Dictionary <int, List <Point> >(); foreach (DataRow dr in dtPoints.Rows) { int versionID = DataUtil.ToInt(dr["版本ID"]); Point point = new Point() { pointID = DataUtil.ToInt(dr["ID"]), versionID = versionID, name = DataUtil.ToString(dr["名称"]), dataSourceAddress = DataUtil.ToString(dr["数据源地址"]).Trim(), offsetAddress = DataUtil.ToString(dr["偏移地址"]).Trim(), dbSAddress = DataUtil.ToString(dr["数据业务地址"]).Trim(), type = Point.ToType(DataUtil.ToString(dr["数据类型"])), isActive = DataUtil.ToInt(dr["是否激活"]), isWrite = DataUtil.ToInt(dr["是否写入"]), scale = DataUtil.ToDouble(dr["倍率"]) }; if (pointsCache.Keys.Contains(versionID)) { pointsCache[versionID].Add(point); } else { pointsCache.Add(versionID, new List <Point>() { point }); } } if (pointsCache.Keys.Count == 0) { TraceManagerForWeb.AppendWarning("机组表没有读取模式关于WEB-PUMP的点表"); return; } #endregion #region 查询JZ表 string sqlJZ = @"select CONVERT(varchar(50),t1.ID) as BASEID ,t.PName as PumpName,t1.PumpJZName , t1.PointAddressID,t1.JZCode from Pump t, PumpJZ t1 where t.ID=t1.PumpId and t1.PumpJZReadMode='WEB-PUMP' and (t.是否删除=0 or t.是否删除 is null) and (t1.是否删除=0 or t1.是否删除 is null) ;"; DataTable dtJZIDs = DBUtil.ExecuteDataTable(sqlJZ, out errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.AppendErrMsg("查询二供机组ID列表失败:" + errMsg); return; } List <PumpJZ> jzs = new List <PumpJZ>(); foreach (DataRow dr in dtJZIDs.Rows) { int versionID = DataUtil.ToInt(dr["PointAddressID"]); List <Point> points = pointsCache[versionID]; Point[] pointsCopy = ByteUtil.DeepClone <List <Point> >(points).ToArray();// 一定要深度辅助一个副本,防止引用类型 PumpJZ jz = new PumpJZ() { _ID = DataUtil.ToString(dr["BASEID"]), _PumpName = DataUtil.ToString(dr["PumpName"]), _PumpJZName = DataUtil.ToString(dr["PumpJZName"]), _PandaPumpJZID = DataUtil.ToString(dr["JZCode"]), pointsVersionID = versionID, points = pointsCopy }; jzs.Add(jz); // 生成机组更新日期字典 if (!_LastUpdateDays.Keys.Contains(jz._ID)) { _LastUpdateDays.Add(jz._ID, ""); } } if (jzs.Count == 0) { TraceManagerForWeb.AppendWarning("机组表没有读取模式为WEB-PUMP的有效机组"); return; } #endregion #region 查询天表 string sqlHisDayDatas = @"select BASEID,TempTime from( select row_number() over(partition by BASEID order by TempTime desc) nRow ,* from PumpHisDayData tt) t where t.nRow=1"; DataTable dtHisDayDatas = DBUtil.ExecuteDataTable(sqlHisDayDatas, out errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.AppendErrMsg("查询二供历史天表缓存信息失败:" + errMsg); return; } String[] keyArr = _LastUpdateDays.Keys.ToArray <String>(); for (int i = 0; i < keyArr.Length; i++) { DataRow[] drs = dtHisDayDatas.Select("BASEID='" + keyArr[i] + "'"); if (drs != null && drs.Length > 0) { _LastUpdateDays[keyArr[i]] = DataUtil.ToDateString(drs[0]["TempTime"]); } } #endregion #region 是否需求请求新token if (tokenCache == null || DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0) { tokenCache = GetToken(); } if (tokenCache == null) { return; } if (DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0) { TraceManagerForWeb.AppendErrMsg("获取二供标记参数为过期标记"); return;// 获取后还是过期秘钥 } #endregion #region 请求二供数据并存入 List <PandaPumpJZ> pandaJZs = GetWebPumpData(); Collect(pandaJZs, ref jzs); string saveSQL = GetSavePointsSQL(jzs); if (string.IsNullOrWhiteSpace(saveSQL)) { TraceManagerForWeb.AppendWarning(string.Format(@"采集机组数量{0}获取存入数据库SQL失败,可能原因没有在线的机组", jzs.Count)); return; } DBUtil.ExecuteNonQuery(saveSQL, out string err); stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 if (!string.IsNullOrWhiteSpace(err)) { TraceManagerForWeb.AppendErrMsg("更新二供实时数据失败" + ",耗时:" + milliseconds.ToString() + "毫秒," + err); } else { TraceManagerForWeb.AppendDebug("更新二供实时数据成功" + ",耗时:" + milliseconds.ToString() + "毫秒"); } #endregion }
private void Collect(List <PandaPumpJZ> pandaJZs, ref List <PumpJZ> jzs) { if (pandaJZs == null) { return; } if (jzs == null) { return; } foreach (PumpJZ jz in jzs) { int errorTimes = 0; // 三个离线就认为该机组离线了 foreach (Point point in jz.points) { // 防止采集的点多了,错误消息炸了,每个都报出来了---直接让机组离线 if (errorTimes >= 3) { TraceManagerForWeb.AppendErrMsg(jz._PumpName + jz._PumpJZName + "三个条目采集失败,已跳过该机组采集,请检查点表和数据源"); jz.IsOnline = false; break; } // 检查未通过 if (!point.CheckPumpWeb(out string err)) { point.MakeFail(jz._PumpName + jz._PumpJZName + point.name + err); TraceManagerForWeb.AppendErrMsg(jz._PumpName + jz._PumpJZName + point.name + err); errorTimes++; continue; } // 拿到数据源 PandaPumpJZ[] curPandaPumpJZs = pandaJZs.Where(p => p.ID.ToUpper() == jz._PandaPumpJZID.ToUpper()).ToArray();// 注意转换大写在比较 if (curPandaPumpJZs.Length == 0) { point.MakeFail("未在WEB数据源中找到机组实时信息,机组编码:" + jz._PandaPumpJZID); TraceManagerForWeb.AppendErrMsg("未在WEB数据源中找到机组实时信息,机组编码:" + jz._PandaPumpJZID); errorTimes++; continue; } object pointDataSource; string tempTime = DataUtil.ToDateString(DateTime.Now); bool tempTimeFlag = false; try { PandaPumpJZ curPandaPumpJZ = curPandaPumpJZs[0]; // 获取在线状态-防止点表没有配置在线状态 Type typeOnLine = curPandaPumpJZ.GetType(); //获取类型 PropertyInfo propertyInfoOnLine = typeOnLine.GetProperty("FOnLine"); //获取采集时间的属性 object curOnLine = propertyInfoOnLine.GetValue(curPandaPumpJZ, null); if (curOnLine != null && DataUtil.ToInt(curOnLine) == 1) { jz.IsOnline = true; } // 先拿到时间 Type typeTempTime = curPandaPumpJZ.GetType(); //获取类型 PropertyInfo propertyInfoTempTime = typeTempTime.GetProperty("TempTime"); //获取采集时间的属性 object curTempTime = propertyInfoTempTime.GetValue(curPandaPumpJZ, null); if (curTempTime != null && !string.IsNullOrWhiteSpace(curTempTime.ToString())) { tempTime = DataUtil.ToDateString(curTempTime); //获取采集时间属性值 tempTimeFlag = true; } // 在拿到值 Type type = curPandaPumpJZ.GetType(); //获取类型 System.Reflection.PropertyInfo propertyInfo = type.GetProperty(point.dataSourceAddress); //获取指定名称的属性 pointDataSource = propertyInfo.GetValue(curPandaPumpJZ, null); //获取属性值 } catch (Exception e) { string er = string.Format("{0}-{1}-{2}采集失败,错误的原因:{3}", jz._PumpName, jz._PumpJZName, point.name, e.Message); point.MakeFail(er); TraceManagerForWeb.AppendErrMsg(er); errorTimes++; continue; } // 根据数据源获取数据 point.ReadWEBPoint(pointDataSource); if (point.State == ValueState.Fail) { string er = string.Format("{0}-{1}-{2}采集失败,取值错误:{3}", jz._PumpName, jz._PumpJZName, point.name, point.Mess); TraceManagerForWeb.AppendErrMsg(er); errorTimes++; continue; } // 判断采集时间是否正常 if (!tempTimeFlag) { jz.IsOnline = false; } } } }
private void CollectAndSaveSnesors() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 Dictionary <int, Station> dicStations = new Dictionary <int, Station>(); #region 查询sensor表 string sqlSensors = @"select * from( select t.ID stationID, t.GUID as stationCode,t.Name stationName,t1.ID sensorID,t1.Name sensorName,t1.PointAddressID from SCADA_Station t ,SCADA_Sensor t1 where t.ID=t1.StationID and t.ReadMode='WEB-ZHCD') x left join PointAddressEntry x1 on x.PointAddressID=x1.ID;"; DataTable dtSensors = DBUtil.ExecuteDataTable(sqlSensors, out string errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { TraceManagerForWeb.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"]), _PointAddressID = DataUtil.ToInt(dr["PointAddressID"]), versionID = DataUtil.ToInt(dr["版本ID"]), dataSourceAddress = DataUtil.ToString(dr["数据源地址"]).Trim(), type = Point.ToType(DataUtil.ToString(dr["数据类型"])), isActive = DataUtil.ToInt(dr["是否激活"]), scale = DataUtil.ToDouble(dr["倍率"]) }; 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) { TraceManagerForWeb.AppendWarning("站点表没有读取模式:WEB-ZHCD的站点表"); return; } #endregion #region 是否需求请求新token if (tokenCache == null || DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0) { tokenCache = GetToken(); } if (tokenCache == null) { return; } if (DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0) { TraceManagerForWeb.AppendErrMsg("获取熊猫标记参数为过期标记"); return;// 获取后还是过期秘钥 } #endregion #region 请求监测点数据并存入 List <ZongHeCeDian> ceDians = GetWebCeDianData(); Collect(ceDians, ref dicStations); string saveSQL = GetSaveSensorsSQL(dicStations); if (string.IsNullOrWhiteSpace(saveSQL)) { TraceManagerForWeb.AppendWarning(string.Format(@"采集WEB-综合测点数量{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)) { TraceManagerForWeb.AppendErrMsg("更新WEB-综合测点实时数据失败" + ",耗时:" + milliseconds.ToString() + "毫秒," + err); } else { TraceManagerForWeb.AppendDebug("更新WEB-综合测点实时数据成功" + ",耗时:" + milliseconds.ToString() + "毫秒"); } #endregion }
private void Collect(List <ZongHeCeDian> ceDians, ref Dictionary <int, Station> dicStations) { if (ceDians == 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) { TraceManagerForWeb.AppendErrMsg("StationName:" + station._Name + "三个条目采集失败,已跳过该站点采集,请检查点表和数据源"); dicStations[key].IsOnline = false; break; } // 检查未通过 if (!sensor.CheckScadaWeb(out string err)) { sensor.MakeFail(sensor.sensorName + err); TraceManagerForWeb.AppendErrMsg("StationName:" + station._Name + "SensorName" + sensor.sensorName + " " + err); errorTimes++; continue; } // 拿到数据源 ZongHeCeDian[] curCeDians = ceDians.Where(y => y.ID.ToUpper() == station._GUID.ToUpper()).ToArray();// 注意转换大写在比较 if (curCeDians.Length == 0) { sensor.MakeFail("未在WEB综合测点数据源中找到配置站点信息,站点编码:" + station._GUID); TraceManagerForWeb.AppendErrMsg("未在WEB综合测点数据源中找到配置站点信息,站点编码:" + station._GUID); errorTimes++; continue; } object pointDataSource; string tempTime = DataUtil.ToDateString(DateTime.Now); bool tempTimeFlag = false; try { ZongHeCeDian curCeDian = curCeDians[0]; // 获取在线状态-防止sensor表没有配置在线状态 Type typeOnLine = curCeDian.GetType(); //获取类型 PropertyInfo propertyInfoOnLine = typeOnLine.GetProperty("FOnLine"); //获取采集时间的属性 object curOnLine = propertyInfoOnLine.GetValue(curCeDian, null); if (curOnLine != null && DataUtil.ToInt(curOnLine) == 1) { dicStations[key].IsOnline = true; } // 先拿到时间 Type typeTempTime = curCeDian.GetType(); //获取类型 PropertyInfo propertyInfoTempTime = typeTempTime.GetProperty("TempTime"); //获取采集时间的属性 object curTempTime = propertyInfoTempTime.GetValue(curCeDian, null); if (curTempTime != null && !string.IsNullOrWhiteSpace(curTempTime.ToString())) { tempTime = DataUtil.ToDateString(curTempTime); //获取采集时间属性值 tempTimeFlag = true; } // 在拿到值 Type type = curCeDian.GetType(); //获取类型 PropertyInfo propertyInfo = type.GetProperty(sensor.dataSourceAddress); //获取指定名称的属性 pointDataSource = propertyInfo.GetValue(curCeDian, null); //获取属性值 } catch (Exception e) { string er = string.Format("未在WEB综合测点数据源中找到配置站点信息:{0}找到点地址为:{1}的点,错误原因:{2}" + station._Name, sensor.sensorName, e.Message); sensor.MakeFail(er); TraceManagerForWeb.AppendErrMsg(er); errorTimes++; continue; } // 根据数据源获取数据 sensor.ReadWEBPoint(pointDataSource); sensor.LastTime = tempTime;// 使用采集时间,不要用当前时间 if (sensor.State == ValueState.Fail) { string er = string.Format("站点名称:{0},sensorName:{1},取值错误:{2}", station._Name, sensor.sensorName, sensor.Mess); TraceManagerForWeb.AppendErrMsg(er); errorTimes++; continue; } // 判断采集时间是否正常 if (!tempTimeFlag) { dicStations[key].IsOnline = 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; }