예제 #1
0
        async Task ExecuteGetWeather()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            try
            {
                var client = new WeatherAPIClient(BaseUrl, new HttpClient());
                var items  = await client.WeatherForecastAsync();

                foreach (var item in items)
                {
                    Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error!", $"Something has gone wrong: {ex.Message}", "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var sports = await weatherApiClient.Sports.GetSportsAsync().ConfigureAwait(false);

            if (sports.Cricket == null || sports.Cricket.Length < 1)
            {
                Console.WriteLine("There aren't currently any cricket events available.");
            }

            else
            {
                Console.WriteLine($"Found {sports.Cricket.Length} cricket events:");

                foreach (var cricket in sports.Cricket)
                {
                    Console.WriteLine($"{cricket.Match}, {cricket.Start}");
                }
            }

            Console.WriteLine();

            if (sports.Football == null || sports.Football.Length < 1)
            {
                Console.WriteLine("There aren't currently any football events available.");
            }

            else
            {
                Console.WriteLine($"Found {sports.Football.Length} football events:");

                foreach (var football in sports.Football)
                {
                    Console.WriteLine($"{football.Match}, {football.Start}");
                }
            }

            Console.WriteLine();

            if (sports.Golf == null || sports.Golf.Length < 1)
            {
                Console.WriteLine("There aren't currently any golf events available.");
            }

            else
            {
                Console.WriteLine($"Found {sports.Golf.Length} golf events:");

                foreach (var golf in sports.Golf)
                {
                    Console.WriteLine($"{golf.Match}, {golf.Start}");
                }
            }

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
예제 #3
0
 public static void Main(string[] args)
 {
     //We share the same EXE for both the main program and the task
     //Decide which one to start based on the command line parameters
     if (args != null && args.Length > 0 && args[0] == "--Task")
     {
         WeatherAPIClient.TaskMain(args).Wait();
     }
     else
     {
         Job.JobMain(args);
     }
 }
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var ipLookup = await weatherApiClient.IPLookup.LookIPAddressAsync(IPAddress).ConfigureAwait(false);

            var stringFormat = "The IP address is located within {0}, {1}, {2}.";

            Console.WriteLine(string.Format(stringFormat, ipLookup.City, ipLookup.Country, ipLookup.Continent));

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
예제 #5
0
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var timeZone = await weatherApiClient.TimeZones.GetTimeZoneAsync().ConfigureAwait(false);

            var stringFormat = "The local time in {0}, {1} is {2}.";

            Console.WriteLine(string.Format(stringFormat, timeZone.Location.Name, timeZone.Location.Country, timeZone.Location.LocalTime));

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
예제 #6
0
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var request = new RequestEntity()
                          .WithCityName("London");

            var astronomyResponse = await weatherApiClient.Astronomy.GetAstronomyAsync(request).ConfigureAwait(false);

            var stringFormat = "Sunrise in {0}, {1} is {2}, and the moon phase is {3}.";

            Console.WriteLine(string.Format(stringFormat, astronomyResponse.Location.Name, astronomyResponse.Location.Country, astronomyResponse.Astronomy.Astro.Sunrise, astronomyResponse.Astronomy.Astro.MoonPhase));

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var request = new HistoryRequestEntity()
                          .WithDate(DateTime.Now.AddDays(-5));

            var history = await weatherApiClient.History.GetHistoryAsync(request).ConfigureAwait(false);

            var stringFormat = "The forecast in {0}, {1} was:";

            Console.WriteLine(string.Format(stringFormat, history.Location.Name, history.Location.Country));

            foreach (var forecast in history.Forecast.ForecastDay)
            {
                Console.WriteLine($"{forecast.Date} - {forecast.Day.Condition.Description}");
            }

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
예제 #8
0
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var currentWeather = await weatherApiClient.Realtime.GetCurrentAsync().ConfigureAwait(false);

            var stringFormat = "The weather in {0}, {1} is {2} degrees C and {3}!";

            Console.WriteLine(string.Format(stringFormat, currentWeather.Location.Name, currentWeather.Location.Country, currentWeather.Current.TemperatureC, currentWeather.Current.Condition.Description));

            var request = new RealtimeRequestEntity()
                          .WithAirQualityData(true)
                          .WithCityName("London")
                          .WithLanguage("fr");

            var londonWeather = await weatherApiClient.Realtime.GetCurrentAsync(request).ConfigureAwait(false);

            Console.WriteLine(string.Format(stringFormat, londonWeather.Location.Name, londonWeather.Location.Country, londonWeather.Current.TemperatureC, londonWeather.Current.Condition.Description));

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
예제 #9
0
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var request = new ForecastRequestEntity()
                          .WithCityName("London")
                          .WithAlerts(true)
                          .WithDays(5);

            var forecastResponse = await weatherApiClient.Forecast.GetForecastAsync(request).ConfigureAwait(false);

            var stringFormat = "The forecast in {0}, {1} is:";

            Console.WriteLine(string.Format(stringFormat, forecastResponse.Location.Name, forecastResponse.Location.Country));

            foreach (var forecast in forecastResponse.Forecast.ForecastDay)
            {
                Console.WriteLine($"{forecast.Date} - {forecast.Day.Condition.Description}");
            }

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }
        public static async Task Main()
        {
            // Create a new WeatherAPI API client with API key.
            var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY"));

            var searchResults = await weatherApiClient.Search.SearchAsync(SearchQuery).ConfigureAwait(false);

            if (searchResults != null && searchResults.Length > 0)
            {
                Console.WriteLine($"Search found {searchResults.Length} results for \"{SearchQuery}\":");

                foreach (var result in searchResults)
                {
                    Console.WriteLine(result.Name);
                }
            }
            else
            {
                Console.WriteLine($"Search was not able to find any results for \"{SearchQuery}\".");
            }

            // Keeps the console window open at the end of the program.
            Console.ReadLine();
        }