aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/GeneralGuideViewVM.cs40
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MainViewVM.cs31
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs244
3 files changed, 315 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/GeneralGuideViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/GeneralGuideViewVM.cs
new file mode 100644
index 000000000..fd0475817
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/GeneralGuideViewVM.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PPC.Common;
+using Tango.PPC.Common.Navigation;
+
+namespace Tango.PPC.Maintenance.ViewModels
+{
+ public class GeneralGuideViewVM : PPCViewModel, INavigationObjectReceiver<GuideBase>
+ {
+ private DateTime _lastTime;
+
+ private GuideBase _guide;
+ public GuideBase Guide
+ {
+ get { return _guide; }
+ set { _guide = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ public override void OnApplicationStarted()
+ {
+ _lastTime = DateTime.Now;
+ }
+
+ public void OnNavigatedToWithObject(GuideBase guide)
+ {
+ if (Guide != guide || (DateTime.Now - _lastTime) > TimeSpan.FromHours(1))
+ {
+ guide.Steps.ForEach(x => x.IsChecked = false);
+ }
+
+ Guide = guide;
+
+ _lastTime = DateTime.Now;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MainViewVM.cs
new file mode 100644
index 000000000..a614f7be2
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MainViewVM.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PPC.Common;
+using Tango.PPC.Maintenance.Views;
+
+namespace Tango.PPC.Maintenance.ViewModels
+{
+ /// <summary>
+ /// Represents the main view VM and entry point for <see cref="Synchronization.MyModule"/>.
+ /// </summary>
+ /// <seealso cref="Tango.PPC.Common.PPCViewModel" />
+ public class MainViewVM : PPCViewModel
+ {
+ /// <summary>
+ /// Called when the application has been started
+ /// </summary>
+ public override void OnApplicationStarted()
+ {
+ //Start initializing here rather then in the constructor.
+ }
+
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+ NavigationManager.NavigateTo<MaintenanceModule>(nameof(MaintenanceView), false);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs
new file mode 100644
index 000000000..aeb349bdc
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs
@@ -0,0 +1,244 @@
+using Ionic.Zip;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Commands;
+using Tango.Explorer;
+using Tango.Integration.Operation;
+using Tango.Logging;
+using Tango.PMR.MachineStatus;
+using Tango.PPC.Common;
+using Tango.PPC.Maintenance.Helpers;
+using Tango.PPC.Maintenance.Models;
+using Tango.PPC.Maintenance.Views;
+using Tango.PPC.Storage;
+
+namespace Tango.PPC.Maintenance.ViewModels
+{
+ public class MaintenanceViewVM : PPCViewModel
+ {
+ public ObservableCollection<GuideBase> Guides { get; set; }
+
+ public RelayCommand<GuideBase> OpenGuideCommand { get; set; }
+
+ private List<MidTankLevelModel> _midTankLevels;
+ public List<MidTankLevelModel> MidTankLevels
+ {
+ get { return _midTankLevels; }
+ set { _midTankLevels = value; RaisePropertyChangedAuto(); }
+ }
+
+ private OverallTemperatureModel _overallTemperature;
+ public OverallTemperatureModel OverallTemperature
+ {
+ get { return _overallTemperature; }
+ set { _overallTemperature = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand OpenDyeingHeadCommand { get; set; }
+
+ public RelayCommand CloseDyeingHeadCommand { get; set; }
+
+ public RelayCommand ExportLogsCommand { get; set; }
+
+ public MaintenanceViewVM()
+ {
+ Guides = new ObservableCollection<GuideBase>(GuideHelper.CreateAllGuides());
+ OverallTemperature = new OverallTemperatureModel();
+
+ OpenGuideCommand = new RelayCommand<GuideBase>(OpenGuide);
+
+ OpenDyeingHeadCommand = new RelayCommand(OpenDyeingHead);
+ CloseDyeingHeadCommand = new RelayCommand(CloseDyeingHead);
+ ExportLogsCommand = new RelayCommand(ExportLogsToStorage);
+ }
+
+ public override void OnApplicationStarted()
+ {
+
+ }
+
+ public override void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+
+ MidTankLevels = MachineProvider.Machine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => new MidTankLevelModel()
+ {
+ Max = MachineOperator.MAX_MIDTANK_LITERS,
+ IDSPack = x,
+ }).ToList();
+
+ MachineProvider.MachineOperator.MachineStatusChanged += MachineOperator_MachineStatusChanged;
+ }
+
+ private void MachineOperator_MachineStatusChanged(object sender, MachineStatus status)
+ {
+ UpdateMidTankLevels(status);
+ OverallTemperature.Temperature = status.OverallTemperature;
+ }
+
+ public async void OpenGuide(GuideBase guide)
+ {
+ await NavigationManager.NavigateWithObject<MaintenanceModule, GeneralGuideView, GuideBase>(guide);
+ }
+
+ private void UpdateMidTankLevels(MachineStatus status)
+ {
+ if (IsVisible)
+ {
+ foreach (var item in status.IDSPacksLevels)
+ {
+ var model = MidTankLevels.SingleOrDefault(x => x.IDSPack.PackIndex == item.Index);
+
+ if (model != null)
+ {
+ model.Level = item.MidTankLevel;
+ }
+ }
+ }
+ }
+
+ private void OpenDyeingHead()
+ {
+ IsFree = false;
+
+ try
+ {
+ NotificationProvider.SetGlobalBusyMessage("Opening dyeing head lead...");
+
+ MachineProvider.MachineOperator.StartMotorHoming(new PMR.Diagnostics.MotorHomingRequest()
+ {
+ Direction = PMR.Diagnostics.MotorDirection.Backward,
+ MotorType = PMR.Hardware.HardwareMotorType.MotoDhLid,
+ Speed = 400,
+ }).Subscribe((response) =>
+ {
+ //Next
+ }, (ex) =>
+ {
+ //Error
+ IsFree = true;
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ LogManager.Log(ex, "Error opening dyeing head lead.");
+ NotificationProvider.ShowError(ex.FlattenMessage());
+ }, () =>
+ {
+ //Complete
+ IsFree = true;
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ NotificationProvider.ShowSuccess("The dyeing head lead is now opened.");
+ });
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error opening dyeing head lead.");
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ NotificationProvider.ShowError(ex.FlattenMessage());
+ IsFree = true;
+ }
+ }
+
+ private void CloseDyeingHead()
+ {
+ IsFree = false;
+
+ try
+ {
+ NotificationProvider.SetGlobalBusyMessage("Closing dyeing head lead...");
+
+ MachineProvider.MachineOperator.StartMotorHoming(new PMR.Diagnostics.MotorHomingRequest()
+ {
+ Direction = PMR.Diagnostics.MotorDirection.Forward,
+ MotorType = PMR.Hardware.HardwareMotorType.MotoDhLid,
+ Speed = 400,
+ }).Subscribe((response) =>
+ {
+ //Next
+ }, (ex) =>
+ {
+ //Error
+ IsFree = true;
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ LogManager.Log(ex, "Error closing dyeing head lead.");
+ NotificationProvider.ShowError(ex.FlattenMessage());
+ }, () =>
+ {
+ //Complete
+ IsFree = true;
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ NotificationProvider.ShowSuccess("The dyeing head lead is now closed.");
+ });
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error closing dyeing head lead.");
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ NotificationProvider.ShowError(ex.FlattenMessage());
+ IsFree = true;
+ }
+ }
+
+ private async void ExportLogsToStorage()
+ {
+ var result = await NavigationManager.
+ NavigateForResult<StorageModule,
+ Storage.Views.MainView, ExplorerFileItem,
+ Storage.Models.StorageNavigationRequest>(
+ new Storage.Models.StorageNavigationRequest()
+ {
+ Intent = Storage.Models.StorageNavigationIntent.SaveFile,
+ DefaultFileName = $"Tango-Logs-{DateTime.Now.ToFileName()}",
+ Filter = "do not display anything",
+ Title = "Export System Logs",
+ });
+
+ if (result != null)
+ {
+ String file = result.Path + ".zip";
+
+ IsFree = false;
+
+ try
+ {
+ NotificationProvider.SetGlobalBusyMessage("Exporting system logs...");
+
+ var appFileLogger = LogManager.RegisteredLoggers.FirstOrDefault(x => x is FileLogger) as FileLogger;
+
+ await Task.Factory.StartNew(() =>
+ {
+ using (ZipFile zip = new ZipFile(file))
+ {
+ zip.Password = "1Creativity";
+
+ if (appFileLogger != null)
+ {
+ zip.AddDirectory(appFileLogger.Folder);
+ }
+
+ zip.ParallelDeflateThreshold = -1;
+ zip.Save();
+ }
+ });
+
+ NotificationProvider.ReleaseGlobalBusyMessage();
+
+ await NotificationProvider.ShowSuccess("System logs exported successfully.");
+ }
+ catch (Exception ex)
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ LogManager.Log(ex, "Error exporting system logs.");
+ await NotificationProvider.ShowError($"An error occurred while trying to export the system logs.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ IsFree = true;
+ }
+ }
+ }
+ }
+}