|
|
@ -3,6 +3,7 @@ using System; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
using Windows.Storage; |
|
|
|
using Windows.UI; |
|
|
|
using Windows.UI; |
|
|
|
using Windows.UI.Xaml.Media; |
|
|
|
using Windows.UI.Xaml.Media; |
|
|
|
|
|
|
|
|
|
|
@ -22,15 +23,21 @@ namespace EyesAndEars.UWP.Services { |
|
|
|
return new Device(deviceId, r, s, c); |
|
|
|
return new Device(deviceId, r, s, c); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) { |
|
|
|
catch (Exception e) { |
|
|
|
Debug.WriteLine($"ERROR: {e.Message}"); |
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
return CreateFallBackDevice(deviceId); |
|
|
|
return CreateFallBackDevice(deviceId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static SolidColorBrush UpdateStatusColour(string status) { |
|
|
|
static SolidColorBrush UpdateStatusColour(string status) { |
|
|
|
return status.Equals("on", StringComparison.OrdinalIgnoreCase) ? |
|
|
|
try { |
|
|
|
|
|
|
|
return status.Equals("on", StringComparison.OrdinalIgnoreCase) ? |
|
|
|
new SolidColorBrush(Colors.SeaGreen) : |
|
|
|
new SolidColorBrush(Colors.SeaGreen) : |
|
|
|
new SolidColorBrush(Colors.DarkRed); |
|
|
|
new SolidColorBrush(Colors.DarkRed); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
|
|
|
return new SolidColorBrush(Colors.DarkOrange); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Note: The Purpose of Mapping a Factory to a Gallery Device. |
|
|
|
/* Note: The Purpose of Mapping a Factory to a Gallery Device. |
|
|
@ -78,13 +85,25 @@ namespace EyesAndEars.UWP.Services { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static LightReading MapToLightReading(string json) { |
|
|
|
static LightReading MapToLightReading(string json) { |
|
|
|
var reading = JsonSerializer.Deserialize<LightReading>(json); |
|
|
|
try { |
|
|
|
return reading; |
|
|
|
var reading = JsonSerializer.Deserialize<LightReading>(json); |
|
|
|
|
|
|
|
return reading; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
|
|
|
return CreateDefaultLightReading(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static DeviceStatus MapToDeviceStatus(string json) { |
|
|
|
static DeviceStatus MapToDeviceStatus(string json) { |
|
|
|
var status = JsonSerializer.Deserialize<DeviceStatus>(json); |
|
|
|
try { |
|
|
|
return status; |
|
|
|
var status = JsonSerializer.Deserialize<DeviceStatus>(json); |
|
|
|
|
|
|
|
return status; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
|
|
|
return CreateDefaultDeviceStatus(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Device CreateFallBackDevice(int deviceId) { |
|
|
|
public static Device CreateFallBackDevice(int deviceId) { |
|
|
@ -95,5 +114,37 @@ namespace EyesAndEars.UWP.Services { |
|
|
|
var d = new Device(deviceId, r, s, c); |
|
|
|
var d = new Device(deviceId, r, s, c); |
|
|
|
return d; |
|
|
|
return d; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static LightReading CreateDefaultLightReading() => |
|
|
|
|
|
|
|
new LightReading { id = 0, reading = 999, time = DateTime.Now }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static DeviceStatus CreateDefaultDeviceStatus() => |
|
|
|
|
|
|
|
new DeviceStatus { id = 0, status = "err", time = DateTime.Now }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task SaveBaseURLAsync(string contents) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var storageFolder = ApplicationData.Current.LocalFolder; |
|
|
|
|
|
|
|
var baseURLFile = await storageFolder.CreateFileAsync("baseURL.txt", |
|
|
|
|
|
|
|
CreationCollisionOption.ReplaceExisting); |
|
|
|
|
|
|
|
await FileIO.WriteTextAsync(baseURLFile, contents); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task<string> GetBaseURLAsync() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var storageFolder = ApplicationData.Current.LocalFolder; |
|
|
|
|
|
|
|
var baseURLFile = await storageFolder.GetFileAsync("baseURL.txt"); |
|
|
|
|
|
|
|
var text = await FileIO.ReadTextAsync(baseURLFile); |
|
|
|
|
|
|
|
return text; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|