예제 #1
0
        protected override void OpenCore()
        {
            _ok      = 0;
            _unknown = 0;

            _broadcastBlock    = new BroadcastBlock <TrafficDensity>(d => d);
            _fiveBatchBlock    = new BatchBlock <TrafficDensity>(BatchSize);
            _fifteenBatchBlock = new BatchBlock <TrafficDensity>(BatchSize);
            _sixtyBatchBlock   = new BatchBlock <TrafficDensity>(BatchSize);

            _oneBatchBlock  = new BatchBlock <TrafficDensity>(BatchSize);
            _cacheBlock     = new DensityCacheBlock();
            _webSocketBlock = new DensityWebSocketBlock();

            _dbBlock = new DensityDbBlock(ThreadCount, _serviceProvider);

            _regionBlocks.Clear();
            foreach (DensityDevice device in _devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        DensityRegionBlock block = new DensityRegionBlock(_serviceProvider);
                        block.LinkTo(_broadcastBlock, _fiveBatchBlock, _fifteenBatchBlock, _sixtyBatchBlock);
                        _regionBlocks.TryAdd(region.MatchId, new Item
                        {
                            Block  = block,
                            DataId = region.DataId
                        });
                    }
                }
            }

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

            _oneBatchBlock.LinkTo(_dbBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = false
            });
            _fiveBatchBlock.LinkTo(_dbBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = false
            });
            _fifteenBatchBlock.LinkTo(_dbBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = false
            });
            _sixtyBatchBlock.LinkTo(_dbBlock.InputBlock, new DataflowLinkOptions {
                PropagateCompletion = false
            });
        }
예제 #2
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))
                        {
                            DensityRegionBlock block = new DensityRegionBlock(_serviceProvider);
                            block.LinkTo(_broadcastBlock, _fiveBatchBlock, _fifteenBatchBlock, _sixtyBatchBlock);
                            _regionBlocks.TryAdd(region.MatchId, new Item
                            {
                                Block  = block,
                                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}");
                        }
                    }
                }
            }
        }