1
0
Fork 0
Browse Source

implement logging system on dashboard.

The code added here is more about populating the area created for logging each web request. The XAML code was done in the previous commit. As I stated there, these logs are more about the providing the user of this program visual feedback about the state of the program. There are times when the various devices (light meters/relays) don't update and it's hard to tell if that's Eyes and Ears, the internet connection or the devices on the other end.
stable
Craig Oates 3 years ago
parent
commit
90b7fedbc5
  1. 8
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
  2. 8
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs
  3. 38
      src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs

8
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml

@ -203,13 +203,13 @@
</Grid>
<Grid Grid.Row="2" Margin="0">
<Grid Grid.Row="2" Margin="0,0,0,0">
<ScrollViewer x:Name="LogViewer" Visibility="Visible"
VerticalScrollBarVisibility="Visible"
HorizontalScrollMode="Disabled"
VerticalScrollMode="Enabled" >
<RichTextBlock x:Name="Logs" FontSize="16">
<Paragraph>Executing Eyes and Ears..s.</Paragraph>
VerticalScrollMode="Enabled" Margin="0,20">
<RichTextBlock x:Name="Logs" FontSize="16"
FontFamily="Consolas">
</RichTextBlock>
</ScrollViewer>
</Grid>

8
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();
}

38
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<Device> UpdateDevice(string url, int deviceId) {
public static async Task<Device> 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)) {