123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using EDosApiWrapper;
- using GDNXFD.Data;
- using GDNXFD.Data.Repositories;
- using log4net;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- namespace GDNXFD.Alert.Interpreter
- {
- public class PollingService
- {
- private ILog logger = LogManager.GetLogger("AppLog");
- private bool cancelPolling = false;
- private bool isRunning = false;
- private int pollingInterval;
- private EDosBJMonitor eDosMonitor;
- //Thread windTurbineMonitorThread;
- public bool IsRunning
- {
- get { return isRunning; }
- }
- public PollingService()
- {
- pollingInterval = GlobalVar.PollingInterval;
- }
- public void Start()
- {
- logger.Info("轮询服务开始!");
- //windTurbineMonitorThread = new Thread(WindTurbineMonitor);
- //windTurbineMonitorThread.Start();
- isRunning = true;
- int cnt = 1;
- while (!cancelPolling)
- {
- if (cnt > 1000000) cnt = 1;
- logger.InfoFormat("开始第{0}次扫描......", cnt++);
- try
- {
- WindTurbineMonitor();
- WindPowerStationMonitor();
- ProjectMonitor();
- LineMonitor();
- ElectricalMonitor();
- EDosMonitor();
- System.Threading.Thread.Sleep(pollingInterval * 1000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("轮询服务异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 500);
- }
- }
- }
- public void Stop()
- {
- logger.Info("正在停止轮询服务...");
- cancelPolling = true;
- //if (windTurbineMonitorThread != null)
- // windTurbineMonitorThread.Join();
- isRunning = false;
- logger.Info("轮询服务停止!");
- }
- private void WindTurbineMonitor()
- {
- var lstWt = DataCache.Instance.WindTurbinies.ToList();
- //var lstWt = DataCache.Instance.WindTurbinies.Where(q=>q.Id== "MG01_01").ToList();
- foreach (WindTurbine wt in lstWt)
- {
- if (cancelPolling) break;
- try
- {
- logger.Debug("获取风机:" + wt.Id + "," + wt.Name + "," + wt.ModelId);
- WindTurbineCalculator wtCal = new WindTurbineCalculator(wt);
- wtCal.Calculate();
- }
- catch (EDosDataLackException)
- {
- //logger.WarnFormat("有效数据不足!");
- }
- catch (EDosException ex)
- {
- logger.ErrorFormat("EDos异常!ErrorCode={0}, Message={1}", ex.ErrorCode, ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("风机监视线程异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- }
- }
- private void WindPowerStationMonitor()
- {
- var lstObj = DataCache.Instance.WindPowerStation;
- //var lstWt = DataCache.Instance.WindTurbinies.Where(q=>q.Id== "MG01_01").ToList();
- foreach (WindPowerStation wt in lstObj)
- {
- if (cancelPolling) break;
- try
- {
- logger.Debug("获取风场:" + wt.Id + "," + wt.Name);
- WindPowerStationCalculator cal = new WindPowerStationCalculator(wt);
- cal.Calculate();
- }
- catch (EDosDataLackException)
- {
- logger.WarnFormat("有效数据不足!");
- }
- catch (EDosException ex)
- {
- logger.ErrorFormat("EDos异常!ErrorCode={0}, Message={1}", ex.ErrorCode, ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("风机监视线程异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- }
- }
- private void ElectricalMonitor()
- {
- var lstObj = DataCache.Instance.WindPowerStation;
- foreach (WindPowerStation wt in lstObj)
- {
- if (cancelPolling) break;
- try
- {
- logger.Debug("获取风场(升压站):" + wt.Id + "," + wt.Name);
- ElectricalCalculator cal = new ElectricalCalculator(wt);
- cal.Calculate();
- }
- catch (EDosDataLackException)
- {
- //logger.WarnFormat("有效数据不足!");
- }
- catch (EDosException ex)
- {
- logger.ErrorFormat("EDos异常!ErrorCode={0}, Message={1}", ex.ErrorCode, ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("电气监视线程异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- }
- }
- private void ProjectMonitor()
- {
- var lstObj = DataCache.Instance.Projects;
- foreach (Project wt in lstObj)
- {
- if (cancelPolling) break;
- try
- {
- logger.Debug("获取工程:" + wt.Id + "," + wt.Name);
- ProjectCalculator cal = new ProjectCalculator(wt);
- cal.Calculate();
- }
- catch (EDosDataLackException)
- {
- //logger.WarnFormat("有效数据不足!");
- }
- catch (EDosException ex)
- {
- logger.ErrorFormat("EDos异常!ErrorCode={0}, Message={1}", ex.ErrorCode, ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("工程监视线程异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- }
- }
- private void LineMonitor()
- {
- var lstObj = DataCache.Instance.Lines;
- foreach (Line wt in lstObj)
- {
- if (cancelPolling) break;
- try
- {
- logger.Debug("获取线路:" + wt.Id + "," + wt.Name);
- LineCalculator cal = new LineCalculator(wt);
- cal.Calculate();
- }
- catch (EDosDataLackException)
- {
- //logger.WarnFormat("有效数据不足!");
- }
- catch (EDosException ex)
- {
- logger.ErrorFormat("EDos异常!ErrorCode={0}, Message={1}", ex.ErrorCode, ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("线路监视线程异常:{0}", ex.Message);
- System.Threading.Thread.Sleep(pollingInterval * 2000);
- }
- }
- }
- /// <summary>
- /// 正对一期完成的FJBJ、FJBJ2、及IFix上的报警
- /// </summary>
- private void EDosMonitor()
- {
- if (eDosMonitor == null)
- eDosMonitor = new EDosBJMonitor();
- eDosMonitor.WindTurbineBJMonitor();
- eDosMonitor.IFixBJMonitor();
- }
- }
- }
|