Craig Oates
4 years ago
10 changed files with 283 additions and 22 deletions
@ -0,0 +1,19 @@
|
||||
using System; |
||||
|
||||
namespace EyesAndEars.UWP.Models { |
||||
|
||||
public class DeviceStatus { |
||||
|
||||
public readonly int Id; |
||||
public readonly string Status; |
||||
public readonly DateTime DateOfStatusRecording; |
||||
|
||||
public DeviceStatus() { } |
||||
|
||||
public DeviceStatus(int id, string status, DateTime dateOfStatusRecording) { |
||||
Id = id; |
||||
Status = status; |
||||
DateOfStatusRecording = dateOfStatusRecording; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
namespace EyesAndEars.UWP.Models { |
||||
public class FactoryDevice { |
||||
|
||||
public int Id { get; set; } |
||||
|
||||
public LightReading LatestReading { get; set; } |
||||
|
||||
public DeviceStatus LatestStatus { get; set; } |
||||
|
||||
public FactoryDevice() { } |
||||
|
||||
public FactoryDevice(int id, LightReading reading, DeviceStatus status) { |
||||
Id = id; |
||||
LatestReading = reading; |
||||
LatestStatus = status; |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
namespace EyesAndEars.UWP.Models { |
||||
public class GalleryDevice { |
||||
|
||||
public readonly int Id; |
||||
|
||||
public readonly DeviceStatus LatestStatus; |
||||
|
||||
public GalleryDevice() { } |
||||
|
||||
public GalleryDevice(int id, DeviceStatus status) { |
||||
Id = id; |
||||
LatestStatus = status; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
using System; |
||||
|
||||
namespace EyesAndEars.UWP.Models { |
||||
|
||||
public class LightReading { |
||||
|
||||
public readonly int Id; |
||||
public readonly int Reading; |
||||
public readonly DateTime MomentReadingWasTaken; |
||||
|
||||
public LightReading() { } |
||||
|
||||
public LightReading(int id, int reading, DateTime momentOfRecording) { |
||||
Id = id; |
||||
Reading = reading; |
||||
MomentReadingWasTaken = momentOfRecording; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
using EyesAndEars.UWP.Models; |
||||
using EyesAndEars.UWP.ViewModels; |
||||
using System; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EyesAndEars.UWP.Services { |
||||
public static class DataServices { |
||||
|
||||
public static async Task<FactoryDevice> UpdateFactoryDevice(int deviceId) { |
||||
//var t = await WebServices.GetLightReading("ht", deviceId); |
||||
// Need to map the json result to the models and display in view. |
||||
return new FactoryDevice(); |
||||
} |
||||
|
||||
public static async Task<GalleryDevice> UpdateGalleryDevice(int deviceId) { |
||||
//var t = await WebServices.GetLightReading("ht", deviceId); |
||||
// Need to map the json result to the models and display in view. |
||||
|
||||
return new GalleryDevice(); |
||||
} |
||||
|
||||
public static MainPageVM CreateFallBackViewModel() { |
||||
// "999" and "-" are acting as sentinals in this context. |
||||
var r = new LightReading(0, 999, DateTime.Now); |
||||
var s = new DeviceStatus(0, "-", DateTime.Now); |
||||
var fD1 = new FactoryDevice(1, r, s); |
||||
var fD2 = new FactoryDevice(2, r, s); |
||||
var fD3 = new FactoryDevice(3, r, s); |
||||
var gD1 = new GalleryDevice(4, s); |
||||
var gD2 = new GalleryDevice(5, s); |
||||
var gD3 = new GalleryDevice(6, s); |
||||
var vm = new MainPageVM(); |
||||
vm.FactoryDevice1 = fD1; |
||||
vm.FactoryDevice2 = fD2; |
||||
vm.FactoryDevice3 = fD3; |
||||
vm.GalleryDevice1 = gD1; |
||||
vm.GalleryDevice2 = gD2; |
||||
vm.GalleryDevice3 = gD3; |
||||
return vm; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
using System.Net.Http; |
||||
using System.Net.Http.Headers; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EyesAndEars.UWP.Services { |
||||
public static class WebServices { |
||||
|
||||
private static readonly HttpClient _client = new HttpClient(); |
||||
|
||||
public static async Task<string> GetLightReading(string url, int deviceId) { |
||||
_client.DefaultRequestHeaders.Accept.Clear(); |
||||
_client.DefaultRequestHeaders.Accept.Add( |
||||
new MediaTypeWithQualityHeaderValue("application/json")); |
||||
return await _client.GetStringAsync($"{url}/api/readings/latest/{deviceId}"); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,103 @@
|
||||
using EyesAndEars.UWP.Models; |
||||
using System.ComponentModel; |
||||
|
||||
namespace EyesAndEars.UWP.ViewModels { |
||||
public class MainPageVM : INotifyPropertyChanged { |
||||
|
||||
/* Note: Why I did not use a collection of some sort and hard-coded the |
||||
* objects instead. |
||||
* ==================================================================== |
||||
* Because the projects requirements are fixed in-place and this |
||||
* program does not have long-term requirements, I decided to not worry |
||||
* about long-term maintenance benefits. If something comes from this |
||||
* projects afterwards, the duplicated nature of the code below will |
||||
* probably need refacorting but I will leave that to the person |
||||
* needing to make that call at that time. |
||||
*/ |
||||
|
||||
public MainPageVM() { } |
||||
|
||||
public MainPageVM(FactoryDevice f1, FactoryDevice f2, FactoryDevice f3, |
||||
GalleryDevice g1, GalleryDevice g2, GalleryDevice g3) { |
||||
|
||||
FactoryDevice1 = f1; |
||||
FactoryDevice2 = f2; |
||||
FactoryDevice3 = f3; |
||||
GalleryDevice1 = g1; |
||||
GalleryDevice2 = g2; |
||||
GalleryDevice3 = g3; |
||||
} |
||||
|
||||
FactoryDevice _factoryDevice1; |
||||
public FactoryDevice FactoryDevice1 { |
||||
get { return _factoryDevice1; } |
||||
set { |
||||
if(value != _factoryDevice1) { |
||||
_factoryDevice1 = value; |
||||
NotifyPropertyChanged("FactoryDevice1"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
FactoryDevice _factoryDevice2; |
||||
public FactoryDevice FactoryDevice2 { |
||||
get { return _factoryDevice2; } |
||||
set { |
||||
if (value != _factoryDevice2) { |
||||
_factoryDevice2 = value; |
||||
NotifyPropertyChanged("FactoryDevice2"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
FactoryDevice _factoryDevice3; |
||||
public FactoryDevice FactoryDevice3 { |
||||
get { return _factoryDevice3; } |
||||
set { |
||||
if (value != _factoryDevice3) { |
||||
_factoryDevice3 = value; |
||||
NotifyPropertyChanged("FactoryDevice3"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
GalleryDevice _galleryDevice1; |
||||
public GalleryDevice GalleryDevice1 { |
||||
get { return _galleryDevice1; } |
||||
set { |
||||
if (value != _galleryDevice1) { |
||||
_galleryDevice1 = value; |
||||
NotifyPropertyChanged("GalleryDevice1"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
GalleryDevice _galleryDevice2; |
||||
public GalleryDevice GalleryDevice2 { |
||||
get { return _galleryDevice2; } |
||||
set { |
||||
if (value != _galleryDevice2) { |
||||
_galleryDevice2 = value; |
||||
NotifyPropertyChanged("GalleryDevice2"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
GalleryDevice _galleryDevice3; |
||||
public GalleryDevice GalleryDevice3 { |
||||
get { return _galleryDevice3; } |
||||
set { |
||||
if (value != _galleryDevice3) { |
||||
_galleryDevice3 = value; |
||||
NotifyPropertyChanged("GalleryDevice3"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
protected void NotifyPropertyChanged(string info) { |
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info)); |
||||
} |
||||
} |
||||
} |
Reference in new issue