aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs87
1 files changed, 71 insertions, 16 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs
index 444c1d09e..452907366 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs
@@ -8,16 +8,20 @@ using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
+using Tango.BL;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.OS;
using Tango.Settings;
+using System.Data.Entity;
+using Tango.PPC.Common.UWF;
namespace Tango.PPC.Technician.ViewModels
{
public class SystemViewVM : PPCViewModel
{
private IOperationSystemManager _os;
+ private IUnifiedWriteFilterManager _uwf;
private Timer _statsTimer;
private bool _resettingDevice;
@@ -56,6 +60,20 @@ namespace Tango.PPC.Technician.ViewModels
set { _ipAddress = value; RaisePropertyChangedAuto(); }
}
+ private String _totalDyeTime;
+ public String TotalDyeTime
+ {
+ get { return _totalDyeTime; }
+ set { _totalDyeTime = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _totalDyeMeters;
+ public String TotalDyeMeters
+ {
+ get { return _totalDyeMeters; }
+ set { _totalDyeMeters = value; RaisePropertyChangedAuto(); }
+ }
+
public RelayCommand ResetDeviceCommand { get; set; }
public RelayCommand RestartCommand { get; set; }
@@ -66,9 +84,10 @@ namespace Tango.PPC.Technician.ViewModels
public RelayCommand ExitToExplorerCommand { get; set; }
- public SystemViewVM(IOperationSystemManager os)
+ public SystemViewVM(IOperationSystemManager os, IUnifiedWriteFilterManager uwf)
{
_os = os;
+ _uwf = uwf;
CPU = 0;
RAM = 0;
@@ -86,7 +105,7 @@ namespace Tango.PPC.Technician.ViewModels
{
_resettingDevice = true;
ResetDeviceCommand.RaiseCanExecuteChanged();
- await MachineProvider.MachineOperator.ResetDFU();
+ await MachineProvider.MachineOperator.Reset();
await NotificationProvider.ShowInfo("Embedded device has been reset successfully.");
}
catch (Exception ex)
@@ -102,11 +121,30 @@ namespace Tango.PPC.Technician.ViewModels
private async void FactoryReset()
{
- if (await NotificationProvider.ShowQuestion("Are you sure you want to reset this device and back to factory settings?"))
+ if (await NotificationProvider.ShowQuestion("Are you sure you want to reset this device back to factory settings?"))
{
Settings.ApplicationState = ApplicationStates.FactoryRestore;
Settings.Save();
- ApplicationManager.Restart();
+ try
+ {
+ NotificationProvider.SetGlobalBusyMessage("Disabling write filter protection...");
+ await _uwf.Disable();
+ await Task.Delay(2000);
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NavigationManager.NavigateTo(Common.Navigation.NavigationView.RestartingSystemView);
+ await Task.Delay(4000);
+ _os.Restart();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error executing factory reset.");
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NotificationProvider.ShowError($"Error executing factory reset.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ }
}
}
@@ -122,6 +160,8 @@ namespace Tango.PPC.Technician.ViewModels
{
if (await NotificationProvider.ShowQuestion("Are you sure you want to restart the device?"))
{
+ await NavigationManager.NavigateTo(Common.Navigation.NavigationView.RestartingSystemView);
+ await Task.Delay(4000);
_os.Restart();
}
}
@@ -130,12 +170,7 @@ namespace Tango.PPC.Technician.ViewModels
{
if (await NotificationProvider.ShowQuestion("Close the application and start OS shell?"))
{
- Process.Start(new ProcessStartInfo()
- {
- UseShellExecute = true,
- FileName = "explorer.exe",
- });
-
+ _os.OpenShell();
ApplicationManager.ShutDown();
}
}
@@ -148,12 +183,6 @@ namespace Tango.PPC.Technician.ViewModels
_statsTimer.Start();
}
- public override void OnApplicationReady()
- {
- base.OnApplicationReady();
- IPAddress = GetIpv4Address();
- }
-
private void _statsTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (IsVisible)
@@ -244,5 +273,31 @@ namespace Tango.PPC.Technician.ViewModels
return "N/A";
}
}
+
+ public async override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+
+ IPAddress = GetIpv4Address();
+
+ try
+ {
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ var jobRuns = await db.JobRuns.Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync();
+
+ TotalDyeTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours();
+
+ int meters = (int)jobRuns.Select(x => x.EndPosition).Sum();
+ TotalDyeMeters = $"{meters.ToString("N0")} meters";
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error loading machine counters.");
+ TotalDyeTime = "error!";
+ TotalDyeMeters = "error!";
+ }
+ }
}
}