123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- 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 EDosBJMonitor
- {
- private ILog logger = LogManager.GetLogger("AppLog");
- private IDictionary<string, eDOSApi.HISTORY_VALUE> dictWtBJ;
- private IDictionary<string, eDOSApi.HISTORY_VALUE> dictIFixBJ;
- private string[] arrWtPoints;
- private string[] arrFixPoints;
- private string eDosServerIP;
- private ushort eDosServerPort;
- private EDosProxy eDos;
- public EDosBJMonitor()
- {
- eDosServerIP = GlobalVar.EDosServerIP;
- eDosServerPort = GlobalVar.EDosServerPort;
- eDos = new EDosProxy(eDosServerIP, eDosServerPort);
- }
- public void WindTurbineBJMonitor()
- {
- if (dictWtBJ == null)
- {
- dictWtBJ = CreateDictWindturbineBJ();
- arrWtPoints = dictWtBJ.Keys.ToArray();
- }
- if (dictWtBJ == null || dictWtBJ.Count == 0)
- return;
- string[] narr = arrWtPoints;// dictWtBJ.Keys.ToArray();
- int len = narr.Length;
- int currentTime = CommonMethod.ConvertDateTimeInt(DateTime.Now);
- eDOSApi.HISTORY_VALUE[] results = eDos.GetRTValueList(narr);
- for (int i = 0; i < results.Length; i++)
- {
- try
- {
- int valueTime = results[i].tTime;
- //有效时间外的值不处理,单位秒, 有效时间暂定义为1小时
- if (currentTime - valueTime > 60 * 60)
- continue;
- //与上次扫描读取的值比对,如果没有更新则不处理
- string key = narr[i];
- int preTime = dictWtBJ[key].tTime;
- if (valueTime <= preTime)
- continue;
- //触发报警
- int ednaValue = (int)results[i].dValue;
- if (ednaValue != 0)
- {
- double interval = 0;
- string wId = DataCache.Instance.DictWTP[key].WindturbineId;
- AlertSnap snap = AlertSnapRepository.GetWindturbineAlertSnap(wId, ednaValue);
- if (snap == null)
- {
- Warning warn = DataCache.Instance.DictWarning[ednaValue];
- WindTurbine wt = (WindTurbine)DataCache.Instance.DictWindturbine2[wId];
- snap = AlertSnapFactory.CreateAlertSnap(warn, wt);
- }
- if (snap.IsOpened)
- {
- TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
- interval = ts.TotalHours;
- if (interval < 1)
- continue;
- }
- snap.IsOpened = true;
- snap.DataInfo = string.Format("EDNAVALUE={0}", ednaValue);
- snap.LastUpdatePerson = "system";
- snap.LastUpdateTime = DateTime.Now;
- if (snap.IsConfirmed && interval > 8)
- snap.IsConfirmed = false;
- AlertSnapRepository.SaveAlertSnap(snap);
- logger.InfoFormat("收到报警:{0}, EDnaValue={1}", snap.AlertText, snap.AlertValue);
- }
- //更新DictBJ
- dictWtBJ[key] = results[i];
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("处理风机报警时异常:{0}", ex.Message);
- //System.Threading.Thread.Sleep(1000);
- }
- }
- }
- public void IFixBJMonitor()
- {
- if (dictIFixBJ == null)
- {
- dictIFixBJ = CreateDictIFixBJ2();
- arrFixPoints = dictIFixBJ.Keys.ToArray();
- }
- if (dictIFixBJ == null || dictIFixBJ.Count == 0)
- return;
- //string[] narr = arrFixPoints;// dictIFixBJ.Keys.ToArray();
- int len = arrFixPoints.Length;
- for(int j=0;j<len;j+=200)
- {
- string[] narr;
- if ((j + 200) > len)
- {
- narr = new string[len - j];
- Array.Copy(arrFixPoints, j, narr, 0, len - j);
- } else
- {
- narr = new string[200];
- Array.Copy(arrFixPoints, j, narr, 0, 200);
- }
- #region 从实时库中取点比较变化
- int currentTime = CommonMethod.ConvertDateTimeInt(DateTime.Now);
- eDOSApi.HISTORY_VALUE[] results = eDos.GetRTValueList(narr);
- for (int i = 0; i < results.Length; i++)
- {
- try
- {
- int valueTime = results[i].tTime;
- //有效时间外的值不处理,单位秒, 有效时间暂定义为1小时
- //if (currentTime - valueTime > 60 * 60)
- // continue;
- //与上次扫描读取的值比对,如果没有更新则不处理
- string key = narr[i];
- int preTime = dictIFixBJ[key].tTime;
- if (valueTime <= preTime)
- continue;
- //触发报警
- int ednaValue = (int)results[i].dValue;
- int preValue = (int)dictIFixBJ[key].dValue;
- if (ednaValue == preValue)
- continue;
- bool ifBJ = true;// ednaValue == 0 ? false : true;
- //if (ifBJ == false)
- // continue;
- AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(key);
- if (snap == null)
- {
- IFixBJTestingPointDI ftpd = DataCache.Instance.DictFixTP[key];
- snap = AlertSnapFactory.CreateAlertSnap(ftpd);
- }
- snap.AlertValue = ednaValue;
- //double interval = 0;
- //if (snap.IsOpened)
- //{
- // TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
- // interval = ts.TotalHours;
- // //if (interval < 1)
- // // continue;
- //}
- if (ifBJ == true)
- {
- snap.IsOpened = true;
- snap.DataInfo = string.Format("{0}={1}", snap.TestingPointKey, ednaValue.ToString());
- snap.LastUpdatePerson = "system";
- snap.LastUpdateTime = DateTime.Now;
- if (snap.IsConfirmed)
- snap.IsConfirmed = false;
- }
- else
- {
- snap.IsOpened = false;
- snap.DataInfo = string.Format("{0}={1}", snap.TestingPointKey, ednaValue.ToString());
- snap.IsConfirmed = false;
- snap.LastClosePerson = "system";
- snap.LastCloseTime = DateTime.Now;
- }
- AlertSnapRepository.SaveAlertSnap(snap);
- if (ifBJ)
- logger.InfoFormat("收到报警:{0}, key={1}", snap.AlertText, snap.TestingPointKey);
- else
- {
- logger.InfoFormat("解除报警:{0}, key={1}", snap.AlertText, snap.TestingPointKey);
- }
- //}
- //更新DictBJ
- dictIFixBJ[key] = results[i];
- }
- catch (Exception ex)
- {
- logger.ErrorFormat("处理升压站报警时异常:{0}", ex.Message);
- //System.Threading.Thread.Sleep(1000);
- continue;
- }
- }
- #endregion
- }
- }
- private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictWindturbineBJ()
- {
- IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
- IList<WindTurbineTestingPointAI> lstWTA = DataCache.Instance.WtBJPoints;
- foreach (WindTurbineTestingPointAI wai in lstWTA)
- {
- string pointA = CommonMethod.BuildPointId(wai.Id);
- if (string.IsNullOrWhiteSpace(pointA))
- continue;
- dictBJ.Add(pointA, new eDOSApi.HISTORY_VALUE());
- }
- return dictBJ;
- }
- private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictIFixBJ()
- {
- IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
- IList<IFixBJTestingPointDI> lstWTA = DataCache.Instance.IFixBJPoints;
- foreach (IFixBJTestingPointDI wai in lstWTA)
- {
- //string pointA = CommonMethod.BuildPointId(wai.Id);
- //if (string.IsNullOrWhiteSpace(pointA))
- // continue;
- var hv = new eDOSApi.HISTORY_VALUE();
- AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(wai.PointKey);
- if (snap != null)
- {
- hv.dValue = snap.AlertValue;
- }
- dictBJ.Add(wai.PointKey, hv);
- }
- return dictBJ;
- }
- Dictionary<string, long> dictSnapValue = null;
- private Dictionary<string, long> CreateDictSnapValue()
- {
- dictSnapValue = new Dictionary<string, long>();
- var lst = AlertSnapRepository.GetTestingPointAlertSnap();
- if (lst != null && lst.Count > 0)
- {
- foreach(var snap in lst)
- {
- if (dictSnapValue.ContainsKey(snap.TestingPointKey) == false)
- dictSnapValue.Add(snap.TestingPointKey, snap.AlertValue);
- }
- }
- return dictSnapValue;
- }
- private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictIFixBJ2()
- {
- if (dictSnapValue == null)
- dictSnapValue = CreateDictSnapValue();
- //var obj = AlertSnapRepository.GetAlertSnaps()
- IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
- IList<IFixBJTestingPointDI> lstWTA = DataCache.Instance.IFixBJPoints;
- foreach (IFixBJTestingPointDI wai in lstWTA)
- {
- //string pointA = CommonMethod.BuildPointId(wai.Id);
- //if (string.IsNullOrWhiteSpace(pointA))
- // continue;
- var hv = new eDOSApi.HISTORY_VALUE();
- if (dictSnapValue.ContainsKey(wai.PointKey))
- hv.dValue = dictSnapValue[wai.PointKey];
- //AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(wai.PointKey);
- //if (snap != null)
- //{
- // hv.dValue = snap.AlertValue;
- //}
- dictBJ.Add(wai.PointKey, hv);
- }
- return dictBJ;
- }
- }
- }
|