Skip to content

Commit c7026e4

Browse files
committed
History added
1 parent 0567096 commit c7026e4

8 files changed

Lines changed: 93 additions & 49 deletions

Source/NETworkManager/Models/Settings/RemoteDesktopSessionInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class RemoteDesktopSessionInfo
44
{
55
public string Name { get; set; }
6-
public string Hostname { get; set; }
6+
public string Host { get; set; }
77
public int? CredentialID { get; set; }
88
public string Group { get; set; }
99
public string Tags { get; set; }
@@ -13,19 +13,19 @@ public RemoteDesktopSessionInfo()
1313

1414
}
1515

16-
public RemoteDesktopSessionInfo(string name, string hostname, string group, string tags)
16+
public RemoteDesktopSessionInfo(string name, string host, string group, string tags)
1717
{
1818
Name = name;
19-
Hostname = hostname;
19+
Host = host;
2020
CredentialID = null;
2121
Group = group;
2222
Tags = tags;
2323
}
2424

25-
public RemoteDesktopSessionInfo(string name, string hostname, int credentialID, string group, string tags)
25+
public RemoteDesktopSessionInfo(string name, string host, int credentialID, string group, string tags)
2626
{
2727
Name = name;
28-
Hostname = hostname;
28+
Host = host;
2929
CredentialID = credentialID;
3030
Group = group;
3131
Tags = tags;

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,21 @@ public List<string> SubnetCalculator_IPv4Splitter_NewSubnetmaskOrCIDRHistory
11481148
#endregion
11491149
#endregion
11501150

1151-
#region RemoteDesktop
1151+
#region RemoteDesktop
1152+
private ObservableCollection<string> _remoteDesktop_HostHistory = new ObservableCollection<string>();
1153+
public ObservableCollection<string> RemoteDesktop_HostHistory
1154+
{
1155+
get { return _remoteDesktop_HostHistory; }
1156+
set
1157+
{
1158+
if (value == _remoteDesktop_HostHistory)
1159+
return;
1160+
1161+
_remoteDesktop_HostHistory = value;
1162+
SettingsChanged = true;
1163+
}
1164+
}
1165+
11521166
private bool _remoteDesktop_AdjustScreenAutomatically;
11531167
public bool RemoteDesktop_AdjustScreenAutomatically
11541168
{

Source/NETworkManager/ViewModels/Applications/RemoteDesktopViewModel.cs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Linq;
1414
using System.Diagnostics;
1515
using NETworkManager.Models.Documentation;
16+
using NETworkManager.Helpers;
17+
using System.Collections.Generic;
1618

1719
namespace NETworkManager.ViewModels.Applications
1820
{
@@ -119,7 +121,7 @@ public RemoteDesktopViewModel(IDialogCoordinator instance)
119121

120122
// Check if RDP 8.1 is available
121123
IsRDP8dot1Available = Models.RemoteDesktop.RemoteDesktop.IsRDP8dot1Available();
122-
124+
123125
if (IsRDP8dot1Available)
124126
{
125127
InterTabClient = new DragablzMainInterTabClient();
@@ -185,24 +187,28 @@ private async void ConnectNewSessionAction()
185187
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
186188
ConfigurationManager.Current.FixAirspace = false;
187189

190+
// Add host to history
191+
AddHostToHistory(instance.Host);
192+
193+
// Create new remote desktop session info
188194
Models.RemoteDesktop.RemoteDesktopSessionInfo remoteDesktopSessionInfo = new Models.RemoteDesktop.RemoteDesktopSessionInfo
189195
{
190-
Hostname = instance.Hostname
196+
Hostname = instance.Host
191197
};
192198

193-
if(instance.UseCredentials)
199+
if (instance.UseCredentials)
194200
{
195201
remoteDesktopSessionInfo.CustomCredentials = true;
196-
197-
if(instance.CustomCredentials)
202+
203+
if (instance.CustomCredentials)
198204
{
199205
remoteDesktopSessionInfo.Username = instance.Username;
200206
remoteDesktopSessionInfo.Password = instance.Password;
201207
}
202208
else
203209
{
204210
CredentialInfo credentialInfo = CredentialManager.GetCredentialByID((int)instance.CredentialID);
205-
211+
206212
remoteDesktopSessionInfo.Username = credentialInfo.Username;
207213
remoteDesktopSessionInfo.Password = credentialInfo.Password;
208214
}
@@ -244,7 +250,7 @@ private async void AddSessionAction()
244250
RemoteDesktopSessionInfo remoteDesktopSessionInfo = new RemoteDesktopSessionInfo
245251
{
246252
Name = instance.Name,
247-
Hostname = instance.Hostname,
253+
Host = instance.Host,
248254
CredentialID = instance.CredentialID,
249255
Group = instance.Group,
250256
Tags = instance.Tags
@@ -275,7 +281,7 @@ private async void ConnectSessionAction()
275281
{
276282
Models.RemoteDesktop.RemoteDesktopSessionInfo sessionInfo = new Models.RemoteDesktop.RemoteDesktopSessionInfo
277283
{
278-
Hostname = SelectedSession.Hostname
284+
Hostname = SelectedSession.Host
279285
};
280286

281287
if (SelectedSession.CredentialID != null) // Credentials need to be unlocked first
@@ -328,8 +334,8 @@ private async void ConnectSessionAction()
328334
{
329335
CredentialInfo credentialInfo = CredentialManager.GetCredentialByID((int)SelectedSession.CredentialID);
330336

331-
if(credentialInfo == null)
332-
{
337+
if (credentialInfo == null)
338+
{
333339
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_CredentialNotFound"] as string, Application.Current.Resources["String_CredentialNotFoundMessage"] as string, MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog);
334340

335341
return;
@@ -338,7 +344,7 @@ private async void ConnectSessionAction()
338344
sessionInfo.CustomCredentials = true;
339345
sessionInfo.Username = credentialInfo.Username;
340346
sessionInfo.Password = credentialInfo.Password;
341-
347+
342348
ConnectSession(sessionInfo, SelectedSession.Name);
343349
}
344350
}
@@ -367,7 +373,7 @@ private async void ConnectSessionAsAction()
367373

368374
Models.RemoteDesktop.RemoteDesktopSessionInfo remoteDesktopSessionInfo = new Models.RemoteDesktop.RemoteDesktopSessionInfo
369375
{
370-
Hostname = instance.Hostname
376+
Hostname = instance.Host
371377
};
372378

373379
if (instance.UseCredentials)
@@ -393,12 +399,11 @@ private async void ConnectSessionAsAction()
393399
{
394400
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
395401
ConfigurationManager.Current.FixAirspace = false;
396-
});
402+
}, true);
397403

398404
// Set name, hostname
399-
connectRemoteDesktopSessionViewModel.ConnectAs = true;
400405
connectRemoteDesktopSessionViewModel.Name = SelectedSession.Name;
401-
connectRemoteDesktopSessionViewModel.Hostname = SelectedSession.Hostname;
406+
connectRemoteDesktopSessionViewModel.Host = SelectedSession.Host;
402407

403408
// Request credentials
404409
connectRemoteDesktopSessionViewModel.UseCredentials = true;
@@ -434,7 +439,7 @@ private async void EditSessionAction()
434439
RemoteDesktopSessionInfo remoteDesktopSessionInfo = new RemoteDesktopSessionInfo
435440
{
436441
Name = instance.Name,
437-
Hostname = instance.Hostname,
442+
Host = instance.Host,
438443
CredentialID = instance.CredentialID,
439444
Group = instance.Group,
440445
Tags = instance.Tags
@@ -476,7 +481,7 @@ private async void CopyAsSessionAction()
476481
RemoteDesktopSessionInfo remoteDesktopSessionInfo = new RemoteDesktopSessionInfo
477482
{
478483
Name = instance.Name,
479-
Hostname = instance.Hostname,
484+
Host = instance.Host,
480485
Group = instance.Group,
481486
Tags = instance.Tags
482487
};
@@ -584,11 +589,24 @@ private void RemoteDesktopSession_Search(object sender, FilterEventArgs e)
584589

585590
string search = Search.Trim();
586591

587-
if (info.Hostname.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
592+
if (info.Host.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
588593
e.Accepted = true;
589594
else
590595
e.Accepted = false;
591596
}
597+
598+
// Modify history list
599+
private void AddHostToHistory(string host)
600+
{
601+
// Create the new list
602+
List<string> list = ListHelper.Modify(SettingsManager.Current.RemoteDesktop_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
603+
604+
// Clear the old items
605+
SettingsManager.Current.RemoteDesktop_HostHistory.Clear();
606+
607+
// Fill with the new items
608+
list.ForEach(x => SettingsManager.Current.RemoteDesktop_HostHistory.Add(x));
609+
}
592610
#endregion
593611
}
594612
}

Source/NETworkManager/ViewModels/Dialogs/RemoteDesktopSessionConnectViewModel.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NETworkManager.Models.Settings;
22
using System;
3+
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Security;
56
using System.Windows.Data;
@@ -49,20 +50,26 @@ public string Name
4950
}
5051
}
5152

52-
private string _hostname;
53-
public string Hostname
53+
private string _host;
54+
public string Host
5455
{
55-
get { return _hostname; }
56+
get { return _host; }
5657
set
5758
{
58-
if (value == _hostname)
59+
if (value == _host)
5960
return;
6061

61-
_hostname = value;
62+
_host = value;
6263
OnPropertyChanged();
6364
}
6465
}
6566

67+
private ICollectionView _hostHistoryView;
68+
public ICollectionView HostHistoryView
69+
{
70+
get { return _hostHistoryView; }
71+
}
72+
6673
private bool _useCredentials;
6774
public bool UseCredentials
6875
{
@@ -153,10 +160,15 @@ public bool CredentialsLocked
153160
}
154161
}
155162

156-
public RemoteDesktopSessionConnectViewModel(Action<RemoteDesktopSessionConnectViewModel> connectCommand, Action<RemoteDesktopSessionConnectViewModel> cancelHandler)
163+
public RemoteDesktopSessionConnectViewModel(Action<RemoteDesktopSessionConnectViewModel> connectCommand, Action<RemoteDesktopSessionConnectViewModel> cancelHandler, bool connectAs = false)
157164
{
158165
_connectCommand = new RelayCommand(p => connectCommand(this));
159166
_cancelCommand = new RelayCommand(p => cancelHandler(this));
167+
168+
ConnectAs = connectAs;
169+
170+
if (!ConnectAs)
171+
_hostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.RemoteDesktop_HostHistory);
160172

161173
if (CredentialManager.Loaded)
162174
_credentials = CollectionViewSource.GetDefaultView(CredentialManager.CredentialInfoList);

Source/NETworkManager/ViewModels/Dialogs/RemoteDesktopSessionViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public string Name
4343
}
4444
}
4545

46-
private string _hostname;
47-
public string Hostname
46+
private string _host;
47+
public string Host
4848
{
49-
get { return _hostname; }
49+
get { return _host; }
5050
set
5151
{
52-
if (value == _hostname)
52+
if (value == _host)
5353
return;
5454

55-
_hostname = value;
55+
_host = value;
5656

5757
if (!_isLoading)
5858
HasSessionInfoChanged();
@@ -165,7 +165,7 @@ public RemoteDesktopSessionViewModel(Action<RemoteDesktopSessionViewModel> saveC
165165
_sessionInfo = sessionInfo ?? new RemoteDesktopSessionInfo();
166166

167167
Name = _sessionInfo.Name;
168-
Hostname = _sessionInfo.Hostname;
168+
Host = _sessionInfo.Host;
169169
CredentialID = _sessionInfo.CredentialID;
170170

171171
// Get the group, if not --> get the first group (ascending), fallback --> default group
@@ -189,7 +189,7 @@ public RemoteDesktopSessionViewModel(Action<RemoteDesktopSessionViewModel> saveC
189189

190190
private void HasSessionInfoChanged()
191191
{
192-
SessionInfoChanged = (_sessionInfo.Name != Name) || (_sessionInfo.Hostname != Hostname) || (_sessionInfo.CredentialID != CredentialID) || (_sessionInfo.Group != Group) || (_sessionInfo.Tags != Tags);
192+
SessionInfoChanged = (_sessionInfo.Name != Name) || (_sessionInfo.Host != Host) || (_sessionInfo.CredentialID != CredentialID) || (_sessionInfo.Group != Group) || (_sessionInfo.Tags != Tags);
193193
}
194194

195195
#region ICommand & Actions

Source/NETworkManager/Views/Dialogs/RemoteDesktopSessionConnectDialog.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@
4949
</Binding>
5050
</TextBox.Text>
5151
</TextBox>
52-
<TextBlock Grid.Column="0" Grid.Row="1" Text="{DynamicResource String_Hostname}" />
53-
<TextBox x:Name="txtHostname" Grid.Column="2" Grid.Row="1" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}" IsEnabled="{Binding ConnectAs, Converter={StaticResource BooleanReverseConverter}}">
54-
<TextBox.Text>
55-
<Binding Path="Hostname" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
52+
<TextBlock Grid.Column="0" Grid.Row="1" Text="{DynamicResource String_Host}" />
53+
<ComboBox x:Name="cbHost" Grid.Column="2" Grid.Row="1" ItemsSource="{Binding HostHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}" IsEnabled="{Binding ConnectAs, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource EditableComboBox}">
54+
<ComboBox.Text>
55+
<Binding Path="Host" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
5656
<Binding.ValidationRules>
5757
<Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
5858
</Binding.ValidationRules>
5959
</Binding>
60-
</TextBox.Text>
61-
</TextBox>
60+
</ComboBox.Text>
61+
</ComboBox>
6262
<TextBlock Grid.Column="0" Grid.Row="3" Text="{DynamicResource String_UseCredentials}" />
6363
<mah:ToggleSwitch Grid.Column="2" Grid.Row="3" OffLabel="" OnLabel="" IsChecked="{Binding UseCredentials}" IsEnabled="{Binding ConnectAs, Converter={StaticResource BooleanReverseConverter}}" />
6464
<StackPanel Grid.Column="2" Grid.Row="5" Orientation="Horizontal" Visibility="{Binding UseCredentials, Converter={StaticResource BooleanToVisibilityConverter}}">
@@ -147,7 +147,7 @@
147147
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
148148
<Setter Property="IsEnabled" Value="True" />
149149
<Style.Triggers>
150-
<DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=txtHostname}" Value="True" >
150+
<DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=cbHost}" Value="True" >
151151
<Setter Property="IsEnabled" Value="False" />
152152
</DataTrigger>
153153
<MultiDataTrigger>

Source/NETworkManager/Views/Dialogs/RemoteDesktopSessionConnectDialog.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public RemoteDesktopSessionConnectDialog()
1212
private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
1313
{
1414
// Need to be in loaded event, focusmanger won't work...
15-
txtHostname.Focus();
15+
cbHost.Focus();
1616
}
1717
}
1818
}

