Skip to content

Commit 798087e

Browse files
committed
Remote Desktop - Connect as (request credentials) added
1 parent 3d95702 commit 798087e

6 files changed

Lines changed: 173 additions & 17 deletions

File tree

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
<system:String x:Key="String_Credentials">Anmeldeinformationen</system:String>
327327
<system:String x:Key="String_Custom">Eigene</system:String>
328328
<system:String x:Key="String_UseCredentials">Anmeldeinformationen verwenden</system:String>
329+
<system:String x:Key="String_ConnectAs">Verbinden als...</system:String>
329330

330331
<!-- Help message -->
331332
<system:String x:Key="String_HelpMessage_ParameterHelp">Zeigt diesen Dialog an.</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
<system:String x:Key="String_Credentials">Credentials</system:String>
327327
<system:String x:Key="String_Custom">Custom</system:String>
328328
<system:String x:Key="String_UseCredentials">Use credentials</system:String>
329+
<system:String x:Key="String_ConnectAs">Connect as...</system:String>
329330

330331
<!-- Help message -->
331332
<system:String x:Key="String_HelpMessage_ParameterHelp">Displays this dialog.</system:String>

Source/NETworkManager/ViewModels/Applications/RemoteDesktopViewModel.cs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,27 @@ private async void ConnectNewSessionAction()
165165

166166
Models.RemoteDesktop.RemoteDesktopSessionInfo remoteDesktopSessionInfo = new Models.RemoteDesktop.RemoteDesktopSessionInfo
167167
{
168-
Hostname = instance.Hostname,
168+
Hostname = instance.Hostname
169169
};
170170

171+
if(instance.UseCredentials)
172+
{
173+
remoteDesktopSessionInfo.CustomCredentials = true;
174+
175+
if(instance.CustomCredentials)
176+
{
177+
remoteDesktopSessionInfo.Username = instance.Username;
178+
remoteDesktopSessionInfo.Password = instance.Password;
179+
}
180+
else
181+
{
182+
CredentialInfo credentialInfo = CredentialManager.GetCredentialByID((int)instance.CredentialID);
183+
184+
remoteDesktopSessionInfo.Username = credentialInfo.Username;
185+
remoteDesktopSessionInfo.Password = credentialInfo.Password;
186+
}
187+
}
188+
171189
ConnectSession(remoteDesktopSessionInfo);
172190
}, instance =>
173191
{
@@ -308,6 +326,68 @@ private async void ConnectSessionAction()
308326
}
309327
}
310328

329+
public ICommand ConnectSessionAsCommand
330+
{
331+
get { return new RelayCommand(p => ConnectSessionAsAction()); }
332+
}
333+
334+
private async void ConnectSessionAsAction()
335+
{
336+
CustomDialog customDialog = new CustomDialog()
337+
{
338+
Title = Application.Current.Resources["String_Header_Connect"] as string
339+
};
340+
341+
RemoteDesktopSessionConnectViewModel connectRemoteDesktopSessionViewModel = new RemoteDesktopSessionConnectViewModel(instance =>
342+
{
343+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
344+
ConfigurationManager.Current.FixAirspace = false;
345+
346+
Models.RemoteDesktop.RemoteDesktopSessionInfo remoteDesktopSessionInfo = new Models.RemoteDesktop.RemoteDesktopSessionInfo
347+
{
348+
Hostname = instance.Hostname
349+
};
350+
351+
if (instance.UseCredentials)
352+
{
353+
remoteDesktopSessionInfo.CustomCredentials = true;
354+
355+
if (instance.CustomCredentials)
356+
{
357+
remoteDesktopSessionInfo.Username = instance.Username;
358+
remoteDesktopSessionInfo.Password = instance.Password;
359+
}
360+
else
361+
{
362+
CredentialInfo credentialInfo = CredentialManager.GetCredentialByID((int)instance.CredentialID);
363+
364+
remoteDesktopSessionInfo.Username = credentialInfo.Username;
365+
remoteDesktopSessionInfo.Password = credentialInfo.Password;
366+
}
367+
}
368+
369+
ConnectSession(remoteDesktopSessionInfo);
370+
}, instance =>
371+
{
372+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
373+
ConfigurationManager.Current.FixAirspace = false;
374+
});
375+
376+
// Set the hostname
377+
connectRemoteDesktopSessionViewModel.Hostname = SelectedSession.Hostname;
378+
379+
// Request credentials
380+
connectRemoteDesktopSessionViewModel.UseCredentials = true;
381+
382+
customDialog.Content = new RemoteDesktopSessionConnectDialog
383+
{
384+
DataContext = connectRemoteDesktopSessionViewModel
385+
};
386+
387+
ConfigurationManager.Current.FixAirspace = true;
388+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
389+
}
390+
311391
public ICommand EditSessionCommand
312392
{
313393
get { return new RelayCommand(p => EditSessionAction()); }

Source/NETworkManager/ViewModels/Dialogs/RemoteDesktopSessionConnectViewModel.cs

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using System;
1+
using NETworkManager.Models.Settings;
2+
using System;
3+
using System.ComponentModel;
24
using System.Security;
5+
using System.Windows.Data;
36
using System.Windows.Input;
47

58
namespace NETworkManager.ViewModels.Dialogs
@@ -32,16 +35,16 @@ public string Hostname
3235
}
3336
}
3437

