public void Run(CancellationToken token)
        {
            var rnd = new Random();

            for (int cameraNum = 0; cameraNum < this.numCameras; cameraNum++)
            {
                double latRange           = this.latNorth - this.latSouth;
                double cameraLatPosition  = rnd.NextDouble() * latRange + this.latSouth;
                double longRange          = this.longEast - this.longWest;
                double cameraLongPosition = rnd.NextDouble() * longRange + this.longWest;
                string cameraName         = $"Camera {cameraNum}";

                var camera = new SpeedCamera(this.eventHubName, cameraNum, cameraName, cameraLatPosition, cameraLongPosition);
                Task.Factory.StartNew(() => camera.SendVehicleAlerts());
            }

            while (!token.IsCancellationRequested)
            {
                // Run until the user stops the cameras by pressing Enter
            }

            this.runCompleteEvent.Set();
        }
Example #2
0
        public void Run(CancellationToken token)
        {
            var rnd = new Random();

            for (int cameraNum = 0; cameraNum < this.numCameras; cameraNum++)
            {
                double cameraLatPosition  = 0;
                double cameraLongPosition = 0;

                if (isTrainingRun)
                {
                    // Generate random positions for cameras, and then save them
                    double latRange = this.latNorth - this.latSouth;
                    cameraLatPosition = rnd.NextDouble() * latRange + this.latSouth;
                    double longRange = this.longEast - this.longWest;
                    cameraLongPosition = rnd.NextDouble() * longRange + this.longWest;

                    CameraStateManager.SaveCameraData(cameraNum, cameraLatPosition, cameraLongPosition);
                }
                else
                {
                    // Use the existing camera positions (must reuse the same locations and names for the training data to be valid)
                    CameraStateManager.GetCameraData(cameraNum, out cameraLatPosition, out cameraLongPosition);
                }

                string cameraName = $"Camera {cameraNum}";
                var    camera     = new SpeedCamera(this.eventHubName, cameraNum, cameraName, cameraLatPosition, cameraLongPosition, isTrainingRun);
                Task.Factory.StartNew(() => camera.SendVehicleAlerts());
            }

            while (!token.IsCancellationRequested)
            {
                // Run until the user stops the cameras by pressing Enter
            }

            this.runCompleteEvent.Set();
        }