Skip to content

Commit d99b8d4

Browse files
committed
Feature: Migrate more dialogs....
1 parent 69a45fd commit d99b8d4

23 files changed

+45
-134
lines changed

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public class DNSLookupSettingsViewModel : ViewModelBase
3434
/// </summary>
3535
private readonly ServerConnectionInfo _profileDialogDefaultValues = new("10.0.0.1", 53, TransportProtocol.Udp);
3636

37-
/// <summary>
38-
/// The dialog coordinator instance.
39-
/// </summary>
40-
private readonly IDialogCoordinator _dialogCoordinator;
41-
4237
/// <summary>
4338
/// Gets the collection view of DNS servers.
4439
/// </summary>
@@ -325,13 +320,10 @@ public int Timeout
325320
/// <summary>
326321
/// Initializes a new instance of the <see cref="DNSLookupSettingsViewModel"/> class.
327322
/// </summary>
328-
/// <param name="instance">The dialog coordinator instance.</param>
329-
public DNSLookupSettingsViewModel(IDialogCoordinator instance)
323+
public DNSLookupSettingsViewModel()
330324
{
331325
_isLoading = true;
332326

333-
_dialogCoordinator = instance;
334-
335327
DNSServers = CollectionViewSource.GetDefaultView(SettingsManager.Current.DNSLookup_DNSServers);
336328
DNSServers.SortDescriptions.Add(new SortDescription(nameof(DNSServerConnectionInfoProfile.Name),
337329
ListSortDirection.Ascending));

Source/NETworkManager/ViewModels/IPGeolocationViewModel.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using log4net;
22
using MahApps.Metro.Controls;
3-
using MahApps.Metro.Controls.Dialogs;
43
using MahApps.Metro.SimpleChildWindow;
54
using NETworkManager.Controls;
65
using NETworkManager.Localization.Resources;
@@ -28,11 +27,6 @@ public class IPGeolocationViewModel : ViewModelBase
2827

2928
private static readonly ILog Log = LogManager.GetLogger(typeof(IPGeolocationViewModel));
3029

31-
/// <summary>
32-
/// The dialog coordinator instance.
33-
/// </summary>
34-
private readonly IDialogCoordinator _dialogCoordinator;
35-
3630
private readonly Guid _tabId;
3731
private bool _firstLoad = true;
3832
private bool _closed;
@@ -175,13 +169,10 @@ private set
175169
/// <summary>
176170
/// Initializes a new instance of the <see cref="IPGeolocationViewModel"/> class.
177171
/// </summary>
178-
/// <param name="instance">The dialog coordinator instance.</param>
179172
/// <param name="tabId">The ID of the tab.</param>
180173
/// <param name="host">The host to query.</param>
181-
public IPGeolocationViewModel(IDialogCoordinator instance, Guid tabId, string host)
174+
public IPGeolocationViewModel(Guid tabId, string host)
182175
{
183-
_dialogCoordinator = instance;
184-
185176
ConfigurationManager.Current.IPGeolocationTabCount++;
186177

187178
_tabId = tabId;
@@ -335,12 +326,9 @@ private Task Export()
335326
{
336327
Log.Error("Error while exporting data as " + instance.FileType, ex);
337328

338-
var settings = AppearanceManager.MetroDialog;
339-
settings.AffirmativeButtonText = Strings.OK;
340-
341-
await _dialogCoordinator.ShowMessageAsync(window, Strings.Error,
342-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
343-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
329+
await DialogHelper.ShowMessageAsync(window, Strings.Error,
330+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
331+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
344332
}
345333

346334
SettingsManager.Current.IPGeolocation_ExportFileType = instance.FileType;

Source/NETworkManager/ViewModels/PingMonitorViewModel.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using LiveCharts.Configurations;
33
using LiveCharts.Wpf;
44
using log4net;
5-
using MahApps.Metro.Controls.Dialogs;
65
using MahApps.Metro.SimpleChildWindow;
76
using NETworkManager.Localization.Resources;
87
using NETworkManager.Models.Export;
@@ -34,16 +33,13 @@ public class PingMonitorViewModel : ViewModelBase
3433
/// <summary>
3534
/// Initializes a new instance of the <see cref="PingMonitorViewModel"/> class.
3635
/// </summary>
37-
/// <param name="instance">The dialog coordinator instance.</param>
3836
/// <param name="hostId">The unique identifier for the host.</param>
3937
/// <param name="removeHostByGuid">Action to remove the host by its GUID.</param>
4038
/// <param name="host">Tuple containing the IP address and hostname.</param>
4139
/// <param name="group">The group name the host belongs to.</param>
42-
public PingMonitorViewModel(IDialogCoordinator instance, Guid hostId, Action<Guid> removeHostByGuid,
40+
public PingMonitorViewModel(Guid hostId, Action<Guid> removeHostByGuid,
4341
(IPAddress ipAddress, string hostname) host, string group)
4442
{
45-
_dialogCoordinator = instance;
46-
4743
HostId = hostId;
4844
_removeHostByGuid = removeHostByGuid;
4945

@@ -63,7 +59,6 @@ public PingMonitorViewModel(IDialogCoordinator instance, Guid hostId, Action<Gui
6359
#region Variables
6460
private static readonly ILog Log = LogManager.GetLogger(typeof(PingMonitorViewModel));
6561

66-
private readonly IDialogCoordinator _dialogCoordinator;
6762
private CancellationTokenSource _cancellationTokenSource;
6863

6964
public readonly Guid HostId;
@@ -506,13 +501,10 @@ public Task Export()
506501
catch (Exception ex)
507502
{
508503
Log.Error("Error while exporting data as " + instance.FileType, ex);
509-
510-
var settings = AppearanceManager.MetroDialog;
511-
settings.AffirmativeButtonText = Strings.OK;
512-
513-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
514-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
515-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
504+
505+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error,
506+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
507+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
516508
}
517509

518510
SettingsManager.Current.PingMonitor_ExportFileType = instance.FileType;
@@ -533,7 +525,7 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
533525

534526
ConfigurationManager.Current.IsChildWindowOpen = true;
535527

536-
return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
528+
return Application.Current.MainWindow.ShowChildWindowAsync(childWindow);
537529
}
538530

539531
#endregion

Source/NETworkManager/ViewModels/PortScannerViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ private Task Export()
501501
var settings = AppearanceManager.MetroDialog;
502502
settings.AffirmativeButtonText = Strings.OK;
503503

504-
await _dialogCoordinator.ShowMessageAsync(window, Strings.Error,
505-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
506-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
504+
await DialogHelper.ShowMessageAsync(window, Strings.Error,
505+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
506+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
507507
}
508508

509509
SettingsManager.Current.PortScanner_ExportFileType = instance.FileType;

Source/NETworkManager/ViewModels/PowerShellSettingsViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,7 @@ private async Task Configure()
194194
}
195195
catch (Exception ex)
196196
{
197-
var settings = AppearanceManager.MetroDialog;
198-
199-
settings.AffirmativeButtonText = Strings.OK;
200-
201-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
202-
MessageDialogStyle.Affirmative, settings);
197+
await DialogHelper.ShowMessageAsync(System.Windows.Application.Current.MainWindow, Strings.Error, ex.Message, ChildWindowIcon.Error);
203198
}
204199
}
205200

Source/NETworkManager/ViewModels/PuTTYSettingsViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,7 @@ private async Task Configure()
505505
}
506506
catch (Exception ex)
507507
{
508-
var settings = AppearanceManager.MetroDialog;
509-
510-
settings.AffirmativeButtonText = Strings.OK;
511-
512-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
513-
MessageDialogStyle.Affirmative, settings);
508+
await DialogHelper.ShowMessageAsync(System.Windows.Application.Current.MainWindow, Strings.Error, ex.Message, ChildWindowIcon.Error);
514509
}
515510
}
516511

Source/NETworkManager/ViewModels/SNMPViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,9 @@ private Task Export()
727727
{
728728
Log.Error("Error while exporting data as " + instance.FileType, ex);
729729

730-
var settings = AppearanceManager.MetroDialog;
731-
settings.AffirmativeButtonText = Strings.OK;
732-
733-
await _dialogCoordinator.ShowMessageAsync(window, Strings.Error,
734-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
735-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
730+
await DialogHelper.ShowMessageAsync(window, Strings.Error,
731+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
732+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
736733
}
737734

738735
SettingsManager.Current.SNMP_ExportFileType = instance.FileType;

Source/NETworkManager/ViewModels/SNTPLookupViewModel.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using log4net;
22
using MahApps.Metro.Controls;
3-
using MahApps.Metro.Controls.Dialogs;
43
using MahApps.Metro.SimpleChildWindow;
54
using NETworkManager.Controls;
65
using NETworkManager.Localization.Resources;
@@ -27,8 +26,6 @@ public class SNTPLookupViewModel : ViewModelBase
2726
#region Variables
2827
private static readonly ILog Log = LogManager.GetLogger(typeof(SNTPLookupViewModel));
2928

30-
private readonly IDialogCoordinator _dialogCoordinator;
31-
3229
private readonly Guid _tabId;
3330
private readonly bool _isLoading;
3431
private bool _closed;
@@ -148,11 +145,10 @@ private set
148145

149146
#region Contructor, load settings
150147

151-
public SNTPLookupViewModel(IDialogCoordinator instance, Guid tabId)
148+
public SNTPLookupViewModel(Guid tabId)
152149
{
153150
_isLoading = true;
154-
155-
_dialogCoordinator = instance;
151+
156152
ConfigurationManager.Current.SNTPLookupTabCount++;
157153

158154
_tabId = tabId;
@@ -258,9 +254,9 @@ private Task Export()
258254
var settings = AppearanceManager.MetroDialog;
259255
settings.AffirmativeButtonText = Strings.OK;
260256

261-
await _dialogCoordinator.ShowMessageAsync(window, Strings.Error,
262-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
263-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
257+
await DialogHelper.ShowMessageAsync(window, Strings.Error,
258+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
259+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
264260
}
265261

266262
SettingsManager.Current.SNTPLookup_ExportFileType = instance.FileType;

Source/NETworkManager/ViewModels/SettingsAutostartViewModel.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
using System;
22
using System.Threading.Tasks;
3-
using MahApps.Metro.Controls.Dialogs;
3+
using System.Windows;
44
using NETworkManager.Localization.Resources;
55
using NETworkManager.Settings;
6+
using NETworkManager.Utilities;
67

78
namespace NETworkManager.ViewModels;
89

910
public class SettingsAutostartViewModel : ViewModelBase
1011
{
1112
#region Constructor
1213

13-
public SettingsAutostartViewModel(IDialogCoordinator instance)
14+
public SettingsAutostartViewModel()
1415
{
1516
_isLoading = true;
1617

17-
_dialogCoordinator = instance;
18-
1918
LoadSettings();
2019

2120
_isLoading = false;
@@ -51,8 +50,8 @@ private async Task EnableDisableAutostart(bool enable)
5150
}
5251
catch (Exception ex)
5352
{
54-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
55-
MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog);
53+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error,
54+
ex.Message, ChildWindowIcon.Error);
5655
}
5756

5857
ConfiguringAutostart = false;
@@ -61,9 +60,6 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, ex.Message,
6160
#endregion
6261

6362
#region Variables
64-
65-
private readonly IDialogCoordinator _dialogCoordinator;
66-
6763
private readonly bool _isLoading;
6864

6965
private bool _startWithWindows;

Source/NETworkManager/ViewModels/SubnetCalculatorSubnettingViewModel.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using log4net;
22
using MahApps.Metro.Controls;
3-
using MahApps.Metro.Controls.Dialogs;
43
using MahApps.Metro.SimpleChildWindow;
54
using NETworkManager.Localization.Resources;
65
using NETworkManager.Models.Export;
@@ -28,10 +27,8 @@ public class SubnetCalculatorSubnettingViewModel : ViewModelBase
2827
{
2928
#region Constructor, load settings
3029

31-
public SubnetCalculatorSubnettingViewModel(IDialogCoordinator instance)
30+
public SubnetCalculatorSubnettingViewModel()
3231
{
33-
_dialogCoordinator = instance;
34-
3532
// Set collection view
3633
SubnetHistoryView =
3734
CollectionViewSource.GetDefaultView(SettingsManager.Current.SubnetCalculator_Subnetting_SubnetHistory);
@@ -48,8 +45,6 @@ public SubnetCalculatorSubnettingViewModel(IDialogCoordinator instance)
4845
#region Variables
4946
private static readonly ILog Log = LogManager.GetLogger(typeof(SubnetCalculatorSubnettingViewModel));
5047

51-
private readonly IDialogCoordinator _dialogCoordinator;
52-
5348
private string _subnet;
5449

5550
public string Subnet
@@ -203,12 +198,9 @@ private Task ExportAction()
203198
{
204199
Log.Error("Error while exporting data as " + instance.FileType, ex);
205200

206-
var settings = AppearanceManager.MetroDialog;
207-
settings.AffirmativeButtonText = Strings.OK;
208-
209-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
210-
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
211-
Environment.NewLine + ex.Message, MessageDialogStyle.Affirmative, settings);
201+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error,
202+
Strings.AnErrorOccurredWhileExportingTheData + Environment.NewLine +
203+
Environment.NewLine + ex.Message, ChildWindowIcon.Error);
212204
}
213205

214206
SettingsManager.Current.SubnetCalculator_Subnetting_ExportFileType = instance.FileType;
@@ -228,7 +220,7 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
228220

229221
ConfigurationManager.Current.IsChildWindowOpen = true;
230222

231-
return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
223+
return Application.Current.MainWindow.ShowChildWindowAsync(childWindow);
232224
}
233225

234226
#endregion
@@ -256,17 +248,8 @@ private async Task Calculate()
256248
var baseCidr = ipNetwork.AddressFamily == AddressFamily.InterNetwork ? 32 : 128;
257249

258250
if (65535 < Math.Pow(2, baseCidr - ipNetwork.Cidr) / Math.Pow(2, baseCidr - newCidr))
259-
{
260-
var settings = AppearanceManager.MetroDialog;
261-
262-
settings.AffirmativeButtonText = Strings.Continue;
263-
settings.NegativeButtonText = Strings.Cancel;
264-
265-
settings.DefaultButtonFocus = MessageDialogResult.Affirmative;
266-
267-
if (await _dialogCoordinator.ShowMessageAsync(this, Strings.AreYouSure,
268-
Strings.TheProcessCanTakeUpSomeTimeAndResources,
269-
MessageDialogStyle.AffirmativeAndNegative, settings) != MessageDialogResult.Affirmative)
251+
{
252+
if(!await DialogHelper.ShowConfirmationMessageAsync(Application.Current.MainWindow, Strings.AreYouSure, Strings.TheProcessCanTakeUpSomeTimeAndResources))
270253
{
271254
IsRunning = false;
272255

0 commit comments

Comments
 (0)