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]);

            int count = 0;

            ICityBikeDataFetcher Futza;

            if (realtime)
            {
                Futza = new RealTimeCityBikeDataFetcher();
            }
            else
            {
                Futza = new OfflineCityBikeDataFetcher();
            }

            Task <int> task = Futza.GetBikeCountInStation(args[0]);

            task.Wait();
            count = task.Result;

            Console.WriteLine("The Helkamas: " + count.ToString());
        }
        static async Task Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("You need to give a Station Name as first argument");
            }

            ICityBikeDataFetcher fetcer;

            if (args.Length >= 2 && args[1] != null && args[1] == "offline")
            {
                fetcer = new OfflineCityBikeDataFetcher();
            }
            else if (args.Length >= 2 && args[1] != null && args[1] == "online")
            {
                fetcer = new RealTimeCityBikeDataFetcher();
            }
            else
            {
                Console.WriteLine("You need to give a Mode (offline/online) as second argument");
                return;
            }

            if (args.Length >= 1 && args[0] != null)
            {
                try
                {
                    if (args[0].Any(c => char.IsDigit(c)))
                    {
                        throw new ArgumentException(String.Format("Station name ({0}) is not allowed to contain numbers!", args[0]), args[0]);
                    }
                    Console.WriteLine("Station: {0} | Bikes amount: {1}", args[0], await fetcer.GetBikeCountInStation(args[0]));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("{0} {1}", e.GetType(), e.Message);
                }
            }
        }
Ejemplo n.º 3
0
        static async Task ShowBikeCount(string input, string type)
        {
            bool ok = true;

            foreach (char c in input)
            {
                if (char.IsDigit(c))
                {
                    ok = false;
                }
            }
            if (ok == true)
            {
                ICityBikeDataFetcher fetcher;
                if (type == "offline")
                {
                    fetcher = new OfflineCityBikeDataFetcher();
                }
                else
                {
                    fetcher = new RealTimeCityBikeDataFetcher();
                }
                try
                {
                    int count = await fetcher.GetBikeCountInStation(input);

                    Console.WriteLine(count);
                }
                catch (NotFoundException e)
                {
                    Console.WriteLine("Not Found: " + e);
                }
            }
            else
            {
                throw new ArgumentException(input);
            }
        }