Skip to content

Commit fa8c122

Browse files
authored
Merge pull request BornToBeRoot#1449 from BornToBeRoot/issue/1425
Try to fix BornToBeRoot#1425 by unloading the profile first
2 parents 9d51451 + f07299e commit fa8c122

17 files changed

Lines changed: 85 additions & 24 deletions

Source/NETworkManager.Profiles/ProfileManager.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static void RenameProfileFile(ProfileFileInfo profileFileInfo, string new
207207

208208
if (switchProfile)
209209
{
210-
SwitchProfile(newProfileFileInfo, false);
210+
Switch(newProfileFileInfo, false);
211211
LoadedProfileFileChanged(LoadedProfileFile);
212212
}
213213

@@ -223,7 +223,7 @@ public static void DeleteProfileFile(ProfileFileInfo profileFileInfo)
223223
{
224224
if (LoadedProfileFile != null && LoadedProfileFile.Equals(profileFileInfo))
225225
{
226-
SwitchProfile(ProfileFiles.FirstOrDefault(x => !x.Equals(profileFileInfo)));
226+
Switch(ProfileFiles.FirstOrDefault(x => !x.Equals(profileFileInfo)));
227227
LoadedProfileFileChanged(LoadedProfileFile);
228228
}
229229

@@ -271,7 +271,7 @@ public static void EnableEncryption(ProfileFileInfo profileFileInfo, SecureStrin
271271
// Switch profile, if it was previously loaded
272272
if (switchProfile)
273273
{
274-
SwitchProfile(newProfileFileInfo, false);
274+
Switch(newProfileFileInfo, false);
275275
LoadedProfileFileChanged(LoadedProfileFile);
276276
}
277277

@@ -322,7 +322,7 @@ public static void ChangeMasterPassword(ProfileFileInfo profileFileInfo, SecureS
322322
// Switch profile, if it was previously loaded
323323
if (switchProfile)
324324
{
325-
SwitchProfile(newProfileFileInfo, false);
325+
Switch(newProfileFileInfo, false);
326326
LoadedProfileFileChanged(LoadedProfileFile);
327327
}
328328

@@ -363,7 +363,7 @@ public static void DisableEncryption(ProfileFileInfo profileFileInfo, SecureStri
363363
// Switch profile, if it was previously loaded
364364
if (switchProfile)
365365
{
366-
SwitchProfile(newProfileFileInfo, false);
366+
Switch(newProfileFileInfo, false);
367367
LoadedProfileFileChanged(LoadedProfileFile);
368368
}
369369

@@ -446,12 +446,28 @@ public static void Save()
446446
ProfilesChanged = false;
447447
}
448448

449-
public static void SwitchProfile(ProfileFileInfo info, bool saveLoadedProfiles = true)
449+
/// <summary>
450+
/// Method to unload the currently loaded profile file.
451+
/// </summary>
452+
/// <param name="saveLoadedProfiles">Save loaded profile file (default is true)</param>
453+
public static void Unload(bool saveLoadedProfiles = true)
450454
{
451455
if (saveLoadedProfiles && LoadedProfileFile != null && ProfilesChanged)
452456
Save();
453457

458+
LoadedProfileFile = null;
459+
454460
Reset();
461+
}
462+
463+
/// <summary>
464+
/// Method to switch to another profile file.
465+
/// </summary>
466+
/// <param name="info">New <see cref="ProfileFileInfo"/> to load.</param>
467+
/// <param name="saveLoadedProfiles">Save loaded profile file (defualt is true)</param>
468+
public static void Switch(ProfileFileInfo info, bool saveLoadedProfiles = true)
469+
{
470+
Unload(saveLoadedProfiles);
455471

456472
Load(info);
457473
}

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ private async Task LoadProfile(ProfileFileInfo info)
10241024
{
10251025
await this.HideMetroDialogAsync(customDialog).ConfigureAwait(false);
10261026

1027+
ProfileManager.Unload();
1028+
10271029
IsProfileFileLocked = true;
10281030
});
10291031

@@ -1044,7 +1046,7 @@ private async Task SwitchProfile(ProfileFileInfo info)
10441046
{
10451047
try
10461048
{
1047-
ProfileManager.SwitchProfile(info);
1049+
ProfileManager.Switch(info);
10481050

10491051
IsProfileFileLocked = false;
10501052
}

Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ public void RefreshProfiles()
345345
if (!_isViewActive)
346346
return;
347347

348-
Profiles.Refresh();
348+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
349+
{
350+
Profiles.Refresh();
351+
}));
349352
}
350353

351354
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ public void RefreshProfiles()
350350
if (!_isViewActive)
351351
return;
352352

353-
Profiles.Refresh();
353+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
354+
{
355+
Profiles.Refresh();
356+
}));
354357
}
355358

356359
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,10 @@ public void RefreshProfiles()
11551155
if (!_isViewActive)
11561156
return;
11571157

1158-
Profiles.Refresh();
1158+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
1159+
{
1160+
Profiles.Refresh();
1161+
}));
11591162
}
11601163

11611164
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,11 @@ public void RefreshProfiles()
474474
{
475475
if (!_isViewActive)
476476
return;
477-
478-
Profiles.Refresh();
477+
478+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
479+
{
480+
Profiles.Refresh();
481+
}));
479482
}
480483

481484
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ public void RefreshProfiles()
350350
if (!_isViewActive)
351351
return;
352352

353-
Profiles.Refresh();
353+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
354+
{
355+
Profiles.Refresh();
356+
}));
354357
}
355358

356359
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,10 @@ public void RefreshProfiles()
475475
if (!_isViewActive)
476476
return;
477477

478-
Profiles.Refresh();
478+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
479+
{
480+
Profiles.Refresh();
481+
}));
479482
}
480483

481484
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/ProfilesViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using NETworkManager.Profiles;
1212
using NETworkManager.Settings;
1313
using System.Diagnostics;
14+
using System.Windows;
1415

1516
namespace NETworkManager.ViewModels
1617
{
@@ -270,8 +271,11 @@ public void RefreshProfiles()
270271
SetGroupView();
271272
}
272273

273-
Groups?.Refresh();
274-
Profiles?.Refresh();
274+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
275+
{
276+
Groups?.Refresh();
277+
Profiles?.Refresh();
278+
}));
275279
}
276280

277281
public void OnProfileDialogOpen()

Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,10 @@ public void RefreshProfiles()
579579
if (!_isViewActive)
580580
return;
581581

582-
Profiles.Refresh();
582+
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
583+
{
584+
Profiles.Refresh();
585+
}));
583586
}
584587

585588
public void OnProfileDialogOpen()

0 commit comments

Comments
 (0)