示例#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);
        }
示例#3
0
 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;
 }
示例#4
0
 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;
 }
示例#5
0
        public static WeatherInfo GetInstance(WeatherInfo wi)
        {
            if (instance == null)
            {
                if (wi == null)
                {
                    instance = new WeatherInfo();
                }

                if (wi != null)
                {
                    instance = new WeatherInfo(wi);
                }
            }
            return(instance);
        }
示例#6
0
        public static WeatherInfo GetInstance(WeatherInfo wi)
        {
            if (instance == null)
            {
                if(wi == null){
                   instance = new WeatherInfo();
                }

                if(wi != null){
                    instance = new WeatherInfo(wi);
                }
            }
            return instance;
        }