Exemplo n.º 1
0
        public static void CreateData(IServiceProvider serviceProvider, List <DensityDevice> devices, DateTime startDate, bool initDatabase = false)
        {
            if (initDatabase)
            {
                ResetDatabase(serviceProvider);
            }

            using (IServiceScope serviceScope = serviceProvider.CreateScope())
            {
                EventBranchBlock branch = new EventBranchBlock(serviceScope.ServiceProvider);
                branch.Open(devices);
                int h = 0;
                foreach (DensityDevice device in devices)
                {
                    foreach (var relation in device.DensityDevice_DensityChannels)
                    {
                        foreach (TrafficRegion region in relation.Channel.Regions)
                        {
                            branch.Post(new TrafficEvent
                            {
                                MatchId  = $"{device.Ip}_{relation.Channel.ChannelIndex}_{region.RegionIndex}",
                                DateTime = startDate.AddHours(h)
                            });
                            ++h;
                        }
                    }
                }

                branch.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 重置服务
        /// </summary>
        private void Reset()
        {
            List <DensityDevice> devices = InitCache();

            _logger.LogInformation((int)LogEvent.系统, "重启数据适配");
            DensityAdapter densityAdapter = _serviceProvider.GetRequiredService <DensityAdapter>();

            densityAdapter.Reset(devices);
            DensityBranchBlock densityBranchBlock = _serviceProvider.GetRequiredService <DensityBranchBlock>();
            EventBranchBlock   eventBranchBlock   = _serviceProvider.GetRequiredService <EventBranchBlock>();

            densityBranchBlock.Reset(devices);
            eventBranchBlock.Reset(devices);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化缓存
        /// </summary>
        /// <param name="devices">设备集合</param>
        private void InitAdapter(List <DensityDevice> devices)
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化数据适配");

            DateTime           minTime            = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, DateTime.Now);
            DateTime           maxTime            = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
            DensityAdapter     densityAdapter     = _serviceProvider.GetRequiredService <DensityAdapter>();
            DensityBranchBlock densityBranchBlock = _serviceProvider.GetRequiredService <DensityBranchBlock>();
            EventBranchBlock   eventBranchBlock   = _serviceProvider.GetRequiredService <EventBranchBlock>();

            densityBranchBlock.Open(devices, minTime, maxTime);
            eventBranchBlock.Open(devices);
            densityAdapter.Start(devices, densityBranchBlock, eventBranchBlock);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 开始适配器
        /// </summary>
        /// <param name="devices">设备集合</param>
        /// <param name="densityBranchBlock">密度数据块分支</param>
        /// <param name="eventBranchBlock">事件数据块分支</param>
        public void Start(List <DensityDevice> devices, DensityBranchBlock densityBranchBlock, EventBranchBlock eventBranchBlock)
        {
            _startTime = DateTime.Now;

            _densityBranchBlock = densityBranchBlock;
            _eventBranchBlock   = eventBranchBlock;

            foreach (DensityDevice device in devices.Where(d => d.DensityDevice_DensityChannels.Count > 0 && d.DensityDevice_DensityChannels.Any(r => r.Channel.Regions.Count > 0)))
            {
                WebSocketClientChannel websocket = new WebSocketClientChannel(GetDeviceUrl(device));
                websocket.WebSocketReceived += ReceiveHandler;
                _clients.TryAdd(GetDeviceKey(device), new Item
                {
                    Channel = websocket
                });
                websocket.Start();
            }
        }