aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Tango.MachineStudio.UpdateService.csproj
blob: 40cc6fb3c45ab2b063fe60a2a2d1c24374a7455d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{CC6D62E9-C300-42F3-B452-79966E902B10}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Tango.MachineStudio.UpdateService</RootNamespace>
    <AssemblyName>Tango.MachineStudio.UpdateService</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <WcfConfigValidationEnabled>True</WcfConfigValidationEnabled>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <UseIISExpress>true</UseIISExpress>
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Web.DynamicData" />
    <Reference Include="System.Web.Entity" />
    <Reference Include="System.Web.ApplicationServices" />
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.EnterpriseServices" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.ServiceModel.Web" />
    <Reference Include="System.Web" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="MachineStudioUpdateService.svc" />
    <Content Include="Web.config" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="..\..\Versioning\GlobalVersionInfo.cs">
      <Link>GlobalVersionInfo.cs</Link>
    </Compile>
    <Compile Include="MachineStudioUpdateService.svc.cs">
      <DependentUpon>MachineStudioUpdateService.svc</DependentUpon>
    </Compile>
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="App_Data\" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="packages.config" />
    <None Include="Properties\PublishProfiles\Publish To Twine Local Via FTP.pubxml" />
    <None Include="Web.Debug.config">
      <DependentUpon>Web.config</DependentUpon>
    </None>
    <None Include="Web.Release.config">
      <DependentUpon>Web.config</DependentUpon>
    </None>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Tango.BL\Tango.BL.csproj">
      <Project>{f441feee-322a-4943-b566-110e12fd3b72}</Project>
      <Name>Tango.BL</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj">
      <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
      <Name>Tango.Core</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Tango.Integration\Tango.Integration.csproj">
      <Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project>
      <Name>Tango.Integration</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Tango.Logging\Tango.Logging.csproj">
      <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project>
      <Name>Tango.Logging</Name>
    </ProjectReference>
    <ProjectReference Include="..\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj">
      <Project>{cb0b0aa2-bb24-4bca-a720-45e397684e12}</Project>
      <Name>Tango.MachineStudio.Common</Name>
    </ProjectReference>
  </ItemGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>65206</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>http://localhost:53044/</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
      <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
    </VisualStudio>
  </ProjectExtensions>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>
er */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
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;
using Tango.Core.DI;
using Tango.Core.ExtensionMethods;
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;

