protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            //{"error":"NO_DATA unknown airline INVALID"}
            var result = HttpExecutor.AirlineInfo(args);

            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData)
            {
                Errors.Add(result.Error);
            }

            if (QueryArgs.ContainsVariable("airlineCode"))
            {
                result.Data.airlineCode = (string)QueryArgs["airlineCode"].PropertyValue.Value;
            }

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(AirlineInfo));

            var rows = new List <Row>();

            if (result.Error == null)
            {
                rows.Add(new Row()
                {
                    Values = ToValues(result.Data, tableDescriptor)
                });
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            var result = HttpExecutor.AirportInfo(args);

            if (result.Error != null)
            {
                Errors.Add(result.Error);
            }

            if (QueryArgs.ContainsVariable("airportCode"))
            {
                result.Data.airportCode = (string)QueryArgs["airportCode"].PropertyValue.Value;
            }

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(AirportInfo));

            var rows = new List <Row>();

            if (result.Error == null)
            {
                rows.Add(new Row()
                {
                    Values = ToValues(result.Data, tableDescriptor)
                });
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override void ValidateArgs()
        {
            base.ValidateArgs();

            if (QueryArgs.ContainsVariable("airport"))
            {
                QueryArgs["airport"].PropertyValue = new PropertyValue(((string)(QueryArgs["airport"].PropertyValue.Value ?? "")).ToUpper());
            }
        }
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            var result = HttpExecutor.GetMapFlight(args);

            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData)
            {
                Errors.Add(result.Error);
            }

            var dto = result.Data;

            if (QueryArgs.ContainsVariable("ident"))
            {
                dto.ident = (string)QueryArgs["ident"].PropertyValue.Value;
            }

            long mapHeight = 480;

            if (QueryArgs.ContainsVariable("mapHeight"))
            {
                mapHeight = (long)QueryArgs["mapHeight"].PropertyValue.Value;
            }

            long mapWidth = 640;

            if (QueryArgs.ContainsVariable("mapWidth"))
            {
                mapWidth = (long)QueryArgs["mapWidth"].PropertyValue.Value;
            }

            dto.mapHeight = mapHeight;
            dto.mapWidth  = mapWidth;

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(MapFlight));

            var rows = new List <Row>();

            if (result.Error == null)
            {
                rows.Add(new Row()
                {
                    Values = ToValues(dto, tableDescriptor)
                });
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override void ValidateArgs()
        {
            base.ValidateArgs();

            if (QueryArgs.ContainsVariable("ident"))
            {
                QueryArgs["ident"].PropertyValue = new PropertyValue(((string)(QueryArgs["ident"].PropertyValue.Value ?? "")).ToUpper());
            }
            else if (QueryArgs.ContainsVariable("faFlightID"))
            {
                var flightid = QueryArgs["faFlightID"];
                QueryArgs.Clear();
                QueryArgs.Add(new EqualQueryArg {
                    Variable = "ident", PropertyValue = new PropertyValue(flightid.PropertyValue.Value)
                });
            }
        }
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            var result = HttpExecutor.GetFlightID(args);

            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData)
            {
                Errors.Add(result.Error);
            }

            long departerTimeValue = 0;

            if (QueryArgs.ContainsVariable("departuretime"))
            {
                departerTimeValue = (long)(QueryArgs["departuretime"].PropertyValue.Value ?? 0L);
            }

            string identValue = string.Empty;

            if (QueryArgs.ContainsVariable("ident"))
            {
                identValue = (string)QueryArgs["ident"].PropertyValue.Value;
            }

            var dto = result.Data;

            dto.departureTime = (DateTime)Conversion.ConvertLongToDateTime(departerTimeValue);
            dto.ident         = identValue;

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(GetFlightId));

            var rows = new List <Row>();

            if (result.Error == null)
            {
                rows.Add(new Row()
                {
                    Values = ToValues(dto, tableDescriptor)
                });
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            var result = HttpExecutor.GetInboundFlightInfo(args);

            //{ "error":"INVALID_ARGUMENT Inbound flight is not known"}
            //{ "error":"INVALID_ARGUMENT: invalid {faFlightID}"}
            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.InvalidArgument) //don't show invalid args as errors
            {
                Errors.Add(result.Error);
            }

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(InboundFlightInfo));

            var dto = result.Data;

            dto.ifaFlightID = dto.faFlightID;

            string faFlightID = string.Empty;

            if (QueryArgs.ContainsVariable("faFlightID"))
            {
                faFlightID = (string)QueryArgs["faFlightID"].PropertyValue.Value;
            }

            dto.faFlightID = faFlightID;

            var rows = new List <Row>();

            if (result.Error == null)
            {
                rows.Add(new Row()
                {
                    Values = ToValues(dto, tableDescriptor)
                });
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            var result = HttpExecutor.GetDeparted(args);

            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData)
            {
                Errors.Add(result.Error);
            }

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(Departed));

            var rows = new List <Row>();

            if (result.Data != null && result.Error == null)
            {
                foreach (var d in result.Data)
                {
                    if (QueryArgs.ContainsVariable("airport"))
                    {
                        d.airport = (string)QueryArgs["airport"].PropertyValue.Value;
                    }

                    if (QueryArgs.ContainsVariable("filter"))
                    {
                        d.filter = (string)QueryArgs["filter"].PropertyValue.Value;
                    }

                    var row = new Row()
                    {
                        Values = ToValues(d, tableDescriptor)
                    };
                    rows.Add(row);
                }
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
Beispiel #9
0
        protected override ExecutedTable ExecuteCore(HttpExecuteArg args)
        {
            //{ "error":"INVALID: invalid {faFlightID}"}
            var result = HttpExecutor.GetHistoricalTrack(args);

            if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData)
            {
                Errors.Add(result.Error);
            }

            TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(GetHistoricalTrack));

            var rows = new List <Row>();

            if (result.Data != null && result.Error == null)
            {
                foreach (var d in result.Data)
                {
                    if (QueryArgs.ContainsVariable("faFlightID"))
                    {
                        d.faFlightID = (string)QueryArgs["faFlightID"].PropertyValue.Value;
                    }

                    var row = new Row()
                    {
                        Values = ToValues(d, tableDescriptor)
                    };
                    rows.Add(row);
                }
            }

            return(new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            });
        }
        protected override void ValidateArgs()
        {
            base.ValidateArgs();

            if (QueryArgs.ContainsVariable("origin"))
            {
                QueryArgs["origin"].PropertyValue = new PropertyValue(((string)(QueryArgs["origin"].PropertyValue.Value ?? "")).ToUpper());
            }

            if (QueryArgs.ContainsVariable("destination"))
            {
                QueryArgs["destination"].PropertyValue = new PropertyValue(((string)(QueryArgs["destination"].PropertyValue.Value ?? "")).ToUpper());
            }

            if (QueryArgs.ContainsVariable("ident"))
            {
                QueryArgs["ident"].PropertyValue = new PropertyValue(((string)(QueryArgs["ident"].PropertyValue.Value ?? "")).ToUpper());
            }

            var departTimeCount = QueryArgs.Args.Where(x => x.Variable == "departuretime").Count();

            if (departTimeCount > 2)
            {
                throw new InvalidOperationException("Can only have 2 departureTime");
            }

            if (QueryArgs.ContainsVariable("ident"))
            {
                var ident = QueryArgs["ident"];
                var match = Regex.Match(ident.PropertyValue.Value.ToString(), @"(\D+)(\d+)", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    var airline  = match.Groups[1].Value;
                    var flightno = match.Groups[2].Value;
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "airline", PropertyValue = new PropertyValue(airline)
                    });
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "flightno", PropertyValue = new PropertyValue(flightno)
                    });
                    QueryArgs.Remove(ident);
                }
            }

            if (departTimeCount == 1)
            {
                var param = QueryArgs["departuretime"];
                if (((param is QueryGreaterThan || param is QueryGreaterThanEqual) && param.LeftProperty) ||
                    ((param is QueryLessThan || param is QueryLessThanEqual) && !param.LeftProperty))
                {
                    param.Variable = "startDate";
                    var startDate = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var endDate   = startDate.AddDays(7); //no end date we just assume a week forward
                    QueryArgs.Add(new QueryArgs {
                        Variable = "endDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(endDate))
                    });
                }
                else if (((param is QueryLessThan || param is QueryLessThanEqual) && param.LeftProperty) ||
                         ((param is QueryGreaterThan || param is QueryGreaterThanEqual) && !param.LeftProperty))
                {
                    param.Variable = "endDate";
                    var endDate   = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var startDate = endDate.AddDays(-7); //no end date we just move a week backword
                    QueryArgs.Add(new QueryArgs {
                        Variable = "startDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(startDate))
                    });
                }
                else if (param is EqualQueryArg)
                {
                    param.Variable = "startDate";
                    var startDate = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var endDate   = startDate.AddMinutes(1);
                    startDate = startDate.AddMinutes(-1);

                    param.PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(startDate));
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "endDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(endDate))
                    });
                }
            }
            else //two departureTImes
            {
                foreach (var param in QueryArgs.Args.Where(x => x.Variable == "departuretime"))
                {
                    if (((param is QueryGreaterThan || param is QueryGreaterThanEqual) && param.LeftProperty) ||
                        ((param is QueryLessThan || param is QueryLessThanEqual) && !param.LeftProperty))
                    {
                        param.Variable = "startDate";
                    }
                    else if (((param is QueryLessThan || param is QueryLessThanEqual) && param.LeftProperty) ||
                             ((param is QueryGreaterThan || param is QueryGreaterThanEqual) && !param.LeftProperty))
                    {
                        param.Variable = "endDate";
                    }
                }
            }
        }