aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs229
1 files changed, 222 insertions, 7 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
index 8ed512670..20cfd6bf4 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
@@ -9,6 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tango.BL;
+using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core.Commands;
@@ -18,6 +19,8 @@ using Tango.PPC.Common;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.ExternalBridge;
using Tango.PPC.Common.Messages;
+using Tango.PPC.Common.OS;
+using Tango.PPC.Common.UWF;
using Tango.SharedUI.Components;
using Tango.WiFi;
@@ -29,8 +32,17 @@ namespace Tango.PPC.MachineSettings.ViewModels
/// <seealso cref="Tango.PPC.Common.PPCViewModel" />
public class MainViewVM : PPCViewModel
{
+ private TimeZoneInfo _previousTimeZone;
+ private bool _previousEnableUWF;
+
#region Properties
+ [TangoInject]
+ private IOperationSystemManager OperationSystemManager { get; set; }
+
+ [TangoInject]
+ private IUnifiedWriteFilterManager UnifiedWriteFilterManager { get; set; }
+
private Machine _machine;
public Machine Machine
{
@@ -52,6 +64,13 @@ namespace Tango.PPC.MachineSettings.ViewModels
set { _selectedColorSpaces = value; RaisePropertyChangedAuto(); }
}
+ private ObservableCollection<Rml> _rmls;
+ public ObservableCollection<Rml> Rmls
+ {
+ get { return _rmls; }
+ set { _rmls = value; RaisePropertyChangedAuto(); }
+ }
+
private bool _enableHotSpot;
public bool EnableHotSpot
{
@@ -108,6 +127,69 @@ namespace Tango.PPC.MachineSettings.ViewModels
set { _lockScreenPassword = value; RaisePropertyChangedAuto(); }
}
+ private Rml _defaultRML;
+ public Rml DefaultRML
+ {
+ get { return _defaultRML; }
+ set { _defaultRML = value; RaisePropertyChangedAuto(); }
+ }
+
+ private SpoolType _defaultSpoolType;
+ public SpoolType DefaultSpoolType
+ {
+ get { return _defaultSpoolType; }
+ set { _defaultSpoolType = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _synchronizeJobs;
+ public bool SynchronizeJobs
+ {
+ get { return _synchronizeJobs; }
+ set { _synchronizeJobs = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private bool _synchronizeDiagnostics;
+ public bool SynchronizeDiagnostics
+ {
+ get { return _synchronizeDiagnostics; }
+ set { _synchronizeDiagnostics = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private bool _autoCheckForUpdates;
+ public bool AutoCheckForUpdates
+ {
+ get { return _autoCheckForUpdates; }
+ set { _autoCheckForUpdates = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<TimeZoneInfo> _timeZones;
+ /// <summary>
+ /// Gets or sets the available time zones.
+ /// </summary>
+ public List<TimeZoneInfo> TimeZones
+ {
+ get { return _timeZones; }
+ set { _timeZones = value; RaisePropertyChangedAuto(); }
+ }
+
+ private TimeZoneInfo _selectedTimeZone;
+ /// <summary>
+ /// Gets or sets the selected time zone.
+ /// </summary>
+ public TimeZoneInfo SelectedTimeZone
+ {
+ get { return _selectedTimeZone; }
+ set { _selectedTimeZone = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _enableUWF;
+ public bool EnableUWF
+ {
+ get { return _enableUWF; }
+ set { _enableUWF = value; RaisePropertyChangedAuto(); }
+ }
+
+
#endregion
#region Commands
@@ -122,12 +204,18 @@ namespace Tango.PPC.MachineSettings.ViewModels
/// </summary>
public RelayCommand DiscardCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the synchronize command.
+ /// </summary>
+ public RelayCommand SynchronizeCommand { get; set; }
+
#endregion
public MainViewVM()
{
SaveCommand = new RelayCommand(Save);
DiscardCommand = new RelayCommand(Discard);
+ SynchronizeCommand = new RelayCommand(Synchronize, () => !MachineDataSynchronizer.IsSynchronizing && IsFree);
}
private void Discard()
@@ -139,9 +227,9 @@ namespace Tango.PPC.MachineSettings.ViewModels
{
if (Validate())
{
- Machine.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
- Machine.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList();
- Machine.MapPrimitivesWithStrings(MachineProvider.Machine);
+ Settings.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
+ Settings.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList();
+ Machine.MapPropertiesTo(MachineProvider.Machine, MappingFlags.NoReferenceTypes);
Settings.EnableHotSpot = EnableHotSpot;
Settings.HotSpotPassword = HotSpotPassword;
@@ -150,10 +238,73 @@ namespace Tango.PPC.MachineSettings.ViewModels
Settings.EnableLockScreen = EnableLockScreen;
Settings.LockScreenTimeout = TimeSpan.FromMinutes(LockScreenTimeoutMinutes);
Settings.LockScreenPassword = LockScreenPassword;
+ Settings.DefaultRmlGuid = DefaultRML?.Guid;
+ Settings.DefaultSpoolTypeGuid = DefaultSpoolType?.Guid;
+ Settings.SynchronizeJobs = SynchronizeJobs;
+ Settings.SynchronizeDiagnostics = SynchronizeDiagnostics;
+ Settings.AutoCheckForUpdates = AutoCheckForUpdates;
+
+ MachineDataSynchronizer.IsEnabled = SynchronizeJobs || SynchronizeDiagnostics;
+
Settings.Save();
await MachineProvider.SaveMachine();
- await NavigationManager.NavigateBack();
+
+ bool isRestarting = false;
+
+ if (_previousTimeZone.ToStringSafe() != SelectedTimeZone.ToStringSafe())
+ {
+ if (await NotificationProvider.ShowQuestion("Changing the time zone requires the application to restart. Do you wish to restart the application?"))
+ {
+ try
+ {
+ LogManager.Log($"Setting new time zone to '{SelectedTimeZone.ToString()}'.");
+ NotificationProvider.SetGlobalBusyMessage("Setting new time zone...");
+ await OperationSystemManager.ChangeTimeZone(SelectedTimeZone);
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ isRestarting = true;
+ ApplicationManager.Restart();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error changing the time zone.");
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NotificationProvider.ShowError($"Error setting timezone.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+
+ if (_previousEnableUWF != EnableUWF)
+ {
+ await NotificationProvider.ShowWarning("Changes to disk protection (UWF) will take effect only after a full system restart.");
+
+ try
+ {
+ LogManager.Log($"Changing UWF mode to '{EnableUWF}'.");
+ if (EnableUWF)
+ {
+ NotificationProvider.SetGlobalBusyMessage("Enabling disk protection (UWF)...");
+ await UnifiedWriteFilterManager.Enable();
+ }
+ else
+ {
+ NotificationProvider.SetGlobalBusyMessage("Disabling disk protection (UWF)...");
+ await UnifiedWriteFilterManager.Disable();
+ }
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ }
+ catch (Exception ex)
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ LogManager.Log(ex, "Error setting UWF mode.");
+ await NotificationProvider.ShowError($"Could not change the disk protection mode\n{ex.FlattenMessage()}");
+ }
+ }
+
+ if (!isRestarting)
+ {
+ await NavigationManager.NavigateBack();
+ }
}
}
@@ -167,10 +318,29 @@ namespace Tango.PPC.MachineSettings.ViewModels
/// </summary>
public override void OnApplicationStarted()
{
+ try
+ {
+ TimeZones = OperationSystemManager.GetAvailableTimeZones().ToList();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error retrieving available time zones.");
+ }
+ }
+
+ public async override void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+ MachineDataSynchronizer.SynchronizationStarted += (_, __) => InvalidateRelayCommands();
+ MachineDataSynchronizer.SynchronizationEnded += (_, __) => InvalidateRelayCommands();
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ Rmls = await new RmlsCollectionBuilder(db).SetAll().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).BuildAsync();
+ }
}
- public override void OnNavigatedTo()
+ public async override void OnNavigatedTo()
{
base.OnNavigatedTo();
@@ -195,8 +365,29 @@ namespace Tango.PPC.MachineSettings.ViewModels
LockScreenTimeoutMinutes = (int)Settings.LockScreenTimeout.TotalMinutes;
LockScreenPassword = Settings.LockScreenPassword;
- SelectedJobTypes = new SelectedObjectCollection<JobTypes>(Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToObservableCollection(), Machine.SupportedJobTypes.ToObservableCollection());
- SelectedColorSpaces = new SelectedObjectCollection<ColorSpaces>(Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace()).ToObservableCollection(), Machine.SupportedColorSpaces.ToObservableCollection());
+ SelectedJobTypes = new SelectedObjectCollection<JobTypes>(Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToObservableCollection(), Settings.SupportedJobTypes.ToObservableCollection());
+ SelectedColorSpaces = new SelectedObjectCollection<ColorSpaces>(Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace()).ToObservableCollection(), Settings.SupportedColorSpaces.ToObservableCollection());
+
+ DefaultRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == Settings.DefaultRmlGuid);
+ DefaultSpoolType = Adapter.SpoolTypes.SingleOrDefault(x => x.Guid == Settings.DefaultSpoolTypeGuid);
+
+ SynchronizeJobs = Settings.SynchronizeJobs;
+ SynchronizeDiagnostics = Settings.SynchronizeDiagnostics;
+
+ AutoCheckForUpdates = Settings.AutoCheckForUpdates;
+
+ SelectedTimeZone = TimeZones.SingleOrDefault(x => x.StandardName == TimeZone.CurrentTimeZone.StandardName);
+ _previousTimeZone = SelectedTimeZone;
+
+ try
+ {
+ EnableUWF = await UnifiedWriteFilterManager.IsEnabled();
+ _previousEnableUWF = EnableUWF;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error getting UWF status.");
+ }
}
private async void OnEnableRemoteAssistanceChanged()
@@ -271,5 +462,29 @@ namespace Tango.PPC.MachineSettings.ViewModels
{
ExternalBridgeService.Enabled = EnableExternalBridge;
}
+
+ private async void Synchronize()
+ {
+ try
+ {
+ IsFree = false;
+ NotificationProvider.SetGlobalBusyMessage("Synchronizing...");
+
+ await MachineDataSynchronizer.Synchronize();
+
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NotificationProvider.ShowSuccess("Synchronization completed successfully.");
+ }
+ catch (Exception ex)
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NotificationProvider.ShowError($"Error occurred while trying to synchronize.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ IsFree = true;
+ }
+ }
}
}