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(); } }
/// <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); }