static async Task Main(string[] args) { string text = System.IO.File.ReadAllText(@"C:\Dev\VisualStudioProjects\GameBackend\Assignment1\bikedata.txt"); //Console.WriteLine(text); ICityBikeDataFetcher fetcher = new RealTimeCityBikeDataFetcher(); if (args[1] == "realtime") { fetcher = new RealTimeCityBikeDataFetcher(); } else if (args[1] == "offline") { fetcher = new OfflineCityBikeDataFetcher(); } Console.WriteLine("Mode: " + args[1]); try { int bikeCount = await fetcher.GetBikeCountInStation(args[0]); Console.WriteLine(args[0]); Console.WriteLine("Bike count: " + bikeCount); } catch (ArgumentException e) { Console.WriteLine("Invalid argument: " + e.Message); } catch (NotFoundException notFoundExc) { Console.WriteLine(notFoundExc.Message + notFoundExc.StationName); } }
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) { bool realtime = true; if (args.Length >= 2) { if (args[1] == "realtime") { realtime = true; } else if (args[1] == "offline") { realtime = false; } } else if (args.Length == 0) { return; } Console.WriteLine(args[0]); string input = args[0]; int count = 0; ICityBikeDataFetcher fetcher; if (realtime) { fetcher = new RealTimeCityBikeDataFetcher(); } else { fetcher = new OfflineCityBikeDataFetcher(); } var task = fetcher.GetBikeCountInStation(input); task.Wait(); count = task.Result; Console.WriteLine("Bikes available: " + count.ToString()); }
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; } }
static async Task Main(string[] args) { if (args[0] == "realtime") { RealTimeCityBikeDataFetcher realTimeCityBikeDataFetcher = new RealTimeCityBikeDataFetcher(); await realTimeCityBikeDataFetcher.GetUrlAsync(); realTimeCityBikeDataFetcher.GetUrl(); } else if (args[0] == "offline") { OfflineCityBikeDataFetcher offlineCityBikeDataFetcher = new OfflineCityBikeDataFetcher(); await offlineCityBikeDataFetcher.GetBikeCountInStation("Olympiastadion"); } else { RealTimeCityBikeDataFetcher realTimeCityBikeDataFetcher = new RealTimeCityBikeDataFetcher(); await realTimeCityBikeDataFetcher.GetUrlAsync(); realTimeCityBikeDataFetcher.GetUrl(); } }
static void Main(string[] args) { try { ICityBikeDataFetcher fetcher = null; if (args[1] == "realtime") { fetcher = new RealTimeCityBikeDataFetcher(); } else if (args[1] == "offline") { fetcher = new OfflineCityBikeDataFetcher(); } else { Console.WriteLine("Invalid argument: " + args[1]); Console.ReadKey(); return; } Task <int> task = fetcher.GetBikeCountInStation(args[0]); task.Wait(); Console.WriteLine(task.Result); }catch (AggregateException e) { if (e.InnerException.GetType() == typeof(ArgumentException)) { Console.WriteLine("Invalid argument: " + e.InnerException.Message); } else if (e.InnerException.GetType() == typeof(NotFoundException)) { Console.WriteLine("Not found: " + e.InnerException.Message); } else { Console.WriteLine(e); } } Console.ReadKey(); }