Ejemplo n.º 1
0
        /// <summary>
        /// the XMLFunction is handeling the parsing from
        /// the RESTful web service
        /// </summary>

        public void XMLFunction(WeatherMap weatherData, Location location)
        {
            urlXML += location.City + "&mode=xml&appid=" + apiKey;
            WebClient client = new WebClient();
            XDocument xmlDoc;
            string    xml;

            try { xml = client.DownloadString(urlXML); }
            catch (WebException) { throw new WeatherDataServiceException("Wrong String of info"); }
            try
            {
                xmlDoc = XDocument.Parse(xml);
                weatherData.Location.City       = xmlDoc.Descendants("city").Attributes("name").First().Value;
                weatherData.Location.Temprature = Convert.ToString(Convert.ToDouble(xmlDoc.Descendants("temperature").Attributes("value").First().Value) + celcUnit);
                weatherData.Location.Humadity   = xmlDoc.Descendants("humidity").Attributes("value").First().Value + " " + xmlDoc.Descendants("humidity").Attributes("unit").First().Value;
                weatherData.Location.Pressure   = xmlDoc.Descendants("pressure").Attributes("value").First().Value + " " + xmlDoc.Descendants("pressure").Attributes("unit").First().Value;
                weatherData.Location.Wind       = xmlDoc.Descendants("speed").Attributes("value").First().Value;
                weatherData.Location.Clouds     = xmlDoc.Descendants("clouds").Attributes("name").First().Value;
                weatherData.Location.Visibility = xmlDoc.Descendants("visibility").Attributes("value").First().Value;
                weatherData.Location.Weather    = xmlDoc.Descendants("weather").Attributes("value").First().Value;
                weatherData.Location.Lastupdate = xmlDoc.Descendants("lastupdate").Attributes("value").First().Value;
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
 // The user will insert the wanted City, which will be attached to the beginning of the URL
 // Adding the key to the end of the URL will give us the complete URL that we can withdraw infromation from
 public void ParseXML(WeatherMap wd)
 {
     try
     {
         WebClient client = new WebClient();
         String    xml    = client.DownloadString(URL + wd.Location.City + Key);
         XDocument xmlDoc = XDocument.Parse(xml);
         wd.Location.City           = xmlDoc.Descendants("city").Attributes("name").First().Value;
         wd.Location.Wind           = xmlDoc.Descendants("speed").Attributes("value").First().Value;
         wd.Location.Lastupdate     = xmlDoc.Descendants("lastupdate").Attributes("value").First().Value;
         wd.Location.Temperature    = xmlDoc.Descendants("temperature").Attributes("value").First().Value;
         wd.Location.Pressure       = xmlDoc.Descendants("pressure").Attributes("value").First().Value;
         wd.Location.TemperatureMax = xmlDoc.Descendants("temperature").Attributes("max").First().Value;
         wd.Location.TemperatureMin = xmlDoc.Descendants("temperature").Attributes("min").First().Value;
         wd.Location.Country        = xmlDoc.Descendants("country").First().Value;
         wd.Location.Sunrise        = xmlDoc.Descendants("sun").Attributes("rise").First().Value;
         wd.Location.Sunset         = xmlDoc.Descendants("sun").Attributes("set").First().Value;
         wd.Location.WindDir        = xmlDoc.Descendants("direction").Attributes("name").First().Value;
         wd.Location.WindDesc       = xmlDoc.Descendants("speed").Attributes("name").First().Value;
         //wd.Location.Visibility = xmlDoc.Descendants("visibility").Attributes("value").First().Value;
         wd.Location.Cloud    = xmlDoc.Descendants("clouds").Attributes("name").First().Value;
         wd.Location.Humidity = xmlDoc.Descendants("humidity").Attributes("value").First().Value;
     }
     catch (XmlException e)
     {
         Console.WriteLine("Could not receive accurate data to " + e.Source);
         Console.WriteLine("The program will now quit...");
         Console.ReadKey();
         System.Environment.Exit(1);
     }
 }
Ejemplo n.º 3
0
 public static IWeatherDataService GetWeatherDataService(string OPEN_WEATHER_MAP)
 {
     if (OPEN_WEATHER_MAP.Equals("OPEN_WEATHER_MAP"))
     {
         return(WeatherMap.Instance());
     }
     return(new WeatherData());
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string key    = File.ReadAllText("appsettings.json");
            string APIkey = JObject.Parse(key).GetValue("DefaultKey").ToString();

            Console.WriteLine("Hello, Do you want to know what the weather? Please enter zip code here:");
            Console.WriteLine();
            string zipCode = Console.ReadLine();

            string apiCall = $"https://api.openweathermap.org/data/2.5/weather?zip={zipCode}&units=imperial&appid={APIkey}";

            Console.WriteLine();
            Console.WriteLine($"It is currently {WeatherMap.GetTemp(apiCall)} °F in your area.");
            Console.WriteLine("-----------------------------------------------------------------------------------------------");
        }
 public static WeatherDataServiceFactory getWeatherDataService(String Source)
 {
     try
     {
         if (Source.Equals(OPEN_WEATHER_MAP))
         {
             return(WeatherMap.Instance());
         }
         else
         {
             throw new WeatherDataException("Invalid Weather Service!");
         }
     }
     finally { }
 }
Ejemplo n.º 6
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.datDisp = ((WeatherApp.DataDisplay)(target));
                return;

            case 2:
                this.weatherMap = ((WeatherApp.WeatherMap)(target));
                return;

            case 3:
                this.Button = ((System.Windows.Controls.Button)(target));

            #line 22 "..\..\MainWindow.xaml"
                this.Button.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.Default = ((System.Windows.Controls.Button)(target));

            #line 23 "..\..\MainWindow.xaml"
                this.Default.Click += new System.Windows.RoutedEventHandler(this.Default_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.TextBox = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }