diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/App.xaml.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/App.xaml.cs index 684dc51..f4679cc 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/App.xaml.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/App.xaml.cs @@ -1,33 +1,20 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; -using Windows.Foundation; -using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; -namespace EyesAndEars.UWP -{ +namespace EyesAndEars.UWP { /// /// Provides application-specific behavior to supplement the default Application class. /// - sealed partial class App : Application - { + sealed partial class App : Application { /// /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// - public App() - { + public App() { this.InitializeComponent(); this.Suspending += OnSuspending; } @@ -37,21 +24,18 @@ namespace EyesAndEars.UWP /// will be used such as when the application is launched to open a specific file. /// /// Details about the launch request and process. - protected override void OnLaunched(LaunchActivatedEventArgs e) - { + protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active - if (rootFrame == null) - { + if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; - if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) - { + if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } @@ -59,10 +43,8 @@ namespace EyesAndEars.UWP Window.Current.Content = rootFrame; } - if (e.PrelaunchActivated == false) - { - if (rootFrame.Content == null) - { + if (e.PrelaunchActivated == false) { + if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter @@ -78,8 +60,7 @@ namespace EyesAndEars.UWP /// /// The Frame which failed navigation /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) - { + void OnNavigationFailed(object sender, NavigationFailedEventArgs e) { throw new Exception("Failed to load Page " + e.SourcePageType.FullName); } @@ -90,8 +71,7 @@ namespace EyesAndEars.UWP /// /// The source of the suspend request. /// Details about the suspend request. - private void OnSuspending(object sender, SuspendingEventArgs e) - { + private void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); //TODO: Save application state and stop any background activity deferral.Complete(); diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj index b89788b..5ce7dc5 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj @@ -169,6 +169,9 @@ 4.7.0 + + 4.3.0 + diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 5d6633a..3762aa2 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -47,9 +47,13 @@ - - @@ -59,9 +63,11 @@ - - + @@ -71,10 +77,14 @@ - - + @@ -83,8 +93,9 @@ - + @@ -93,8 +104,10 @@ - + @@ -103,8 +116,9 @@ - + diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs index 10d622f..0318898 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs @@ -1,32 +1,35 @@ -using EyesAndEars.UWP.ViewModels; -using EyesAndEars.UWP.Services; +using EyesAndEars.UWP.Services; +using EyesAndEars.UWP.ViewModels; +using System; +using System.Diagnostics; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using EyesAndEars.UWP.Models; -using System; -using System.Threading.Tasks; -using System.Threading; - -// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 - -namespace EyesAndEars.UWP -{ - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public sealed partial class MainPage : Page - { - private MainPageVM _vm = new MainPageVM(); - public MainPage() - { - this.InitializeComponent(); - IntialiseDataContextAsync(); - // Need to set a refresh timer so it updates every 1 second or so... + +namespace EyesAndEars.UWP { + + public sealed partial class MainPage : Page { + + MainPageVM _vm = new MainPageVM(); + DispatcherTimer _dispatcherTimer = new DispatcherTimer(); + + public MainPage() { + InitializeComponent(); + IntialiseDataContext(); + IntialiseRefreshTime(); } - private void IntialiseDataContextAsync() { + private void IntialiseDataContext() { try { // The Update features are not yet working... + + /* + * Note: Why I Did Not Use "await" Here. + * ============================================================ + * "await" is not used here because the app. is useless until + * the data is retreived from DataServices (I.E. Web). It is, + * also, called from "MainPain" above and the compiler don't + * like you doing that. + */ _vm.FactoryDevice1 = DataServices.UpdateFactoryDevice(1).Result; _vm.FactoryDevice2 = DataServices.UpdateFactoryDevice(2).Result; _vm.FactoryDevice3 = DataServices.UpdateFactoryDevice(3).Result; @@ -36,15 +39,55 @@ namespace EyesAndEars.UWP DataContext = _vm; } catch (Exception) { + /* + * Note: About this Exception + * ============================================================ + * This is catch-block is here to give the user a chance to + * update the base-URL or show me what the app. is doing before + * it is abruptly closed by Windows. It, also, gives the server + * a bit of time to fix any problems it is having before this + * app. thinks it is broken. Make no mistake, though. All this + * is doing it buying the user some time. The app. is not is a + * good state if execeptions are getting caught here -- + * regardless of the type or the reasons why. + */ _vm = DataServices.CreateFallBackViewModel(); DataContext = _vm; - //throw; + } + } + + void IntialiseRefreshTime() { + // TimeSpan Intervals: Days, Hours, Minutes, Seconds, Milliseconds. + _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); + _dispatcherTimer.Tick += UpdateViewModel; + _dispatcherTimer.Start(); + } + + async void UpdateViewModel(object sender, object e) { + try { + // I SHOULD PUT THE TRY-CATCH BLOCK IN DATASERVICES AND IF + // ERROR THROWN THERE, A ERROR/WARNING VM OBJECT SHOULD BE MADE + // UPDATED THERE. + // The Update features are not yet working... + _vm.FactoryDevice1 = await DataServices.UpdateFactoryDevice(1); + _vm.FactoryDevice2 = await DataServices.UpdateFactoryDevice(2); + _vm.FactoryDevice3 = await DataServices.UpdateFactoryDevice(3); + _vm.GalleryDevice1 = await DataServices.UpdateGalleryDevice(4); + _vm.GalleryDevice2 = await DataServices.UpdateGalleryDevice(5); + _vm.GalleryDevice3 = await DataServices.UpdateGalleryDevice(6); + Debug.WriteLine($"Updated GUI | VM: {_vm.FactoryDevice1.LatestReading.Reading}"); + } + catch (Exception) { + // Shouldn't be relying on this at this point in the cycle. + // If there is a problem it should be shown as such... + // and dealt with as one. + _vm = DataServices.CreateFallBackViewModel(); } } private async void RefreshButton_Click(object sender, RoutedEventArgs e) { // GET THE INITIALISATION WORKING FIRST AND THE DEFAULT CYCLE... - + } private void SaveURLButton_Click(object sender, RoutedEventArgs e) { diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs index ab10f64..7265d81 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs @@ -9,7 +9,7 @@ namespace EyesAndEars.UWP.Models { public readonly DateTime DateOfStatusRecording; public DeviceStatus() { } - + public DeviceStatus(int id, string status, DateTime dateOfStatusRecording) { Id = id; Status = status; diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/AssemblyInfo.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/AssemblyInfo.cs index 3da156b..9646b70 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/AssemblyInfo.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs index 2aeea3b..5a0a1c5 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs @@ -7,15 +7,16 @@ namespace EyesAndEars.UWP.Services { public static class DataServices { public static async Task UpdateFactoryDevice(int deviceId) { - //var t = await WebServices.GetLightReading("ht", deviceId); + // This should cause an error right now -- deliberate for error checking. + var t = await WebServices.GetLightReading("ht", deviceId); // Need to map the json result to the models and display in view. return new FactoryDevice(); } public static async Task UpdateGalleryDevice(int deviceId) { - //var t = await WebServices.GetLightReading("ht", deviceId); + // This should cause an error right now -- deliberate for error checking. + var t = await WebServices.GetLightReading("ht", deviceId); // Need to map the json result to the models and display in view. - return new GalleryDevice(); } diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs index 6f94343..b02695a 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs @@ -19,7 +19,7 @@ namespace EyesAndEars.UWP.ViewModels { public MainPageVM(FactoryDevice f1, FactoryDevice f2, FactoryDevice f3, GalleryDevice g1, GalleryDevice g2, GalleryDevice g3) { - + FactoryDevice1 = f1; FactoryDevice2 = f2; FactoryDevice3 = f3; @@ -29,10 +29,10 @@ namespace EyesAndEars.UWP.ViewModels { } FactoryDevice _factoryDevice1; - public FactoryDevice FactoryDevice1 { + public FactoryDevice FactoryDevice1 { get { return _factoryDevice1; } set { - if(value != _factoryDevice1) { + if (value != _factoryDevice1) { _factoryDevice1 = value; NotifyPropertyChanged("FactoryDevice1"); }