public static List <ForeseeWeatherInfo> GetForeseeWeatherData() { Database WeatherHelperDataContext = DatabaseConfig.GetWeatherHelperDatabase(); List <ForeseeWeatherInfo> result = null; try { using (DbCommand command = WeatherHelperDataContext.GetSqlStringCommand( @"select * from V_FWeatherData order by [date],areacode")) { IDataReader reader = WeatherHelperDataContext.ExecuteReader(command); result = new List <ForeseeWeatherInfo>(); while (reader.Read()) { ForeseeWeatherInfo response = new ForeseeWeatherInfo(); response.AreaName = reader["AreaName"].ToString(); response.CountryName = reader["WCCountryName"].ToString(); response.ForeseWeatherID = reader["ForeseWeatherID"].ToString(); response.AreaCode = reader["AreaCode"].ToString(); response.WCCode = reader["WCCode"].ToString(); response.Skycodeday = reader["Skycodeday"].ToString(); response.Date = reader["Date"].ToString(); response.Skytextday = reader["Skytextday"].ToString(); response.Day = reader["Day"].ToString(); response.Shortday = reader["Shortday"].ToString(); response.Precip = reader["Precip"].ToString(); //response.SkycodeImg = reader["SkycodeImg"].ToString(); response.Low = reader["Low"].ToString(); response.High = reader["High"].ToString(); response.WeatherStatus = reader["WeatherStatus"].ToString(); result.Add(response); } return(result); } } catch (Exception ex) { throw ex; } }
public static QueryWeatherResponse ParserWeatherXMLInfo(XmlDocument XmlDoc, QueryWeatherRequest request) { if (XmlDoc == null) { throw new ArgumentNullException("XmlDoc"); } if (request == null) { throw new ArgumentNullException("request"); } QueryWeatherResponse respone = new QueryWeatherResponse(); if (XmlDoc.SelectSingleNode(@"weatherdata/weather/current") != null) { respone.CurrentDay = new WeatherInfo(); respone.CurrentDay.WCCode = XmlDoc.SelectSingleNode(@"weatherdata/weather").Attributes["weatherlocationcode"].InnerText.Split(':')[1]; respone.CurrentDay.Temperature = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["temperature"].InnerText; respone.CurrentDay.Skycode = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["skycode"].InnerText; respone.CurrentDay.Skytext = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["skytext"].InnerText; respone.CurrentDay.Observationtime = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["observationtime"].InnerText; respone.CurrentDay.Observationpoint = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["observationpoint"].InnerText; respone.CurrentDay.Feelslike = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["feelslike"].InnerText; respone.CurrentDay.Humidity = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["humidity"].InnerText; respone.CurrentDay.Windspeed = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["windspeed"].InnerText; respone.CurrentDay.Winddisplay = XmlDoc.SelectSingleNode(@"weatherdata/weather/current").Attributes["winddisplay"].InnerText; respone.CurrentDay.WeatherStatus = ChangeSkyCodeToWeatherStatus(respone.CurrentDay.Skycode); respone.OthreDays = new List <ForeseeWeatherInfo>(); for (int i = 0; i < XmlDoc.SelectNodes(@"weatherdata/weather/forecast").Count; i++) { ForeseeWeatherInfo weatherinfo = new ForeseeWeatherInfo(); weatherinfo.Low = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["low"].InnerText; weatherinfo.High = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["high"].InnerText; weatherinfo.Skycodeday = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["skycodeday"].InnerText; weatherinfo.Skytextday = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["skytextday"].InnerText; weatherinfo.Date = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["date"].InnerText; weatherinfo.Day = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["day"].InnerText; weatherinfo.Shortday = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["shortday"].InnerText; weatherinfo.Precip = XmlDoc.SelectNodes(@"weatherdata/weather/forecast")[i].Attributes["precip"].InnerText; weatherinfo.WeatherStatus = ChangeSkyCodeToWeatherStatus(weatherinfo.Skycodeday); weatherinfo.AreaCode = request.AreaCode; weatherinfo.WCCode = request.WCCode; respone.OthreDays.Add(weatherinfo); } if (respone.OthreDays.Count > 0) { respone.CurrentDay.High = respone.OthreDays[0].High; respone.CurrentDay.Low = respone.OthreDays[0].Low; } return(respone); } else { throw new XMLNodeNotFoundException(); } }