|
|
|
using EyesAndEars.UWP.Services;
|
|
|
|
using EyesAndEars.UWP.ViewModels;
|
|
|
|
using System;
|
|
|
|
using Windows.ApplicationModel;
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
|
|
namespace EyesAndEars.UWP {
|
|
|
|
|
|
|
|
public sealed partial class MainPage : Page {
|
|
|
|
|
|
|
|
MainPageVM _vm = new MainPageVM();
|
|
|
|
DispatcherTimer _dispatcherTimer = new DispatcherTimer();
|
|
|
|
|
|
|
|
public MainPage() {
|
|
|
|
InitializeComponent();
|
|
|
|
IntialiseDataContext();
|
|
|
|
SetVersionNumber();
|
|
|
|
IntialiseRefreshTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetVersionNumber() {
|
|
|
|
var package = Package.Current;
|
|
|
|
var packageId = package.Id;
|
|
|
|
var version = packageId.Version;
|
|
|
|
VersionNumber.Text = $"Ver: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
|
|
|
|
}
|
|
|
|
|
|
|
|
async void IntialiseDataContext() {
|
|
|
|
// Device 3 and 6 are not in use.
|
|
|
|
_vm.BaseURL = await DataServices.GetBaseURLAsync();
|
|
|
|
_vm.Device1 = DataServices.CreateFallBackDevice(1);
|
|
|
|
_vm.Device2 = DataServices.CreateFallBackDevice(2);
|
|
|
|
// _vm.Device3 = DataServices.CreateFallBackDevice(3);
|
|
|
|
_vm.Device4 = DataServices.CreateFallBackDevice(4);
|
|
|
|
_vm.Device5 = DataServices.CreateFallBackDevice(5);
|
|
|
|
// _vm.Device6 = DataServices.CreateFallBackDevice(6);
|
|
|
|
_vm.CurrentTime = DateTime.UtcNow.ToShortTimeString();
|
|
|
|
DataContext = _vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntialiseRefreshTime() {
|
|
|
|
// TimeSpan Intervals: Days, Hours, Minutes, Seconds, Milliseconds.
|
|
|
|
_dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
|
|
|
|
_dispatcherTimer.Tick += UpdateViewModel;
|
|
|
|
_dispatcherTimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
async void UpdateViewModel(object sender, object e) {
|
|
|
|
var url = _vm.BaseURL;
|
|
|
|
if (!string.IsNullOrEmpty(url)) {
|
|
|
|
// Devices 3 and 6 are not in use.
|
|
|
|
_vm.Device1 = await DataServices.UpdateDevice(url, 1, Logs);
|
|
|
|
_vm.Device2 = await DataServices.UpdateDevice(url, 2, Logs);
|
|
|
|
// _vm.Device3 = await DataServices.UpdateDevice(url, 3);
|
|
|
|
_vm.Device4 = await DataServices.UpdateDevice(url, 4, Logs);
|
|
|
|
_vm.Device5 = await DataServices.UpdateDevice(url, 5, Logs);
|
|
|
|
// _vm.Device6 = await DataServices.UpdateDevice(url, 6);
|
|
|
|
_vm.CurrentTime = DateTime.UtcNow.ToShortTimeString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IntialiseDataContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async void SaveURLButton_Click(object sender, RoutedEventArgs e) {
|
|
|
|
await DataServices.SaveBaseURLAsync(WebAddressBox.Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayButton_Checked(object sender, RoutedEventArgs e) {
|
|
|
|
PlayButton.Content = "\uE768";
|
|
|
|
_dispatcherTimer.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayButton_Unchecked(object sender, RoutedEventArgs e) {
|
|
|
|
PlayButton.Content = "\uE71A";
|
|
|
|
_dispatcherTimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LogToggle_Unchecked(object sender, RoutedEventArgs e) {
|
|
|
|
LogViewer.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LogToggle_Checked(object sender, RoutedEventArgs e) {
|
|
|
|
LogViewer.Visibility = Visibility.Visible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|