diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj
index c8238c3..65487fe 100644
--- a/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj
+++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj
@@ -108,6 +108,8 @@
false
prompt
true
+ true
+ true
bin\x64\Release\
diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
index f28d788..c40d0dc 100644
--- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
+++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
@@ -164,7 +164,8 @@
ToolTipService.ToolTip="This is a link to a webpage with information about Nicola and the project."/>
IntialiseDataContext();
- }
- void SaveURLButton_Click(object sender, RoutedEventArgs e) {
- // WORK ON THIS WENT YOU HAVE A LIVE SYSTEM WORKING WITH KNOWABLE DEFAULTS.
+ async void SaveURLButton_Click(object sender, RoutedEventArgs e) {
+ await DataServices.SaveBaseURLAsync(WebAddressBox.Text);
}
}
}
diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/Default.rd.xml b/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/Default.rd.xml
index af00722..d5fe98b 100644
--- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/Default.rd.xml
+++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Properties/Default.rd.xml
@@ -25,7 +25,26 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs
index f966fe6..d795050 100644
--- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs
+++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs
@@ -3,6 +3,7 @@ using System;
using System.Diagnostics;
using System.Text.Json;
using System.Threading.Tasks;
+using Windows.Storage;
using Windows.UI;
using Windows.UI.Xaml.Media;
@@ -22,15 +23,21 @@ namespace EyesAndEars.UWP.Services {
return new Device(deviceId, r, s, c);
}
catch (Exception e) {
- Debug.WriteLine($"ERROR: {e.Message}");
+ Debug.WriteLine(e.Message);
return CreateFallBackDevice(deviceId);
}
}
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.DarkRed);
+ }
+ catch (Exception e) {
+ Debug.WriteLine(e.Message);
+ return new SolidColorBrush(Colors.DarkOrange);
+ }
}
/* Note: The Purpose of Mapping a Factory to a Gallery Device.
@@ -78,13 +85,25 @@ namespace EyesAndEars.UWP.Services {
}
static LightReading MapToLightReading(string json) {
- var reading = JsonSerializer.Deserialize(json);
- return reading;
+ try {
+ var reading = JsonSerializer.Deserialize(json);
+ return reading;
+ }
+ catch (Exception e) {
+ Debug.WriteLine(e.Message);
+ return CreateDefaultLightReading();
+ }
}
static DeviceStatus MapToDeviceStatus(string json) {
- var status = JsonSerializer.Deserialize(json);
- return status;
+ try {
+ var status = JsonSerializer.Deserialize(json);
+ return status;
+ }
+ catch (Exception e) {
+ Debug.WriteLine(e.Message);
+ return CreateDefaultDeviceStatus();
+ }
}
public static Device CreateFallBackDevice(int deviceId) {
@@ -95,5 +114,37 @@ namespace EyesAndEars.UWP.Services {
var d = new Device(deviceId, r, s, c);
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 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 "";
+ }
+
+ }
}
}
diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs
index 7d4c379..1f74c35 100644
--- a/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs
+++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs
@@ -28,6 +28,17 @@ namespace EyesAndEars.UWP.ViewModels {
Device3 = g3;
}
+ string _baseURL;
+ public string BaseURL {
+ get { return _baseURL; }
+ set {
+ if (value != _baseURL) {
+ _baseURL = value;
+ NotifyPropertyChanged("BaseURL");
+ }
+ }
+ }
+
Device _device1;
public Device Device1 {
get { return _device1; }