Example #1
0
 public static void SetDestinationAirportData(this PlaneContract planeContract, AirportContract airportContract)
 {
     planeContract.DestinationAirportName      = airportContract.Name;
     planeContract.DestinationAirportLatitude  = airportContract.Latitude;
     planeContract.DestinationAirportLongitude = airportContract.Longitude;
     planeContract.Color = airportContract.Color;
 }
Example #2
0
        public static void SetNewDestinationAndDepartureAirports(this PlaneContract planeContract, AirportContract newDestinationAirportContract)
        {
            planeContract.DepartureAirportName      = planeContract.DestinationAirportName;
            planeContract.DepartureAirportLatitude  = planeContract.DestinationAirportLatitude;
            planeContract.DepartureAirportLongitude = planeContract.DestinationAirportLongitude;

            planeContract.SetDestinationAirportData(newDestinationAirportContract);
        }
Example #3
0
        public async Task <HttpResponseMessage> UpdatePlane(PlaneContract planeContract, string updatePlaneUrl)
        {
            var response = await _httpClient.PutAsync(
                updatePlaneUrl,
                new StringContent(JsonConvert.SerializeObject(planeContract),
                                  Encoding.UTF8, "application/json"));

            return(response);
        }
Example #4
0
        public static void AddPositionToHistory(this PlaneContract planeContract, double latitude, double longitude)
        {
            if (planeContract.PreviousPositionsLatitude.Count >= planeContract.PositionsHistory)
            {
                planeContract.PreviousPositionsLatitude.RemoveAt(0);
                planeContract.PreviousPositionsLongitude.RemoveAt(0);
            }

            planeContract.PreviousPositionsLatitude.Add(latitude);
            planeContract.PreviousPositionsLongitude.Add(longitude);
        }
Example #5
0
        public IActionResult UpdatePlane([FromBody] PlaneContract planeContract)
        {
            try
            {
                _trafficInfoService.UpdatePlane(planeContract);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Example #6
0
 public void AddPlane(PlaneContract planeContract)
 {
     //tolist local copy needed for concurrent collection modification errors
     //if (!_TrafficInfoContract.Planes.Any(p => p.Name == planeContract.Name))
     if (!_trafficInfoContract.Planes.Select(p => p.Name)
         .ToList()
         .Contains(planeContract.Name))
     {
         _trafficInfoContract.Planes.Add(planeContract);
     }
     else
     {
         throw new Exception(planeContract.Name + " already exists");
     }
 }
Example #7
0
        public Plane(string name)
        {
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddConsole();
            });

            _logger = loggerFactory.CreateLogger <Plane>();
            PlaneReachedItsDestination = false;
            _planeContract             = new PlaneContract
            {
                Name = name,
                SpeedInMetersPerSecond = 1000000 //business constant - speed is as such for updates to be notable - export to some config ?
            };
        }
Example #8
0
        public void UpdatePlane(PlaneContract planeContract)
        {
            if (!_trafficInfoContract.Planes.Select(p => p.Name)
                .ToList()
                .Contains(planeContract.Name))
            {
                throw new Exception(planeContract.Name + " does not exist");
            }
            else
            {
                var planeToUpdate = _trafficInfoContract.Planes.First(p => p.Name == planeContract.Name);

                //make a separate presentation model out of it?
                planeToUpdate.Latitude     = planeContract.Latitude;
                planeToUpdate.Longitude    = planeContract.Longitude;
                planeToUpdate.Color        = planeContract.Color;
                planeToUpdate.SymbolRotate = planeContract.SymbolRotate;
            }
        }
Example #9
0
        /// <summary>
        /// Updates Latitude and Longitude by speed, destination airport amd time passed since last departure airport till now
        /// Based on: https://www.movable-type.co.uk/scripts/latlong.html#destPoint
        /// </summary>
        /// <param name="geoCoordinate"></param>
        public static void MovePlane(ref PlaneContract plane, DateTime currentTime)//TODO is ref really needed here ????
        {
            //given:
            //  departure time and current time
            //  speed
            //  destination position and departure position

            //calculate:
            //  traveled distance
            //  bearing
            //  current position from departure position, distance and bearing

            //double lat1 = plane.DepartureAirport.Latitude;
            //double lon1 = plane.DepartureAirport.Longitude;
            double lat1 = plane.Latitude;
            double lon1 = plane.Longitude;
            double lat2 = plane.DestinationAirportLatitude;
            double lon2 = plane.DestinationAirportLongitude;

            double lat1Rad = ToRadians(lat1);
            double lon1Rad = ToRadians(lon1);
            double lat2Rad = ToRadians(lat2);
            double lon2Rad = ToRadians(lon2);

            //var travelDurationInMiliseconds = currentTime.Subtract(plane.DepartureTime).TotalMilliseconds;
            var travelDurationSinceLastUpdateInMiliseconds = currentTime.Subtract(plane.LastPositionUpdate).TotalMilliseconds;
            var distanceCoveredInMeters = plane.SpeedInMetersPerSecond * travelDurationSinceLastUpdateInMiliseconds / 1000;
            //var bearing = CalculateBearing(plane.DepartureAirport.Latitude, plane.DepartureAirport.Longitude, plane.DestinationAirport.Latitude, plane.DestinationAirport.Longitude);

            var bearing  = BearingFromCoordinates(lat1Rad, lon1Rad, lat2Rad, lon2Rad);
            var position = CalculatePosition(lat1Rad, lon1Rad, bearing, distanceCoveredInMeters);

            plane.SymbolRotate = bearing;
            plane.Latitude     = position[0];
            plane.Longitude    = position[1];
        }
Example #10
0
 public static void SetDepartureAirportData(this PlaneContract planeContract, AirportContract airportContract)
 {
     planeContract.DepartureAirportName      = airportContract.Name;
     planeContract.DepartureAirportLatitude  = airportContract.Latitude;
     planeContract.DepartureAirportLongitude = airportContract.Longitude;
 }