示例#1
0
 /// <summary>
 /// 更新设备下的通道集合
 /// </summary>
 /// <param name="device">设备</param>
 /// <param name="channels">通道集合</param>
 private void UpdateChannels(FlowDevice device, List <FlowChannel> channels)
 {
     device.FlowDevice_FlowChannels = new List <FlowDevice_FlowChannel>();
     if (channels != null)
     {
         foreach (var channel in channels)
         {
             FlowDevice_FlowChannel relation = new FlowDevice_FlowChannel
             {
                 DeviceId  = device.DeviceId,
                 ChannelId = channel.ChannelId
             };
             device.FlowDevice_FlowChannels.Add(relation);
             if (!ChannelsManager.UpdateChannel(_context, channel))
             {
                 ChannelsManager.AddChannel(_context, channel);
             }
         }
     }
 }
示例#2
0
        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);
        }