Source/NETworkManager/Views/Dialogs/RemoteDesktopSessionDialog.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
</Binding>
5050
</TextBox.Text>
5151
</TextBox>
52-
<TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_Hostname}" />
53-
<TextBox x:Name="txtHostname" Grid.Column="2" Grid.Row="2" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}">
52+
<TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_Host}" />
53+
<TextBox x:Name="txtHost" Grid.Column="2" Grid.Row="2" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostname}">
5454
<TextBox.Text>
55-
<Binding Path="Hostname" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
55+
<Binding Path="Host" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
5656
<Binding.ValidationRules>
5757
<Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
5858
</Binding.ValidationRules>
@@ -112,7 +112,7 @@
112112
<MultiDataTrigger>
113113
<MultiDataTrigger.Conditions>
114114
<Condition Binding="{Binding Path=(Validation.HasError), ElementName=txtName}" Value="False" />
115-
<Condition Binding="{Binding Path=(Validation.HasError), ElementName=txtHostname}" Value="False" />
115+
<Condition Binding="{Binding Path=(Validation.HasError), ElementName=txtHost}" Value="False" />
116116
<Condition Binding="{Binding Path=(Validation.HasError), ElementName=cbGroup}" Value="False" />
117117
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.SessionInfoChanged}" Value="True" />
118118
</MultiDataTrigger.Conditions>

0 commit comments

Comments
 (0)