diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj index b8724c9..b89788b 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj @@ -122,7 +122,14 @@ MainPage.xaml + + + + + + + @@ -130,7 +137,7 @@ - + @@ -151,9 +158,17 @@ + + 2.9.8 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + 6.2.9 + + 4.7.0 + diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 41c39d1..5d6633a 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -19,7 +19,7 @@ + Source="Images\logo.png"/> @@ -47,9 +47,9 @@ - - @@ -125,7 +125,6 @@ FontFamily="Segoe MDL2 Assets" Content="" Height="79" Width="79" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="28" - Click="InfoButton_Click" ToolTipService.Placement="Mouse" ToolTipService.ToolTip="This is a link to a webpage with information about Nicola and the project."/> diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs index db27073..10d622f 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs @@ -1,17 +1,11 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; +using EyesAndEars.UWP.ViewModels; +using EyesAndEars.UWP.Services; 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; +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 @@ -22,21 +16,39 @@ namespace EyesAndEars.UWP /// 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... } - private void InfoButton_Click(object sender, RoutedEventArgs e) { - + private void IntialiseDataContextAsync() { + try { + // The Update features are not yet working... + _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) { + _vm = DataServices.CreateFallBackViewModel(); + DataContext = _vm; + //throw; + } } - private void RefreshButton_Click(object sender, RoutedEventArgs e) { - + 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. } } } diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs new file mode 100644 index 0000000..ab10f64 --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs @@ -0,0 +1,19 @@ +using System; + +namespace EyesAndEars.UWP.Models { + + public class DeviceStatus { + + public readonly int Id; + public readonly string Status; + public readonly DateTime DateOfStatusRecording; + + public DeviceStatus() { } + + public DeviceStatus(int id, string status, DateTime dateOfStatusRecording) { + Id = id; + Status = status; + DateOfStatusRecording = dateOfStatusRecording; + } + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/FactoryDevice.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/FactoryDevice.cs new file mode 100644 index 0000000..080b53e --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/FactoryDevice.cs @@ -0,0 +1,19 @@ +namespace EyesAndEars.UWP.Models { + public class FactoryDevice { + + public int Id { get; set; } + + public LightReading LatestReading { get; set; } + + public DeviceStatus LatestStatus { get; set; } + + public FactoryDevice() { } + + public FactoryDevice(int id, LightReading reading, DeviceStatus status) { + Id = id; + LatestReading = reading; + LatestStatus = status; + } + + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/GalleryDevice.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/GalleryDevice.cs new file mode 100644 index 0000000..23c83f2 --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/GalleryDevice.cs @@ -0,0 +1,15 @@ +namespace EyesAndEars.UWP.Models { + public class GalleryDevice { + + public readonly int Id; + + public readonly DeviceStatus LatestStatus; + + public GalleryDevice() { } + + public GalleryDevice(int id, DeviceStatus status) { + Id = id; + LatestStatus = status; + } + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/LightReading.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/LightReading.cs new file mode 100644 index 0000000..aa77bc1 --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Models/LightReading.cs @@ -0,0 +1,19 @@ +using System; + +namespace EyesAndEars.UWP.Models { + + public class LightReading { + + public readonly int Id; + public readonly int Reading; + public readonly DateTime MomentReadingWasTaken; + + public LightReading() { } + + public LightReading(int id, int reading, DateTime momentOfRecording) { + Id = id; + Reading = reading; + MomentReadingWasTaken = momentOfRecording; + } + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs new file mode 100644 index 0000000..2aeea3b --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs @@ -0,0 +1,42 @@ +using EyesAndEars.UWP.Models; +using EyesAndEars.UWP.ViewModels; +using System; +using System.Threading.Tasks; + +namespace EyesAndEars.UWP.Services { + public static class DataServices { + + public static async Task UpdateFactoryDevice(int deviceId) { + //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); + // Need to map the json result to the models and display in view. + + return new GalleryDevice(); + } + + public static MainPageVM CreateFallBackViewModel() { + // "999" and "-" are acting as sentinals in this context. + var r = new LightReading(0, 999, DateTime.Now); + var s = new DeviceStatus(0, "-", DateTime.Now); + var fD1 = new FactoryDevice(1, r, s); + var fD2 = new FactoryDevice(2, r, s); + var fD3 = new FactoryDevice(3, r, s); + var gD1 = new GalleryDevice(4, s); + var gD2 = new GalleryDevice(5, s); + var gD3 = new GalleryDevice(6, s); + var vm = new MainPageVM(); + vm.FactoryDevice1 = fD1; + vm.FactoryDevice2 = fD2; + vm.FactoryDevice3 = fD3; + vm.GalleryDevice1 = gD1; + vm.GalleryDevice2 = gD2; + vm.GalleryDevice3 = gD3; + return vm; + } + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/WebServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/WebServices.cs new file mode 100644 index 0000000..adc9cb7 --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/WebServices.cs @@ -0,0 +1,18 @@ +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +namespace EyesAndEars.UWP.Services { + public static class WebServices { + + private static readonly HttpClient _client = new HttpClient(); + + public static async Task GetLightReading(string url, int deviceId) { + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add( + new MediaTypeWithQualityHeaderValue("application/json")); + return await _client.GetStringAsync($"{url}/api/readings/latest/{deviceId}"); + } + + } +} diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs new file mode 100644 index 0000000..6f94343 --- /dev/null +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs @@ -0,0 +1,103 @@ +using EyesAndEars.UWP.Models; +using System.ComponentModel; + +namespace EyesAndEars.UWP.ViewModels { + public class MainPageVM : INotifyPropertyChanged { + + /* Note: Why I did not use a collection of some sort and hard-coded the + * objects instead. + * ==================================================================== + * Because the projects requirements are fixed in-place and this + * program does not have long-term requirements, I decided to not worry + * about long-term maintenance benefits. If something comes from this + * projects afterwards, the duplicated nature of the code below will + * probably need refacorting but I will leave that to the person + * needing to make that call at that time. + */ + + public MainPageVM() { } + + public MainPageVM(FactoryDevice f1, FactoryDevice f2, FactoryDevice f3, + GalleryDevice g1, GalleryDevice g2, GalleryDevice g3) { + + FactoryDevice1 = f1; + FactoryDevice2 = f2; + FactoryDevice3 = f3; + GalleryDevice1 = g1; + GalleryDevice2 = g2; + GalleryDevice3 = g3; + } + + FactoryDevice _factoryDevice1; + public FactoryDevice FactoryDevice1 { + get { return _factoryDevice1; } + set { + if(value != _factoryDevice1) { + _factoryDevice1 = value; + NotifyPropertyChanged("FactoryDevice1"); + } + } + } + + FactoryDevice _factoryDevice2; + public FactoryDevice FactoryDevice2 { + get { return _factoryDevice2; } + set { + if (value != _factoryDevice2) { + _factoryDevice2 = value; + NotifyPropertyChanged("FactoryDevice2"); + } + } + } + + FactoryDevice _factoryDevice3; + public FactoryDevice FactoryDevice3 { + get { return _factoryDevice3; } + set { + if (value != _factoryDevice3) { + _factoryDevice3 = value; + NotifyPropertyChanged("FactoryDevice3"); + } + } + } + + GalleryDevice _galleryDevice1; + public GalleryDevice GalleryDevice1 { + get { return _galleryDevice1; } + set { + if (value != _galleryDevice1) { + _galleryDevice1 = value; + NotifyPropertyChanged("GalleryDevice1"); + } + } + } + + GalleryDevice _galleryDevice2; + public GalleryDevice GalleryDevice2 { + get { return _galleryDevice2; } + set { + if (value != _galleryDevice2) { + _galleryDevice2 = value; + NotifyPropertyChanged("GalleryDevice2"); + } + } + } + + GalleryDevice _galleryDevice3; + public GalleryDevice GalleryDevice3 { + get { return _galleryDevice3; } + set { + if (value != _galleryDevice3) { + _galleryDevice3 = value; + NotifyPropertyChanged("GalleryDevice3"); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected void NotifyPropertyChanged(string info) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info)); + } + } +}