public void ProximityGadgetClosestAircraftJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var json = new ProximityGadgetClosestAircraftJson();

            TestUtilities.TestProperty(json, "Altitude", null, "Abc");
            TestUtilities.TestProperty(json, "BearingFromHere", null, "Abc");
            TestUtilities.TestProperty(json, "Callsign", null, "Abc");
            TestUtilities.TestProperty(json, "Destination", null, "Abc");
            TestUtilities.TestProperty(json, "DistanceFromHere", null, "Abc");
            TestUtilities.TestProperty(json, "Emergency", false);
            TestUtilities.TestProperty(json, "GroundSpeed", null, "Abc");
            TestUtilities.TestProperty(json, "HasPicture", false);
            TestUtilities.TestProperty(json, "Icao24", null, "Abc");
            TestUtilities.TestProperty(json, "Icao24Invalid", false);
            TestUtilities.TestProperty(json, "Latitude", null, "Abc");
            TestUtilities.TestProperty(json, "Longitude", null, "Abc");
            TestUtilities.TestProperty(json, "Manufacturer", null, "Abc");
            TestUtilities.TestProperty(json, "Model", null, "Abc");
            TestUtilities.TestProperty(json, "Operator", null, "Abc");
            TestUtilities.TestProperty(json, "OperatorIcao", null, "Abc");
            TestUtilities.TestProperty(json, "Origin", null, "Abc");
            TestUtilities.TestProperty(json, "Registration", null, "Abc");
            TestUtilities.TestProperty(json, "Squawk", null, "Abc");
            TestUtilities.TestProperty(json, "Track", null, "Abc");
            TestUtilities.TestProperty(json, "Type", null, "Abc");
            TestUtilities.TestProperty(json, "VerticalRate", null, "Abc");
            Assert.AreEqual(0, json.Stopovers.Count);
        }
