Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Ping Monitor grouping #2645

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3808,4 +3808,7 @@ Try again in a few seconds.</value>
<data name="ResolveMACAddressIsDisabled" xml:space="preserve">
<value>Resolve MAC address is disabled!</value>
</data>
<data name="CloseGroup" xml:space="preserve">
<value>Close group</value>
</data>
</root>
30 changes: 21 additions & 9 deletions Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public class PingMonitorHostViewModel : ViewModelBase, IProfileManager

private readonly bool _isLoading;
private bool _isViewActive = true;


private string _group = Strings.Hosts; // Default group name

private string _host;

public string Host
Expand Down Expand Up @@ -275,6 +277,8 @@ public PingMonitorHostViewModel(IDialogCoordinator instance)

// Hosts
HostsView = CollectionViewSource.GetDefaultView(Hosts);
HostsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(PingMonitorView.Group)));
HostsView.SortDescriptions.Add(new SortDescription(nameof(PingMonitorView.Group), ListSortDirection.Ascending));

// Profiles
SetProfilesView();
Expand Down Expand Up @@ -328,15 +332,15 @@ private bool PingProfile_CanExecute(object obj)

private void PingProfileAction()
{
if (SetHost(SelectedProfile.PingMonitor_Host))
if (SetHost(SelectedProfile.PingMonitor_Host, SelectedProfile.Group))
Start().ConfigureAwait(false);
}

public ICommand CloseAllCommand => new RelayCommand(_ => CloseAllAction());
public ICommand CloseGroupCommand => new RelayCommand(CloseGroupAction);

private void CloseAllAction()
private void CloseGroupAction(object group)
{
RemoveAllHosts();
RemoveGroup(group.ToString());
}

public ICommand ExportCommand => new RelayCommand(_ => ExportAction());
Expand Down Expand Up @@ -405,8 +409,9 @@ private void ClearSearchAction()
/// Set the host to ping.
/// </summary>
/// <param name="host">Host to ping</param>
/// <param name="group">Group to add the host to</param>
/// <returns>True if the host was set successfully, otherwise false</returns>
public bool SetHost(string host)
public bool SetHost(string host, string group = null)
{
// Check if it is already running or canceling
if (IsRunning || IsCanceling)
Expand All @@ -417,8 +422,11 @@ public bool SetHost(string host)
return false;
}

if (group != null)
_group = group;

Host = host;

return true;
}

Expand Down Expand Up @@ -457,7 +465,7 @@ public async Task Start()

// Add host(s) to list and start the ping
foreach (var hostView in hosts.hosts.Select(currentHost =>
new PingMonitorView(Guid.NewGuid(), RemoveHostByGuid, currentHost)))
new PingMonitorView(Guid.NewGuid(), RemoveHostByGuid, currentHost, _group)))
{
// Check if the user has canceled the operation
if (_cancellationTokenSource.IsCancellationRequested)
Expand All @@ -477,6 +485,7 @@ public async Task Start()
}

Host = string.Empty;
_group = Strings.Hosts; // Reset the group

IsCanceling = false;
IsRunning = false;
Expand All @@ -488,10 +497,13 @@ private void Stop()
_cancellationTokenSource.Cancel();
}

private void RemoveAllHosts()
private void RemoveGroup(string group)
{
for (var i = Hosts.Count - 1; i >= 0; i--)
{
if (!Hosts[i].Group.Equals(group))
continue;

Hosts[i].Stop();
Hosts.RemoveAt(i);
}
Expand Down
20 changes: 18 additions & 2 deletions Source/NETworkManager/ViewModels/PingMonitorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PingMonitorViewModel : ViewModelBase
#region Contructor, load settings

public PingMonitorViewModel(IDialogCoordinator instance, Guid hostId, Action<Guid> removeHostByGuid,
(IPAddress ipAddress, string hostname) host)
(IPAddress ipAddress, string hostname) host, string group)
{
_dialogCoordinator = instance;

Expand All @@ -38,7 +38,8 @@ public class PingMonitorViewModel : ViewModelBase

IPAddress = host.ipAddress;
Hostname = host.hostname;

Group = group;

InitialTimeChart();

ExpandHostView = SettingsManager.Current.PingMonitor_ExpandHostView;
Expand Down Expand Up @@ -100,6 +101,21 @@ private init
OnPropertyChanged();
}
}

private string _group;

public string Group
{
get => _group;
set
{
if (value == _group)
return;

_group = value;
OnPropertyChanged();
}
}

private bool _isRunning;

Expand Down