Skip to content

Commit 5d2caf2

Browse files
authored
Feature: SNMP Timeout added again (#2126)
1 parent a4b1db4 commit 5d2caf2

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

Source/NETworkManager.Models/Network/SNMPClient.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ protected virtual void OnComplete()
4040
Complete?.Invoke(this, EventArgs.Empty);
4141
}
4242

43-
public event EventHandler UserHasCanceled;
43+
public event EventHandler Canceled;
4444

45-
protected virtual void OnUserHasCanceled()
45+
protected virtual void OnCanceled()
4646
{
47-
UserHasCanceled?.Invoke(this, EventArgs.Empty);
47+
Canceled?.Invoke(this, EventArgs.Empty);
4848
}
4949
#endregion
5050

@@ -74,7 +74,7 @@ public void GetAsync(IPAddress ipAddress, string oid, SNMPOptions options)
7474
}
7575
catch (OperationCanceledException)
7676
{
77-
OnUserHasCanceled();
77+
OnCanceled();
7878
}
7979
catch (ErrorException)
8080
{
@@ -119,7 +119,7 @@ public void GetAsyncV3(IPAddress ipAddress, string oid, SNMPOptionsV3 options)
119119
}
120120
catch (OperationCanceledException)
121121
{
122-
OnUserHasCanceled();
122+
OnCanceled();
123123
}
124124
catch (ErrorException)
125125
{
@@ -153,7 +153,7 @@ public void WalkAsync(IPAddress ipAddress, string oid, SNMPOptions options)
153153
}
154154
catch (OperationCanceledException)
155155
{
156-
OnUserHasCanceled();
156+
OnCanceled();
157157
}
158158
catch (ErrorException)
159159
{
@@ -190,7 +190,7 @@ public void WalkAsyncV3(IPAddress ipAddress, string oid, SNMPOptionsV3 options)
190190
}
191191
catch (OperationCanceledException)
192192
{
193-
OnUserHasCanceled();
193+
OnCanceled();
194194
}
195195
catch (ErrorException)
196196
{
@@ -220,7 +220,7 @@ public void SetAsync(IPAddress ipAddress, string oid, string data, SNMPOptions o
220220
}
221221
catch (OperationCanceledException)
222222
{
223-
OnUserHasCanceled();
223+
OnCanceled();
224224
}
225225
catch (ErrorException)
226226
{
@@ -258,7 +258,7 @@ public void SetAsyncV3(IPAddress ipAddress, string oid, string data, SNMPOptions
258258
}
259259
catch (OperationCanceledException)
260260
{
261-
OnUserHasCanceled();
261+
OnCanceled();
262262
}
263263
catch (ErrorException)
264264
{

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,6 @@ private void WriteDefaultPowerShellProfileToRegistry()
15741574
if (!SettingsManager.Current.Appearance_PowerShellModifyGlobalProfile)
15751575
return;
15761576

1577-
Debug.WriteLine("Test");
1578-
15791577
HashSet<string> paths = new();
15801578

15811579
// PowerShell

Source/NETworkManager/ViewModels/SNMPViewModel.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ private async void StartWork()
554554
snmpClient.Received += Snmp_Received;
555555
snmpClient.DataUpdated += SnmpClient_DataUpdated;
556556
snmpClient.Error += Snmp_Error;
557-
snmpClient.UserHasCanceled += Snmp_UserHasCanceled;
557+
snmpClient.Canceled += Snmp_Canceled;
558558
snmpClient.Complete += Snmp_Complete;
559559

560560
if (Version != SNMPVersion.V3)
@@ -608,6 +608,9 @@ private async void StartWork()
608608
}
609609
}
610610

611+
// Set timeout
612+
_cancellationTokenSource.CancelAfter(SettingsManager.Current.SNMP_Timeout);
613+
611614
// Add to history...
612615
AddHostToHistory(Host);
613616
AddOIDToHistory(OID);
@@ -668,21 +671,15 @@ private void SnmpClient_DataUpdated(object sender, EventArgs e)
668671
IsStatusMessageDisplayed = true;
669672
}
670673

671-
private void Snmp_TimeoutReached(object sender, EventArgs e)
672-
{
673-
StatusMessage = Localization.Resources.Strings.TimeoutOnSNMPQuery;
674-
IsStatusMessageDisplayed = true;
675-
}
676-
677674
private void Snmp_Error(object sender, EventArgs e)
678675
{
679676
StatusMessage = Mode == SNMPMode.Set ? Localization.Resources.Strings.ErrorInResponseCheckIfYouHaveWritePermissions : Localization.Resources.Strings.ErrorInResponse;
680677
IsStatusMessageDisplayed = true;
681678
}
682679

683-
private void Snmp_UserHasCanceled(object sender, EventArgs e)
680+
private void Snmp_Canceled(object sender, EventArgs e)
684681
{
685-
StatusMessage = Localization.Resources.Strings.CanceledByUserMessage;
682+
StatusMessage = CancelScan ? Localization.Resources.Strings.CanceledByUserMessage : Localization.Resources.Strings.TimeoutOnSNMPQuery;
686683
IsStatusMessageDisplayed = true;
687684
}
688685

Source/NETworkManager/Views/SNMPSettingsView.xaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
<StackPanel>
1212
<TextBlock Text="{x:Static localization:Strings.SNMP}" Style="{StaticResource HeaderTextBlock}" />
1313
<TextBlock Text="{x:Static localization:Strings.WalkMode}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
14-
<ComboBox ItemsSource="{Binding WalkModes}" SelectedItem="{Binding WalkMode}" Width="250" HorizontalAlignment="Left" Margin="0,0,0,10" />
15-
<!--
14+
<ComboBox ItemsSource="{Binding WalkModes}" SelectedItem="{Binding WalkMode}" Width="250" HorizontalAlignment="Left" Margin="0,0,0,10" />
1615
<TextBlock Text="{x:Static localization:Strings.TimeoutMS}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
17-
<mah:NumericUpDown Value="{Binding Timeout}" Maximum="900000" Minimum="100" Interval="100" Margin="0,0,0,10" />
18-
-->
16+
<mah:NumericUpDown Value="{Binding Timeout}" Maximum="900000" Minimum="100" Interval="100" Margin="0,0,0,10" />
1917
<TextBlock Text="{x:Static localization:Strings.Port}" Style="{StaticResource CenterTextBlock}" Margin="0,0,0,10" />
2018
<TextBox Width="150" HorizontalAlignment="Left" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExamplePort161}" Style="{StaticResource DefaultTextBox}">
2119
<TextBox.Text>

0 commit comments

Comments
 (0)