本文整理汇总了C#中Scanner.QueryFlight方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.QueryFlight方法的具体用法?C# Scanner.QueryFlight怎么用?C# Scanner.QueryFlight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.QueryFlight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryLoop
static async Task QueryLoop(Logger logger)
{
var scanner = new Scanner(ConfigurationManager.AppSettings["apiKey"]);
var fromPlace = (await scanner.QueryLocation("Geneva")).First();
while (true)
{
Console.Write("Where to: ");
var whereTo = Console.ReadLine();
var toPlace = await GetLocation(whereTo, scanner, logger);
if (toPlace == null)
{
continue;
}
logger.LogOutput("Going to {0}{1}", toPlace.PlaceName, Environment.NewLine);
Console.Write("Check for next ? weeks: ");
var howManyWeeks = int.Parse(Console.ReadLine());
logger.LogInput("Checking for {0} weeks{1}", howManyWeeks, Environment.NewLine);
var flightResponseSettings = new FlightResponseSettings(
sortOrder: SortOrder.Ascending,
sortType: SortType.Price,
maxStops: 0,
outboundDepartureStartTime: new LocalTime(17, 0, 0),
outboundDepartureEndTime: new LocalTime(22, 0, 0),
inboundDepartureStartTime: new LocalTime(13, 0, 0),
inboundDepartureEndTime: new LocalTime(20, 0, 0));
var today = SystemClock.Instance.Now.InUtc().LocalDateTime.Date;
var thisFriday = today.Next(IsoDayOfWeek.Friday);
for (int i = 0; i < howManyWeeks; i++)
{
var outboundDate = thisFriday.PlusWeeks(i);
var inboundDate = outboundDate.PlusDays(2);
var itineraries = await scanner.QueryFlight(
new FlightQuerySettings(
new FlightRequestSettings(fromPlace, toPlace, outboundDate, inboundDate, 2),
flightResponseSettings));
var itinerary = itineraries.FirstOrDefault();
if (itinerary == null)
{
logger.LogOutput("Couldn't find itinerary" + Environment.NewLine);
}
else
{
logger.LogOutput(WriteItinerary(itinerary));
}
logger.LogOutput("----------------------------------------------------{0}", Environment.NewLine);
}
}
}
示例2: SearchSimplified
private static async Task SearchSimplified()
{
var scanner = new Scanner(ConfigurationManager.AppSettings["apiKey"]);
var from = (await scanner.QueryLocation("London")).First();
var to = (await scanner.QueryLocation("New York")).First();
var now = new LocalDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
var outboundDate = now.PlusWeeks(1);
var inboundDate = now.PlusWeeks(2);
//Query flights
var itineraries = await scanner.QueryFlight(
new FlightQuerySettings(
new FlightRequestSettings(from, to, outboundDate, inboundDate),
new FlightResponseSettings(SortType.Price, SortOrder.Ascending)),
WriteToDebug());
itineraries = itineraries
.Take(5)
.ToList();
if (!itineraries.Any())
{
WriteLine("No flights");
return;
}
foreach (var itinerary in itineraries)
{
WriteItinerary(itinerary, Currency.Default);
}
WriteSeparator();
//Query bookings (note, this is forbidden by SkyScanner, should only query exact booking details if a user requests them)
var bookingQueryTasks = itineraries.Select(scanner.QueryBooking);
var bookingResults = (await Task.WhenAll(bookingQueryTasks))
.OrderBy(response =>
response.BookingOptions
.Select(option => option.BookingItems.Sum(item => item.Price))
.Min());
foreach (var response in bookingResults)
{
WriteBookingResult(response, Currency.Default);
}
}
示例3: SearchDetailed
private static async Task SearchDetailed()
{
//Initialize Scanner
var scanner = new Scanner(
ConfigurationManager.AppSettings["apiKey"],
RetryExecutionStrategy.Default);
//Query locales
var locales = await scanner.QueryLocale();
var currentLocale = locales.FirstOrDefault(locale => locale.Name.StartsWith("English"));
if (currentLocale == null)
{
WriteLine(ErrorColor, "Couldn't find locale, using default instead");
currentLocale = Locale.Default;
}
//Query markets
var markets = await scanner.QueryMarket(currentLocale);
var currentMarket = markets.FirstOrDefault(market => market.Name == "Switzerland");
if (currentMarket == null)
{
WriteLine(ErrorColor, "Couldn't find market, using default instead");
currentMarket = Market.Default;
}
//Query currencies
var currencies = await scanner.QueryCurrency();
var currentCurrency = currencies.FirstOrDefault(currency => currency.Code == "CHF");
if (currentCurrency == null)
{
WriteLine(ErrorColor, "Couldn't find currency, using default instead");
currentCurrency = Currency.Default;
}
//Query location
const string fromPlaceName = "London";
var from = (await scanner.QueryLocation(new LocationAutosuggestSettings(fromPlaceName,
LocationAutosuggestQueryType.Query, currentMarket, currentCurrency, currentLocale))).First();
if (from == null)
{
WriteLine(ErrorColor, "Couldn't find '{0}'", fromPlaceName);
return;
}
//Query destination location
const string toPlaceName = "New York";
var to = (await scanner.QueryLocation(new LocationAutosuggestSettings(toPlaceName,
LocationAutosuggestQueryType.Query, currentMarket, currentCurrency, currentLocale))).FirstOrDefault();
if (to == null)
{
WriteLine(ErrorColor, "Couldn't find '{0}'", toPlaceName);
return;
}
//Setup flight search settings
var flightResponseSettings = new FlightResponseSettings(
sortOrder: SortOrder.Ascending,
sortType: SortType.Price,
maxStops: 2,
maxDuration: 14 * 60,
outboundDepartureStartTime: new LocalTime(08, 0, 0),
outboundDepartureEndTime: new LocalTime(12, 0, 0),
inboundDepartureStartTime: new LocalTime(08, 0, 0),
inboundDepartureEndTime: new LocalTime(18, 30, 0)
);
var now = new LocalDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
var outboundDate = now.PlusWeeks(1);
var inboundDate = now.PlusWeeks(2);
Write("Flights from ");
Write(ImportantColor, from.PlaceName);
Write(" to ");
WriteLine(ImportantColor, to.PlaceName);
Write(" on ");
Write(ImportantColor, outboundDate.ToString("d", CultureInfo.InvariantCulture));
Write(" and back on ");
WriteLine(ImportantColor, inboundDate.ToString("d", CultureInfo.InvariantCulture));
//Query flights
var itineraries = await scanner.QueryFlight(
new FlightQuerySettings(
new FlightRequestSettings(from, to, outboundDate, inboundDate, 1,
currency: currentCurrency, marketCountry: currentMarket, locale: currentLocale),
flightResponseSettings), WriteToDebug());
itineraries = itineraries
.Take(5)
.ToList();
if (!itineraries.Any())
{
WriteLine("No flights");
return;
}
foreach (var itinerary in itineraries)
//.........这里部分代码省略.........