public void TestMethod1()
        {
            LaneManager bla = new LaneManager(null, new settings());
            FieldInfo fi = typeof(LaneManager).GetField("_lanes", BindingFlags.NonPublic | BindingFlags.Instance);
            Dictionary<string, Lane> lanes = fi.GetValue(bla) as Dictionary<string, Lane>;

            Lane A, B = null;
            lanes.TryGetValue("N4", out A);
            lanes.TryGetValue("N5", out B);

            Assert.IsTrue(A.IsCompatible(B));
            Assert.IsTrue(B.IsCompatible(A));
        }
        private void mainloop()
        {
            Stopwatch timer = new Stopwatch();
            Queue<vehicle> vehicleQueue = new Queue<vehicle>(_xmlData.vehicles);
            vehicle candidate = null;
            LaneManager laneManager = new LaneManager(_server,_xmlData.settings);

            //todo: wait on incoming connections first
            while (!isStopped)
            {
                if (_server.IsStopped)
                {
                    Thread.Sleep(1);
                    continue;
                }

                if (!timer.IsRunning)
                    timer.Start();

                try
                {
                    if (candidate == null)
                        candidate = vehicleQueue.Dequeue();
                }
                catch { }

                try
                {
                    if (candidate != null && candidate.spawnTime < timer.ElapsedMilliseconds)
                    {
                        string arg = String.Format("{0},{1},{2}", candidate.type, candidate.location, candidate.direction);
                    //    if (candidate.type != "PEDESTRIAN" && candidate.type != "BICYCLE")
                        _server.RPCSendQueue.Enqueue(new RPCData() { type = 0, arg = arg });
                        //if (candidate.location == "N" && candidate.type == "PEDESTRIAN")
                        //    _controllerDialog.LoggerControl.Log(LogType.Spam, String.Format("Vehicle {0} spawned on {1}", candidate.type, candidate.location));
                        candidate = null;
                    }

                    RPCData sensorInfo;
                    while (_server.RPCReceiveQueue.TryDequeue(out sensorInfo))
                    {
                        string[] sensorInfoS = sensorInfo.arg.Split(',');
                        laneManager.SetSensor(sensorInfoS[0], sensorInfoS[1], sensorInfoS[2]);
                    }

                    DateTime currentDate = _xmlData.settings.startDate + new TimeSpan(timer.ElapsedTicks);

                    if (currentDate.TimeOfDay > ALL_DISABLED_START && !isDisabled && currentDate.TimeOfDay < ALL_DISABLED_START + ALL_DISABLED_TIME)
                    {
                        laneManager.SetAnyTrafficLights((l) => l.Vehicle != Vehicle.CAR, (int) ALL_DISABLED_TIME.TotalMilliseconds, TrafficLightState.Off);
                        isDisabled = true;
                    }

                    if (currentDate.TimeOfDay > CAR_OUTAGE_START && !outageDisabled && currentDate.TimeOfDay < CAR_OUTAGE_START + CAR_OUTAGE_TIME)
                    {
                        laneManager.SetAnyTrafficLights((l) => l.Vehicle == Vehicle.CAR, (int)CAR_OUTAGE_TIME.TotalMilliseconds, TrafficLightState.Outage);
                        outageDisabled = true;
                    }

                    if (currentDate.TimeOfDay > CAR_DISABLED_START && !isDisabledCars && currentDate.TimeOfDay < CAR_DISABLED_START + CAR_DISABLED_TIME)
                    {
                        laneManager.SetAnyTrafficLights((l) => l.Vehicle == Vehicle.CAR, (int)CAR_DISABLED_TIME.TotalMilliseconds, TrafficLightState.Off);
                        isDisabledCars = true;
                    }

                    laneManager.Update();
                }
            #if DEBUG
                catch (EncoderFallbackException e)
            #else
                catch (Exception e)
            #endif
                {
                    _controllerDialog.LoggerControl.Log(e);
                }

                Thread.Sleep(1);
            }
        }