diff options
| author | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
|---|---|---|
| committer | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
| commit | 00a491d93733d4625ad329b2ba8237f445364b3f (patch) | |
| tree | 4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs | |
| parent | 124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff) | |
| download | Tango-00a491d9.tar.gz Tango-00a491d9.zip | |
merge
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.cs | 229 |
1 files changed, 7 insertions, 222 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 20cfd6bf4..8ed512670 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,7 +9,6 @@ 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; @@ -19,8 +18,6 @@ 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; @@ -32,17 +29,8 @@ 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 { @@ -64,13 +52,6 @@ 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 { @@ -127,69 +108,6 @@ 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 @@ -204,18 +122,12 @@ 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() @@ -227,9 +139,9 @@ namespace Tango.PPC.MachineSettings.ViewModels { if (Validate()) { - Settings.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList(); - Settings.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList(); - Machine.MapPropertiesTo(MachineProvider.Machine, MappingFlags.NoReferenceTypes); + Machine.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList(); + Machine.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList(); + Machine.MapPrimitivesWithStrings(MachineProvider.Machine); Settings.EnableHotSpot = EnableHotSpot; Settings.HotSpotPassword = HotSpotPassword; @@ -238,73 +150,10 @@ 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(); - - 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(); - } + await NavigationManager.NavigateBack(); } } @@ -318,29 +167,10 @@ 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 async override void OnNavigatedTo() + public override void OnNavigatedTo() { base.OnNavigatedTo(); @@ -365,29 +195,8 @@ namespace Tango.PPC.MachineSettings.ViewModels LockScreenTimeoutMinutes = (int)Settings.LockScreenTimeout.TotalMinutes; LockScreenPassword = Settings.LockScreenPassword; - 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."); - } + 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()); } private async void OnEnableRemoteAssistanceChanged() @@ -462,29 +271,5 @@ 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; - } - } } } |
