public WeatherInfo getWeatherData(string api) { var json = ""; if ("OPEN_WEATHER_MAP".Equals(api)) { WebClient w = new WebClient(); try { json = w.DownloadString("http://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.ToString() + "&lon=" + location.lng.ToString()); if (!string.IsNullOrEmpty(json)) { return(JsonConvert.DeserializeObject <WeatherInfo>(json)); } else { return(WeatherInfo.GetInstance(null)); } } catch (WeatherDataServiceException e) { Console.WriteLine(e.StackTrace); } } return(null); }
static void Main(string[] args) { Factory factory = new Factory(); WeatherInfo singleton = WeatherInfo.GetInstance(factory.getWeatherData(factory.platform)); Console.Write(singleton); }
private WeatherInfo(WeatherInfo wi) { this.clouds = wi.clouds; this.cod = wi.cod; this.coord = wi.coord; this.dt = wi.dt; this.id = wi.id; this.main = wi.main; this.name = wi.name; this.rain = wi.rain; this.sys = wi.sys; this.weather = wi.weather; this.wind = wi.wind; }
public static WeatherInfo GetInstance(WeatherInfo wi) { if (instance == null) { if (wi == null) { instance = new WeatherInfo(); } if (wi != null) { instance = new WeatherInfo(wi); } } return(instance); }
public static WeatherInfo GetInstance(WeatherInfo wi) { if (instance == null) { if(wi == null){ instance = new WeatherInfo(); } if(wi != null){ instance = new WeatherInfo(wi); } } return instance; }