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); }
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; }
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 }