using System.Collections.Generic; using System.Linq; using GDNXFD.Data.Repositories; using log4net; namespace GDNXFD.Data { public class DataCache { private ILog logger = LogManager.GetLogger("AppLog"); #region 单例模式 private DataCache() { } public static DataCache Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly DataCache instance = new DataCache(); } #endregion #region 所有风机数据 private IList windTurbinies; public IList WindTurbinies { get { if (windTurbinies == null) { windTurbinies = WindTurbineRepository.GetWindTurbinies(); logger.Info("加载风机数据,总数:" + windTurbinies.Count); } return windTurbinies; } } public void ReloadWindTurbinies() { windTurbinies = null; } public IList GetWindTurbiniesByModelId(string modelId) { return WindTurbinies.Where(q => q.ModelId == modelId).ToList(); } private Dictionary dictWindturbine; public Dictionary DictWindturbine { get { if (dictWindturbine == null) { dictWindturbine = new Dictionary(); foreach (WindTurbine wps in this.WindTurbinies) { if (dictWindturbine.ContainsKey(wps.Name)) continue; dictWindturbine.Add(wps.Name, wps); } } return dictWindturbine; } } private Dictionary dictWindturbine2; public Dictionary DictWindturbine2 { get { if (dictWindturbine2 == null) { dictWindturbine2 = new Dictionary(); foreach (WindTurbine wps in this.WindTurbinies) { if (dictWindturbine2.ContainsKey(wps.Name)) continue; dictWindturbine2.Add(wps.Id, wps); } } return dictWindturbine2; } } #endregion #region 风机测点 //包含所有自定义报警规则中出现的测点统一编码,在生成Interpreter时,填充 public IList RelateUniformCodes { get; set; } private string[] aiCodes; public string[] AICodes { get { if (aiCodes == null && RelateUniformCodes != null && RelateUniformCodes.Count > 0) { aiCodes = RelateUniformCodes.Where(s => s.StartsWith("AI")).ToArray(); } return aiCodes; } } private string[] diCodes; public string[] DICodes { get { if (diCodes == null && RelateUniformCodes != null && RelateUniformCodes.Count > 0) { diCodes = RelateUniformCodes.Where(s => s.StartsWith("DI")).ToArray(); } return diCodes; } } private IList windTurbineAIPoints; public IList WindTurbineAIPoints { get { if (windTurbineAIPoints == null) { windTurbineAIPoints = WindTurbineRepository.GetWindTurbineAIPoints(AICodes); logger.Info("加载风机AI测点,总数:" + windTurbineAIPoints.Count); //logger.Info("AICodes = " + AICodes); } return windTurbineAIPoints; } } private IList windTurbineDIPoints; public IList WindTurbineDIPoints { get { if (windTurbineDIPoints == null) { windTurbineDIPoints = WindTurbineRepository.GetWindTurbineDIPoints(DICodes); logger.Info("加载风机DI测点,总数:" + windTurbineDIPoints.Count); logger.Info("DICodes = " + DICodes); } return windTurbineDIPoints; } } private IList windTurbineAlertPoints; public IList WindTurbineAlertPoints { get { if (windTurbineAlertPoints == null) { windTurbineAlertPoints = WindTurbineRepository.GetWindTurbineAIPoints("FJBJ3"); logger.Info("加载风机报警测点,总数:" + windTurbineAlertPoints.Count); logger.Info("统一编码 : FJBJ3 "); } return windTurbineAlertPoints; } } #endregion #region 数据字典 private IList dataDict; public IList DataDict { get { if (dataDict == null) { dataDict = WindPowerStationRepository.GetDataDictionary(); logger.Info("加载数据字典,总数:" + dataDict.Count); } return dataDict; } } public void ReloadDataDict() { dataDict = null; } public IList GetDataDictByCategory(string category) { if (DataDict != null) { var tmp = DataDict.Where(c => c.Category == category && c.Enabled); if (tmp != null) return tmp.OrderBy(c => c.OrderNo).ToList(); } return null; } #endregion #region 风电场 private IList windPowerStation; public IList WindPowerStation { get { if (windPowerStation == null) { windPowerStation = WindPowerStationRepository.GetWindPowerStations(); logger.Info("加载风电场,总数:" + windPowerStation.Count); } return windPowerStation; } } public void ReloadWindPowerStation() { windPowerStation = null; } public WindPowerStation GetWindPowerStationByID(string id) { return WindPowerStation.Where(c => c.Id == id).FirstOrDefault(); } private Dictionary dictStation; public Dictionary DictStation { get { if (dictStation == null) { dictStation = new Dictionary(); foreach(WindPowerStation wps in this.WindPowerStation) { if (dictStation.ContainsKey(wps.Name)) continue; dictStation.Add(wps.Name, wps); } } return dictStation; } } private Dictionary dictStation2; public Dictionary DictStation2 { get { if (dictStation2 == null) { dictStation2 = new Dictionary(); foreach (WindPowerStation wps in this.WindPowerStation) { if (dictStation2.ContainsKey(wps.Name)) continue; dictStation2.Add(wps.Id, wps); } } return dictStation2; } } #endregion #region 风机类型 private IList equipmentModel; public IList EquipmentModel { get { if (equipmentModel == null) { equipmentModel = WindTurbineRepository.GetEquipmentModels(); logger.Info("加载设备类型,总数:" + equipmentModel.Count); } return equipmentModel; } } public void ReloadEquipmentModels() { equipmentModel = null; } public EquipmentModel GetEquipmentModelByID(string id) { if (equipmentModel != null) { return equipmentModel.Where(c => c.Id == id).FirstOrDefault(); } return null; } private Dictionary dictModel; public Dictionary DictModel { get { if (dictModel == null) { dictModel = new Dictionary(); foreach (EquipmentModel wps in this.EquipmentModel) { if (dictModel.ContainsKey(wps.Id)) continue; dictModel.Add(wps.Id, wps); } } return dictModel; } } #endregion #region 线路 private IList lines; public IList Lines { get { if (lines == null) { lines = WindPowerStationRepository.GetLines(); logger.Info("加载线路,总数:" + lines.Count); } return lines; } } public void ReloadLines() { lines = null; } public Line GetLinesByID(string id) { return Lines.Where(c => c.Id == id).FirstOrDefault(); } private Dictionary dictLine; public Dictionary DictLine { get { if (dictLine == null) { dictLine = new Dictionary(); foreach (Line wps in this.Lines) { if (dictLine.ContainsKey(wps.Name)) continue; dictLine.Add(wps.Name, wps); } } return dictLine; } } private Dictionary dictLine2; public Dictionary DictLine2 { get { if (dictLine2 == null) { dictLine2 = new Dictionary(); foreach (Line wps in this.Lines) { if (dictLine2.ContainsKey(wps.Name)) continue; dictLine2.Add(wps.Id, wps); } } return dictLine2; } } #endregion #region 工程 private IList projects; public IList Projects { get { if (projects == null) { projects = WindPowerStationRepository.GetProjects(); logger.Info("加载工程,总数:" + projects.Count); } return projects; } } public void ReloadProjects() { projects = null; } public Project GetProjectsByID(string id) { return Projects.Where(c => c.Id == id).FirstOrDefault(); } private Dictionary dictProject; public Dictionary DictProject { get { if (dictProject == null) { dictProject = new Dictionary(); foreach (Project wps in this.Projects) { if (dictProject.ContainsKey(wps.Name)) continue; dictProject.Add(wps.Name, wps); } } return dictProject; } } private Dictionary dictProject2; public Dictionary DictProject2 { get { if (dictProject2 == null) { dictProject2 = new Dictionary(); foreach (Project wps in this.Projects) { if (dictProject2.ContainsKey(wps.Name)) continue; dictProject2.Add(wps.Id, wps); } } return dictProject2; } } #endregion #region 测点(风电场、线路、工程) private IList ltPoint; public IList LevelTypeTestingPoints { get { if (ltPoint == null) { ltPoint = WindPowerStationRepository.GetLevelTypeTestingPoints(); logger.Info("加载分级测点数据,总数:" + ltPoint.Count); } return ltPoint; } } public void ReloadLevelTypeTestingPoints() { ltPoint = null; } public IList GetTestingPointByLevelType(string levelType) { return LevelTypeTestingPoints.Where(q => q.LevelType == levelType).ToList(); } #endregion #region 电气测点 private IList etPointAIs; public IList ElectricalTestingPointAIs { get { if (etPointAIs == null) { etPointAIs = WindPowerStationRepository.GetElectricalTestingPointAIs(); logger.Info("加载电气AI测点数据,总数:" + etPointAIs.Count); } return etPointAIs; } } public void ReloadElectricalTestingPointAIs() { etPointAIs = null; } public IList GetElecTestingPointAIByStationId(string stationId) { return ElectricalTestingPointAIs.Where(q => q.WindPowerStationId == stationId).ToList(); } private IList etPointDIs; public IList ElectricalTestingPointDIs { get { if (etPointDIs == null) { etPointDIs = WindPowerStationRepository.GetElectricalTestingPointDIs(); logger.Info("加载电气AI测点数据,总数:" + etPointDIs.Count); } return etPointDIs; } } public void ReloadElectricalTestingPointDIs() { etPointDIs = null; } public IList GetElecTestingPointDIByStationId(string stationId) { return ElectricalTestingPointDIs.Where(q => q.WindPowerStationId == stationId).ToList(); } #endregion #region EDOS报警测点(风机报警、风机首出报警,电气报警(来自IFIX)) private IList wtBJPoints; public IList WtBJPoints { get { if (wtBJPoints == null) { wtBJPoints = WindTurbineRepository.GetWindTurbineAIPointsFJBJ(); logger.Info("加载风机报警测点数据,总数:" + wtBJPoints.Count); } return wtBJPoints; } } private Dictionary dictWTP; public Dictionary DictWTP { get { if (dictWTP == null) { dictWTP = new Dictionary(); foreach (WindTurbineTestingPointAI wps in this.WtBJPoints) { string key = CommonMethod.BuildPointId(wps.Id); if (key != null) { if (dictWTP.ContainsKey(key)) continue; dictWTP.Add(key, wps); } } } return dictWTP; } } public void ReloadWtBJPoints() { wtBJPoints = null; } private IList ifixBJPoints; public IList IFixBJPoints { get { if (ifixBJPoints == null) { ifixBJPoints = WindPowerStationRepository.GetIFixBJPoints(); logger.Info("加载IFIX报警测点数据,总数:" + ifixBJPoints.Count); } return ifixBJPoints; } } private Dictionary dictFixTP; public Dictionary DictFixTP { get { if (dictFixTP == null) { dictFixTP = new Dictionary(); foreach (IFixBJTestingPointDI wps in this.ifixBJPoints) { if (dictFixTP.ContainsKey(wps.PointKey)) continue; dictFixTP.Add(wps.PointKey, wps); } } return dictFixTP; } } public void ReloadIFixBJPoints() { ifixBJPoints = null; } private IList warning; public IList Warning { get { if (warning == null) { warning = WindPowerStationRepository.GetWarning(); logger.Info("加载风机报警数据,总数:" + warning.Count); } return warning; } } public void ReloadWarning() { warning = null; } private Dictionary dictWarning; public Dictionary DictWarning { get { if (dictWarning == null) { dictWarning = new Dictionary(); foreach (Warning wps in this.Warning) { if (dictWarning.ContainsKey(wps.EDnaValue)) continue; dictWarning.Add(wps.EDnaValue, wps); } } return dictWarning; } } #endregion } }