Esempio n. 1
0
        private AircraftListJsonBuilderFilter ExpandModelFilters(List<GetAircraftListFilter> filters)
        {
            AircraftListJsonBuilderFilter result = null;

            if(filters != null) {
                foreach(var jsonFilter in filters) {
                    switch(jsonFilter.Field) {
                        case GetAircraftListFilterField.Airport:        result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Airport = v); break;
                        case GetAircraftListFilterField.Altitude:       result = JsonToIntRangeFilter(jsonFilter, result,     (f,v) => f.Altitude = v); break;
                        case GetAircraftListFilterField.Callsign:       result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Callsign = v); break;
                        case GetAircraftListFilterField.Country:        result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Icao24Country = v); break;
                        case GetAircraftListFilterField.Distance:       result = JsonToDoubleRangeFilter(jsonFilter, result,  (f,v) => f.Distance = v); break;
                        case GetAircraftListFilterField.HasPosition:    result = JsonToBoolFilter(jsonFilter, result,         (f,v) => f.MustTransmitPosition = v); break;
                        case GetAircraftListFilterField.Icao:           result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Icao24 = v); break;
                        case GetAircraftListFilterField.IsInteresting:  result = JsonToBoolFilter(jsonFilter, result,         (f,v) => f.IsInteresting = v); break;
                        case GetAircraftListFilterField.IsMilitary:     result = JsonToBoolFilter(jsonFilter, result,         (f,v) => f.IsMilitary = v); break;
                        case GetAircraftListFilterField.ModelIcao:      result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Type = v); break;
                        case GetAircraftListFilterField.Operator:       result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Operator = v); break;
                        case GetAircraftListFilterField.OperatorIcao:   result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.OperatorIcao = v); break;
                        case GetAircraftListFilterField.PositionBounds: result = JsonToCoordPair(jsonFilter, result,          (f,v) => f.PositionWithin = v); break;
                        case GetAircraftListFilterField.Registration:   result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.Registration = v); break;
                        case GetAircraftListFilterField.Squawk:         result = JsonToIntRangeFilter(jsonFilter, result,     (f,v) => f.Squawk = v); break;
                        case GetAircraftListFilterField.UserTag:        result = JsonToStringFilter(jsonFilter, result,       (f,v) => f.UserTag = v); break;

                        case GetAircraftListFilterField.EngineType:     result = JsonToEnumFilter<EngineType>(jsonFilter, result,             (f,v) => f.EngineType = v); break;
                        case GetAircraftListFilterField.Species:        result = JsonToEnumFilter<Species>(jsonFilter, result,                (f,v) => f.Species = v); break;
                        case GetAircraftListFilterField.WTC:            result = JsonToEnumFilter<WakeTurbulenceCategory>(jsonFilter, result, (f,v) => f.WakeTurbulenceCategory = v); break;
                    }
                }
            }

            return result;
        }
Esempio n. 2
0
        private void DoAssignFilter<T>(ref AircraftListJsonBuilderFilter result, Action<AircraftListJsonBuilderFilter, T> assignFilter, T filter)
        {
            if(result == null) {
                result = new AircraftListJsonBuilderFilter();
            }

            assignFilter(result, filter);
        }