示例#2
0
        /// <summary>
        /// Returns a model given an aircraft list and a point to measure from.
        /// </summary>
        /// <param name="aircraftList"></param>
        /// <param name="originLatitude"></param>
        /// <param name="originLongitude"></param>
        /// <returns></returns>
        public static ProximityGadgetAircraftJson ToModel(IEnumerable <IAircraft> aircraftList, double?originLatitude, double?originLongitude)
        {
            ProximityGadgetAircraftJson result = null;

            if (aircraftList != null)
            {
                result = new ProximityGadgetAircraftJson();

                if (originLatitude == null || originLongitude == null)
                {
                    result.WarningMessage = "Position not supplied";
                }
                else
                {
                    IAircraft closestAircraft = null;
                    double?   closestDistance = null;

                    foreach (var aircraft in aircraftList)
                    {
                        double?distance = null;
                        if (aircraft.Latitude != null && aircraft.Longitude != null)
                        {
                            distance = GreatCircleMaths.Distance(originLatitude, originLongitude, aircraft.Latitude, aircraft.Longitude);
                            if (distance != null && closestAircraft == null || distance < closestDistance)
                            {
                                closestAircraft = aircraft;
                                closestDistance = distance;
                            }
                        }

                        if (aircraft.Emergency == true)
                        {
                            result.EmergencyAircraft.Add(ProximityGadgetClosestAircraftJson.ToModel(aircraft, originLatitude, originLongitude));
                        }
                    }

                    if (closestAircraft != null)
                    {
                        result.ClosestAircraft = ProximityGadgetClosestAircraftJson.ToModel(closestAircraft, originLatitude, originLongitude);
                    }
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Creates a new model from an aircraft object passed across. The aircraft passed in is assumed to be a clone, i.e.
        /// the properties on the aircraft cannot change over the lifetime of the call.
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="originLatitude">The latitude to measure distances from.</param>
        /// <param name="originLongitude">The longitude to measure distances from.</param>
        /// <returns></returns>
        public static ProximityGadgetClosestAircraftJson ToModel(IAircraft aircraft, double?originLatitude, double?originLongitude)
        {
            ProximityGadgetClosestAircraftJson result = null;

            if (aircraft != null)
            {
                double?distance = null;
                if (aircraft.Latitude != null && aircraft.Longitude != null)
                {
                    distance = GreatCircleMaths.Distance(originLatitude, originLongitude, aircraft.Latitude, aircraft.Longitude);
                }

                result = new ProximityGadgetClosestAircraftJson()
                {
                    Altitude         = FormatNullable(aircraft.Altitude),
                    BearingFromHere  = FormatNullable(GreatCircleMaths.Bearing(originLatitude, originLongitude, aircraft.Latitude, aircraft.Longitude, null, false, false), null, 1),
                    Callsign         = aircraft.Callsign,
                    Destination      = aircraft.Destination,
                    DistanceFromHere = FormatNullable(distance, null, 2),
                    Emergency        = aircraft.Emergency.GetValueOrDefault(),
                    GroundSpeed      = FormatNullable(aircraft.GroundSpeed),
                    HasPicture       = !String.IsNullOrEmpty(aircraft.PictureFileName),
                    Icao24           = aircraft.Icao24 ?? "",
                    Icao24Invalid    = aircraft.Icao24Invalid,
                    Latitude         = FormatNullable(aircraft.Latitude),
                    Longitude        = FormatNullable(aircraft.Longitude),
                    Manufacturer     = aircraft.Manufacturer,
                    Model            = aircraft.Model,
                    Operator         = aircraft.Operator,
                    OperatorIcao     = aircraft.OperatorIcao,
                    Origin           = aircraft.Origin,
                    Registration     = aircraft.Registration,
                    Squawk           = aircraft.Squawk.GetValueOrDefault() == 0 ? null : String.Format("{0:0000}", aircraft.Squawk),
                    Track            = FormatNullable(aircraft.Track, null, 1),
                    Type             = aircraft.Type,
                    VerticalRate     = FormatNullable(aircraft.VerticalRate),
                };
            }

            return(result);
        }
        /// <summary>
        /// Creates an object that represents an aircraft in <see cref="ProximityGadgetAircraftJson"/>.
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="distance"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        private ProximityGadgetClosestAircraftJson CreateProximityGadgetClosestAircraftJson(IAircraft aircraft, double? distance, double? latitude, double? longitude)
        {
            var result = new ProximityGadgetClosestAircraftJson() {
                Altitude = FormatNullable(aircraft.Altitude),
                BearingFromHere = FormatNullable(GreatCircleMaths.Bearing(latitude, longitude, aircraft.Latitude, aircraft.Longitude, null, false, false), null, 1),
                Callsign = aircraft.Callsign,
                Destination = aircraft.Destination,
                DistanceFromHere = FormatNullable(distance, null, 2),
                Emergency = aircraft.Emergency.GetValueOrDefault(),
                GroundSpeed = FormatNullable(aircraft.GroundSpeed),
                HasPicture = !String.IsNullOrEmpty(aircraft.PictureFileName),
                Icao24 = aircraft.Icao24 ?? "",
                Icao24Invalid = aircraft.Icao24Invalid,
                Latitude = FormatNullable(aircraft.Latitude),
                Longitude = FormatNullable(aircraft.Longitude),
                Manufacturer = aircraft.Manufacturer,
                Model = aircraft.Model,
                Operator = aircraft.Operator,
                OperatorIcao = aircraft.OperatorIcao,
                Origin = aircraft.Origin,
                Registration = aircraft.Registration,
                Squawk = aircraft.Squawk.GetValueOrDefault() == 0 ? null : String.Format("{0:0000}", aircraft.Squawk),
                Track = FormatNullable(aircraft.Track, null, 1),
                Type = aircraft.Type,
                VerticalRate = FormatNullable(aircraft.VerticalRate),
            };
            result.Stopovers.AddRange(aircraft.Stopovers);

            return result;
        }