Пример #1
0
        public IHttpActionResult SearchWeatherReport([FromBody] ForecastSearchRequest request)
        {
            try {
                // fetch the forecast
                var      openWeatherApi = new OpenWeatherMapAPI(_apiKey);
                Forecast forecast       = openWeatherApi.QueryForecast($"{request.CityName}"); //,{request.CountryCode}

                // store the results
                var      forecastRepo = new ForecastRepository(_mongoDbPath);
                ObjectId?forecastId   = forecastRepo.StoreForecast(forecast);

                // return the query result
                if (forecastId.HasValue)
                {
                    return(Ok(forecastId.Value));
                }
                else
                {
                    return(BadRequest("Could not store results of query"));
                }
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        public void OnGet()
        {
            string            city   = "aalborg";
            OpenWeatherMapAPI owmAPI = new OpenWeatherMapAPI();

            WeatherIconSrc = owmAPI.GetIconUrl(city);
            Temperature    = owmAPI.GetCurrentTemperature(city);
            CategoryRepository cr = new CategoryRepository();

            Categories = cr.GetAllCategories();
            RideRepository rr = new RideRepository();

            AllRides = rr.GetAllRides();
        }
Пример #3
0
        public string GetLocalTemperature()                                // Retrieves the temperature for the City member in the class and returns it as a string
        {
            OpenWeatherMapAPI openWeatherMapAPI = new OpenWeatherMapAPI(); // Intitializing required variables
            double            temp = 0.0;

            try
            {
                temp = openWeatherMapAPI.GetCurrentTemperature(City); // Tries to run the code
            }
            catch (WebException)                                      //If the code can't run and the data isn't retrieved, a WebException is thrown and caught
            {
                return("N/A");                                        // The output string is set to placeholder text
            }
            return($"{temp}°C");                                      // If the code runs succesfully and the data is retrieved, the text is set to the temperature
        }
Пример #4
0
        public string GetIconUrl()                                         // Retrieves a url for an icon for the City member in the class and returns it as a string
        {
            OpenWeatherMapAPI openWeatherMapAPI = new OpenWeatherMapAPI(); // Initializing required variables
            string            iconUrl           = "";

            try
            {
                iconUrl = openWeatherMapAPI.GetIconUrl(City); // Tries to run the code
            }
            catch (WebException)                              // If the code can't run and the data isn't retrieved, a WebException is thrown and caught
            {
                return(@"\img\placeholder.png");              // A URL for a placeholder image is returned instead of the intended URL
            }
            return(iconUrl);                                  // If the code runs succesfully and the data is retrieved, the URL is returned
        }
Пример #5
0
        private static void Main(string[] args)
        {
            //Get our API Class.
            using (OpenWeatherMapAPI api = new OpenWeatherMapAPI())
            {
                //Make a Sync call.
                OpenWeatherMapAPI.WeatherResult result = api.GetWeather("London,Ca");
                //Use result data
                Console.WriteLine(result.Name + " " + result.TimeStamp);

                //Make an Async call.
                Task <OpenWeatherMapAPI.WeatherResult> task = api.GetWeatherAsync("Fenton,Mi");
                //do other stuff
                Console.WriteLine("OtherStuff");
                //Use result data
                task.Wait();
                Console.WriteLine(task.Result.Name + " " + task.Result.TimeStamp);

                Console.WriteLine("Press Any Key To Continue...");
                Console.Read();
            }
        }
Пример #6
0
 public MediaController(OpenWeatherMapAPI openWeatherMapAPI)
 {
     _openWeatherMapAPI = openWeatherMapAPI;
 }