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: SNMP Timeout added again #2126

Merged
merged 1 commit into from
Apr 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Source/NETworkManager.Models/Network/SNMPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ protected virtual void OnComplete()
Complete?.Invoke(this, EventArgs.Empty);
}

public event EventHandler UserHasCanceled;
public event EventHandler Canceled;

protected virtual void OnUserHasCanceled()
protected virtual void OnCanceled()
{
UserHasCanceled?.Invoke(this, EventArgs.Empty);
Canceled?.Invoke(this, EventArgs.Empty);
}
#endregion

Expand Down Expand Up @@ -74,7 +74,7 @@ public void GetAsync(IPAddress ipAddress, string oid, SNMPOptions options)
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down Expand Up @@ -119,7 +119,7 @@ public void GetAsyncV3(IPAddress ipAddress, string oid, SNMPOptionsV3 options)
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down Expand Up @@ -153,7 +153,7 @@ public void WalkAsync(IPAddress ipAddress, string oid, SNMPOptions options)
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down Expand Up @@ -190,7 +190,7 @@ public void WalkAsyncV3(IPAddress ipAddress, string oid, SNMPOptionsV3 options)
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down Expand Up @@ -220,7 +220,7 @@ public void SetAsync(IPAddress ipAddress, string oid, string data, SNMPOptions o
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ public void SetAsyncV3(IPAddress ipAddress, string oid, string data, SNMPOptions
}
catch (OperationCanceledException)
{
OnUserHasCanceled();
OnCanceled();
}
catch (ErrorException)
{
Expand Down
2 changes: 0 additions & 2 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,6 @@ private void WriteDefaultPowerShellProfileToRegistry()
if (!SettingsManager.Current.Appearance_PowerShellModifyGlobalProfile)
return;

Debug.WriteLine("Test");

HashSet<string> paths = new();

// PowerShell
Expand Down
15 changes: 6 additions & 9 deletions Source/NETworkManager/ViewModels/SNMPViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ private async void StartWork()
snmpClient.Received += Snmp_Received;
snmpClient.DataUpdated += SnmpClient_DataUpdated;
snmpClient.Error += Snmp_Error;
snmpClient.UserHasCanceled += Snmp_UserHasCanceled;
snmpClient.Canceled += Snmp_Canceled;
snmpClient.Complete += Snmp_Complete;

if (Version != SNMPVersion.V3)
Expand Down Expand Up @@ -608,6 +608,9 @@ private async void StartWork()
}
}

// Set timeout
_cancellationTokenSource.CancelAfter(SettingsManager.Current.SNMP_Timeout);

// Add to history...
AddHostToHistory(Host);
AddOIDToHistory(OID);
Expand Down Expand Up @@ -668,21 +671,15 @@ private void SnmpClient_DataUpdated(object sender, EventArgs e)
IsStatusMessageDisplayed = true;
}

private void Snmp_TimeoutReached(object sender, EventArgs e)
{
StatusMessage = Localization.Resources.Strings.TimeoutOnSNMPQuery;
IsStatusMessageDisplayed = true;
}

private void Snmp_Error(object sender, EventArgs e)
{
StatusMessage = Mode == SNMPMode.Set ? Localization.Resources.Strings.ErrorInResponseCheckIfYouHaveWritePermissions : Localization.Resources.Strings.ErrorInResponse;
IsStatusMessageDisplayed = true;
}

private void Snmp_UserHasCanceled(object sender, EventArgs e)
private void Snmp_Canceled(object sender, EventArgs e)
{
StatusMessage = Localization.Resources.Strings.CanceledByUserMessage;
StatusMessage = CancelScan ? Localization.Resources.Strings.CanceledByUserMessage : Localization.Resources.Strings.TimeoutOnSNMPQuery;
IsStatusMessageDisplayed = true;
}

Expand Down
6 changes: 2 additions & 4 deletions Source/NETworkManager/Views/SNMPSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
<StackPanel>
<TextBlock Text="{x:Static localization:Strings.SNMP}" Style="{StaticResource HeaderTextBlock}" />
<TextBlock Text="{x:Static localization:Strings.WalkMode}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
<ComboBox ItemsSource="{Binding WalkModes}" SelectedItem="{Binding WalkMode}" Width="250" HorizontalAlignment="Left" Margin="0,0,0,10" />
<!--
<ComboBox ItemsSource="{Binding WalkModes}" SelectedItem="{Binding WalkMode}" Width="250" HorizontalAlignment="Left" Margin="0,0,0,10" />
<TextBlock Text="{x:Static localization:Strings.TimeoutMS}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
<mah:NumericUpDown Value="{Binding Timeout}" Maximum="900000" Minimum="100" Interval="100" Margin="0,0,0,10" />
-->
<mah:NumericUpDown Value="{Binding Timeout}" Maximum="900000" Minimum="100" Interval="100" Margin="0,0,0,10" />
<TextBlock Text="{x:Static localization:Strings.Port}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
<TextBox Width="150" HorizontalAlignment="Left" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExamplePort161}" Style="{StaticResource DefaultTextBox}">
<TextBox.Text>
Expand Down