예제 #1
0
        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);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Factory factory = new Factory();

            WeatherInfo singleton = WeatherInfo.GetInstance(factory.getWeatherData(factory.platform));

            Console.Write(singleton);
        }