Skip to content

Commit 1a2305d

Browse files
authored
Merge pull request #69 from BornToBeRoot/remotedesktop-customcredentials
Remote Desktop - Connect as...
2 parents 72dd70d + 798087e commit 1a2305d

6 files changed

Lines changed: 324 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@
323323
<system:String x:Key="String_RemainingTime">Verbleibende Zeit</system:String>
324324
<system:String x:Key="String_UserInterfaceLocked">Benutzeroberfläche gesperrt!</system:String>
325325
<system:String x:Key="String_CredentialNotFoundMessage">Die Anmeldeinformation wurde gelöscht. Bearbeiten Sie die Sitzung und wählen Sie eine andere Anmeldeinformation oder löschen die vorhandene.</system:String>
326+
<system:String x:Key="String_Credentials">Anmeldeinformationen</system:String>
327+
<system:String x:Key="String_Custom">Eigene</system:String>
328+
<system:String x:Key="String_UseCredentials">Anmeldeinformationen verwenden</system:String>
329+
<system:String x:Key="String_ConnectAs">Verbinden als...</system:String>
326330

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@
323323
<system:String x:Key="String_RemainingTime">Remaining time</system:String>
324324
<system:String x:Key="String_UserInterfaceLocked">User interface locked!</system:String>
325325
<system:String x:Key="String_CredentialNotFoundMessage">Edit the session and select a different credential or delete the existing one</system:String>
326+
<system:String x:Key="String_Credentials">Credentials</system:String>
327+
<system:String x:Key="String_Custom">Custom</system:String>
328+
<system:String x:Key="String_UseCredentials">Use credentials</system:String>
329+
<system:String x:Key="String_ConnectAs">Connect as...</system:String>
326330

327331
<!-- Help message -->
328332
<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: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
using NETworkManager.Models.Settings;
2+
using System;
3+
using System.ComponentModel;
4+
using System.Security;
5+
using System.Windows.Data;
26
using System.Windows.Input;
37

48
namespace NETworkManager.ViewModels.Dialogs
@@ -30,11 +34,118 @@ public string Hostname
3034
OnPropertyChanged();
3135
}
3236
}
33-
37+
38+
private bool _useCredentials;
39+
public bool UseCredentials
40+
{
41+
get { return _useCredentials; }
42+
set
43+
{
44+
if (value == _useCredentials)
45+
return;
46+
47+
_useCredentials = value;
48+
OnPropertyChanged();
49+
}
50+
}
51+
52+
private bool _customCredentials = true;
53+
public bool CustomCredentials
54+
{
55+
get { return _customCredentials; }
56+
set
57+
{
58+
if (value == _customCredentials)
59+
return;
60+
61+
_customCredentials = value;
62+
OnPropertyChanged();
63+
}
64+
}
65+
66+
private string _username;
67+
public string Username
68+
{
69+
get { return _username; }
70+
set
71+
{
72+
if (value == _username)
73+
return;
74+
75+
_username = value;
76+
OnPropertyChanged();
77+
}
78+
}
79+
80+
private SecureString _password = new SecureString();
81+
public SecureString Password
82+
{
83+
get { return _password; }
84+
set
85+
{
86+
if (value == _password)
87+
return;
88+
89+
_password = value;
90+
OnPropertyChanged();
91+
}
92+
}
93+
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+
34128
public RemoteDesktopSessionConnectViewModel(Action<RemoteDesktopSessionConnectViewModel> connectCommand, Action<RemoteDesktopSessionConnectViewModel> cancelHandler)
35129
{
36130
_connectCommand = new RelayCommand(p => connectCommand(this));
37131
_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;
38148
}
149+
#endregion
39150
}
40151
}

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}">

0 commit comments

Comments
 (0)