diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-16 12:06:36 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-16 12:06:36 +0300 |
| commit | 9dbb8f8eb3d07ee07cf7ce1beab72df056e157c6 (patch) | |
| tree | cd5ace2339d8f3f4a4b92381843497d4f6b21301 /Software/Visual_Studio/PPC | |
| parent | a3aedf6ba1e0f9cc65877c88f66af6f330484086 (diff) | |
| download | Tango-9dbb8f8eb3d07ee07cf7ce1beab72df056e157c6.tar.gz Tango-9dbb8f8eb3d07ee07cf7ce1beab72df056e157c6.zip | |
New Implementation of PPC WiFI networks management!
Diffstat (limited to 'Software/Visual_Studio/PPC')
21 files changed, 827 insertions, 299 deletions
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 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="MachineSettingsModule.cs" /> - <Compile Include="Models\AvailableNetworkVM.cs" /> + <Compile Include="MachineSettingsModuleSettings.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> @@ -160,7 +160,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <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> </Project>
\ 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<AvailableNetworkVM> _networks; - public ObservableCollection<AvailableNetworkVM> 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 /// </summary> public RelayCommand DiscardCommand { get; set; } - public RelayCommand<AvailableNetworkVM> ConnectToWiFiCommand { get; set; } - - public RelayCommand<AvailableNetworkVM> DisconnectFromWiFiCommand { get; set; } - #endregion public MainViewVM() { - Networks = new ObservableCollection<AvailableNetworkVM>(); - 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<AvailableNetworkVM>(ConnectToWiFi); - DisconnectFromWiFiCommand = new RelayCommand<AvailableNetworkVM>(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<JobTypes>(Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().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 @@ <Grid x:Name="Container"> <touch:LightTouchScrollViewer> <StackPanel Margin="50"> - <!--WIFI--> <touch:TouchExpander Header="Connectivity" IsExpanded="True" FontSize="{StaticResource TangoExpanderHeaderFontSize}"> <StackPanel Margin="10 30 10 10"> - <DockPanel TextElement.FontSize="{StaticResource TangoDefaultFontSize}"> - <TextBlock VerticalAlignment="Center">Enable WiFi Adapter</TextBlock> - <touch:TouchToggleSlider Style="{StaticResource TangoToggleButtonGrayAccent}" HorizontalAlignment="Right" Margin="0 0 110 0" Width="90" IsChecked="{Binding Machine.EnableExternalBridge}"></touch:TouchToggleSlider> - </DockPanel> - - <touch:TouchNativeListBox PreventTouchDownSelect="False" Margin="0 30 0 30" Height="300" ItemsSource="{Binding NetworksView}" SelectionMode="Single"> - <touch:TouchNativeListBox.ItemTemplate> - <DataTemplate DataType="{x:Type models:AvailableNetworkVM}"> - <StackPanel Margin="0" TextElement.FontSize="{StaticResource TangoDefaultFontSize}"> - <StackPanel.Style> - <Style TargetType="StackPanel"> - <Setter Property="Background" Value="{StaticResource TangoPrimaryBackgroundBrush}"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> - <Setter Property="Background" Value="{StaticResource TangoMidBackgroundBrush}"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </StackPanel.Style> - <StackPanel Orientation="Horizontal" Margin="10 15"> - <touch:TouchIcon Foreground="{StaticResource TangoPrimaryAccentBrush}" Width="48" Height="48"> - <touch:TouchIcon.Style> - <Style TargetType="touch:TouchIcon"> - <Setter Property="Icon" Value="WifiStrengthOff"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='0'}" Value="True"> - <Setter Property="Icon" Value="WifiStrength1"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='20'}" Value="True"> - <Setter Property="Icon" Value="WifiStrength2"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='50'}" Value="True"> - <Setter Property="Icon" Value="WifiStrength3"></Setter> - </DataTrigger> - <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='80'}" Value="True"> - <Setter Property="Icon" Value="WifiStrength4"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </touch:TouchIcon.Style> - </touch:TouchIcon> - - <StackPanel Margin="20 0 0 0" VerticalAlignment="Center"> - <TextBlock VerticalAlignment="Center" Text="{Binding Network.Name,Mode=OneWay}"></TextBlock> - - <StackPanel Orientation="Horizontal"> - <TextBlock Foreground="{StaticResource TangoGrayTextBrush}" FontWeight="Normal" Text="Connected, " Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> - <TextBlock Foreground="{StaticResource TangoGrayTextBrush}" FontWeight="Normal" Text="Secure" Visibility="{Binding Network.IsSecure,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> - <TextBlock Foreground="{StaticResource TangoGrayTextBrush}" FontWeight="Normal" Text="Open" Visibility="{Binding Network.IsSecure,Converter={StaticResource BooleanToVisibilityInverseConverter}}"></TextBlock> - </StackPanel> - </StackPanel> - </StackPanel> - - <Grid Margin="20" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}"> - <Grid Height="80" Visibility="{Binding IsInCredentialsStage,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> - <touch:TouchCheckBox VerticalAlignment="Top" Margin="60 0 0 0" IsChecked="{Binding ConnectAutomatically}" Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Connect automatically</touch:TouchCheckBox> - - <touch:TouchButton Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ConnectToWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Connect</touch:TouchButton> - <touch:TouchButton Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.DisconnectFromWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityConverter}}">Disconnect</touch:TouchButton> - </Grid> - - <Grid Visibility="{Binding IsInCredentialsStage,Converter={StaticResource BooleanToVisibilityConverter}}"> - <StackPanel> - <StackPanel Width="300" HorizontalAlignment="Left" Visibility="{Binding IsUserNameRequired,Converter={StaticResource BooleanToVisibilityConverter}}"> - <TextBlock>Enter user name</TextBlock> - <touch:TouchTextBox Margin="0 5 0 0" Background="{StaticResource TangoPrimaryBackgroundBrush}" Text="{Binding UserName}"></touch:TouchTextBox> - </StackPanel> - <StackPanel Margin="0 10 0 0" Width="300" HorizontalAlignment="Left" Visibility="{Binding IsPasswordRequired,Converter={StaticResource BooleanToVisibilityConverter}}"> - <TextBlock>Enter the network security</TextBlock> - <touch:TouchTextBox Margin="0 5 0 0" IsPassword="True" Background="{StaticResource TangoPrimaryBackgroundBrush}" Text="{Binding Password}"></touch:TouchTextBox> - </StackPanel> - - <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 20 0 0"> - <touch:TouchButton Style="{StaticResource TangoHollowButton}" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CancelConnectToWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Cancel</touch:TouchButton> - <touch:TouchButton Margin="10 0 0 0" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ConnectToWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding Network.IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Next</touch:TouchButton> - </StackPanel> - </StackPanel> - </Grid> - - <Grid Visibility="{Binding Connecting,Converter={StaticResource BooleanToVisibilityConverter}}" Background="{StaticResource TangoMidBackgroundBrush}"> - <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="60 0 0 0" VerticalAlignment="Center"> - <touch:TouchBusyIndicator IsIndeterminate="{Binding Connecting}" Width="50" Height="50" /> - <TextBlock VerticalAlignment="Center" Margin="20 0 0 0">Connecting...</TextBlock> - </StackPanel> - </Grid> - </Grid> - </StackPanel> - </DataTemplate> - </touch:TouchNativeListBox.ItemTemplate> - </touch:TouchNativeListBox> + <connectivity:AvailableWiFiConnectionsControl DataContext="{Binding ConnectivityProvider}" /> </StackPanel> </touch:TouchExpander> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml new file mode 100644 index 000000000..80581551e --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml @@ -0,0 +1,91 @@ +<UserControl x:Class="Tango.PPC.Common.Connectivity.AvailableWiFiConnectionsControl" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:Tango.PPC.Common.Connectivity" + mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="350" d:DataContext="{d:DesignInstance Type=local:IConnectivityProvider, IsDesignTimeCreatable=False}"> + <Grid> + <StackPanel> + <DockPanel LastChildFill="False"> + <TextBlock DockPanel.Dock="Left" FontSize="{StaticResource TangoDefaultFontSize}" VerticalAlignment="Center">Available WiFi Connections</TextBlock> + <touch:TouchIconButton Padding="20" RippleBrush="{StaticResource TangoRippleDarkBrush}" CornerRadius="50" Foreground="{StaticResource TangoPrimaryAccentBrush}" Command="{Binding RefreshAvailableWiFiNetworksCommand}" DockPanel.Dock="Right" Icon="Refresh" Height="60" /> + </DockPanel> + <touch:TouchNativeListBox PreventTouchDownSelect="False" Margin="0 20 0 30" Height="300" ItemsSource="{Binding AvailableWiFiNetworksViewSource}" SelectionMode="Single"> + <touch:TouchNativeListBox.ItemTemplate> + <DataTemplate> + <StackPanel Margin="0" TextElement.FontSize="{StaticResource TangoDefaultFontSize}"> + <StackPanel.Style> + <Style TargetType="StackPanel"> + <Setter Property="Background" Value="{StaticResource TangoPrimaryBackgroundBrush}"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="True"> + <Setter Property="Background" Value="{StaticResource TangoMidBackgroundBrush}"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </StackPanel.Style> + <StackPanel Orientation="Horizontal" Margin="10 15"> + <touch:TouchIcon Foreground="{StaticResource TangoPrimaryAccentBrush}" Width="48" Height="48"> + <touch:TouchIcon.Style> + <Style TargetType="touch:TouchIcon"> + <Setter Property="Icon" Value="WifiStrengthOff"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='0'}" Value="True"> + <Setter Property="Icon" Value="WifiStrength1"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='20'}" Value="True"> + <Setter Property="Icon" Value="WifiStrength2"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='50'}" Value="True"> + <Setter Property="Icon" Value="WifiStrength3"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding SignalStrength,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter='80'}" Value="True"> + <Setter Property="Icon" Value="WifiStrength4"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </touch:TouchIcon.Style> + </touch:TouchIcon> + + <StackPanel Margin="20 0 0 0" VerticalAlignment="Center"> + <TextBlock VerticalAlignment="Center" Text="{Binding Name,Mode=OneWay}"></TextBlock> + + <StackPanel Orientation="Horizontal"> + <TextBlock Foreground="{StaticResource TangoPrimaryAccentBrush}" FontWeight="Normal" Text="Connected, " Visibility="{Binding IsConnected,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> + <TextBlock Foreground="{StaticResource TangoGrayTextBrush}" FontWeight="Normal" Text="Secure" Visibility="{Binding IsSecure,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> + <TextBlock Foreground="{StaticResource TangoGrayTextBrush}" FontWeight="Normal" Text="Open" Visibility="{Binding IsSecure,Converter={StaticResource BooleanToVisibilityInverseConverter}}"></TextBlock> + </StackPanel> + </StackPanel> + </StackPanel> + + <Grid Margin="20" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}"> + <Grid Height="80"> + <touch:TouchCheckBox VerticalAlignment="Top" Margin="60 0 0 0" IsChecked="{Binding AutoConnect}" Visibility="{Binding IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Connect automatically</touch:TouchCheckBox> + <touch:TouchButton Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ConnectToWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding IsConnected,Converter={StaticResource BooleanToVisibilityInverseConverter}}">Connect</touch:TouchButton> + <touch:TouchButton Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.DisconnectFromWiFiCommand}" CommandParameter="{Binding}" Width="150" CornerRadius="17" Height="40" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="{Binding IsConnected,Converter={StaticResource BooleanToVisibilityConverter}}">Disconnect</touch:TouchButton> + </Grid> + + <Grid Visibility="{Binding Connecting,Converter={StaticResource BooleanToVisibilityConverter}}" Background="{StaticResource TangoMidBackgroundBrush}"> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="60 0 0 0" VerticalAlignment="Center"> + <touch:TouchBusyIndicator IsIndeterminate="{Binding Connecting}" Width="50" Height="50" /> + <TextBlock VerticalAlignment="Center" Margin="20 0 0 0">Connecting...</TextBlock> + </StackPanel> + </Grid> + + <Grid Visibility="{Binding Disconnecting,Converter={StaticResource BooleanToVisibilityConverter}}" Background="{StaticResource TangoMidBackgroundBrush}"> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="60 0 0 0" VerticalAlignment="Center"> + <touch:TouchBusyIndicator IsIndeterminate="{Binding Disconnecting}" Width="50" Height="50" /> + <TextBlock VerticalAlignment="Center" Margin="20 0 0 0">Disconnecting...</TextBlock> + </StackPanel> + </Grid> + </Grid> + </StackPanel> + </DataTemplate> + </touch:TouchNativeListBox.ItemTemplate> + </touch:TouchNativeListBox> + </StackPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml.cs new file mode 100644 index 000000000..8d85aa5ad --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/AvailableWiFiConnectionsControl.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.Common.Connectivity +{ + /// <summary> + /// Interaction logic for AvailableWiFiConnectionsControl.xaml + /// </summary> + public partial class AvailableWiFiConnectionsControl : UserControl + { + public AvailableWiFiConnectionsControl() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/ConnectionStateEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/ConnectionStateEventArgs.cs new file mode 100644 index 000000000..ff20161a0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/ConnectionStateEventArgs.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.Connectivity +{ + public class ConnectionStateEventArgs : EventArgs + { + public bool IsConnected { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs new file mode 100644 index 000000000..85c25128a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; + +namespace Tango.PPC.Common.Connectivity +{ + /// <summary> + /// Represents an internet connection manager. + /// </summary> + public interface IConnectivityProvider + { + /// <summary> + /// Occurs when the connectivity provider state has changed (e.g network connected/disconnected). + /// </summary> + event EventHandler<ConnectionStateEventArgs> ConnectionStateChanged; + + /// <summary> + /// Gets a value indicating whether there is any Internet connection available. + /// </summary> + bool IsConnected { get; } + + /// <summary> + /// Gets the available WiFi networks. + /// </summary> + ObservableCollection<WiFiNetwork> AvailableWiFiNetworks { get; } + + /// <summary> + /// Gets the available WiFi networks as a sorted view source by signal strength. + /// </summary> + ICollectionView AvailableWiFiNetworksViewSource { get; set; } + + /// <summary> + /// Gets the available WiFi networks. + /// </summary> + /// <returns></returns> + Task<List<WiFiNetwork>> GetAvailableWiFiNetworks(); + + /// <summary> + /// Resets the available WiFi networks collection. + /// </summary> + Task RefreshAvailableWiFiNetworks(); + + /// <summary> + /// Checks the Internet connection. + /// </summary> + /// <returns></returns> + Task<bool> CheckInternetConnection(); + + /// <summary> + /// Gets the connect to WiFi command. + /// </summary> + RelayCommand<WiFiNetwork> ConnectToWiFiCommand { get; } + + /// <summary> + /// Gets the disconnect from WiFi command. + /// </summary> + RelayCommand<WiFiNetwork> DisconnectFromWiFiCommand { get; } + + /// <summary> + /// Gets or sets the refresh available WiFi networks command. + /// </summary> + RelayCommand RefreshAvailableWiFiNetworksCommand { get; set; } + + /// <summary> + /// Connects the specified network. + /// </summary> + /// <param name="network">The network.</param> + /// <returns></returns> + Task<bool> Connect(WiFiNetwork network); + + /// <summary> + /// Disconnects the specified network. + /// </summary> + /// <param name="network">The network.</param> + /// <returns></returns> + void Disconnect(WiFiNetwork network); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiAuthentication.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiAuthentication.cs new file mode 100644 index 000000000..dfa3576c4 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiAuthentication.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.WiFi; + +namespace Tango.PPC.Common.Connectivity +{ + public class WiFiAuthentication : ExtendedObject + { + public AuthRequest AuthRequest { get; set; } + + public bool IsUserNameRequired + { + get { return AuthRequest.IsUsernameRequired; } + } + + public bool IsPasswordRequired + { + get { return AuthRequest.IsPasswordRequired; } + } + + public String UserName + { + get { return AuthRequest.Username; } + set { AuthRequest.Username = value; RaisePropertyChangedAuto(); } + } + + public String Password + { + get { return AuthRequest.Password; } + set { AuthRequest.Password = value; RaisePropertyChangedAuto(); } + } + + public WiFiAuthentication(AuthRequest request) + { + AuthRequest = request; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiNetwork.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiNetwork.cs new file mode 100644 index 000000000..766e25e40 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/WiFiNetwork.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.Commands; +using Tango.WiFi; + +namespace Tango.PPC.Common.Connectivity +{ + public class WiFiNetwork : ExtendedObject + { + private Wifi _wifi; + + public bool IsConnected + { + get { return AccessPoint.IsConnected; } + } + + public String Name + { + get { return AccessPoint.Name; } + } + + public double SignalStrength + { + get { return AccessPoint.SignalStrength; } + } + + public bool IsSecure + { + get { return AccessPoint.IsSecure; } + } + + public bool HasProfile + { + get { return AccessPoint.HasProfile; } + } + + private AccessPoint _accessPoint; + public AccessPoint AccessPoint + { + get { return _accessPoint; } + set + { + _accessPoint = value; + + foreach (var prop in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) + { + RaisePropertyChanged(prop.Name); + } + } + } + + private bool _autoConnect; + public bool AutoConnect + { + get { return _autoConnect; } + set { _autoConnect = value; RaisePropertyChangedAuto(); } + } + + private bool _connecting; + public bool Connecting + { + get { return _connecting; } + set { _connecting = value; RaisePropertyChangedAuto(); } + } + + private bool _disconnecting; + public bool Disconnecting + { + get { return _disconnecting; } + set { _disconnecting = value; RaisePropertyChangedAuto(); } + } + + public WiFiNetwork(AccessPoint accessPoint, Wifi wifi) + { + _wifi = wifi; + AccessPoint = accessPoint; + } + + public WiFiAuthentication CreateAuthenticationRequest() + { + return new WiFiAuthentication(new AuthRequest(AccessPoint)); + } + + public Task<bool> Connect(WiFiAuthentication request) + { + return Task.Factory.StartNew<bool>(() => + { + try + { + Connecting = true; + return AccessPoint.Connect(request.AuthRequest, false); + } + catch (Exception) + { + throw; + } + finally + { + Connecting = false; + } + }); + } + + public Task Disconnect() + { + return Task.Factory.StartNew(() => + { + try + { + Disconnecting = true; + _wifi.Disconnect(); + AccessPoint.DeleteProfile(); + } + catch (Exception) + { + throw; + } + finally + { + Disconnecting = false; + } + }); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 3e908f3a4..9b1fa961c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -41,6 +41,11 @@ namespace Tango.PPC.Common public int MachineScanningTimeoutSeconds { get; set; } /// <summary> + /// Gets or sets the name of the name of a WiFi network to automatically connect to when the application starts. + /// </summary> + public String AutoConnectWiFiName { get; set; } + + /// <summary> /// Initializes a new instance of the <see cref="PPCSettings"/> class. /// </summary> public PPCSettings() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs index 0fb2be851..23213f194 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs @@ -8,6 +8,7 @@ using Tango.Core.DI; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; @@ -74,6 +75,12 @@ namespace Tango.PPC.Common [TangoInject] public IPrintingManager PrintingManager { get; set; } + /// <summary> + /// Gets or sets the connectivity provider. + /// </summary> + [TangoInject] + public IConnectivityProvider ConnectivityProvider { get; set; } + private PPCSettings _settings; /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 0fe4f3f42..5de2fbf81 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -106,6 +106,13 @@ <Compile Include="Connection\DefaultMachineProvider.cs" /> <Compile Include="Connection\IMachineProvider.cs" /> <Compile Include="Connection\MachineOperatorChangedEventArgs.cs" /> + <Compile Include="Connectivity\AvailableWiFiConnectionsControl.xaml.cs"> + <DependentUpon>AvailableWiFiConnectionsControl.xaml</DependentUpon> + </Compile> + <Compile Include="Connectivity\ConnectionStateEventArgs.cs" /> + <Compile Include="Connectivity\WiFiAuthentication.cs" /> + <Compile Include="Connectivity\WiFiNetwork.cs" /> + <Compile Include="Connectivity\IConnectivityProvider.cs" /> <Compile Include="Controls\AsyncAdornerControl.cs" /> <Compile Include="Controls\TwineCatalogControl.xaml.cs"> <DependentUpon>TwineCatalogControl.xaml</DependentUpon> @@ -144,6 +151,10 @@ <Compile Include="Update\UploadCompletedRequest.cs" /> <Compile Include="Update\UploadVersionRequest.cs" /> <Compile Include="Update\UploadVersionResponse.cs" /> + <Page Include="Connectivity\AvailableWiFiConnectionsControl.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Controls\MultiPieChart.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -260,6 +271,10 @@ <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> <Name>Tango.Transport</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.WiFi\Tango.WiFi.csproj"> + <Project>{6aa425c9-ea6a-4b01-aaed-5ff122e8b663}</Project> + <Name>Tango.WiFi</Name> + </ProjectReference> </ItemGroup> <ItemGroup> <BootstrapperPackage Include=".NETFramework,Version=v4.6"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs new file mode 100644 index 000000000..ec51b9a98 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs @@ -0,0 +1,265 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.BL; +using Tango.Core; +using Tango.Core.Commands; +using Tango.Core.Cryptography; +using Tango.PPC.Common; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Connectivity; +using Tango.PPC.Common.Notifications; +using Tango.Settings; +using Tango.WiFi; + +namespace Tango.PPC.UI.Connectivity +{ + public class DefaultConnectivityProvider : ExtendedObject, IConnectivityProvider + { + private Wifi _wifi; + private INotificationProvider _notification; + + /// <summary> + /// Occurs when the connectivity provider state has changed (e.g network connected/disconnected). + /// </summary> + public event EventHandler<ConnectionStateEventArgs> ConnectionStateChanged; + + private bool _isConnected; + /// <summary> + /// Gets a value indicating whether there is any Internet connection available. + /// </summary> + public bool IsConnected + { + get { return _isConnected; } + set { _isConnected = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Gets the available WiFi networks. + /// </summary> + public ObservableCollection<WiFiNetwork> AvailableWiFiNetworks { get; } + + /// <summary> + /// Gets the available WiFi networks as a sorted view source by signal strength. + /// </summary> + public ICollectionView AvailableWiFiNetworksViewSource { get; set; } + + /// <summary> + /// Gets the connect to WiFi command. + /// </summary> + public RelayCommand<WiFiNetwork> ConnectToWiFiCommand { get; private set; } + + /// <summary> + /// Gets the disconnect from WiFi command. + /// </summary> + public RelayCommand<WiFiNetwork> DisconnectFromWiFiCommand { get; private set; } + + /// <summary> + /// + /// </summary> + public RelayCommand RefreshAvailableWiFiNetworksCommand { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="DefaultConnectivityProvider"/> class. + /// </summary> + public DefaultConnectivityProvider(IPPCApplicationManager applicationManager, INotificationProvider notificationProvider) + { + _notification = notificationProvider; + + AvailableWiFiNetworks = new ObservableCollection<WiFiNetwork>(); + AvailableWiFiNetworks.EnableCrossThreadOperations(); + AvailableWiFiNetworksViewSource = CollectionViewSource.GetDefaultView(AvailableWiFiNetworks); + + AvailableWiFiNetworksViewSource.SortDescriptions.Add(new SortDescription(nameof(WiFiNetwork.IsConnected), ListSortDirection.Descending)); + AvailableWiFiNetworksViewSource.SortDescriptions.Add(new SortDescription(nameof(WiFiNetwork.SignalStrength), ListSortDirection.Descending)); + + _wifi = new Wifi(); + + applicationManager.Ready += ApplicationManager_Ready; + + ConnectToWiFiCommand = new RelayCommand<WiFiNetwork>(async (x) => + { + await Connect(x); + }); + + DisconnectFromWiFiCommand = new RelayCommand<WiFiNetwork>((x) => + { + Disconnect(x); + }); + + RefreshAvailableWiFiNetworksCommand = new RelayCommand(() => + { + RefreshAvailableWiFiNetworks(); + }); + } + + /// <summary> + /// Handles the application manager ApplicationReady event. + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void ApplicationManager_Ready(object sender, EventArgs e) + { + Task.Factory.StartNew(async () => + { + Thread.Sleep(2000); + + await RefreshAvailableWiFiNetworks(); + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + + var auto_connect_network = AvailableWiFiNetworks.ToList().FirstOrDefault(x => x.Name == settings.AutoConnectWiFiName); + + if (auto_connect_network != null && !auto_connect_network.IsConnected) + { + await Connect(auto_connect_network); + } + }); + } + + /// <summary> + /// Gets the available WiFi networks. + /// </summary> + /// <returns></returns> + public Task<List<WiFiNetwork>> GetAvailableWiFiNetworks() + { + return Task.Factory.StartNew<List<WiFiNetwork>>(() => + { + var accessPoints = _wifi.GetAccessPoints(); + + AvailableWiFiNetworks.Where(x => !accessPoints.ToList().Exists(y => y.Name == x.Name)).ToList().ForEach(x => AvailableWiFiNetworks.Remove(x)); + + foreach (var ap in accessPoints.ToList()) + { + var network = AvailableWiFiNetworks.FirstOrDefault(x => x.Name == ap.Name); + + if (network == null) + { + network = new WiFiNetwork(ap, _wifi); + AvailableWiFiNetworks.Add(network); + } + else + { + network.AccessPoint = ap; + } + } + + return AvailableWiFiNetworks.ToList(); + }); + } + + /// <summary> + /// Resets the available WiFi networks collection. + /// </summary> + public Task RefreshAvailableWiFiNetworks() + { + return Task.Factory.StartNew(() => + { + AvailableWiFiNetworks.Clear(); + GetAvailableWiFiNetworks().Wait(); + }); + } + + /// <summary> + /// Checks the Internet connection. + /// </summary> + /// <returns></returns> + public Task<bool> CheckInternetConnection() + { + return Task.Factory.StartNew<bool>(() => + { + try + { + using (var client = new WebClient()) + using (client.OpenRead("http://clients3.google.com/generate_204")) + { + return true; + } + } + catch + { + return false; + } + }); + } + + /// <summary> + /// Connects the specified network. + /// </summary> + /// <param name="network">The network.</param> + /// <returns></returns> + public async Task<bool> Connect(WiFiNetwork network) + { + var auth = network.CreateAuthenticationRequest(); + + bool result = false; + + if ((auth.IsPasswordRequired || auth.IsUserNameRequired) && !network.HasProfile) + { + var vm = await _notification.ShowDialog<WiFiAuthenticationViewVM>(new WiFiAuthenticationViewVM(auth, network)); + + if (vm.DialogResult) + { + result = await network.Connect(auth); + await RefreshAvailableWiFiNetworks(); + } + else + { + return false; + } + } + else + { + result = await network.Connect(auth); + await RefreshAvailableWiFiNetworks(); + return result; + } + + if (result) + { + OnConnectionStateChanged(true); + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + settings.AutoConnectWiFiName = network.AutoConnect ? network.Name : null; + settings.Save(); + } + + return result; + } + + /// <summary> + /// Disconnects the specified network. + /// </summary> + /// <param name="network">The network.</param> + /// <returns></returns> + public void Disconnect(WiFiNetwork network) + { + Task.Factory.StartNew(() => + { + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + settings.AutoConnectWiFiName = null; + settings.Save(); + network.AutoConnect = false; + network.Disconnect().Wait(); + RefreshAvailableWiFiNetworks().Wait(); + OnConnectionStateChanged(false); + }); + } + + /// <summary> + /// Called when the connection state has been changed + /// </summary> + /// <param name="connected">if set to <c>true</c> [connected].</param> + protected virtual void OnConnectionStateChanged(bool connected) + { + IsConnected = connected; + ConnectionStateChanged?.Invoke(this, new ConnectionStateEventArgs() { IsConnected = connected }); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml new file mode 100644 index 000000000..311c3ce99 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml @@ -0,0 +1,45 @@ +<UserControl x:Class="Tango.PPC.UI.Connectivity.WiFiAuthenticationView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:local="clr-namespace:Tango.PPC.UI.Connectivity" + mc:Ignorable="d" + Background="{StaticResource TangoPrimaryBackgroundBrush}" MinWidth="500" Height="570" d:DataContext="{d:DesignInstance Type=local:WiFiAuthenticationViewVM, IsDesignTimeCreatable=False}"> + <Grid Margin="10"> + <Grid.RowDefinitions> + <RowDefinition Height="200"/> + <RowDefinition Height="1*"/> + <RowDefinition Height="50"/> + </Grid.RowDefinitions> + + <StackPanel> + <touch:TouchIcon Icon="WifiStrength3Lock" Width="100" Height="100" Foreground="{StaticResource TangoPrimaryAccentBrush}" Margin="10" /> + <TextBlock HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}"> + <Run>Connect to </Run> + <Run Foreground="{StaticResource TangoPrimaryAccentBrush}" FontStyle="Italic" Text="{Binding WiFiNetwork.Name,Mode=OneWay}"></Run> + </TextBlock> + </StackPanel> + + <Grid Grid.Row="1"> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" TextElement.FontSize="{StaticResource TangoDefaultFontSize}"> + <StackPanel Margin="0 0 0 40" Visibility="{Binding WiFiAuthentication.IsUserNameRequired,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock TextAlignment="Center">Enter user name</TextBlock> + <touch:TouchTextBox Margin="0 10 0 0" Background="{StaticResource TangoPrimaryBackgroundBrush}" Text="{Binding WiFiAuthentication.UserName}"></touch:TouchTextBox> + </StackPanel> + <StackPanel Margin="0 0 0 0" Visibility="{Binding WiFiAuthentication.IsPasswordRequired,Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock x:Name="txtPassword" TextAlignment="Center">Enter the network security key</TextBlock> + <touch:TouchTextBox Margin="0 10 0 0" IsPassword="True" Background="{StaticResource TangoPrimaryBackgroundBrush}" Text="{Binding WiFiAuthentication.Password}"></touch:TouchTextBox> + </StackPanel> + </StackPanel> + </Grid> + + <Grid Grid.Row="2"> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> + <touch:TouchButton Command="{Binding CloseCommand}" CornerRadius="25" Width="170" Height="50" Style="{StaticResource TangoHollowButton}">CANCEL</touch:TouchButton> + <touch:TouchButton CornerRadius="25" Width="170" Height="50" Margin="10 0 0 0" Command="{Binding OKCommand}">CONNECT</touch:TouchButton> + </StackPanel> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml.cs new file mode 100644 index 000000000..690f2321f --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationView.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Connectivity +{ + /// <summary> + /// Interaction logic for WiFiAuthenticationView.xaml + /// </summary> + public partial class WiFiAuthenticationView : UserControl + { + public WiFiAuthenticationView() + { + InitializeComponent(); + + this.Loaded += WiFiAuthenticationView_Loaded; + } + + private void WiFiAuthenticationView_Loaded(object sender, RoutedEventArgs e) + { + txtPassword.Focus(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationViewVM.cs new file mode 100644 index 000000000..68fb2496b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/WiFiAuthenticationViewVM.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common.Connectivity; +using Tango.SharedUI; + +namespace Tango.PPC.UI.Connectivity +{ + public class WiFiAuthenticationViewVM : DialogViewVM + { + public WiFiAuthentication WiFiAuthentication { get; set; } + + public WiFiNetwork WiFiNetwork { get; set; } + + public WiFiAuthenticationViewVM(WiFiAuthentication wifiAuthentication,WiFiNetwork wifiNetwork) : base() + { + WiFiAuthentication = wifiAuthentication; + WiFiNetwork = wifiNetwork; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index db9ee3863..2d0ac96fa 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -108,14 +108,19 @@ namespace Tango.PPC.UI.PPCApplication /// <summary> /// Called when the main window content has been rendered /// </summary> - private async void OnMainWindowContentRendered() + private void OnMainWindowContentRendered() { LogManager.Log("Main window content rendered."); - PPCSettings settings = null; - ContentRendered?.Invoke(this, new EventArgs()); + StartApplication(); + } + + private async void StartApplication() + { + PPCSettings settings = null; + await Task.Factory.StartNew(() => { LogManager.Log("Reading PPC settings..."); @@ -154,14 +159,14 @@ namespace Tango.PPC.UI.PPCApplication } else { - OnDbInitialized(); + PostDbInitialize(); } } /// <summary> /// Called when the database has been initialized /// </summary> - private void OnDbInitialized() + private void PostDbInitialize() { LogManager.Log($"Raising {nameof(ApplicationStarted)} event..."); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index d1772d0a0..d91bee884 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -112,6 +112,11 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="Authentication\DefaultAuthenticationProvider.cs" /> + <Compile Include="Connectivity\DefaultConnectivityProvider.cs" /> + <Compile Include="Connectivity\WiFiAuthenticationView.xaml.cs"> + <DependentUpon>WiFiAuthenticationView.xaml</DependentUpon> + </Compile> + <Compile Include="Connectivity\WiFiAuthenticationViewVM.cs" /> <Compile Include="Converters\AppBarItemConverter.cs" /> <Compile Include="Converters\NotificationItemConverter.cs" /> <Compile Include="Modules\DefaultStudioModuleLoader.cs" /> @@ -149,6 +154,10 @@ <Compile Include="Views\MainView.xaml.cs"> <DependentUpon>MainView.xaml</DependentUpon> </Compile> + <Page Include="Connectivity\WiFiAuthenticationView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="MainWindow.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -285,6 +294,10 @@ <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> <Name>Tango.Transport</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.WiFi\Tango.WiFi.csproj"> + <Project>{6aa425c9-ea6a-4b01-aaed-5ff122e8b663}</Project> + <Name>Tango.WiFi</Name> + </ProjectReference> <ProjectReference Include="..\Modules\Tango.PPC.Jobs\Tango.PPC.Jobs.csproj"> <Project>{096f16c8-6d06-4b5f-9496-b9d2df2d94a3}</Project> <Name>Tango.PPC.Jobs</Name> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 61c2ca7c4..5c416a289 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -6,6 +6,7 @@ using Tango.Logging; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.Diagnostics; using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.ExternalBridge; @@ -16,6 +17,7 @@ using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; using Tango.PPC.Common.Threading; using Tango.PPC.UI.Authentication; +using Tango.PPC.UI.Connectivity; using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; using Tango.PPC.UI.Notifications; @@ -54,6 +56,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister<IPPCExternalBridgeService>(); TangoIOC.Default.Unregister<IMachineSetupManager>(); TangoIOC.Default.Unregister<IPrintingManager>(); + TangoIOC.Default.Unregister<IConnectivityProvider>(); TangoIOC.Default.Register<IDispatcherProvider, DefaultDispetcherProvider>(new DefaultDispetcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register<INotificationProvider, DefaultNotificationProvider>(); @@ -68,6 +71,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<IPPCExternalBridgeService, PPCExternalBridgeService>(); TangoIOC.Default.Register<IMachineSetupManager, MachineSetupManager>(); TangoIOC.Default.Register<IPrintingManager, DefaultPrintingManager>(); + TangoIOC.Default.Register<IConnectivityProvider, DefaultConnectivityProvider>(); //TangoIOC.Default.Register<TeamFoundationServiceExtendedClient>(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); |
