Exemplo n.º 1
0
        public IHttpActionResult GetDestinationName(string id)
        {
            XmlManager.TripAndWeatherSheet tripAndWeatherSheet = new XmlManager.TripAndWeatherSheet();

            try
            {
                XmlManager.LocationSheetList locationSheetList;
                locationSheetList = ResRobot.ResRobot.GetLocations(id);

                XmlManager.TripSheet tripSheet = new XmlManager.TripSheet();
                tripSheet = ResRobot.ResRobot.GetTripBetweenLocations(740000133, int.Parse(locationSheetList.LocationSheets.First().ID));

                XmlManager.WeatherSheet weatherSheet = SMHI.SMHI.GetWeatherFromSMHIByLonLatDateTime(tripSheet.DestinationLon, tripSheet.DestinationLat,
                                                                                                    DateTime.Parse(tripSheet.DestinationTime));

                tripAndWeatherSheet.tripSheet    = tripSheet;
                tripAndWeatherSheet.weatherSheet = weatherSheet;
            }
            catch (Exception ex)
            {
                tripAndWeatherSheet.Error = true;
                tripAndWeatherSheet.ExMsg = ex.Message;
            }

            return(Ok(tripAndWeatherSheet));
        }
Exemplo n.º 2
0
        /// <summary>
        /// GETs weather information from the WebService API.
        /// </summary>
        /// <param name="lat">Latitude coordinates.</param>
        /// <param name="lon">Longitude coordinates.</param>
        /// <param name="dateTime">Gets the weather at specified time.</param>
        /// <param name="connectionString">WebService API URL.</param>
        /// <returns>Returns a WeatherSheet with weather information in it.</returns>
        public static XmlManager.WeatherSheet ReceiveWeather(string lat, string lon, DateTime dateTime, string connectionString)
        {
            string StringDateTime = XmlManager.XmlManager.ConvertDateTimeToAPICompatiableDateTimeFormat(dateTime);

            string data = new WebClient().DownloadString(connectionString + "/api/weather/" + lon + "/" + lat + "/" + StringDateTime + "/");

            XmlManager.WeatherSheet xmlSheet = JsonConvert.DeserializeObject <XmlManager.WeatherSheet>(data);

            return(xmlSheet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets WeatherSheet data from SMHI API based upon long and lat coordinate.
        /// </summary>
        /// <param name="lon">Longitude coordinate.</param>
        /// <param name="lat">Latitude coodinate</param>
        /// <param name="dateTime">Specified time to get the closest forecast to</param>
        /// <returns></returns>
        public static XmlManager.WeatherSheet GetWeatherFromSMHIByLonLatDateTime(string lon, string lat, DateTime dateTime)
        {
            String JSonSMHIData = new System.Net.WebClient().DownloadString(
                "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/" + lon + "/lat/" + lat + "/data.json");

            Information information = Newtonsoft.Json.JsonConvert.DeserializeObject <Information>(JSonSMHIData);

            XmlManager.WeatherSheet weatherSheet = GetWeatherWithClosestTime(information, dateTime);

            return(weatherSheet);
        }
Exemplo n.º 4
0
        public IHttpActionResult GetWeather(string lon, string lat, string dateTimeString)
        {
            XmlManager.WeatherSheet weatherSheet = new XmlManager.WeatherSheet();
            DateTime dateTime = XmlManager.XmlManager.ConvertAPICompatiableDateTimeFormatToDateTime(dateTimeString);

            try
            {
                weatherSheet = SMHI.SMHI.GetWeatherFromSMHIByLonLatDateTime(lon, lat, dateTime);
            }
            catch (Exception ex)
            {
                weatherSheet.Error = true;
                weatherSheet.ExMsg = ex.Message;
            }

            return(Ok(weatherSheet));
        }