From: Gustavo Martin Date: Mon, 19 May 2014 05:43:57 +0000 (+0200) Subject: WindowsPhone: WeatherInformation X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=f9c1a5a35a2c9e94ba64e2967be5cbcfdd5d7026;p=CSharpForFun%2F.git WindowsPhone: WeatherInformation --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation.sln b/WindowsPhone/WeatherInformation/WeatherInformation.sln new file mode 100644 index 0000000..54c1b02 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherInformation", "WeatherInformation\WeatherInformation.csproj", "{71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|ARM.ActiveCfg = Debug|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|ARM.Build.0 = Debug|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|ARM.Deploy.0 = Debug|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|x86.ActiveCfg = Debug|x86 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|x86.Build.0 = Debug|x86 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Debug|x86.Deploy.0 = Debug|x86 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|Any CPU.Build.0 = Release|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|Any CPU.Deploy.0 = Release|Any CPU + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|ARM.ActiveCfg = Release|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|ARM.Build.0 = Release|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|ARM.Deploy.0 = Release|ARM + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|x86.ActiveCfg = Release|x86 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|x86.Build.0 = Release|x86 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7}.Release|x86.Deploy.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml new file mode 100644 index 0000000..895af5e --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs new file mode 100644 index 0000000..fcf2361 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs @@ -0,0 +1,247 @@ +using System; +using System.Diagnostics; +using System.Resources; +using System.Windows; +using System.Windows.Markup; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; +using WeatherInformation.Resources; +using WeatherInformation.ViewModels; + +namespace WeatherInformation +{ + public partial class App : Application + { + private static MainViewModel viewModel = null; + + /// + /// ViewModel estático que usan las vistas con el que se van a enlazar. + /// + /// Objeto MainViewModel. + public static MainViewModel ViewModel + { + get + { + // Retrasar la creación del modelo de vista hasta que sea necesario + if (viewModel == null) + viewModel = new MainViewModel(); + + return viewModel; + } + } + + /// + /// Proporcionar acceso sencillo al marco raíz de la aplicación telefónica. + /// + /// Marco raíz de la aplicación telefónica. + public static PhoneApplicationFrame RootFrame { get; private set; } + + /// + /// Constructor para el objeto Application. + /// + public App() + { + // Controlador global para excepciones no detectadas. + UnhandledException += Application_UnhandledException; + + // Inicialización XAML estándar + InitializeComponent(); + + // Inicialización especifica del teléfono + InitializePhoneApplication(); + + // Inicialización del idioma + InitializeLanguage(); + + // Mostrar información de generación de perfiles gráfica durante la depuración. + if (Debugger.IsAttached) + { + // Mostrar los contadores de velocidad de marcos actual + Application.Current.Host.Settings.EnableFrameRateCounter = true; + + // Mostrar las áreas de la aplicación que se están volviendo a dibujar en cada marco. + //Application.Current.Host.Settings.EnableRedrawRegions = true; + + // Habilitar el modo de visualización de análisis de no producción, + // que muestra áreas de una página que se entregan a la GPU con una superposición coloreada. + //Application.Current.Host.Settings.EnableCacheVisualization = true; + + // Impedir que la pantalla se apague mientras se realiza la depuración deshabilitando + // la detección de inactividad de la aplicación. + // Precaución: solo debe usarse en modo de depuración. Las aplicaciones que deshabiliten la detección de inactividad del usuario seguirán en ejecución + // y consumirán energía de la batería cuando el usuario no esté usando el teléfono. + PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; + } + } + + // Código para ejecutar cuando la aplicación se inicia (p.ej. a partir de Inicio) + // Este código no se ejecutará cuando la aplicación se reactive + private void Application_Launching(object sender, LaunchingEventArgs e) + { + } + + // Código para ejecutar cuando la aplicación se activa (se trae a primer plano) + // Este código no se ejecutará cuando la aplicación se inicie por primera vez + private void Application_Activated(object sender, ActivatedEventArgs e) + { + // Asegurarse de que el estado de la aplicación se restaura adecuadamente + if (!App.ViewModel.IsDataLoaded) + { + App.ViewModel.LoadData(); + } + } + + // Código para ejecutar cuando la aplicación se desactiva (se envía a segundo plano) + // Este código no se ejecutará cuando la aplicación se cierre + private void Application_Deactivated(object sender, DeactivatedEventArgs e) + { + } + + // Código para ejecutar cuando la aplicación se cierra (p.ej., al hacer clic en Atrás) + // Este código no se ejecutará cuando la aplicación se desactive + private void Application_Closing(object sender, ClosingEventArgs e) + { + // Asegurarse de que el estado de la aplicación requerida persiste aquí. + } + + // Código para ejecutar si hay un error de navegación + private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) + { + if (Debugger.IsAttached) + { + // Ha habido un error de navegación; interrumpir el depurador + Debugger.Break(); + } + } + + // Código para ejecutar en excepciones no controladas + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + if (Debugger.IsAttached) + { + // Se ha producido una excepción no controlada; interrumpir el depurador + Debugger.Break(); + } + } + + #region Inicialización de la aplicación telefónica + + // Evitar inicialización doble + private bool phoneApplicationInitialized = false; + + // No agregar ningún código adicional a este método + private void InitializePhoneApplication() + { + if (phoneApplicationInitialized) + return; + + // Crear el marco pero no establecerlo como RootVisual todavía; esto permite que + // la pantalla de presentación permanezca activa hasta que la aplicación esté lista para la presentación. + RootFrame = new PhoneApplicationFrame(); + RootFrame.Navigated += CompleteInitializePhoneApplication; + + // Controlar errores de navegación + RootFrame.NavigationFailed += RootFrame_NavigationFailed; + + // Controlar solicitudes de restablecimiento para borrar la pila de retroceso + RootFrame.Navigated += CheckForResetNavigation; + + // Asegurarse de que no volvemos a inicializar + phoneApplicationInitialized = true; + } + + // No agregar ningún código adicional a este método + private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) + { + // Establecer el objeto visual raíz para permitir que la aplicación se presente + if (RootVisual != RootFrame) + RootVisual = RootFrame; + + // Quitar este controlador porque ya no es necesario + RootFrame.Navigated -= CompleteInitializePhoneApplication; + } + + private void CheckForResetNavigation(object sender, NavigationEventArgs e) + { + // Si la aplicación ha recibido una navegación 'reset', tenemos que comprobarlo + // en la siguiente navegación para ver si se debe restablecer la pila de páginas + if (e.NavigationMode == NavigationMode.Reset) + RootFrame.Navigated += ClearBackStackAfterReset; + } + + private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) + { + // Anular registro del evento para que no se vuelva a llamar + RootFrame.Navigated -= ClearBackStackAfterReset; + + // Borrar solo la pila de navegaciones 'new' (hacia delante) y 'refresh' + if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh) + return; + + // Por coherencia de la IU, borrar toda la pila de páginas + while (RootFrame.RemoveBackEntry() != null) + { + ; // no hacer nada + } + } + + #endregion + + // Inicializar la fuente y la dirección de flujo de la aplicación según se define en sus cadenas de recursos traducidas. + // + // Para asegurarse de que la fuente de la aplicación está alineada con sus idiomas admitidos y que + // FlowDirection para todos esos idiomas sigue su dirección tradicional, ResourceLanguage + // y ResourceFlowDirection se debe inicializar en cada archivo resx para que estos valores coincidan con ese + // referencia cultural del archivo. Por ejemplo: + // + // AppResources.es-ES.resx + // El valor de ResourceLanguage debe ser "es-ES" + // El valor de ResourceFlowDirection debe ser "LeftToRight" + // + // AppResources.ar-SA.resx + // El valor de ResourceLanguage debe ser "ar-SA" + // El valor de ResourceFlowDirection debe ser "RightToLeft" + // + // Para obtener más información sobre cómo traducir aplicaciones para Windows Phone, consulta http://go.microsoft.com/fwlink/?LinkId=262072. + // + private void InitializeLanguage() + { + try + { + // Establecer la fuente para que coincida con el idioma definido por + // Cadena de recursos ResourceLanguage para cada idioma admitido. + // + // Recurrir a la fuente del idioma neutro si el idioma + // del teléfono no se admite. + // + // Si se produce un error del compilador, falta ResourceLanguage + // el archivo de recursos. + RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage); + + // Establecer FlowDirection de todos los elementos del marco raíz según + // en la cadena de recursos ResourceFlowDirection para cada + // idioma admitido. + // + // Si se produce un error del compilador, falta ResourceFlowDirection + // el archivo de recursos. + FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection); + RootFrame.FlowDirection = flow; + } + catch + { + // Si se detecta aquí una excepción, lo más probable es que se deba a + // ResourceLanguage no se ha establecido correctamente en un idioma admitido + // o ResourceFlowDirection se ha establecido en un valor distinto de LeftToRight + // o RightToLeft. + + if (Debugger.IsAttached) + { + Debugger.Break(); + } + + throw; + } + } + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/AlignmentGrid.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/AlignmentGrid.png new file mode 100644 index 0000000..f7d2e97 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/AlignmentGrid.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/ApplicationIcon.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/ApplicationIcon.png new file mode 100644 index 0000000..7d95d4e Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/ApplicationIcon.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileLarge.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileLarge.png new file mode 100644 index 0000000..e0c59ac Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileLarge.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileMedium.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileMedium.png new file mode 100644 index 0000000..e93b89d Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileMedium.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileSmall.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileSmall.png new file mode 100644 index 0000000..550b1b5 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/FlipCycleTileSmall.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileMediumLarge.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileMediumLarge.png new file mode 100644 index 0000000..686e6b5 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileMediumLarge.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileSmall.png b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileSmall.png new file mode 100644 index 0000000..d4b5ede Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Assets/Tiles/IconicTileSmall.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/add.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/add.png new file mode 100644 index 0000000..4b524d6 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/add.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/feature.settings.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/feature.settings.png new file mode 100644 index 0000000..8efcfc2 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/feature.settings.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/LocalizedStrings.cs b/WindowsPhone/WeatherInformation/WeatherInformation/LocalizedStrings.cs new file mode 100644 index 0000000..f0b3b30 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/LocalizedStrings.cs @@ -0,0 +1,14 @@ +using WeatherInformation.Resources; + +namespace WeatherInformation +{ + /// + /// Proporciona acceso a los recursos de cadena. + /// + public class LocalizedStrings + { + private static AppResources _localizedResources = new AppResources(); + + public AppResources LocalizedResources { get { return _localizedResources; } } + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml new file mode 100644 index 0000000..8c1626b --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs new file mode 100644 index 0000000..d53481a --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; +using WeatherInformation.Resources; + +namespace WeatherInformation +{ + public partial class MainPage : PhoneApplicationPage + { + // Constructor + public MainPage() + { + InitializeComponent(); + + // Establecer el contexto de datos del control ListBox control en los datos de ejemplo + DataContext = App.ViewModel; + + // Código de ejemplo para traducir ApplicationBar + //BuildLocalizedApplicationBar(); + } + + // Cargar datos para los elementos ViewModel + protected override void OnNavigatedTo(NavigationEventArgs e) + { + if (!App.ViewModel.IsDataLoaded) + { + App.ViewModel.LoadData(); + } + } + + private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + + } + + private void Location_Click(object sender, EventArgs e) + { + NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative)); + } + + private void Settings_Click(object sender, EventArgs e) + { + + } + + // Código de ejemplo para compilar una ApplicationBar traducida + //private void BuildLocalizedApplicationBar() + //{ + // // Establecer ApplicationBar de la página en una nueva instancia de ApplicationBar. + // ApplicationBar = new ApplicationBar(); + + // // Crear un nuevo botón y establecer el valor de texto en la cadena traducida de AppResources. + // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); + // appBarButton.Text = AppResources.AppBarButtonText; + // ApplicationBar.Buttons.Add(appBarButton); + + // // Crear un nuevo elemento de menú con la cadena traducida de AppResources. + // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); + // ApplicationBar.MenuItems.Add(appBarMenuItem); + //} + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml new file mode 100644 index 0000000..c7d1ae2 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs new file mode 100644 index 0000000..2862df7 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; +using System.IO.IsolatedStorage; +using Windows.Devices.Geolocation; +using System.Device.Location; +using System.Windows.Shapes; +using System.Windows.Media; +using Microsoft.Phone.Maps.Controls; + +namespace WeatherInformation +{ + public partial class MapPage : PhoneApplicationPage + { + public MapPage() + { + InitializeComponent(); + } + + protected override void OnNavigatedTo(NavigationEventArgs e) + { + if (!IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent")) + { + MessageBoxResult result = + MessageBox.Show("This app accesses your phone's location. Is that ok?", + "Location", + MessageBoxButton.OKCancel); + + if (result == MessageBoxResult.OK) + { + IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true; + } + else + { + IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false; + } + + IsolatedStorageSettings.ApplicationSettings.Save(); + } + + bool locationConsentValue; + if (IsolatedStorageSettings.ApplicationSettings.TryGetValue("LocationConsent", out locationConsentValue)) + { + this.GetLocation(); + } + } + + private async void GetLocation() + { + + if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true) + { + // The user has opted out of Location. + return; + } + + Geolocator geolocator = new Geolocator(); + geolocator.DesiredAccuracyInMeters = 50; + + try + { + Geoposition geoposition = await geolocator.GetGeopositionAsync( + maximumAge: TimeSpan.FromMinutes(5), + timeout: TimeSpan.FromSeconds(10) + ); + GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(geoposition.Coordinate); + + // Create a small circle to mark the current location. + Ellipse myCircle = new Ellipse(); + myCircle.Fill = new SolidColorBrush(Colors.Blue); + myCircle.Height = 20; + myCircle.Width = 20; + myCircle.Opacity = 50; + + // Create a MapOverlay to contain the circle. + MapOverlay myLocationOverlay = new MapOverlay(); + myLocationOverlay.Content = myCircle; + myLocationOverlay.PositionOrigin = new Point(0.5, 0.5); + myLocationOverlay.GeoCoordinate = myGeoCoordinate; + + // Create a MapLayer to contain the MapOverlay. + MapLayer myLocationLayer = new MapLayer(); + myLocationLayer.Add(myLocationOverlay); + + this.mapWeatherInformation.Center = myGeoCoordinate; + this.mapWeatherInformation.ZoomLevel = 13; + + // Add the MapLayer to the Map. + this.mapWeatherInformation.Layers.Add(myLocationLayer); + + + + //LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00"); + //LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00"); + } + catch (Exception ex) + { + if ((uint)ex.HResult == 0x80004004) + { + // the application does not have the right capability or the location master switch is off + //StatusTextBlock.Text = "location is disabled in phone settings."; + } + //else + { + // something else happened acquring the location + } + } + } + + public static class CoordinateConverter + { + public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate) + { + return new GeoCoordinate + ( + geocoordinate.Latitude, + geocoordinate.Longitude, + geocoordinate.Altitude ?? Double.NaN, + geocoordinate.Accuracy, + geocoordinate.AltitudeAccuracy ?? Double.NaN, + geocoordinate.Speed ?? Double.NaN, + geocoordinate.Heading ?? Double.NaN + ); + } + } + + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Clouds.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Clouds.cs new file mode 100644 index 0000000..5570271 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Clouds.cs @@ -0,0 +1,10 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Clouds + { + public int all { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs new file mode 100644 index 0000000..21a07b8 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs @@ -0,0 +1,11 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Coord + { + public double lon { get; set; } + public int lat { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs new file mode 100644 index 0000000..05d0c21 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class CurrentWeather + { + public Coord coord { get; set; } + public Sys sys { get; set; } + public List weather { get; set; } + public string @base { get; set; } + public Main main { get; set; } + public Wind wind { get; set; } + public Rain rain { get; set; } + public Clouds clouds { get; set; } + public int dt { get; set; } + public int id { get; set; } + public string name { get; set; } + public int cod { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs new file mode 100644 index 0000000..2840930 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs @@ -0,0 +1,14 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Main + { + public double temp { get; set; } + public int pressure { get; set; } + public int humidity { get; set; } + public double temp_min { get; set; } + public double temp_max { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Rain.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Rain.cs new file mode 100644 index 0000000..14229be --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Rain.cs @@ -0,0 +1,20 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Rain + { + private double threeHours; + + public void set3h(double three) + { + this.threeHours = three; + } + + public double get3h() + { + return this.threeHours; + } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Sys.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Sys.cs new file mode 100644 index 0000000..002e8cd --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Sys.cs @@ -0,0 +1,13 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Sys + { + public double message { get; set; } + public string country { get; set; } + public int sunrise { get; set; } + public int sunset { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Weather.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Weather.cs new file mode 100644 index 0000000..6f5529f --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Weather.cs @@ -0,0 +1,13 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Weather + { + public int id { get; set; } + public string main { get; set; } + public string description { get; set; } + public string icon { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs new file mode 100644 index 0000000..6668990 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs @@ -0,0 +1,11 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Wind + { + public double speed { get; set; } + public int deg { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/City.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/City.cs new file mode 100644 index 0000000..6dd2b8b --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/City.cs @@ -0,0 +1,14 @@ +using System; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class City + { + public int id { get; set; } + public string name { get; set; } + public Coord coord { get; set; } + public string country { get; set; } + public int population { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Coord.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Coord.cs new file mode 100644 index 0000000..3f2f2f8 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Coord.cs @@ -0,0 +1,11 @@ +using System; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class Coord + { + public double lon { get; set; } + public double lat { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/ForecastWeather.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/ForecastWeather.cs new file mode 100644 index 0000000..e8e6bfe --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/ForecastWeather.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class ForecastWeather + { + public string cod { get; set; } + public double message { get; set; } + public City city { get; set; } + public int cnt { get; set; } + public List list { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/List.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/List.cs new file mode 100644 index 0000000..6b9c0dd --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/List.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class List + { + public int dt { get; set; } + public Temp temp { get; set; } + public double pressure { get; set; } + public int humidity { get; set; } + public List weather { get; set; } + public double speed { get; set; } + public int deg { get; set; } + public int clouds { get; set; } + public double rain { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Temp.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Temp.cs new file mode 100644 index 0000000..cc420c3 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Temp.cs @@ -0,0 +1,15 @@ +using System; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class Temp + { + public double day { get; set; } + public double min { get; set; } + public double max { get; set; } + public double night { get; set; } + public double eve { get; set; } + public double morn { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Weather.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Weather.cs new file mode 100644 index 0000000..de25421 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Weather.cs @@ -0,0 +1,13 @@ +using System; + +namespace WeatherInformation.Model.ForecastWeatherParser +{ + public class Weather + { + public int id { get; set; } + public string main { get; set; } + public string description { get; set; } + public string icon { get; set; } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/JsonDataParser/JsonParser.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/JsonDataParser/JsonParser.cs new file mode 100644 index 0000000..3f077cb --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/JsonDataParser/JsonParser.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; +using WeatherInformation.Model.CurrentWeatherParser; +using WeatherInformation.Model.ForecastWeatherParser; +using System; + +namespace WeatherInformation.Model.JsonDataParser +{ + class JsonParser + { + /// + /// The _json settings. + /// + private static readonly JsonSerializerSettings _jsonSettings = + new JsonSerializerSettings + { + Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) + { + //Console.WriteLine(args.ErrorContext.Error.Message); No logs for WP8 :( + args.ErrorContext.Handled = true; + } + }; + + public TWeatherData ParserWeatherData(String jsonData) + { + return JsonConvert.DeserializeObject(jsonData, _jsonSettings); + } + } +} diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/ServiceParser.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/ServiceParser.cs new file mode 100644 index 0000000..d855c90 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/ServiceParser.cs @@ -0,0 +1,31 @@ +using WeatherInformation.Model.CurrentWeatherParser; +using WeatherInformation.Model.ForecastWeatherParser; +using WeatherInformation.Model.JsonDataParser; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WeatherInformation.Model.Services +{ + class ServiceParser + { + private readonly JsonParser _jsonParser; + + public ServiceParser(JsonParser jsonParser) + { + this._jsonParser = jsonParser; + } + + public CurrentWeather GetCurrentWeather(String jsonData) + { + return this._jsonParser.ParserWeatherData(jsonData); + } + + public ForecastWeather GetForecastWeather(String jsonData) + { + return this._jsonParser.ParserWeatherData(jsonData); + } + } +} diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AppManifest.xml b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AppManifest.xml new file mode 100644 index 0000000..3b998eb --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AppManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1181882 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie los valores de estos atributos para modificar la información +// asociada a un ensamblado. +[assembly: AssemblyTitle("WeatherInformation")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WeatherInformation")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si ComVisible se establece en False, los componentes COM no verán los +// tipos de este ensamblado. Si necesita obtener acceso a un tipo de este ensamblado desde +// COM, establezca el atributo ComVisible en True en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM +[assembly: Guid("21be107b-f7de-4ff1-b103-90430c323fe2")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y revisión +// mediante el carácter '*', como se muestra a continuación: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("es-ES")] diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml new file mode 100644 index 0000000..6f0fb18 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + Assets\ApplicationIcon.png + + + + + + + + + + + + + + + + Assets\Tiles\FlipCycleTileSmall.png + 0 + Assets\Tiles\FlipCycleTileMedium.png + WeatherInformation + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs new file mode 100644 index 0000000..78ffd40 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// Este código fue generado por una herramienta. +// Versión de runtime:4.0.30319.17626 +// +// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si +// se vuelve a generar el código. +// +//------------------------------------------------------------------------------ + +namespace WeatherInformation.Resources +{ + using System; + + + /// + /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. + /// + // StronglyTypedResourceBuilder generó automáticamente esta clase + // a través de una herramienta como ResGen o Visual Studio. + // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + // con la opción /str o recompila tu proyecto de Visual Studio. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class AppResources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal AppResources() + { + } + + /// + /// Devuelve la instancia de ResourceManager almacenada en caché usada por esta clase. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager + { + get + { + if (object.ReferenceEquals(resourceMan, null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WeatherInformation.Resources.AppResources", typeof(AppResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las + /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + + /// + /// Busca una cadena traducida similar a LeftToRight. + /// + public static string ResourceFlowDirection + { + get + { + return ResourceManager.GetString("ResourceFlowDirection", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a us-EN. + /// + public static string ResourceLanguage + { + get + { + return ResourceManager.GetString("ResourceLanguage", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a MI APLICACIÓN. + /// + public static string ApplicationTitle + { + get + { + return ResourceManager.GetString("ApplicationTitle", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a Valor de propiedad en tiempo de ejecución de ejemplo. + /// + public static string SampleProperty + { + get + { + return ResourceManager.GetString("SampleProperty", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar al texto del botón. + /// + public static string AppBarButtonText + { + get + { + return ResourceManager.GetString("AppBarButtonText", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a elemento de menú. + /// + public static string AppBarMenuItemText + { + get + { + return ResourceManager.GetString("AppBarMenuItemText", resourceCulture); + } + } + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx new file mode 100644 index 0000000..7f350d6 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + LeftToRight + Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language + + + es-ES + Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. + + + MI APLICACIÓN + + + Valor de propiedad en tiempo de ejecución de ejemplo + + + agregar + + + Elemento de menú + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml new file mode 100644 index 0000000..4c4241e --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/ItemViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/ItemViewModel.cs new file mode 100644 index 0000000..7988bde --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/ItemViewModel.cs @@ -0,0 +1,130 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; + +namespace WeatherInformation.ViewModels +{ + public class ItemViewModel : INotifyPropertyChanged + { + private string _lineOne; + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace. + /// + /// + public string LineOne + { + get + { + return _lineOne; + } + set + { + if (value != _lineOne) + { + _lineOne = value; + NotifyPropertyChanged("LineOne"); + } + } + } + + private string _lineTwo; + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace. + /// + /// + public string LineTwo + { + get + { + return _lineTwo; + } + set + { + if (value != _lineTwo) + { + _lineTwo = value; + NotifyPropertyChanged("LineTwo"); + } + } + } + + private string _lineThree; + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace. + /// + /// + public string LineThree + { + get + { + return _lineThree; + } + set + { + if (value != _lineThree) + { + _lineThree = value; + NotifyPropertyChanged("LineThree"); + } + } + } + + private string _lineFour; + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace. + /// + /// + public string LineFour + { + get + { + return _lineFour; + } + set + { + if (value != _lineFour) + { + _lineFour = value; + NotifyPropertyChanged("LineFour"); + } + } + } + + private string _lineFive; + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace. + /// + /// + public string LineFive + { + get + { + return _lineFive; + } + set + { + if (value != _lineFive) + { + _lineFive = value; + NotifyPropertyChanged("LineFive"); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + private void NotifyPropertyChanged(String propertyName) + { + PropertyChangedEventHandler handler = PropertyChanged; + if (null != handler) + { + handler(this, new PropertyChangedEventArgs(propertyName)); + } + } + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..3deea79 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Globalization; +using WeatherInformation.Model.ForecastWeatherParser; +using WeatherInformation.Model.JsonDataParser; +using WeatherInformation.Model.Services; +using WeatherInformation.Resources; + +namespace WeatherInformation.ViewModels +{ + public class MainViewModel : INotifyPropertyChanged + { + public MainViewModel() + { + this.ForecastItems = new ObservableCollection(); + this.CurrentItems = new ObservableCollection(); + this._serviceParser = new ServiceParser(new JsonParser()); + } + + /// + /// Colección para objetos ItemViewModel. + /// + public ObservableCollection ForecastItems { get; private set; } + public ObservableCollection CurrentItems { get; private set; } + //public string ForecastHeader { get; private set; } + + private string _sampleProperty = "Sample Runtime Property Value"; + + private readonly ServiceParser _serviceParser; + + string _jsonForeCastWeatherData = + "{" + + "\"cod\":\"200\"," + + "\"message\":0.0048," + + "\"city\":{\"id\":2641549,\"name\":\"Newtonhill\",\"coord\":{\"lon\":-2.15,\"lat\":57.033329},\"country\":\"GB\",\"population\":0}," + + "\"cnt\":15," + + "\"list\":[" + + "{\"dt\":1397304000,\"temp\":{\"day\":286.15,\"min\":284.62,\"max\":286.15,\"night\":284.62,\"eve\":285.7,\"morn\":286.15},\"pressure\":1016.67,\"humidity\":84,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.68,\"deg\":252,\"clouds\":0,\"rain\":0.25}," + + "{\"dt\":1397390400,\"temp\":{\"day\":284.92,\"min\":282.3,\"max\":284.92,\"night\":282.3,\"eve\":283.79,\"morn\":284.24},\"pressure\":1021.62,\"humidity\":84,\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"speed\":7.91,\"deg\":259,\"clouds\":92}," + + "{\"dt\":1397476800,\"temp\":{\"day\":282.1,\"min\":280.32,\"max\":282.1,\"night\":280.32,\"eve\":281.51,\"morn\":281.65},\"pressure\":1033.84,\"humidity\":92,\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"speed\":8.37,\"deg\":324,\"clouds\":20}," + + "{\"dt\":1397563200,\"temp\":{\"day\":280.73,\"min\":280.11,\"max\":281.4,\"night\":281.4,\"eve\":280.75,\"morn\":280.11},\"pressure\":1039.27,\"humidity\":97,\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"speed\":7.31,\"deg\":184,\"clouds\":12}," + + "{\"dt\":1397649600,\"temp\":{\"day\":281.73,\"min\":281.03,\"max\":282.22,\"night\":281.69,\"eve\":282.22,\"morn\":281.03},\"pressure\":1036.05,\"humidity\":90,\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"speed\":7.61,\"deg\":205,\"clouds\":68}," + + "{\"dt\":1397736000,\"temp\":{\"day\":282.9,\"min\":281.45,\"max\":283.21,\"night\":282.71,\"eve\":283.06,\"morn\":281.49},\"pressure\":1029.39,\"humidity\":83,\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"speed\":6.17,\"deg\":268,\"clouds\":56}," + + "{\"dt\":1397822400,\"temp\":{\"day\":285.26,\"min\":281.55,\"max\":285.26,\"night\":282.48,\"eve\":285.09,\"morn\":281.55},\"pressure\":1025.83,\"humidity\":0,\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"01d\"}],\"speed\":5.31,\"deg\":221,\"clouds\":10}," + + "{\"dt\":1397908800,\"temp\":{\"day\":284.29,\"min\":281.5,\"max\":284.29,\"night\":282.53,\"eve\":283.58,\"morn\":281.5},\"pressure\":1024.55,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":5.51,\"deg\":192,\"clouds\":6}," + + "{\"dt\":1397995200,\"temp\":{\"day\":283.36,\"min\":281.62,\"max\":284.34,\"night\":284.04,\"eve\":284.34,\"morn\":281.62},\"pressure\":1019.58,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.66,\"deg\":149,\"clouds\":0,\"rain\":0.48}," + + "{\"dt\":1398081600,\"temp\":{\"day\":282.24,\"min\":280.51,\"max\":282.41,\"night\":280.51,\"eve\":282.41,\"morn\":280.9},\"pressure\":1027.35,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":8.17,\"deg\":221,\"clouds\":10,\"rain\":0.94}," + + "{\"dt\":1398168000,\"temp\":{\"day\":282.28,\"min\":279.76,\"max\":282.28,\"night\":280.69,\"eve\":281.13,\"morn\":279.76},\"pressure\":1038.31,\"humidity\":0,\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"01d\"}],\"speed\":6.33,\"deg\":172,\"clouds\":1}," + + "{\"dt\":1398254400,\"temp\":{\"day\":281.54,\"min\":280.52,\"max\":281.54,\"night\":281.44,\"eve\":281.23,\"morn\":280.52},\"pressure\":1022.4,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":7.84,\"deg\":140,\"clouds\":91,\"rain\":1.24}," + + "{\"dt\":1398340800,\"temp\":{\"day\":282.1,\"min\":280.66,\"max\":282.78,\"night\":280.97,\"eve\":282.78,\"morn\":280.66},\"pressure\":1013.39,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":9.43,\"deg\":164,\"clouds\":98,\"rain\":1.03}," + + "{\"dt\":1398427200,\"temp\":{\"day\":282.11,\"min\":280.72,\"max\":282.32,\"night\":282.32,\"eve\":280.99,\"morn\":280.72},\"pressure\":1018.65,\"humidity\":0,\"weather\":[{\"id\":502,\"main\":\"Rain\",\"description\":\"heavy intensity rain\",\"icon\":\"10d\"}],\"speed\":5.26,\"deg\":158,\"clouds\":83,\"rain\":14.4}," + + "{\"dt\":1398513600,\"temp\":{\"day\":282.75,\"min\":280.61,\"max\":282.75,\"night\":280.61,\"eve\":281.75,\"morn\":281.96},\"pressure\":1007.4,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":9.18,\"deg\":198,\"clouds\":35,\"rain\":0.55}" + + "]}"; + + /// + /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace + /// + /// + public string SampleProperty + { + get + { + return _sampleProperty; + } + set + { + if (value != _sampleProperty) + { + _sampleProperty = value; + NotifyPropertyChanged("SampleProperty"); + } + } + } + + /// + /// Propiedad de ejemplo que devuelve una cadena traducida + /// + public string LocalizedSampleProperty + { + get + { + return AppResources.SampleProperty; + } + } + + public bool IsDataLoaded + { + get; + private set; + } + + /// + /// Crear y agregar unos pocos objetos ItemViewModel a la colección Items. + /// + public void LoadData() + { + ForecastWeather weather = this._serviceParser.GetForecastWeather(this._jsonForeCastWeatherData); + + foreach (WeatherInformation.Model.ForecastWeatherParser.List item in weather.list) + { + DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + DateTime date = unixTime.AddSeconds(item.dt).ToLocalTime(); + this.ForecastItems.Add(new ItemViewModel() + { + LineOne = date.ToString("ddd", CultureInfo.InvariantCulture), + LineTwo = date.ToString("dd", CultureInfo.InvariantCulture), + LineThree = String.Format("{0:0.##}", item.temp.max), + LineFour = String.Format("{0:0.##}", item.temp.min), + LineFive = "/Assets/Tiles/IconicTileMediumLarge.png" + }); + } + + this.IsDataLoaded = true; + } + + public event PropertyChangedEventHandler PropertyChanged; + private void NotifyPropertyChanged(String propertyName) + { + PropertyChangedEventHandler handler = PropertyChanged; + if (null != handler) + { + handler(this, new PropertyChangedEventArgs(propertyName)); + } + } + } +} \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj new file mode 100644 index 0000000..9bd64e9 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj @@ -0,0 +1,197 @@ + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {71D9693C-AF50-4D7F-AC37-811BA1F1A0D7} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + WeatherInformation + WeatherInformation + WindowsPhone + v8.0 + $(TargetFrameworkVersion) + true + + + true + true + WeatherInformation_$(Configuration)_$(Platform).xap + Properties\AppManifest.xml + WeatherInformation.App + true + 11.0 + true + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\x86\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\x86\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\ARM\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\ARM\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + + App.xaml + + + + MainPage.xaml + + + MapPage.xaml + + + + + + + + + + + + + + + + + + + + True + True + AppResources.resx + + + + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + + + + + + + Designer + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + PublicResXFileCodeGenerator + AppResources.Designer.cs + + + + + ..\packages\Newtonsoft.Json.6.0.3\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll + + + + + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/packages.config b/WindowsPhone/WeatherInformation/WeatherInformation/packages.config new file mode 100644 index 0000000..b1d93b5 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file