viernes, 25 de febrero de 2011

Obtención de Datos del Clima basado en un WOEID usando Yahoo API en C# para Windows Phone 7

Para el desarrollo de aplicaciones mobiles de apoyo al viajero uno de los temas más socorridos es el estado del tiempo.





using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace F.Phone.Services.Weather
{
    public class YahooWeather
    {
        public const string WeatherUrl = "http://weather.yahooapis.com/forecastrss?w={0}";
        public const string AppKey = "YOUR-APP-ID";
        WebClient proxy;
        WebClient Proxy
        {
            get
            {
                if (proxy == null)
                {
                    proxy = new WebClient();

                }


                return proxy;
            }
        }

        public bool IsInError { get; set; }
        public string ErrorDescription { get; set; }
        public event EventHandler<DownloadStringCompletedEventArgs> DownloadedString;
        /// <summary>
        ///
        /// </summary>
        /// <param name="woeid"></param>
        public void GetWeatherReport(string woeid) {
            try{
            Proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Proxy_DownloadStringCompleted);
            Proxy.DownloadStringAsync(
                new Uri(
                    string.Format (WeatherUrl , woeid )
                ));
            }
            catch (Exception ex)
            {
                IsInError = true;
                ErrorDescription = ex.Message;
            }

        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (DownloadedString != null)
                {

                    DownloadedString(sender, e);

                }
            }
            catch (Exception ex)
            {
                IsInError = true;
                ErrorDescription = ex.Message;
            }
            finally {
                proxy = null;
            }
        }

    }
}


Transacciones Fiori

  /UI2/CACHE Register service for UI2 cache use /UI2/CACHE_DEL Delete cache entries /UI2/CHIP Chip Registration /UI2/CUST Customizing of UI ...