Example #1
0
        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);
            }
        }
        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 #3
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 #4
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 #5
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());
        }
Example #6
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 #7
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 #8
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();
            }
        }
Example #9
0
 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();
 }