예제 #1
0
        public static async Task Main(string[] args)
        {
            ICityBikeDataFetcher fetcher;

            fetcher = new RealTimeCityBikeDataFetcher();
            var   task = fetcher.GetBikeCountInStation("Petikontie");
            await task;
        }
        static void Main(string[] args)
        {
            string input     = args[0].ToString();
            var    a         = new RealTimeCityBikeDataFetcher();
            var    bikeCount = a.GetBikeCountInStation(input);

            Console.WriteLine("\n---- Response: " + bikeCount);
            if (bikeCount != null)
            {
                Console.WriteLine("Station " + input + " has " + bikeCount.Result + " bikes available");
            }
        }
        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());
        }
예제 #4
0
 static async Task Main(string[] args)
 {
     if (args[0].Equals("offline") || args[0].Equals("Offline"))
     {
         while (true)
         {
             OfflineCityBikeDataFetch fetch = new OfflineCityBikeDataFetch();
             Console.WriteLine("Anna haettavan aseman nimi: ");
             Console.WriteLine(await fetch.GetBikeCountInStation(Console.ReadLine()) + " pyörä(ä)");
         }
     }
     else if (args[0].Equals("Realtime") || args[0].Equals("realtime"))
     {
         while (true)
         {
             RealTimeCityBikeDataFetcher fetch = new RealTimeCityBikeDataFetcher();
             Console.WriteLine("Anna haettavan aseman nimi: ");
             Console.WriteLine(await fetch.GetBikeCountInStation(Console.ReadLine()) + " pyörä(ä)");
         }
     }
 }
        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);
                }
            }
        }
예제 #6
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);
            }
        }