@ -6,11 +6,15 @@ using System.Threading.Tasks;
using Windows.Storage ;
using Windows.Storage ;
using Windows.UI ;
using Windows.UI ;
using Windows.UI.Xaml.Media ;
using Windows.UI.Xaml.Media ;
using Windows.UI.Xaml.Controls ;
using Windows.UI.Xaml.Documents ;
using Windows.UI.Text ;
namespace EyesAndEars.UWP.Services {
namespace EyesAndEars.UWP.Services {
public static class DataServices {
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 {
try {
var id = MapFactoryDeviceToGalleyDevice ( deviceId ) ; // Has note.
var id = MapFactoryDeviceToGalleyDevice ( deviceId ) ; // Has note.
var readingAPI = $"{url}/api/readings/latest/{id}" ;
var readingAPI = $"{url}/api/readings/latest/{id}" ;
@ -20,7 +24,9 @@ namespace EyesAndEars.UWP.Services {
var r = MapToLightReading ( readingJSON ) ;
var r = MapToLightReading ( readingJSON ) ;
var s = MapToDeviceStatus ( statusJSON ) ;
var s = MapToDeviceStatus ( statusJSON ) ;
var c = UpdateStatusColour ( deviceId , s . status , r . reading ) ;
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 ) {
catch ( Exception e ) {
Debug . WriteLine ( e . Message ) ;
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 ) {
private static SolidColorBrush UpdateStatusColour ( int device , string status , int reading ) {
try {
try {
if ( status . Equals ( "on" , StringComparison . OrdinalIgnoreCase ) ) {
if ( status . Equals ( "on" , StringComparison . OrdinalIgnoreCase ) ) {