diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 4473624..92ecf9d 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -203,13 +203,13 @@ - + - - Executing Eyes and Ears..s. + VerticalScrollMode="Enabled" Margin="0,20"> + diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs index 94b528d..15e46b1 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs @@ -50,11 +50,11 @@ namespace EyesAndEars.UWP { var url = _vm.BaseURL; if (!string.IsNullOrEmpty(url)) { // Devices 3 and 6 are not in use. - _vm.Device1 = await DataServices.UpdateDevice(url, 1); - _vm.Device2 = await DataServices.UpdateDevice(url, 2); + _vm.Device1 = await DataServices.UpdateDevice(url, 1, Logs); + _vm.Device2 = await DataServices.UpdateDevice(url, 2, Logs); // _vm.Device3 = await DataServices.UpdateDevice(url, 3); - _vm.Device4 = await DataServices.UpdateDevice(url, 4); - _vm.Device5 = await DataServices.UpdateDevice(url, 5); + _vm.Device4 = await DataServices.UpdateDevice(url, 4, Logs); + _vm.Device5 = await DataServices.UpdateDevice(url, 5, Logs); // _vm.Device6 = await DataServices.UpdateDevice(url, 6); _vm.CurrentTime = DateTime.UtcNow.ToShortTimeString(); } diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs index fa2916a..606b51e 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs @@ -6,11 +6,15 @@ using System.Threading.Tasks; using Windows.Storage; using Windows.UI; using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Documents; +using Windows.UI.Text; namespace EyesAndEars.UWP.Services { public static class DataServices { - public static async Task UpdateDevice(string url, int deviceId) { + public static async Task UpdateDevice(string url, int deviceId, + RichTextBlock logs) { try { var id = MapFactoryDeviceToGalleyDevice(deviceId); // Has note. var readingAPI = $"{url}/api/readings/latest/{id}"; @@ -20,7 +24,9 @@ namespace EyesAndEars.UWP.Services { var r = MapToLightReading(readingJSON); var s = MapToDeviceStatus(statusJSON); var c = UpdateStatusColour(deviceId, s.status, r.reading); - return new Device(deviceId, r, s, c); + var dev = new Device(deviceId, r, s, c); + LogUpdate(logs, dev); + return dev; } catch (Exception e) { Debug.WriteLine(e.Message); @@ -28,6 +34,34 @@ namespace EyesAndEars.UWP.Services { } } + private static void LogUpdate(RichTextBlock logs, Device dev) { + // Devices 3 and 6 are not in use. + string device; + if (dev.Id == 1) device = "factory1"; + else if (dev.Id == 2) device = "factory2"; + else if (dev.Id == 4) device = "gallery1"; + else device = "gallery2"; + Paragraph paragraph = new Paragraph(); + var run1 = new Run { + FontWeight = FontWeights.Bold, + Text = $"{DateTime.Now} | " + }; + var run2 = new Run { + Foreground = dev.StatusColour, + FontWeight = FontWeights.Bold, + Text = device + }; + var run3 = new Run { + Foreground = dev.StatusColour, + Text = $" | {dev.LatestReading.id} | {dev.LatestReading.reading} | " + + $"{dev.LatestStatus.status} | {dev.LatestReading.time}" + }; + paragraph.Inlines.Add(run1); + paragraph.Inlines.Add(run2); + paragraph.Inlines.Add(run3); + logs.Blocks.Insert(0, paragraph); + } + private static SolidColorBrush UpdateStatusColour(int device, string status, int reading) { try { if (status.Equals("on", StringComparison.OrdinalIgnoreCase)) {