Example #1
0
        /// <summary>
        /// Extract the filter arguments from the request and returns them collected into an object.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private AircraftListJsonBuilderFilter ConstructFilter(RequestReceivedEventArgs args)
        {
            var result = new AircraftListJsonBuilderFilter()
            {
                AltitudeLower                = QueryNInt(args, "fAltL"),
                AltitudeUpper                = QueryNInt(args, "fAltU"),
                CallsignContains             = QueryString(args, "fCall", true),
                DistanceLower                = QueryNDouble(args, "fDstL"),
                DistanceUpper                = QueryNDouble(args, "fDstU"),
                EngineTypeEquals             = QueryNEnum <EngineType>(args, "fEgt"),
                Icao24CountryContains        = QueryString(args, "fCou", true),
                IsInterestingEquals          = QueryNBool(args, "fInt"),
                IsMilitaryEquals             = QueryNBool(args, "fMil"),
                MustTransmitPosition         = QueryNBool(args, "fNoPos") ?? false,
                OperatorContains             = QueryString(args, "fOp", true),
                RegistrationContains         = QueryString(args, "fReg", true),
                SpeciesEquals                = QueryNEnum <Species>(args, "fSpc"),
                SquawkLower                  = QueryNInt(args, "fSqkL"),
                SquawkUpper                  = QueryNInt(args, "fSqkU"),
                TypeStartsWith               = QueryString(args, "fTyp", true),
                WakeTurbulenceCategoryEquals = QueryNEnum <WakeTurbulenceCategory>(args, "fWtc"),
            };

            double?northBounds = QueryNDouble(args, "fNBnd");
            double?eastBounds  = QueryNDouble(args, "fEBnd");
            double?southBounds = QueryNDouble(args, "fSBnd");
            double?westBounds  = QueryNDouble(args, "fWBnd");

            if (northBounds != null && southBounds != null && westBounds != null && eastBounds != null)
            {
                result.PositionWithin = new Pair <Coordinate>(
                    new Coordinate((float)northBounds, (float)westBounds),
                    new Coordinate((float)southBounds, (float)eastBounds)
                    );
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Extract the filter arguments from the request and returns them collected into an object.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private AircraftListJsonBuilderFilter ConstructFilter(RequestReceivedEventArgs args)
        {
            var result = new AircraftListJsonBuilderFilter();

            foreach (string name in args.QueryString)
            {
                if (name.Length < 3)
                {
                    continue;
                }
                var caselessName = name.ToUpper();
                var partialName  = caselessName.Substring(0, 3);
                switch (partialName.ToUpper())
                {
                case "FAI":     if (caselessName.StartsWith("FAIR"))
                    {
                        result.Airport = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FAL":     if (caselessName.StartsWith("FALT"))
                    {
                        result.Altitude = DecodeIntRangeFilter(result.Altitude, name, args.QueryString[name]);
                    }
                    break;

                case "FCA":     if (caselessName.StartsWith("FCALL"))
                    {
                        result.Callsign = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FCO":     if (caselessName.StartsWith("FCOU"))
                    {
                        result.Icao24Country = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FDS":     if (caselessName.StartsWith("FDST"))
                    {
                        result.Distance = DecodeDoubleRangeFilter(result.Distance, name, args.QueryString[name]);
                    }
                    break;

                case "FEG":     if (caselessName.StartsWith("FEGT"))
                    {
                        result.EngineType = DecodeEnumFilter <EngineType>(name, args.QueryString[name]);
                    }
                    break;

                case "FIC":     if (caselessName.StartsWith("FICO"))
                    {
                        result.Icao24 = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FIN":     if (caselessName.StartsWith("FINT"))
                    {
                        result.IsInteresting = DecodeBoolFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FMI":     if (caselessName.StartsWith("FMIL"))
                    {
                        result.IsMilitary = DecodeBoolFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FNO":     if (caselessName.StartsWith("FNOPOS"))
                    {
                        result.MustTransmitPosition = DecodeBoolFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FOP":     if (caselessName.StartsWith("FOPICAO"))
                    {
                        result.OperatorIcao = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    else
                    {
                        result.Operator = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FRE":     if (caselessName.StartsWith("FREG"))
                    {
                        result.Registration = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FSP":     if (caselessName.StartsWith("FSPC"))
                    {
                        result.Species = DecodeEnumFilter <Species>(name, args.QueryString[name]);
                    }
                    break;

                case "FSQ":     if (caselessName.StartsWith("FSQK"))
                    {
                        result.Squawk = DecodeIntRangeFilter(result.Squawk, name, args.QueryString[name]);
                    }
                    break;

                case "FTY":     if (caselessName.StartsWith("FTYP"))
                    {
                        result.Type = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FUT":     if (caselessName.StartsWith("FUT"))
                    {
                        result.UserTag = DecodeStringFilter(name, args.QueryString[name]);
                    }
                    break;

                case "FWT":     if (caselessName.StartsWith("FWTC"))
                    {
                        result.WakeTurbulenceCategory = DecodeEnumFilter <WakeTurbulenceCategory>(name, args.QueryString[name]);
                    }
                    break;
                }
            }

            double?northBounds = QueryNDouble(args, "fNBnd");
            double?eastBounds  = QueryNDouble(args, "fEBnd");
            double?southBounds = QueryNDouble(args, "fSBnd");
            double?westBounds  = QueryNDouble(args, "fWBnd");

            if (northBounds != null && southBounds != null && westBounds != null && eastBounds != null)
            {
                result.PositionWithin = new Pair <Coordinate>(
                    new Coordinate((float)northBounds, (float)westBounds),
                    new Coordinate((float)southBounds, (float)eastBounds)
                    );
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Returns true if the aircraft passes the filter criteria passed across.
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private bool PassesFilter(IAircraft aircraft, AircraftListJsonBuilderFilter filter)
        {
            bool result = filter == null;

            if (!result)
            {
                result = true;
                if (filter.AltitudeLower != null)
                {
                    result = aircraft.Altitude != null && aircraft.Altitude >= filter.AltitudeLower;
                }
                if (result && filter.AltitudeUpper != null)
                {
                    result = aircraft.Altitude != null && aircraft.Altitude <= filter.AltitudeUpper;
                }
                if (result && !String.IsNullOrEmpty(filter.CallsignContains))
                {
                    result = aircraft.Callsign != null && aircraft.Callsign.Contains(filter.CallsignContains);
                }
                if (result && filter.EngineTypeEquals != null)
                {
                    result = aircraft.EngineType == filter.EngineTypeEquals;
                }
                if (result && !String.IsNullOrEmpty(filter.Icao24CountryContains))
                {
                    result = aircraft.Icao24Country != null && aircraft.Icao24Country.ToUpperInvariant().Contains(filter.Icao24CountryContains);
                }
                if (result && filter.IsInterestingEquals != null)
                {
                    result = aircraft.IsInteresting == filter.IsInterestingEquals;
                }
                if (result && filter.IsMilitaryEquals != null)
                {
                    result = aircraft.IsMilitary == filter.IsMilitaryEquals;
                }
                if (result && filter.MustTransmitPosition)
                {
                    result = aircraft.Latitude != null && aircraft.Longitude != null;
                }
                if (result && !String.IsNullOrEmpty(filter.OperatorContains))
                {
                    result = aircraft.Operator != null && aircraft.Operator.ToUpperInvariant().Contains(filter.OperatorContains);
                }
                if (result && filter.PositionWithin != null)
                {
                    result = IsWithinBounds(aircraft.Latitude, aircraft.Longitude, filter.PositionWithin);
                }
                if (result && !String.IsNullOrEmpty(filter.RegistrationContains))
                {
                    result = aircraft.Registration != null && aircraft.Registration.Contains(filter.RegistrationContains);
                }
                if (result && filter.SpeciesEquals != null)
                {
                    result = aircraft.Species == filter.SpeciesEquals;
                }
                if (result && filter.SquawkLower != null)
                {
                    result = aircraft.Squawk != null && aircraft.Squawk >= filter.SquawkLower;
                }
                if (result && filter.SquawkUpper != null)
                {
                    result = aircraft.Squawk != null && aircraft.Squawk <= filter.SquawkUpper;
                }
                if (result && !String.IsNullOrEmpty(filter.TypeStartsWith))
                {
                    result = aircraft.Type != null && aircraft.Type.StartsWith(filter.TypeStartsWith);
                }
                if (result && filter.WakeTurbulenceCategoryEquals != null)
                {
                    result = aircraft.WakeTurbulenceCategory == filter.WakeTurbulenceCategoryEquals;
                }
            }

            return(result);
        }
        /// <summary>
        /// Extract the filter arguments from the request and returns them collected into an object.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private AircraftListJsonBuilderFilter ConstructFilter(RequestReceivedEventArgs args)
        {
            var result = new AircraftListJsonBuilderFilter() {
                AltitudeLower =                 QueryNInt(args, "fAltL"),
                AltitudeUpper =                 QueryNInt(args, "fAltU"),
                CallsignContains =              QueryString(args, "fCall", true),
                DistanceLower =                 QueryNDouble(args, "fDstL"),
                DistanceUpper =                 QueryNDouble(args, "fDstU"),
                EngineTypeEquals =              QueryNEnum<EngineType>(args, "fEgt"),
                Icao24CountryContains =         QueryString(args, "fCou", true),
                IsInterestingEquals =           QueryNBool(args, "fInt"),
                IsMilitaryEquals =              QueryNBool(args, "fMil"),
                MustTransmitPosition =          QueryNBool(args, "fNoPos") ?? false,
                OperatorContains =              QueryString(args, "fOp", true),
                RegistrationContains =          QueryString(args, "fReg", true),
                SpeciesEquals =                 QueryNEnum<Species>(args, "fSpc"),
                SquawkLower =                   QueryNInt(args, "fSqkL"),
                SquawkUpper =                   QueryNInt(args, "fSqkU"),
                TypeStartsWith =                QueryString(args, "fTyp", true),
                WakeTurbulenceCategoryEquals =  QueryNEnum<WakeTurbulenceCategory>(args, "fWtc"),
            };

            double? northBounds = QueryNDouble(args, "fNBnd");
            double? eastBounds = QueryNDouble(args, "fEBnd");
            double? southBounds = QueryNDouble(args, "fSBnd");
            double? westBounds = QueryNDouble(args, "fWBnd");

            if(northBounds != null && southBounds != null && westBounds != null && eastBounds != null) {
                result.PositionWithin = new Pair<Coordinate>(
                    new Coordinate((float)northBounds, (float)westBounds),
                    new Coordinate((float)southBounds, (float)eastBounds)
                );
            }

            return result;
        }
        /// <summary>
        /// Returns true if the aircraft passes the filter criteria passed across.
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private bool PassesFilter(IAircraft aircraft, AircraftListJsonBuilderFilter filter)
        {
            bool result = filter == null;

            if(!result) {
                result = true;
                if(filter.AltitudeLower != null)                                  result = aircraft.Altitude != null && aircraft.Altitude >= filter.AltitudeLower;
                if(result && filter.AltitudeUpper != null)                        result = aircraft.Altitude != null && aircraft.Altitude <= filter.AltitudeUpper;
                if(result && !String.IsNullOrEmpty(filter.CallsignContains))      result = aircraft.Callsign != null && aircraft.Callsign.Contains(filter.CallsignContains);
                if(result && filter.EngineTypeEquals != null)                     result = aircraft.EngineType == filter.EngineTypeEquals;
                if(result && !String.IsNullOrEmpty(filter.Icao24CountryContains)) result = aircraft.Icao24Country != null && aircraft.Icao24Country.ToUpperInvariant().Contains(filter.Icao24CountryContains);
                if(result && filter.IsInterestingEquals != null)                  result = aircraft.IsInteresting == filter.IsInterestingEquals;
                if(result && filter.IsMilitaryEquals != null)                     result = aircraft.IsMilitary == filter.IsMilitaryEquals;
                if(result && filter.MustTransmitPosition)                         result = aircraft.Latitude != null && aircraft.Longitude != null;
                if(result && !String.IsNullOrEmpty(filter.OperatorContains))      result = aircraft.Operator != null && aircraft.Operator.ToUpperInvariant().Contains(filter.OperatorContains);
                if(result && filter.PositionWithin != null)                       result = IsWithinBounds(aircraft.Latitude, aircraft.Longitude, filter.PositionWithin);
                if(result && !String.IsNullOrEmpty(filter.RegistrationContains))  result = aircraft.Registration != null && aircraft.Registration.Contains(filter.RegistrationContains);
                if(result && filter.SpeciesEquals != null)                        result = aircraft.Species == filter.SpeciesEquals;
                if(result && filter.SquawkLower != null)                          result = aircraft.Squawk != null && aircraft.Squawk >= filter.SquawkLower;
                if(result && filter.SquawkUpper != null)                          result = aircraft.Squawk != null && aircraft.Squawk <= filter.SquawkUpper;
                if(result && !String.IsNullOrEmpty(filter.TypeStartsWith))        result = aircraft.Type != null && aircraft.Type.StartsWith(filter.TypeStartsWith);
                if(result && filter.WakeTurbulenceCategoryEquals != null)         result = aircraft.WakeTurbulenceCategory == filter.WakeTurbulenceCategoryEquals;
            }

            return result;
        }