public async System.Threading.Tasks.Task InputLoop() { string input = null; var parser = new Parser(); while (!nameof(Commands.Quit).Equals(input, StringComparison.OrdinalIgnoreCase)) { txtOut.WriteLine("Syntax: Origin-Destination outDate [inDate]"); txtOut.Write(">>"); input = txtIn.ReadLine(); if (!Command(input)) { foreach (string query in input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { SASQuery req = null; try { req = parser.Parse(query); req.Mode = options.Mode; } catch (ParserException ex) { txtOut.Write("Syntax error:" + ex.Message); } catch { txtOut.Write("Syntax error:"); } if (req != null) { SearchResult result = null; try { result = await client.SearchAsync(req); } catch { txtOut.WriteLine("Error"); } if (result != null) { if (result.errors != null && result.errors.Any()) { txtOut.WriteLine("flysas.com says: " + result.errors.First().errorMessage); } else { var printer = new TablePrinter(txtOut); txtOut.WriteLine("*********Outbound*******"); printer.PrintFlights(result.outboundFlights, options); if (req.InDate.HasValue) { txtOut.WriteLine("*********Inbound*******"); printer.PrintFlights(result.inboundFlights, options); } } } txtOut.Write(Environment.NewLine + Environment.NewLine); } } } } }
public async System.Threading.Tasks.Task Run(string input) { var parser = new Parser(); foreach (string query in input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { if (!Command(query)) { SASQuery req = null; try { req = parser.Parse(query.Trim()); req.Mode = options.Mode; } catch (ParserException ex) { txtOut.WriteLine("Syntax error:" + ex.Message); } catch { txtOut.WriteLine("Syntax error:"); } if (req != null) { var outDateStart = req.OutDate.Value; var inDateStart = req.InDate; for (var i = 0; i < options.Days; i++) { req.OutDate = outDateStart.AddDays(i); if (inDateStart.HasValue) { req.InDate = inDateStart.Value.AddDays(i); } SearchResult result = null; try { result = await client.SearchAsync(req); } catch { txtOut.WriteLine("Error"); } if (result != null) { if (result.errors != null && result.errors.Any()) { txtOut.WriteLine("flysas.com says: " + result.errors.First().errorMessage); } else { var printer = new TablePrinter(txtOut); txtOut.WriteLine("********* Outbound " + req.OutDate.Value.ToString("yyyy-MM-dd") + " *******"); printer.PrintFlights(result.outboundFlights, options, req.From, req.To); if (req.InDate.HasValue) { txtOut.WriteLine("********* Inbound " + req.InDate.Value.ToString("yyyy-MM-dd") + " *******"); printer.PrintFlights(result.inboundFlights, options, req.To, req.From); } } } txtOut.Write(Environment.NewLine + Environment.NewLine); } } } } }