namespace Tango.PPC.MachineSettings.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
    {
        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
        {
            get { return _machine; }
            set { _machine = value; RaisePropertyChangedAuto(); }
        }

        private SelectedObjectCollection<JobTypes> _selectedJobTypes;
        public SelectedObjectCollection<JobTypes> SelectedJobTypes
        {
            get { return _selectedJobTypes; }
            set { _selectedJobTypes = value; RaisePropertyChangedAuto(); }
        }

        private SelectedObjectCollection<ColorSpaces> _selectedColorSpaces;
        public SelectedObjectCollection<ColorSpaces> SelectedColorSpaces
        {
            get { return _selectedColorSpaces; }
            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
        {
            get { return _enableHotSpot; }
            set { _enableHotSpot = value; RaisePropertyChangedAuto(); OnEnableHotSpotChanged(); }
        }

        private String _hotSpotPassword;
        public String HotSpotPassword
        {
            get { return _hotSpotPassword; }
            set { _hotSpotPassword = value; RaisePropertyChangedAuto(); }
        }

        private bool _enableExternalBridge;
        public bool EnableExternalBridge
        {
            get { return _enableExternalBridge; }
            set { _enableExternalBridge = value; RaisePropertyChangedAuto(); OnEnableExternalBridgeChanged(); }
        }

        private String _externalBridgePassword;
        public String ExternalBridgePassword
        {
            get { return _externalBridgePassword; }
            set { _externalBridgePassword = value; RaisePropertyChangedAuto(); }
        }

        private bool _enableRemoteAssistance;
        public bool EnableRemoteAssistance
        {
            get { return _enableRemoteAssistance; }
            set { _enableRemoteAssistance = value; RaisePropertyChangedAuto(); OnEnableRemoteAssistanceChanged(); }
        }

        private bool _enableLockScreen;
        public bool EnableLockScreen
        {
            get { return _enableLockScreen; }
            set { _enableLockScreen = value; RaisePropertyChangedAuto(); }
        }

        private int _lockScreenTimeoutMinutes;
        public int LockScreenTimeoutMinutes
        {
            get { return _lockScreenTimeoutMinutes; }
            set { _lockScreenTimeoutMinutes = value; RaisePropertyChangedAuto(); }
        }

        private String _lockScreenPassword;
        public String LockScreenPassword
        {
            get { return _lockScreenPassword; }
            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

        /// <summary>
        /// Gets or sets the save command.
        /// </summary>
        public RelayCommand SaveCommand { get; set; }

        /// <summary>
        /// Gets or sets the discard command.
        /// </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()
        {
            NavigationManager.NavigateBack();
        }

        private async void Save()
        {
            if (Validate())
            {
                Settings.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
                Settings.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList();
                Machine.MapPropertiesTo(MachineProvider.Machine, MappingFlags.NoReferenceTypes);

                Settings.EnableHotSpot = EnableHotSpot;
                Settings.HotSpotPassword = HotSpotPassword;
                Settings.EnableExternalBridge = EnableExternalBridge;
                Settings.ExternalBridgePassword = ExternalBridgePassword;
                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();

                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();
                            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()}");
                    }
                }

                await NavigationManager.NavigateBack();
            }
        }

        protected override void OnValidating()
        {
            base.OnValidating();
        }

        /// <summary>
        /// Called when the application has been started
        /// </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()
        {
            base.OnNavigatedTo();

            Machine = MachineProvider.Machine.ShallowClone();

            RaisePropertyChanged(nameof(Machine));

            _enableHotSpot = HotSpotProvider.IsEnabled;
            RaisePropertyChanged(nameof(EnableHotSpot));

            HotSpotPassword = Settings.HotSpotPassword;

            _enableExternalBridge = ExternalBridgeService.Enabled;
            RaisePropertyChanged(nameof(EnableExternalBridge));

            ExternalBridgePassword = Settings.ExternalBridgePassword;

            _enableRemoteAssistance = RemoteAssistanceProvider.IsEnabled;
            RaisePropertyChanged(nameof(EnableRemoteAssistance));

            EnableLockScreen = Settings.EnableLockScreen;
            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.");
            }
        }

        private async void OnEnableRemoteAssistanceChanged()
        {
            if (EnableRemoteAssistance)
            {
                try
                {
                    await RemoteAssistanceProvider.EnableRemoteAssistance();
                }
                catch
                {
                    await NotificationProvider.ShowError("An error occurred while trying to activate the remote assistance service. Please check your device settings and try again.");
                    _enableRemoteAssistance = false;
                }
            }
            else
            {
                try
                {
                    await RemoteAssistanceProvider.DisableRemoteAssistance();
                }
                catch
                {
                    await NotificationProvider.ShowError("An error occurred while trying to deactivate the remote assistance service. Please check your device settings and try again.");
                    _enableRemoteAssistance = true;
                }
            }

            RaisePropertyChanged(nameof(EnableRemoteAssistance));
        }

        private async void OnEnableHotSpotChanged()
        {
            if (EnableHotSpot)
            {
                if (HotSpotPassword == null || HotSpotPassword.Length < 8 || HotSpotPassword.Length > 16)
                {
                    await NotificationProvider.ShowError("Hot spot requires a password of 8 to 16 characters.");
                    _enableHotSpot = false;
                    RaisePropertyChanged(nameof(EnableHotSpot));
                    return;
                }

                try
                {
                    await HotSpotProvider.EnableHotSpot(HotSpotPassword);
                }
                catch
                {
                    await NotificationProvider.ShowError("An error occurred while trying to activate the hot spot network. Please check your device settings and try again.");
                    _enableHotSpot = false;
                }
            }
            else
            {
                try
                {
                    await HotSpotProvider.DisableHotSpot();
                }
                catch
                {
                    await NotificationProvider.ShowError("An error occurred while trying to deactivate the hot spot network.");
                    _enableHotSpot = true;
                }
            }

            RaisePropertyChanged(nameof(EnableHotSpot));
        }

        private void OnEnableExternalBridgeChanged()
        {
            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;
            }
        }
    }
}