aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-11 19:43:35 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-11 19:43:35 +0200
commit48f781d037a83c51fdd555fb6c9d1c2b4e424efe (patch)
treec13666e1ecb34dca68a8755af5c69534a493951f /Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
parent1952756022f71729aab3cea304d039f9b340b5d2 (diff)
downloadTango-48f781d037a83c51fdd555fb6c9d1c2b4e424efe.tar.gz
Tango-48f781d037a83c51fdd555fb6c9d1c2b4e424efe.zip
Working on PPC hotspot and external bridge.
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.cs97
1 files changed, 93 insertions, 4 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 6bbe1c47b..267012e2e 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
@@ -3,6 +3,7 @@ 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;
@@ -43,6 +44,33 @@ namespace Tango.PPC.MachineSettings.ViewModels
set { _selectedJobTypes = 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(); }
+ }
#endregion
@@ -73,10 +101,25 @@ namespace Tango.PPC.MachineSettings.ViewModels
private async void Save()
{
- Machine.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
- Machine.ShallowCopyTo(MachineProvider.Machine);
- await MachineProvider.SaveMachine();
- await NavigationManager.NavigateBack();
+ if (Validate())
+ {
+ Machine.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
+ Machine.ShallowCopyTo(MachineProvider.Machine);
+
+ Settings.EnableHotSpot = EnableHotSpot;
+ Settings.HotSpotPassword = HotSpotPassword;
+ Settings.EnableExternalBridge = EnableExternalBridge;
+ Settings.ExternalBridgePassword = ExternalBridgePassword;
+ Settings.Save();
+
+ await MachineProvider.SaveMachine();
+ await NavigationManager.NavigateBack();
+ }
+ }
+
+ protected override void OnValidating()
+ {
+ base.OnValidating();
}
/// <summary>
@@ -94,8 +137,54 @@ namespace Tango.PPC.MachineSettings.ViewModels
Machine = new Machine();
MachineProvider.Machine.ShallowCopyTo(Machine);
RaisePropertyChanged(nameof(Machine));
+ _enableHotSpot = ConnectivityProvider.IsHotspotActive;
+ RaisePropertyChanged(nameof(EnableHotSpot));
+
SelectedJobTypes = new SelectedObjectCollection<JobTypes>(Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToObservableCollection(), Machine.SupportedJobTypes.ToObservableCollection());
}
+
+ 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 ConnectivityProvider.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 ConnectivityProvider.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;
+ }
}
}