static async Task AsyncMain(string[] args) { bool useOffline = false; if (args != null && args.Length != 0) { if (args.Length > 1) { if (args[1] == "offline") { useOffline = true; } else if (args[1] != "realtime") { Console.WriteLine("Mode not specified! Defaulting to realtime."); } } else { Console.WriteLine("Mode not specified! Defaulting to realtime."); } try { if (useOffline) { OfflineCityBikeDataFetcher offlineCityBikeDataFetcher = new OfflineCityBikeDataFetcher(); await offlineCityBikeDataFetcher.GetBikeCountInStation(args[0]); } else { RealTimeCityBikeDataFetcher realTimeCityBikeDataFetcher = new RealTimeCityBikeDataFetcher(); realTimeCityBikeDataFetcher.Deserial(await realTimeCityBikeDataFetcher.GetJson()); await realTimeCityBikeDataFetcher.GetBikeCountInStation(args[0]); } } catch (ArgumentException ex) { Console.WriteLine("Invalid argument: " + ex.Message); } catch (NotFoundException ex) { Console.WriteLine("Not found: " + ex.Message); } catch (Exception e) { Console.WriteLine("Error: " + e); } } else { Console.WriteLine("Error: No arguments"); } }
static void Main(string[] args) { try{ if (Regex.IsMatch(args[0], @"^[a-zA-Z]+$")) { Task <int> result; if (args[1] == "offline") { OfflineCityBikeDataFetcher fetcher = new OfflineCityBikeDataFetcher(); result = fetcher.GetBikeCountInStation(args[0]); result.Wait(); } else { RealTimeCityBikeDataFetcher fetcher = new RealTimeCityBikeDataFetcher(); result = fetcher.GetBikeCountInStation(args[0]); result.Wait(); } if (result.Result == -1) { throw new NotFoundException(); } else { Console.WriteLine(args[0] + ": " + result.Result); } } else { throw new ArgumentException(); } } catch (ArgumentException) { Console.WriteLine("Invalid argument: " + args[0]); } catch (NotFoundException) { Console.WriteLine("Not found: " + args[0]); } }
static void Main(string[] args) { var x = new RealTimeCityBikeDataFetcher(); var stationName = "Petikontie"; var onlineOrOffline = "realtime"; if (args.Length > 0) { stationName = args[0]; if (args.Length == 2) { onlineOrOffline = args[1]; } } try { if (onlineOrOffline == "realtime") { var cnt = x.GetBikeCountInStation(stationName); Console.WriteLine(cnt.Result); } else { var cnt = x.GetBikeCountInStationOffline(stationName); Console.WriteLine(cnt.Result); } } catch (NotFoundException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }
static async Task Main(string[] args) { if (args[0] == "realtime") { RealTimeCityBikeDataFetcher querier = new RealTimeCityBikeDataFetcher(); Task <int> bikeamount = querier.GetBikeCountInStation(args[1]); int result = await bikeamount; Console.WriteLine(result); } else if (args[0] == "offline") { OfflineCityBikeDataFetcher offQuerier = new OfflineCityBikeDataFetcher(); Task <int> bikeamount = offQuerier.GetBikeCountInStation(args[1]); int result = await bikeamount; Console.WriteLine(result); } else { Console.WriteLine("ERROR!"); } }
static async Task Main(string[] args) { string stationName = args[0]; // If station name has more than one word -> Combine station name/arguments into one if (args.Length > 2) //If more than two arguments { for (int i = 1; i < args.Length - 1; i++) { stationName += " " + args[i]; } } try { if (args[args.Length - 1] == "realtime") { RealTimeCityBikeDataFetcher onlineFetcher = new RealTimeCityBikeDataFetcher(); Console.WriteLine("Number of Available Bikes: " + await onlineFetcher.GetBikeCountInStation(stationName)); } else if (args[args.Length - 1] == "offline") { OfflineCityBikeFetcher offlineFetcher = new OfflineCityBikeFetcher(); Console.WriteLine("Number of Available Bikes: " + await offlineFetcher.GetBikeCountInStation(stationName)); } } catch (ArgumentException ex) { Console.WriteLine("Invalid argument: " + ex.Message); } catch (NotFoundException ex) { Console.WriteLine("Not found: " + ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static async Task MainAsync(string [] args) { string mode; string stationName; try { mode = args [0]; stationName = args [1]; } catch (Exception ex) { Console.WriteLine("Not enough arguments! use 'offline|realtime station_name'"); return; } ICityBikeDataFetcher fetcher; if (mode == "offline" || mode == "Offline") { fetcher = new OfflineCityBikeDataFetcher( ); var task = await fetcher.GetBikeCountInStation(stationName); Console.WriteLine(task); } else if (mode == "realtime" || mode == "Realtime") { fetcher = new RealTimeCityBikeDataFetcher( ); var task = await fetcher.GetBikeCountInStation(stationName); Console.WriteLine(task); } else { Console.WriteLine("Use offline or realtime"); return; } }