From 9dbb8f8eb3d07ee07cf7ce1beab72df056e157c6 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 16 Aug 2018 12:06:36 +0300 Subject: New Implementation of PPC WiFI networks management! --- .../MachineSettingsModuleSettings.cs | 14 +++ .../Models/AvailableNetworkVM.cs | 80 -------------- .../Tango.PPC.MachineSettings.csproj | 4 +- .../ViewModels/MainViewVM.cs | 120 --------------------- .../Tango.PPC.MachineSettings/Views/MainView.xaml | 94 +--------------- 5 files changed, 18 insertions(+), 294 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/MachineSettingsModuleSettings.cs delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Models/AvailableNetworkVM.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/MachineSettingsModuleSettings.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/MachineSettingsModuleSettings.cs new file mode 100644 index 000000000..869ecc5d6 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/MachineSettingsModuleSettings.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; + +namespace Tango.PPC.MachineSettings +{ + public class MachineSettingsModuleSettings : SettingsBase + { + + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Models/AvailableNetworkVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Models/AvailableNetworkVM.cs deleted file mode 100644 index b4b4db45a..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Models/AvailableNetworkVM.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; -using Tango.Core.Commands; -using Tango.WiFi; - -namespace Tango.PPC.MachineSettings.Models -{ - public class AvailableNetworkVM : ExtendedObject - { - public AvailableWifiNetwork Network { get; set; } - - private bool _connectAutomatically; - public bool ConnectAutomatically - { - get { return _connectAutomatically; } - set { _connectAutomatically = value; RaisePropertyChangedAuto(); } - } - - private bool _connecting; - public bool Connecting - { - get { return _connecting; } - set { _connecting = value; RaisePropertyChangedAuto(); } - } - - private bool _requireAuthentication; - public bool RequireAuthentication - { - get { return _requireAuthentication; } - set { _requireAuthentication = value; RaisePropertyChangedAuto(); } - } - - private String _userName; - public String UserName - { - get { return _userName; } - set { _userName = value; RaisePropertyChangedAuto(); } - } - - private String _password; - public String Password - { - get { return _password; } - set { _password = value; RaisePropertyChangedAuto(); } - } - - private bool _requiresPassword; - public bool IsPasswordRequired - { - get { return _requiresPassword; } - set { _requiresPassword = value; RaisePropertyChangedAuto(); } - } - - private bool _requiresUserName; - public bool IsUserNameRequired - { - get { return _requiresUserName; } - set { _requiresUserName = value; RaisePropertyChangedAuto(); } - } - - private bool _isInCredentialsStage; - - public bool IsInCredentialsStage - { - get { return _isInCredentialsStage; } - set { _isInCredentialsStage = value; RaisePropertyChangedAuto(); } - } - - - public double SignalStrength - { - get { return Network.SignalStrength; } - } - - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Tango.PPC.MachineSettings.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Tango.PPC.MachineSettings.csproj index 0a5c02268..8a81a8add 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Tango.PPC.MachineSettings.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Tango.PPC.MachineSettings.csproj @@ -78,7 +78,7 @@ GlobalVersionInfo.cs - + Code @@ -160,7 +160,7 @@ - + \ No newline at end of file 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 a0996f110..310a09846 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 @@ -16,7 +16,6 @@ using Tango.PPC.Common; using Tango.PPC.Common.Connection; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Messages; -using Tango.PPC.MachineSettings.Models; using Tango.SharedUI.Components; using Tango.WiFi; @@ -44,34 +43,6 @@ namespace Tango.PPC.MachineSettings.ViewModels set { _selectedJobTypes = value; RaisePropertyChangedAuto(); } } - private WiFiManager _wiFiManager; - public WiFiManager WiFiManager - { - get { return _wiFiManager; } - set { _wiFiManager = value; RaisePropertyChangedAuto(); } - } - - private bool _enableWifi; - public bool EnableWiFi - { - get { return _enableWifi; } - set { _enableWifi = value; RaisePropertyChangedAuto(); } - } - - private ObservableCollection _networks; - public ObservableCollection Networks - { - get { return _networks; } - set { _networks = value; RaisePropertyChangedAuto(); } - } - - private ICollectionView _networksView; - public ICollectionView NetworksView - { - get { return _networksView; } - set { _networksView = value; RaisePropertyChangedAuto(); } - } - #endregion @@ -87,96 +58,12 @@ namespace Tango.PPC.MachineSettings.ViewModels /// public RelayCommand DiscardCommand { get; set; } - public RelayCommand ConnectToWiFiCommand { get; set; } - - public RelayCommand DisconnectFromWiFiCommand { get; set; } - #endregion public MainViewVM() { - Networks = new ObservableCollection(); - NetworksView = CollectionViewSource.GetDefaultView(Networks); - NetworksView.SortDescriptions.Add(new SortDescription(nameof(AvailableNetworkVM.SignalStrength), ListSortDirection.Descending)); - SaveCommand = new RelayCommand(Save); DiscardCommand = new RelayCommand(Discard); - WiFiManager = new WiFiManager(); - - WiFiManager.AvailableWifiNetworks.CollectionChanged += AvailableWifiNetworks_CollectionChanged; - - EnableWiFi = true; - - ConnectToWiFiCommand = new RelayCommand(ConnectToWiFi); - DisconnectFromWiFiCommand = new RelayCommand(DisconnectFromWiFi); - } - - private void DisconnectFromWiFi(AvailableNetworkVM network) - { - network.Network.Disconnect(); - } - - private async void ConnectToWiFi(AvailableNetworkVM network) - { - var request = network.Network.CreateAuthenticationRequest(); - - if (!network.IsInCredentialsStage) - { - if (request.IsPasswordRequired || request.IsUserNameRequired) - { - network.IsInCredentialsStage = true; - network.IsUserNameRequired = request.IsUserNameRequired; - network.IsPasswordRequired = request.IsPasswordRequired; - return; - } - else - { - network.Connecting = true; - await network.Network.Connect(request); - } - } - else - { - network.IsInCredentialsStage = false; - - if (request.IsUserNameRequired) - { - request.UserName = network.UserName; - } - if (request.IsPasswordRequired) - { - request.Password = network.Password; - } - - network.Connecting = true; - var connected = await network.Network.Connect(request); - network.Connecting = false; - - if (connected) - { - network.Network.IsConnected = true; - } - } - } - - private void AvailableWifiNetworks_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - InvokeUI(() => - { - Networks.Where(x => !WiFiManager.AvailableWifiNetworks.ToList().Exists(y => y.Name == x.Network.Name)).ToList().ForEach(x => Networks.Remove(x)); - - foreach (var n in WiFiManager.AvailableWifiNetworks.ToList()) - { - var network = Networks.FirstOrDefault(x => x.Network.Name == n.Name); - - if (network == null) - { - network = new AvailableNetworkVM(); - network.Network = n; - Networks.Add(network); - } - } - }); } private void Discard() @@ -211,13 +98,6 @@ namespace Tango.PPC.MachineSettings.ViewModels RaisePropertyChanged(nameof(Machine)); SelectedJobTypes = new SelectedObjectCollection(Enum.GetValues(typeof(JobTypes)).Cast().ToObservableCollection(), Machine.SupportedJobTypes.ToObservableCollection()); - - - //Wifi - if (EnableWiFi) - { - WiFiManager.Enabled = true; - } } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml index ec41e0b03..4823f0811 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml @@ -7,8 +7,8 @@ xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.PPC.MachineSettings.ViewModels" + xmlns:connectivity="clr-namespace:Tango.PPC.Common.Connectivity;assembly=Tango.PPC.Common" xmlns:global="clr-namespace:Tango.PPC.MachineSettings" - xmlns:models="clr-namespace:Tango.PPC.MachineSettings.Models" xmlns:local="clr-namespace:Tango.PPC.MachineSettings.Views" mc:Ignorable="d" d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -39,100 +39,10 @@ - - - Enable WiFi Adapter - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Connect automatically - - Connect - Disconnect - - - - - - Enter user name - - - - Enter the network security - - - - - Cancel - Next - - - - - - - - Connecting... - - - - - - - + -- cgit v1.3.1