protected override ExecutedTable ExecuteCore(HttpExecuteArg args) { var result = HttpExecutor.AirlineFlightSchedule(args); if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData) { Errors.Add(result.Error); } TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(AirlineFlightSchedule)); var rows = new List <Row>(); if (result.Data != null && result.Error == null) { foreach (var d in result.Data) { var row = new Row() { Values = ToValues(d, tableDescriptor) }; rows.Add(row); } } 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 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.GetInFlightInfo(args); if (result.Error != null && result.Error.Type != ApiExecuteErrorType.NoData) { Errors.Add(result.Error); } TableDescriptor tableDescriptor = PropertyDescriptor.GenerateRunDescriptor(typeof(InFlightInfo)); var dto = result.Data; var rows = new List <Row>(); if (result.Error == null) { rows.Add(new Row() { Values = ToValues(dto, tableDescriptor) }); } return(new ExecutedTable(tableDescriptor) { Rows = rows.ToArray() }); }
private async Task <ExecuteResult> ExecuteInternal(HttpExecuteArg args) { var json = string.Empty; ApiExecuteError error = null; try { using (var client = new HttpClient()) { var dict = new Dictionary <string, string>(); foreach (var arg in args.Variables) { dict.Add(arg.Variable, arg.Value.ToString()); } client.DefaultRequestHeaders.Add("Authorization", Authorization); var result = await client.PostAsync(BaseUrl + args.TableName, new FormUrlEncodedContent(dict)); if (result.StatusCode == System.Net.HttpStatusCode.Unauthorized) //auth error { error = new ApiExecuteError(ApiExecuteErrorType.AuthError, "Authentication error"); } else if (result.StatusCode != HttpStatusCode.OK) // some other error { string message = await result.Content.ReadAsStringAsync(); error = new ApiExecuteError(ApiExecuteErrorType.Fail, message); } else { //{"error":"NO_DATA unknown airport INVALID"} //{"error":"NO_DATA flight not found"} //{"error":"INVALID_ARGUMENT endDate is too far in the future (12 months)"} json = await result.Content.ReadAsStringAsync(); } } } catch (Exception) { return(new ExecuteResult() { Result = string.Empty, Error = new ApiExecuteError(ApiExecuteErrorType.Fail, "Api error") }); } return(new ExecuteResult() { Result = json, Error = error }); }
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() }); }
public sealed override ExecutedTable Execute(LimitStatement statement) { LimitQuery(statement); ValidateArgs(); var args = new HttpExecuteArg() { Variables = QueryArgs.Args.Select(x => new HttpQueryVariabels() { Variable = x.Variable, Value = x.PropertyValue.Value.ToString() }), TableName = TableName }; return(ExecuteCore(args)); }
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() }); }
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 abstract ExecutedTable ExecuteCore(HttpExecuteArg args);
public ExecuteResult GetInFlightInfo(HttpExecuteArg args) { return(Task.Run(async() => await ExecuteInternal(args)).Result); }
public ExecuteResult GetAirlineFlightSchedule(HttpExecuteArg args) { return(Task.Run(async() => await ExecuteInternal(args)).Result); }
public ExecuteResult GetDeparted(HttpExecuteArg args) { return(Task.Run(async() => await ExecuteInternal(args)).Result); }
public ExecuteResult GetHistoricalTrack(HttpExecuteArg args) { return(Task.Run(async() => await ExecuteInternal(args)).Result); }