Exemplo n.º 1
0
        protected override void ResetCore(List <DensityDevice> devices)
        {
            foreach (DensityDevice newDevice in devices)
            {
                foreach (var relation in newDevice.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        if (!_regionBlocks.ContainsKey(region.MatchId))
                        {
                            EventRegionBlock regionBlock = new EventRegionBlock(_serviceProvider);
                            regionBlock.LinkTo(_broadcastBlock, _updateDbBlock.InputBlock);
                            _regionBlocks.TryAdd(region.MatchId, new Item
                            {
                                Block  = regionBlock,
                                DataId = region.DataId
                            });
                            _logger.LogInformation((int)LogEvent.事件数据块, $"事件添加区域 {region.MatchId}");
                        }
                    }
                }
            }

            foreach (DensityDevice oldDevice in _devices)
            {
                foreach (var relation in oldDevice.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        if (devices.SelectMany(d => d.DensityDevice_DensityChannels)
                            .Select(r => r.Channel)
                            .SelectMany(c => c.Regions)
                            .All(r => r.MatchId != region.MatchId))
                        {
                            if (_regionBlocks.TryRemove(region.MatchId, out Item item))
                            {
                                item.Block.InputBlock.Complete();
                                item.Block.WaitCompletion();
                            }
                            _logger.LogInformation((int)LogEvent.高点数据块, $"事件删除区域 {region.MatchId}");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void OpenCore()
        {
            _ok      = 0;
            _unknown = 0;

            _broadcastBlock = new BroadcastBlock <TrafficEvent>(e => e);
            _insertDbBlock  = new EventInsertDbBlock(ThreadCount, _serviceProvider);
            _updateDbBlock  = new EventUpdateDbBlock(ThreadCount, _serviceProvider);
            _cacheBlock     = new EventCacheBlock();
            _webSocketBlock = new EventWebSocketBlock(_serviceProvider);

            _regionBlocks.Clear();
            foreach (DensityDevice device in _devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        EventRegionBlock regionBlock = new EventRegionBlock(_serviceProvider);
                        regionBlock.LinkTo(_broadcastBlock, _updateDbBlock.InputBlock);
                        _regionBlocks.TryAdd(region.MatchId, new Item
                        {
                            Block  = regionBlock,
                            DataId = region.DataId
                        });
                    }
                }
            }

            _broadcastBlock.LinkTo(_insertDbBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            _broadcastBlock.LinkTo(_cacheBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            _broadcastBlock.LinkTo(_webSocketBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });
        }