A UWP dashboard which provides live updates for the 'Personal Flash in Real-Time (Andy)' and 'Personal Flash in Real-Time (Tony)' artworks -- part of the 'Return to Ritherdon' project by Nicola Ellis. Documentation can be found at
https://git.abbether.net/return-to-ritherdon/rtr-docs/src/branch/master/eyes-and-ears
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
4.3 KiB
97 lines
4.3 KiB
using EyesAndEars.UWP.Services; |
|
using EyesAndEars.UWP.ViewModels; |
|
using System; |
|
using System.Diagnostics; |
|
using Windows.UI.Xaml; |
|
using Windows.UI.Xaml.Controls; |
|
|
|
namespace EyesAndEars.UWP { |
|
|
|
public sealed partial class MainPage : Page { |
|
|
|
MainPageVM _vm = new MainPageVM(); |
|
DispatcherTimer _dispatcherTimer = new DispatcherTimer(); |
|
|
|
public MainPage() { |
|
InitializeComponent(); |
|
IntialiseDataContext(); |
|
IntialiseRefreshTime(); |
|
} |
|
|
|
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; |
|
_vm.GalleryDevice1 = DataServices.UpdateGalleryDevice(4).Result; |
|
_vm.GalleryDevice2 = DataServices.UpdateGalleryDevice(5).Result; |
|
_vm.GalleryDevice3 = DataServices.UpdateGalleryDevice(6).Result; |
|
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; |
|
} |
|
} |
|
|
|
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) { |
|
// WORK ON THIS WENT YOU HAVE A LIVE SYSTEM WORKING WITH KNOWABLE DEFAULTS. |
|
} |
|
} |
|
}
|
|
|