/// <summary> /// 删除路口 /// </summary> /// <param name="crossingId">路口编号</param> /// <param name="userName">用户名</param> /// <returns>删除结果</returns> public IStatusCodeActionResult Remove(int crossingId, string userName = null) { RoadCrossing roadCrossing = _context.RoadCrossings.SingleOrDefault(d => d.CrossingId == crossingId); if (roadCrossing == null) { return(new NotFoundResult()); } try { _context.RoadCrossings.Remove(roadCrossing); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑路口, userName), $"删除路口 {roadCrossing}"); return(new OkResult()); } catch (DbUpdateException) { if (_context.Channels.Count(c => c.CrossingId == crossingId) > 0) { ModelStateDictionary modelState = new ModelStateDictionary(); modelState.AddModelError("Channel", "存在关联的通道"); return(new BadRequestObjectResult(modelState)); } else { throw; } } }
/// <summary> /// 添加路口 /// </summary> /// <param name="roadCrossing">路口</param> /// <param name="userName">用户名</param> /// <returns>添加结果</returns> public ObjectResult Add([FromBody] RoadCrossing roadCrossing, string userName = null) { _context.RoadCrossings.Add(roadCrossing); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑路口, userName), $"添加路口 {roadCrossing}"); return(new OkObjectResult(roadCrossing)); }
// END CUT HERE // BEGIN CUT HERE public static void Main() { RoadCrossing ___test = new RoadCrossing(); ___test.run_test(-1); try { } catch(Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
// END CUT HERE // BEGIN CUT HERE public static void Main() { RoadCrossing ___test = new RoadCrossing(); ___test.run_test(-1); try { } catch (Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
/// <summary> /// 查询路口 /// </summary> /// <param name="crossingId">路口编号</param> /// <returns>查询结果</returns> public IStatusCodeActionResult Get(int crossingId) { RoadCrossing roadCrossing = _context.RoadCrossings.SingleOrDefault(c => c.CrossingId == crossingId); if (roadCrossing == null) { return(new NotFoundObjectResult(null)); } else { return(new OkObjectResult(roadCrossing)); } }
/// <summary> /// 更新路口 /// </summary> /// <param name="updateRoadCrossing">路口</param> /// <param name="userName">用户名</param> /// <returns>更新结果</returns> public IStatusCodeActionResult Update(RoadCrossing updateRoadCrossing, string userName = null) { RoadCrossing roadCrossing = _context.RoadCrossings.SingleOrDefault(d => d.CrossingId == updateRoadCrossing.CrossingId); if (roadCrossing == null) { return(new NotFoundResult()); } roadCrossing.CrossingName = updateRoadCrossing.CrossingName; _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑路口, userName), $"更新路口 {roadCrossing}"); return(new OkResult()); }
public IActionResult Update([FromBody] RoadCrossing roadCrossing) { return(_manager.Update(roadCrossing, User?.Identity?.Name)); }
public static List <DensityDevice> CreateDensityDevice(IServiceProvider serviceProvider, int deviceCount, int channelCount, int regionCount, string ip = "127.0.0.1", bool initDatabase = false) { List <DensityDevice> devices = new List <DensityDevice>(); using (IServiceScope serviceScope = serviceProvider.CreateScope()) { using (DensityContext context = serviceScope.ServiceProvider.GetRequiredService <DensityContext>()) { if (initDatabase) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); } int deviceId = 20000; int crossingId = 20000; int regionId = 20000; int port = 17000; for (int i = 0; i < deviceCount; ++i) { DensityDevice device = new DensityDevice { DeviceId = deviceId, DeviceModel = (int)DeviceModel.MO_AF_A11_04_4X, Ip = ip, DataPort = port, Port = port }; device.DeviceName = "高点测试设备" + device.DataPort; device.DensityDevice_DensityChannels = new List <DensityDevice_DensityChannel>(); for (int j = 0; j < channelCount; ++j) { RoadCrossing roadCrossing = new RoadCrossing { CrossingId = crossingId, CrossingName = "高点测试路口" + crossingId }; DensityChannel channel = new DensityChannel() { ChannelId = $"channel_{device.DeviceId}_{j + 1}", ChannelName = $"高点测试通道 { device.DeviceId} {j + 1}", ChannelType = (int)ChannelType.GB28181, ChannelIndex = j + 1, CrossingId = crossingId, Regions = new List <TrafficRegion>(), RoadCrossing = roadCrossing }; DensityDevice_DensityChannel relation = new DensityDevice_DensityChannel { ChannelId = channel.ChannelId, DeviceId = device.DeviceId, Channel = channel }; port++; deviceId++; crossingId++; device.DensityDevice_DensityChannels.Add(relation); for (int k = 0; k < regionCount; ++k) { channel.Regions.Add(new TrafficRegion { ChannelId = channel.ChannelId, Channel = channel, RegionIndex = k + 1, RegionName = "高点测试区域" + regionId++, Region = "[]", IsVip = true, CarCount = 1, DensityRange = 1, Density = 1, Frequency = 1, Warning = 1, Saturation = 1, WarningDuration = 1 }); } } context.Devices.Add(device); devices.Add(device); context.SaveChanges(); } } } return(devices); }
public static List <FlowDevice> CreateFlowDevice(IServiceProvider serviceProvider, int deviceCount, int channelCount, int laneCount, bool initDatabase = false, string ip1 = "127.0.0.", int ip2 = 1, int id = 100) { List <FlowDevice> devices = new List <FlowDevice>(); using (FlowContext context = serviceProvider.CreateScope().ServiceProvider.GetRequiredService <FlowContext>()) { if (initDatabase) { ResetDatabase(serviceProvider); } for (int i = 0; i < deviceCount; ++i) { FlowDevice device = new FlowDevice { DeviceId = id, DeviceName = $"流量测试设备_{id}", DeviceModel = (int)DeviceModel.MO_AF_A11_04_4X, Ip = $"{ip1}{ip2++}", Port = 17000, FlowDevice_FlowChannels = new List <FlowDevice_FlowChannel>() }; for (int j = 0; j < channelCount; ++j) { RoadCrossing roadCrossing = new RoadCrossing { CrossingId = id, CrossingName = $"流量测试路口_{id}" }; RoadSection roadSection = new RoadSection { SectionId = id, SectionName = $"流量测试通路段_{id}", SectionType = (int)SectionType.主干路, SpeedLimit = 10, Length = 10, Direction = (int)LaneDirection.由东向西 }; FlowChannel channel = new FlowChannel { ChannelId = $"channel_{id}", ChannelName = $"流量测试通道_{id}", ChannelIndex = j + 1, CrossingId = id, SectionId = id, ChannelType = (int)ChannelType.GB28181, Lanes = new List <Lane>(), RoadCrossing = roadCrossing, RoadSection = roadSection }; FlowDevice_FlowChannel relation = new FlowDevice_FlowChannel { DeviceId = id, ChannelId = channel.ChannelId, Channel = channel }; id++; device.FlowDevice_FlowChannels.Add(relation); for (int k = 0; k < laneCount; ++k) { LaneDirection direction; if (k >= 0 && k < 3) { direction = LaneDirection.由南向北; } else if (k >= 3 && k < 6) { direction = LaneDirection.由北向南; } else if (k >= 6 && k < 9) { direction = LaneDirection.由东向西; } else { direction = LaneDirection.由西向东; } FlowDirection flowDirection; if (k % 3 == 0) { flowDirection = FlowDirection.直行; } else if (k % 3 == 1) { flowDirection = FlowDirection.左转; } else { flowDirection = FlowDirection.右转; } channel.Lanes.Add(new Lane { ChannelId = channel.ChannelId, LaneId = $"{k + 1:D2}", LaneName = $"流量测试车道_{k + 1:D2}", Channel = channel, Direction = (int)direction, FlowDirection = (int)flowDirection, LaneIndex = k + 1, Region = "[]", Length = 10 }); } } context.Devices.Add(device); devices.Add(device); context.SaveChanges(); } } return(devices); }
/// <summary> /// 获取路口 /// </summary> /// <param name="memoryCache">缓存</param> /// <param name="crossingId">路段编号</param> /// <param name="defaultCrossing">默认返回结果</param> /// <returns>路段</returns> public static RoadCrossing GetCrossing(this IMemoryCache memoryCache, int?crossingId, RoadCrossing defaultCrossing) { if (crossingId.HasValue) { return(memoryCache.TryGetValue(GetCrossingKey(crossingId.Value), out RoadCrossing crossing) ? crossing : defaultCrossing); } else { return(defaultCrossing); } }
public void QueryVipRegions() { List <DensityDevice> devices = new List <DensityDevice>(); int deviceCount = 1; int channelCount = 1; int regionCount = 12; HashSet <string> vips = new HashSet <string>(); //随机创建重点区域 Random random = new Random(); using (IServiceScope serviceScope = TestInit.ServiceProvider.CreateScope()) { using (DensityContext context = serviceScope.ServiceProvider.GetRequiredService <DensityContext>()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); int deviceId = 1; int crossingId = 1; int regionId = 1; int channelId = 1; for (int i = 0; i < deviceCount; ++i) { DensityDevice densityDevice = new DensityDevice { DeviceId = deviceId++, Ip = "192.168.200.204", Port = 18000 + i }; densityDevice.DeviceName = "设备" + densityDevice.Port; densityDevice.DensityDevice_DensityChannels = new List <DensityDevice_DensityChannel>(); for (int j = 0; j < channelCount; ++j) { RoadCrossing roadCrossing = new RoadCrossing { CrossingId = crossingId, CrossingName = "路口" + crossingId }; DensityChannel channel = new DensityChannel() { ChannelId = channelId.ToString(), ChannelName = $"通道 {densityDevice.DeviceId} {j+1}", ChannelIndex = j + 1, CrossingId = crossingId, Regions = new List <TrafficRegion>(), RoadCrossing = roadCrossing }; DensityDevice_DensityChannel relation = new DensityDevice_DensityChannel { ChannelId = channel.ChannelId, DeviceId = densityDevice.DeviceId, Channel = channel }; channelId++; crossingId++; densityDevice.DensityDevice_DensityChannels.Add(relation); for (int k = 0; k < regionCount; ++k) { int value = random.Next(1, 2); TrafficRegion region = new TrafficRegion { ChannelId = channel.ChannelId, Channel = channel, Region = "1", RegionIndex = k + 1, RegionName = "区域" + regionId++, IsVip = value == 1 }; if (value == 1) { vips.Add(region.DataId); } channel.Regions.Add(region); } } context.Devices.Add(densityDevice); devices.Add(densityDevice); } context.SaveChanges(); } DensityDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, DateTime.Today, DateTime.Today); TestInit.RefreshDensityCache(devices); DensitiesManager manager = TestInit.ServiceProvider.GetRequiredService <DensitiesManager>(); var v = manager.QueryVipRegions(); foreach (TrafficDensity density in v) { Assert.IsTrue(vips.Contains(density.DataId)); } } }