Esempio n. 3
0
        private AircraftListJsonBuilderFilter AircraftListJsonBuilderFilterFromQueryString()
        {
            AircraftListJsonBuilderFilter result = null;

            var query = PipelineContext.Request.Query;

            foreach (var kvp in query.Where(r => r.Key.Length > 3 && (r.Key[0] == 'f' || r.Key[0] == 'F')))
            {
                var key   = kvp.Key.ToUpper();
                var value = kvp.Value == null || kvp.Value.Length < 1 ? "" : kvp.Value[0] ?? "";
                switch (key.Substring(0, 3))
                {
                case "FAI":     result = DecodeStringFilter("FAIR", key, value, result, (f, v) => f.Airport = v); break;

                case "FCA":     result = DecodeStringFilter("FCALL", key, value, result, (f, v) => f.Callsign = v); break;

                case "FCO":     result = DecodeStringFilter("FCOU", key, value, result, (f, v) => f.Icao24Country = v); break;

                case "FIC":     result = DecodeStringFilter("FICO", key, value, result, (f, v) => f.Icao24 = v); break;

                case "FOP":     result = DecodeStringFilter("FOPICAO", key, value, result, (f, v) => f.OperatorIcao = v);
                    result             = DecodeStringFilter("FOP", key, value, result, (f, v) => f.Operator = v); break;

                case "FRE":     result = DecodeStringFilter("FREG", key, value, result, (f, v) => f.Registration = v); break;

                case "FTY":     result = DecodeStringFilter("FTYP", key, value, result, (f, v) => f.Type = v); break;

                case "FUT":     result = DecodeStringFilter("FUT", key, value, result, (f, v) => f.UserTag = v); break;

                case "FIN":     result = DecodeBoolFilter("FINT", key, value, result, (f, v) => f.IsInteresting = v); break;

                case "FMI":     result = DecodeBoolFilter("FMIL", key, value, result, (f, v) => f.IsMilitary = v); break;

                case "FNO":     result = DecodeBoolFilter("FNOPOS", key, value, result, (f, v) => f.MustTransmitPosition = v); break;

                case "FAL":     result = DecodeIntRangeFilter("FALT", key, value, result, f => f.Altitude, (f, v) => f.Altitude = v); break;

                case "FSQ":     result = DecodeIntRangeFilter("FSQK", key, value, result, f => f.Squawk, (f, v) => f.Squawk = v); break;

                case "FDS":     result = DecodeDoubleRangeFilter("FDST", key, value, result, f => f.Distance, (f, v) => f.Distance = v); break;

                case "FEG":     result = DecodeEnumFilter <EngineType>            ("FEGT", key, value, result, (f, v) => f.EngineType = v); break;

                case "FSP":     result = DecodeEnumFilter <Species>               ("FSPC", key, value, result, (f, v) => f.Species = v); break;

                case "FWT":     result = DecodeEnumFilter <WakeTurbulenceCategory>("FWTC", key, value, result, (f, v) => f.WakeTurbulenceCategory = v); break;
                }
            }

            result = DecodeBounds(result, query["FNBND"], query["FWBND"], query["FSBND"], query["FEBND"]);

            return(result);
        }
Esempio n. 4
0
        private AircraftListJsonBuilderFilter JsonToCoordPair(GetAircraftListFilter jsonFilter, AircraftListJsonBuilderFilter result, Action<AircraftListJsonBuilderFilter, Pair<Coordinate>> assignPair)
        {
            if(jsonFilter.North != null && jsonFilter.South != null && jsonFilter.West != null && jsonFilter.East != null) {
                if(result == null) {
                    result = new AircraftListJsonBuilderFilter();
                }

                result.PositionWithin = new Pair<Coordinate>(
                    new Coordinate(jsonFilter.North.Value, jsonFilter.West.Value),
                    new Coordinate(jsonFilter.South.Value, jsonFilter.East.Value)
                );
            }

            return result;
        }
Esempio n. 5
0
        private AircraftListJsonBuilderFilter DecodeBounds(AircraftListJsonBuilderFilter result, string northText, string westText, string southText, string eastText)
        {
            if(!String.IsNullOrEmpty(northText) && !String.IsNullOrEmpty(westText) && !String.IsNullOrEmpty(southText) && !String.IsNullOrEmpty(eastText)) {
                if(double.TryParse(northText, NumberStyles.Any, CultureInfo.InvariantCulture, out double north) &&
                   double.TryParse(southText, NumberStyles.Any, CultureInfo.InvariantCulture, out double south) &&
                   double.TryParse(westText,  NumberStyles.Any, CultureInfo.InvariantCulture, out double west) &&
                   double.TryParse(eastText,  NumberStyles.Any, CultureInfo.InvariantCulture, out double east)) {
                    if(result == null) {
                        result = new AircraftListJsonBuilderFilter();
                    }
                    result.PositionWithin = new Pair<Coordinate>(
                        new Coordinate(north, west),
                        new Coordinate(south, east)
                    );
                }
            }

            return result;
        }
Esempio n. 6
0
        private AircraftListJsonBuilderFilter DecodeStringFilter(string prefix, string key, string value, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterString> assignFilter)
        {
            var filter = new FilterString();

            switch (DecodeFilter(prefix, filter, key))
            {
            case 'C':
            case 'E':
            case 'Q':
            case 'S':
                filter.Value = value;
                DoAssignFilter(ref result, assignFilter, filter);
                break;
            }

            return(result);
        }
