1
0
Fork 0
Browse Source

add expand models and services to a rough init status.

pull/6/head
Craig Oates 4 years ago
parent
commit
48e05a32d8
  1. 17
      src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj
  2. 7
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
  3. 46
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs
  4. 19
      src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs
  5. 19
      src/EyesAndEars.UWP/EyesAndEars.UWP/Models/FactoryDevice.cs
  6. 15
      src/EyesAndEars.UWP/EyesAndEars.UWP/Models/GalleryDevice.cs
  7. 19
      src/EyesAndEars.UWP/EyesAndEars.UWP/Models/LightReading.cs
  8. 42
      src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs
  9. 18
      src/EyesAndEars.UWP/EyesAndEars.UWP/Services/WebServices.cs
  10. 103
      src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs

17
src/EyesAndEars.UWP/EyesAndEars.UWP/EyesAndEars.UWP.csproj

@ -122,7 +122,14 @@
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Models\DeviceStatus.cs" />
<Compile Include="Models\FactoryDevice.cs" />
<Compile Include="Models\GalleryDevice.cs" />
<Compile Include="Models\LightReading.cs" />
<Compile Include="Services\DataServices.cs" />
<Compile Include="ViewModels\MainPageVM.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\WebServices.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
@ -130,7 +137,7 @@
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="images\logo.png" />
<Content Include="Images\logo.png" />
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
@ -151,9 +158,17 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NetCore.Analyzers">
<Version>2.9.8</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.9</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>4.7.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">

7
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml

@ -19,7 +19,7 @@
<StackPanel Grid.Row="0" Orientation="Horizontal"
VerticalAlignment="Top">
<Image Grid.Column="0" Width="88" Height="88" VerticalAlignment="Center"
Source="images\logo.png"/>
Source="Images\logo.png"/>
<StackPanel Padding="8,0">
<TextBlock Text="Return to Ritheron Project" FontSize="40"/>
<StackPanel Orientation="Horizontal">
@ -47,9 +47,9 @@
<Grid x:Name="Factory1Grid" Grid.Row="0" Grid.Column="0"
Background="DarkRed" Margin="0,0,0,12" Width="300" Height="300">
<StackPanel Margin="12" VerticalAlignment="Stretch">
<TextBlock x:Name="Factory1Time" Text="2020-23-32 23:23"
<TextBlock x:Name="Factory1Time" Text="{x:Bind _vm.FactoryDevice1.LatestStatus.DateOfStatusRecording}"
Foreground="White" FontSize="24"/>
<TextBlock x:Name="Factory1Reading" Text="00" Foreground="White"
<TextBlock x:Name="Factory1Reading" Text="{x:Bind _vm.FactoryDevice1.LatestReading.Reading}" Foreground="White"
VerticalAlignment="Bottom" FontSize="144"/>
<TextBlock Text="Factory1" Foreground="White" FontSize="36"
VerticalAlignment="Bottom"/>
@ -125,7 +125,6 @@
FontFamily="Segoe MDL2 Assets" Content="&#xE946;"
Height="79" Width="79" VerticalAlignment="Center"
HorizontalAlignment="Left" FontSize="28"
Click="InfoButton_Click"
ToolTipService.Placement="Mouse"
ToolTipService.ToolTip="This is a link to a webpage with information about Nicola and the project."/>

46
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs

@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using EyesAndEars.UWP.ViewModels;
using EyesAndEars.UWP.Services;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using EyesAndEars.UWP.Models;
using System;
using System.Threading.Tasks;
using System.Threading;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@ -22,21 +16,39 @@ namespace EyesAndEars.UWP
/// </summary>
public sealed partial class MainPage : Page
{
private MainPageVM _vm = new MainPageVM();
public MainPage()
{
this.InitializeComponent();
IntialiseDataContextAsync();
// Need to set a refresh timer so it updates every 1 second or so...
}
private void InfoButton_Click(object sender, RoutedEventArgs e) {
private void IntialiseDataContextAsync() {
try {
// The Update features are not yet working...
_vm.FactoryDevice1 = DataServices.UpdateFactoryDevice(1).Result;
_vm.FactoryDevice2 = DataServices.UpdateFactoryDevice(2).Result;
_vm.FactoryDevice3 = DataServices.UpdateFactoryDevice(3).Result;
_vm.GalleryDevice1 = DataServices.UpdateGalleryDevice(4).Result;
_vm.GalleryDevice2 = DataServices.UpdateGalleryDevice(5).Result;
_vm.GalleryDevice3 = DataServices.UpdateGalleryDevice(6).Result;
DataContext = _vm;
}
catch (Exception) {
_vm = DataServices.CreateFallBackViewModel();
DataContext = _vm;
//throw;
}
}
private void RefreshButton_Click(object sender, RoutedEventArgs e) {
private async void RefreshButton_Click(object sender, RoutedEventArgs e) {
// GET THE INITIALISATION WORKING FIRST AND THE DEFAULT CYCLE...
}
private void SaveURLButton_Click(object sender, RoutedEventArgs e) {
// WORK ON THIS WENT YOU HAVE A LIVE SYSTEM WORKING WITH KNOWABLE DEFAULTS.
}
}
}

19
src/EyesAndEars.UWP/EyesAndEars.UWP/Models/DeviceStatus.cs

@ -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;
}
}
}

19
src/EyesAndEars.UWP/EyesAndEars.UWP/Models/FactoryDevice.cs

@ -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;
}
}
}

15
src/EyesAndEars.UWP/EyesAndEars.UWP/Models/GalleryDevice.cs

@ -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;
}
}
}

19
src/EyesAndEars.UWP/EyesAndEars.UWP/Models/LightReading.cs

@ -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;
}
}
}

42
src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs

@ -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;
}
}
}

18
src/EyesAndEars.UWP/EyesAndEars.UWP/Services/WebServices.cs

@ -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}");
}
}
}

103
src/EyesAndEars.UWP/EyesAndEars.UWP/ViewModels/MainPageVM.cs

@ -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));
}
}
}