public static async Task Main(string[] args)
        {
            OnlineCityBikeDataFetcher  fetcher      = new OnlineCityBikeDataFetcher();
            OfflineCityBikeDataFetcher fetchOffline = new OfflineCityBikeDataFetcher();

            if (args.Length > 1 && !args[1].Equals("online"))
            {
                if (args[1].Equals("offline"))
                {
                    fetchOffline = new OfflineCityBikeDataFetcher();
                    int bikeCount = await fetchOffline.GetBikeCountInStation(args[0]);

                    if (bikeCount < 0)
                    {
                        Console.WriteLine("Cannot fetch data.");
                    }
                    else
                    {
                        Console.WriteLine("Offline: bike count " + args[0] + ": " + bikeCount);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid argument");
                }
            }
            else
            {
                fetcher = new OnlineCityBikeDataFetcher();
                Console.WriteLine("Bike count " + args[0] + ": " + await fetcher.GetBikeCountInStation(args[0]));
            }
        }
Example #2
0
        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");
            }
        }
Example #3
0
        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]);
            }
        }
Example #4
0
 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!");
     }
 }
Example #5
0
        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;
            }
        }
Example #6
0
        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();
            }
        }