public static WeatherData ConvertFromJsonData(WeatherDataJson jsonData) { WeatherData weatherData = new WeatherData(); DateTime sunrise = ConvertUTCTimeToDateTime(jsonData.DataMembers.Sys[WeatherServiceProvider.Sunrise]); DateTime sunset = ConvertUTCTimeToDateTime(jsonData.DataMembers.Sys[WeatherServiceProvider.Sunset]); weatherData.Name = jsonData.DataMembers.Name.ToLower(); weatherData.UpdateDate = jsonData.UpdateDate; weatherData.IsCloud = jsonData.DataMembers.Clouds == null ? false : true; weatherData.IsRain = jsonData.DataMembers.Rain == null ? false : true; weatherData.Sunset = sunset; weatherData.Sunrise = sunrise; return(weatherData); }
public static WeatherDataJson ConvertFromJSON(string json) { WeatherDataJson weatherData = new WeatherDataJson(); WeatherDataMembersJson weatherDataMember = new WeatherDataMembersJson(); try { weatherDataMember = JsonConvert.DeserializeObject <WeatherDataMembersJson> (json); weatherData.DataMembers = weatherDataMember; weatherData.UpdateDate = DateTime.Now; } catch (Exception) { } return(weatherData); }
private WeatherDataJson GetDataFromWCF(ServiceProvider.IServiceProvider service) { WeatherDataJson weatherData = new WeatherDataJson(); string data = string.Empty; var end_adress = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/WeatherWCF/WeatherService/"); using (WeatherServiceClient proxy = new WeatherServiceClient(new BasicHttpBinding(), end_adress)) { data = proxy.GetData(service.ServiceName(CityName)); } if (!string.IsNullOrEmpty(data)) { weatherData = ConvertHelper.ConvertFromJSON(data); } return(weatherData); }
public string GetData() { string data = string.Empty; GetParameters(Parameters); DateTime updateDate = DateTime.Now.AddHours(-1); WeatherData = LocalCache.Instance.Get <WeatherData>(CityName); if (WeatherData == null || (WeatherData != null && WeatherData.UpdateDate < updateDate)) { LocalCache.Instance.Remove(CityName); WeatherData = GetDataFromDatabase(CityName, updateDate); if (WeatherData == null) { WeatherDataJson jsonData = new WeatherDataJson(); jsonData = GetDataFromWCF(new WeatherServiceProvider()); if (jsonData.DataMembers != null) { WeatherData = ConvertHelper.ConvertFromJsonData(jsonData); DatabaseOperation(new InsertOrUpdateOperation(), WeatherData); } } LocalCache.Instance.Add(WeatherData, CityName); } if (WeatherData != null) { if (DataFormat == DataFormat.JSON) { data = ConvertHelper.ConvertToJSON(WeatherData); } else { data = ConvertHelper.ConvertToXml(WeatherData); } } return(data); }