123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using Abp.Dependency;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using ToolLibrary.LogHelper;
- using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
- using YunDa.ISAS.DataTransferObject.DataMonitoring.LinkageExecuteActivityDto;
- using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
- using YunDa.ISAS.DataTransferObject.GeneralInformation.TransformerSubstationDto;
- using YunDa.ISAS.Redis.Repositories;
- using ConstantModel = YunDa.ISAS.DataTransferObject.EquipmentLiveData.ConstantModel;
- namespace Yunda.ISAS.DataMonitoringServer.DataCenter
- {
- public class RunningDataCache : ISingletonDependency
- {
- private readonly RedisDataRepository _redisDataRepository;
- public TransformerSubstationOutput _transformerSubstation;
- public bool IsRunning { get; set; }
- public RunningDataCache(RedisDataRepository redisDataRepository)
- {
- _redisDataRepository= redisDataRepository;
- Task.Factory.StartNew( () => {
- while (true)
- {
- UpdateEquipmentDataModelDicRedis();
- Task.Delay(TimeSpan.FromSeconds(10*60)).Wait();
- }
- },TaskCreationOptions.LongRunning);
- }
- public async void UpdateEquipmentDataModelDicRedis()
- {
- try
- {
- await _redisDataRepository.EquipmentDataModelDicRedis.DeleteKeyAsync(ConstantModel.EquipmentDataModelDicRedisKey);
- await _redisDataRepository.EquipmentDataModelDicRedis.HashSetUpdateManyAsync(ConstantModel.EquipmentDataModelDicRedisKey, EquipmentDataDic.Keys.ToList(), EquipmentDataDic.Values.ToList());
- }
- catch (Exception e)
- {
- Log4Helper.Error(this.GetType(), "内存数据库插入", e);
- }
- }
- public ConcurrentDictionary<Guid, EquipmentDataModel> EquipmentDataDic { get; set; }
- = new ConcurrentDictionary<Guid, EquipmentDataModel>();
- public TelemeteringModel GetTelemeteringModel(Guid? guid =null,string name ="")
- {
- foreach (var item in EquipmentDataDic.Values)
- {
- if (!string.IsNullOrWhiteSpace(name))
- {
- var relemeteringModel = item.Telemeterings.FirstOrDefault(t => t.Name.Contains(name));
- if (relemeteringModel != null)
- {
- return relemeteringModel;
- }
- }
- else
- {
- var relemeteringModel = item.Telemeterings.FirstOrDefault(t => t.Id == guid);
- if (relemeteringModel != null)
- {
- return relemeteringModel;
- }
- }
- }
- return null;
- }
- public TelesignalisationModel GetTelesignalisationModel(Guid? guid = null, string name = "")
- {
- foreach (var item in EquipmentDataDic.Values)
- {
- if (!string.IsNullOrWhiteSpace(name))
- {
- var telesignalisationModel = item.Telesignalisations.FirstOrDefault(t => t.Name.Contains( name));
- if (telesignalisationModel != null)
- {
- return telesignalisationModel;
- }
- }
- else
- {
- var telesignalisationModel = item.Telesignalisations.FirstOrDefault(t => t.Id == guid);
- if (telesignalisationModel != null)
- {
- return telesignalisationModel;
- }
- }
- }
- return null;
- }
- //public ConcurrentDictionary<Guid, TelemeteringModel> TelemeteringDic { get; set; } =
- // new ConcurrentDictionary<Guid, TelemeteringModel>();
- //public ConcurrentDictionary<Guid, TelesignalisationModel> TelesignalisationDic { get; set; } =
- // new ConcurrentDictionary<Guid, TelesignalisationModel>();
- /// <summary>
- /// 遥控策略数据缓存
- /// </summary>
- public ConcurrentBag<LinkageExecuteActivityOutput> LinkageExecuteActivities { get; set; }
- = new ConcurrentBag<LinkageExecuteActivityOutput>();
- /// <summary>
- /// 摄像头数据缓存
- /// </summary>
- public ConcurrentBag<VideoDev> VideoDevs { get; set; }
- = new ConcurrentBag<VideoDev>();
- /// <summary>
- /// 遥控数据缓存
- /// </summary>
- public ConcurrentBag<TelecommandModel> TelecommandModels { get; set; }
- = new ConcurrentBag<TelecommandModel>();
- /// <summary>
- /// 遥测小时统计列表
- /// </summary>
- public Dictionary<Guid, TelemeteringHourStatisticsModel> TelemeteringHourStatisticsDic { get; set; }
- = new Dictionary<Guid, TelemeteringHourStatisticsModel>();
- /// <summary>
- /// 联动策略缓存
- /// </summary>
- public ConcurrentBag<LinkageStrategyModel> LinkageStrategys { get; set; }
- = new ConcurrentBag<LinkageStrategyModel>();
- }
- }
|