Esempio n. 7
0
        private AircraftListJsonBuilderFilter DecodeIntRangeFilter(string prefix, string key, string value, AircraftListJsonBuilderFilter result, Func <AircraftListJsonBuilderFilter, FilterRange <int> > getFilter, Action <AircraftListJsonBuilderFilter, FilterRange <int> > assignFilter)
        {
            if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out int intValue))
            {
                var filter = result == null ? new FilterRange <int>() : getFilter(result);
                switch (DecodeFilter(prefix, filter, key))
                {
                case 'L':   filter.LowerValue = intValue; break;

                case 'U':   filter.UpperValue = intValue; break;

                default:    filter = null; break;
                }
                if (filter != null)
                {
                    DoAssignFilter(ref result, assignFilter, filter);
                }
            }

            return(result);
        }
Esempio n. 8
0
        private AircraftListJsonBuilderFilter DecodeEnumFilter <T>(string prefix, string key, string value, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterEnum <T> > assignFilter)
            where T : struct, IComparable
        {
            if (!String.IsNullOrEmpty(value) && Enum.TryParse <T>(value, out T enumValue))
            {
                if (Enum.IsDefined(typeof(T), enumValue))
                {
                    var filter = new FilterEnum <T>()
                    {
                        Value = enumValue,
                    };
                    if (DecodeFilter(prefix, filter, key) == 'Q')
                    {
                        DoAssignFilter(ref result, assignFilter, filter);
                    }
                }
            }

            return(result);
        }
Esempio n. 9
0
        private AircraftListJsonBuilderFilter DecodeBoolFilter(string prefix, string key, string value, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterBool> assignFilter)
        {
            var filter = new FilterBool();

            if (DecodeFilter(prefix, filter, key) == 'Q')
            {
                if (!String.IsNullOrEmpty(value))
                {
                    filter.Value = value != "0" && !value.Equals("false", StringComparison.OrdinalIgnoreCase);
                    DoAssignFilter(ref result, assignFilter, filter);
                }
            }

            return(result);
        }
Esempio n. 10
0
        private AircraftListJsonBuilderFilter JsonToStringFilter(GetAircraftListFilter jsonFilter, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterString> assignFilter)
        {
            switch (jsonFilter.Condition)
            {
            case FilterCondition.Contains:
            case FilterCondition.EndsWith:
            case FilterCondition.Equals:
            case FilterCondition.StartsWith:
                DoAssignFilter(ref result, assignFilter, new FilterString()
                {
                    Condition        = jsonFilter.Condition,
                    Value            = jsonFilter.Value ?? "",
                    ReverseCondition = jsonFilter.Not,
                });
                break;
            }

            return(result);
        }
Esempio n. 11
0
        private AircraftListJsonBuilderFilter JsonToIntRangeFilter(GetAircraftListFilter jsonFilter, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterRange <int> > assignFilter)
        {
            switch (jsonFilter.Condition)
            {
            case FilterCondition.Missing:
            case FilterCondition.Between:
                DoAssignFilter(ref result, assignFilter, new FilterRange <int>()
                {
                    Condition        = FilterCondition.Between,
                    LowerValue       = (int?)jsonFilter.From,
                    UpperValue       = (int?)jsonFilter.To,
                    ReverseCondition = jsonFilter.Not,
                });
                break;
            }

            return(result);
        }
Esempio n. 12
0
        private AircraftListJsonBuilderFilter JsonToEnumFilter <T>(GetAircraftListFilter jsonFilter, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterEnum <T> > assignFilter)
            where T : struct, IComparable
        {
            switch (jsonFilter.Condition)
            {
            case FilterCondition.Missing:
            case FilterCondition.Equals:
                if (!String.IsNullOrEmpty(jsonFilter.Value) && Enum.TryParse <T>(jsonFilter.Value, out T enumValue))
                {
                    if (Enum.IsDefined(typeof(T), enumValue))
                    {
                        DoAssignFilter(ref result, assignFilter, new FilterEnum <T>()
                        {
                            Condition        = FilterCondition.Equals,
                            Value            = enumValue,
                            ReverseCondition = jsonFilter.Not,
                        });
                    }
                }
                break;
            }

            return(result);
        }
Esempio n. 13
0
        private AircraftListJsonBuilderFilter JsonToBoolFilter(GetAircraftListFilter jsonFilter, AircraftListJsonBuilderFilter result, Action <AircraftListJsonBuilderFilter, FilterBool> assignFilter)
        {
            switch (jsonFilter.Condition)
            {
            case FilterCondition.Missing:
            case FilterCondition.Equals:
                if (jsonFilter.Is != null)
                {
                    DoAssignFilter(ref result, assignFilter, new FilterBool()
                    {
                        Condition        = FilterCondition.Equals,
                        Value            = jsonFilter.Is.Value,
                        ReverseCondition = jsonFilter.Not,
                    });
                }
                break;
            }

            return(result);
        }