35-
private bool _useCredential;
36-
public bool UseCredential
38+
private bool _useCredentials;
39+
public bool UseCredentials
3740
{
38-
get { return _useCredential; }
41+
get { return _useCredentials; }
3942
set
4043
{
41-
if (value == _useCredential)
44+
if (value == _useCredentials)
4245
return;
4346

44-
_useCredential = value;
47+
_useCredentials = value;
4548
OnPropertyChanged();
4649
}
4750
}
@@ -88,10 +91,61 @@ public SecureString Password
8891
}
8992
}
9093

94+
private int? _credentialID = null;
95+
public int? CredentialID
96+
{
97+
get { return _credentialID; }
98+
set
99+
{
100+
if (value == _credentialID)
101+
return;
102+
103+
_credentialID = value;
104+
OnPropertyChanged();
105+
}
106+
}
107+
108+
ICollectionView _credentials;
109+
public ICollectionView Credentials
110+
{
111+
get { return _credentials; }
112+
}
113+
114+
private bool _credentialsLocked;
115+
public bool CredentialsLocked
116+
{
117+
get { return _credentialsLocked; }
118+
set
119+
{
120+
if (value == _credentialsLocked)
121+
return;
122+
123+
_credentialsLocked = value;
124+
OnPropertyChanged();
125+
}
126+
}
127+
91128
public RemoteDesktopSessionConnectViewModel(Action<RemoteDesktopSessionConnectViewModel> connectCommand, Action<RemoteDesktopSessionConnectViewModel> cancelHandler)
92129
{
93130
_connectCommand = new RelayCommand(p => connectCommand(this));
94131
_cancelCommand = new RelayCommand(p => cancelHandler(this));
132+
133+
if (CredentialManager.Loaded)
134+
_credentials = CollectionViewSource.GetDefaultView(CredentialManager.CredentialInfoList);
135+
else
136+
CredentialsLocked = true;
137+
}
138+
139+
#region ICommand & Actions
140+
public ICommand UnselectCredentialCommand
141+
{
142+
get { return new RelayCommand(p => UnselectCredentialAction()); }
143+
}
144+
145+
private void UnselectCredentialAction()
146+
{
147+
CredentialID = null;
95148
}
149+
#endregion
96150
}
97151
}

Source/NETworkManager/Views/Applications/RemoteDesktopView.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
</Rectangle>
8383
</MenuItem.Icon>
8484
</MenuItem>
85+
<MenuItem Header="{DynamicResource String_ConnectAs}" Command="{Binding ConnectSessionAsCommand}">
86+
<MenuItem.Icon>
87+
<Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
88+
<Rectangle.OpacityMask>
89+
<VisualBrush Stretch="Uniform" Visual="{IconPacks:PackIconFontAwesome Kind=Desktop}" />
90+
</Rectangle.OpacityMask>
91+
</Rectangle>
92+
</MenuItem.Icon>
93+
</MenuItem>
8594
<MenuItem Header="{DynamicResource String_Edit}" Command="{Binding EditSessionCommand}">
8695
<MenuItem.Icon>
8796
<Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">

