Skip to content

Commit 206ed2f

Browse files
committed
Added exception handling
1 parent e60aed9 commit 206ed2f

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.Windows;
1+
using System.Diagnostics;
42

53
namespace NETworkManager.Utilities
64
{
75
public static class CustomCommand
86
{
97
public static void Run(CustomCommandInfo info)
108
{
11-
try
12-
{
13-
if (string.IsNullOrEmpty(info.Arguments))
14-
Process.Start(info.FilePath);
15-
else
16-
Process.Start(info.FilePath, info.Arguments);
17-
}
18-
catch (Exception ex)
19-
{
20-
MessageBox.Show(ex.Message, "Error in Utilities.CustomCommand.Run()", MessageBoxButton.OK, MessageBoxImage.Error);
21-
}
9+
if (string.IsNullOrEmpty(info.Arguments))
10+
Process.Start(info.FilePath);
11+
else
12+
Process.Start(info.FilePath, info.Arguments);
2213
}
2314
}
2415
}

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ private void PerformDNSLookupHostnameAction()
372372

373373
private void CustomCommandAction(object guid)
374374
{
375-
CustomCommand(guid);
375+
CustomCommand(guid);
376376
}
377-
377+
378378
public ICommand AddProfileSelectedHostCommand => new RelayCommand(p => AddProfileSelectedHostAction());
379379
private async void AddProfileSelectedHostAction()
380380
{
@@ -590,7 +590,7 @@ private void ScanFinished()
590590
IsScanRunning = false;
591591
}
592592

593-
private void CustomCommand(object guid)
593+
private async void CustomCommand(object guid)
594594
{
595595
if (guid is Guid id)
596596
{
@@ -605,10 +605,20 @@ private void CustomCommand(object guid)
605605

606606
info.FilePath = Regex.Replace(info.FilePath, "\\$\\$hostname\\$\\$", hostname, RegexOptions.IgnoreCase);
607607
info.FilePath = Regex.Replace(info.FilePath, "\\$\\$ipaddress\\$\\$", ipAddress, RegexOptions.IgnoreCase);
608-
info.Arguments = Regex.Replace(info.Arguments, "\\$\\$hostname\\$\\$", hostname, RegexOptions.IgnoreCase);
609-
info.Arguments = Regex.Replace(info.Arguments, "\\$\\$ipaddress\\$\\$", ipAddress, RegexOptions.IgnoreCase);
608+
if (!string.IsNullOrEmpty(info.Arguments))
609+
{
610+
info.Arguments = Regex.Replace(info.Arguments, "\\$\\$hostname\\$\\$", hostname, RegexOptions.IgnoreCase);
611+
info.Arguments = Regex.Replace(info.Arguments, "\\$\\$ipaddress\\$\\$", ipAddress, RegexOptions.IgnoreCase);
612+
}
610613

611-
Utilities.CustomCommand.Run(info);
614+
try
615+
{
616+
Utilities.CustomCommand.Run(info);
617+
}
618+
catch (Exception ex)
619+
{
620+
await _dialogCoordinator.ShowMessageAsync(this, Resources.Localization.Strings.ResourceManager.GetString("Error", LocalizationManager.Culture), ex.Message, MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog);
621+
}
612622
}
613623
}
614624

0 commit comments

Comments
 (0)