Source/NETworkManager/Views/Dialogs/RemoteDesktopSessionConnectDialog.xaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<UserControl.Resources>
1313
<Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1414
<Converter:BooleanReverseToVisibilityConverter x:Key="BooleanReverseToVisibilityConverter" />
15+
<Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
1516
</UserControl.Resources>
1617
<Grid Margin="0,20">
1718
<Grid.RowDefinitions>
@@ -36,7 +37,7 @@
3637
<RowDefinition Height="Auto" />
3738
<RowDefinition Height="10" />
3839
<RowDefinition Height="Auto" />
39-
</Grid.RowDefinitions>
40+
</Grid.RowDefinitions>
4041
<TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Hostname}" />
4142
<TextBox x:Name="txtHostname" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}">
4243
<TextBox.Text>
@@ -48,13 +49,13 @@
4849
</TextBox.Text>
4950
</TextBox>
5051
<TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_UseCredentials}" />
51-
<mah:ToggleSwitch Grid.Column="2" Grid.Row="2" OffLabel="" OnLabel="" IsChecked="{Binding UseCredential}" />
52-
<StackPanel Grid.Column="2" Grid.Row="4" Orientation="Horizontal" Visibility="{Binding UseCredential, Converter={StaticResource BooleanToVisibilityConverter}}">
53-
<RadioButton Content="{DynamicResource String_Credentials}" />
52+
<mah:ToggleSwitch Grid.Column="2" Grid.Row="2" OffLabel="" OnLabel="" IsChecked="{Binding UseCredentials}" />
53+
<StackPanel Grid.Column="2" Grid.Row="4" Orientation="Horizontal" Visibility="{Binding UseCredentials, Converter={StaticResource BooleanToVisibilityConverter}}">
54+
<RadioButton Content="{DynamicResource String_Credentials}" IsEnabled="{Binding CredentialsLocked, Converter={StaticResource BooleanReverseConverter}}" />
5455
<RadioButton Content="{DynamicResource String_Custom}" IsChecked="{Binding CustomCredentials}" Margin="10,0,0,0"/>
5556
</StackPanel>
5657
</Grid>
57-
<Grid Grid.Row="1" Visibility="{Binding UseCredential, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,10,0,0">
58+
<Grid Grid.Row="1" Visibility="{Binding UseCredentials, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,10,0,0">
5859
<Grid Visibility="{Binding CustomCredentials, Converter={StaticResource BooleanToVisibilityConverter}}">
5960
<Grid.Resources>
6061
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
@@ -70,7 +71,7 @@
7071
<RowDefinition Height="Auto" />
7172
<RowDefinition Height="10" />
7273
<RowDefinition Height="Auto" />
73-
</Grid.RowDefinitions>
74+
</Grid.RowDefinitions>
7475
<TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Username}" />
7576
<TextBox x:Name="txtUsername" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleUsername}">
7677
<TextBox.Text>
@@ -100,7 +101,7 @@
100101
</Grid.ColumnDefinitions>
101102
<Grid.RowDefinitions>
102103
<RowDefinition Height="Auto" />
103-
</Grid.RowDefinitions>
104+
</Grid.RowDefinitions>
104105
<TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Credential}" />
105106
<ComboBox x:Name="cbCredentialID" Grid.Column="2" Grid.Row="0" SelectedValuePath="ID" SelectedValue="{Binding CredentialID}" Style="{StaticResource DefaultComboBox}" ItemsSource="{Binding Credentials}">
106107
<ComboBox.InputBindings>
@@ -133,11 +134,21 @@
133134
<Button Content="{DynamicResource String_Button_Connect}" Command="{Binding ConnectCommand}" IsDefault="True" Margin="10,0,0,0">
134135
<Button.Style>
135136
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
136-
<Setter Property="IsEnabled" Value="False" />
137+
<Setter Property="IsEnabled" Value="True" />
137138
<Style.Triggers>
138-
<DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=txtHostname}" Value="False" >
139-
<Setter Property="IsEnabled" Value="True" />
139+
<DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=txtHostname}" Value="True" >
140+
<Setter Property="IsEnabled" Value="False" />
140141
</DataTrigger>
142+
<MultiDataTrigger>
143+
<MultiDataTrigger.Conditions>
144+
<Condition Binding="{Binding UseCredentials}" Value="True" />
145+
<Condition Binding="{Binding CustomCredentials}" Value="False" />
146+
<Condition Binding="{Binding CredentialID}" Value="{x:Null}" />
147+
</MultiDataTrigger.Conditions>
148+
<MultiDataTrigger.Setters>
149+
<Setter Property="IsEnabled" Value="False" />
150+
</MultiDataTrigger.Setters>
151+
</MultiDataTrigger>
141152
</Style.Triggers>
142153
</Style>
143154
</Button.Style>

0 commit comments

Comments
 (0)