Skip to content

Commit

Permalink
Removed xamarin related. Revised .NET SDK detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 10, 2024
1 parent d971501 commit c9c5c05
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 174 deletions.
37 changes: 0 additions & 37 deletions SharpSnmpLib/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,5 @@ public static PhysicalAddress ToPhysicalAddress(this OctetString address)

return new PhysicalAddress(raw);
}

private static bool? _desSupported;

internal static bool DESSupported
{
get
{
if (_desSupported != null)
{
return _desSupported.Value;
}

_desSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3.1.");
return _desSupported.Value;
}
}

private static bool? _aesSupported;

internal static bool AESSupported
{
get
{
if (_aesSupported != null)
{
return _aesSupported.Value;
}

_aesSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.");
return _aesSupported.Value;
}
}
}
}
4 changes: 2 additions & 2 deletions SharpSnmpLib/Messaging/Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public async Task DiscoverAsync(VersionCode version, IPEndPoint broadcastAddress
}

_bufferSize = udp.ReceiveBufferSize;
#if NET6_0
#if NET6_0_OR_GREATER
var source = new CancellationTokenSource();

Check warning on line 331 in SharpSnmpLib/Messaging/Discoverer.cs

View workflow job for this annotation

GitHub Actions / linux

Dispose 'source' when it is no longer needed. (https://rules.sonarsource.com/csharp/RSPEC-2930)

Check warning on line 331 in SharpSnmpLib/Messaging/Discoverer.cs

View workflow job for this annotation

GitHub Actions / macos

Dispose 'source' when it is no longer needed. (https://rules.sonarsource.com/csharp/RSPEC-2930)
source.CancelAfter(interval);
try
Expand All @@ -354,7 +354,7 @@ await Task.WhenAny(
// However, the shutdown call is necessary to release the socket binding.
}
}
#if !NET6_0
#if !NET6_0_OR_GREATER
private async Task ReceiveAsync(Socket socket)
{
while (true)
Expand Down
4 changes: 2 additions & 2 deletions SharpSnmpLib/Messaging/Discovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Discovery(int messageId, int requestId, int maxMessageSize, SnmpType type
/// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
/// <param name="receiver">The receiver.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponse is incompatible with trimming.")]
#endif
public ReportMessage GetResponse(int timeout, IPEndPoint receiver)
Expand All @@ -205,7 +205,7 @@ public ReportMessage GetResponse(int timeout, IPEndPoint receiver)
/// </summary>
/// <param name="receiver">The receiver.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public async Task<ReportMessage> GetResponseAsync(IPEndPoint receiver)
Expand Down
30 changes: 15 additions & 15 deletions SharpSnmpLib/Messaging/Messenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static NumberGenerator RequestCounter
/// <param name="community">Community name.</param>
/// <param name="variables">Variable binds.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("GetAsync is incompatible with trimming.")]
#endif
public static async Task<IList<Variable>> GetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables)
Expand Down Expand Up @@ -145,7 +145,7 @@ public static async Task<IList<Variable>> GetAsync(VersionCode version, IPEndPoi
/// <param name="community">Community name.</param>
/// <param name="variables">Variable binds.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("SetAsync is incompatible with trimming.")]
#endif
public static async Task<IList<Variable>> SetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables)
Expand Down Expand Up @@ -197,7 +197,7 @@ public static async Task<IList<Variable>> SetAsync(VersionCode version, IPEndPoi
/// Returns row count if the OID is a table. Otherwise this value is meaningless.
/// </returns>
/// <remarks>This method only supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("WalkAsync is incompatible with trimming.")]
#endif
public static async Task<int> WalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList<Variable> list, WalkMode mode)
Expand Down Expand Up @@ -257,7 +257,7 @@ public static async Task<int> WalkAsync(VersionCode version, IPEndPoint endpoint
/// <c>true</c> if the specified seed has next item; otherwise, <c>false</c>.
/// </returns>
/// <remarks>This method only supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("HasNextAsync is incompatible with trimming.")]
#endif
private static async Task<Tuple<bool, Variable?>> HasNextAsync(VersionCode version, IPEndPoint endpoint, OctetString community, Variable seed)
Expand Down Expand Up @@ -295,7 +295,7 @@ public static async Task<int> WalkAsync(VersionCode version, IPEndPoint endpoint
/// <param name="report">The report.</param>
/// <returns>Returns row count if the OID is a table. Otherwise this value is meaningless.</returns>
/// <remarks>This method only supports SNMP v2c and v3.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("BulkWalkAsync is incompatible with trimming.")]
#endif
public static async Task<int> BulkWalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList<Variable> list, int maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report)
Expand Down Expand Up @@ -404,7 +404,7 @@ public static async Task SendTrapV2Async(int requestId, VersionCode version, End
/// <param name="report">The report.</param>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
[CLSCompliant(false)]
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("SendInformAsync is incompatible with trimming.")]
#endif
public static async Task SendInformAsync(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, IPrivacyProvider privacy, ISnmpMessage report)
Expand Down Expand Up @@ -495,7 +495,7 @@ public static async Task SendInformAsync(int requestId, VersionCode version, IPE
/// <c>true</c> if the specified seed has next item; otherwise, <c>false</c>.
/// </returns>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("BulkHasNextAsync is incompatible with trimming.")]
#endif
private static async Task<Tuple<bool, IList<Variable>, ISnmpMessage>> BulkHasNextAsync(VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, Variable seed, int maxRepetitions, IPrivacyProvider privacy, ISnmpMessage report)
Expand Down Expand Up @@ -582,7 +582,7 @@ private static async Task<Tuple<bool, IList<Variable>, ISnmpMessage>> BulkHasNex
/// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
/// <returns></returns>
/// <remarks>This method supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Get is incompatible with trimming.")]
#endif
public static IList<Variable> Get(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, int timeout)
Expand Down Expand Up @@ -631,7 +631,7 @@ public static IList<Variable> Get(VersionCode version, IPEndPoint endpoint, Octe
/// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
/// <returns></returns>
/// <remarks>This method supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Set is incompatible with trimming.")]
#endif
public static IList<Variable> Set(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, int timeout)
Expand Down Expand Up @@ -684,7 +684,7 @@ public static IList<Variable> Set(VersionCode version, IPEndPoint endpoint, Octe
/// Returns row count if the OID is a table. Otherwise this value is meaningless.
/// </returns>
/// <remarks>This method supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Walk is incompatible with trimming.")]
#endif
public static int Walk(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList<Variable> list, int timeout, WalkMode mode)
Expand Down Expand Up @@ -742,7 +742,7 @@ public static int Walk(VersionCode version, IPEndPoint endpoint, OctetString com
/// <c>true</c> if the specified seed has next item; otherwise, <c>false</c>.
/// </returns>
/// <remarks>This method supports SNMP v1 and v2c.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("HasNext is incompatible with trimming.")]
#endif
private static bool HasNext(VersionCode version, IPEndPoint endpoint, OctetString community, Variable seed, int timeout, out Variable? next)
Expand Down Expand Up @@ -782,7 +782,7 @@ private static bool HasNext(VersionCode version, IPEndPoint endpoint, OctetStrin
/// <param name="report">The report.</param>
/// <returns>Returns row count if the OID is a table. Otherwise this value is meaningless.</returns>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("BulkWalk is incompatible with trimming.")]
#endif
public static int BulkWalk(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList<Variable> list, int timeout, int maxRepetitions, WalkMode mode, IPrivacyProvider? privacy, ISnmpMessage? report)
Expand Down Expand Up @@ -891,7 +891,7 @@ public static void SendTrapV2(int requestId, VersionCode version, EndPoint recei
/// <param name="report">The report.</param>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
[CLSCompliant(false)]
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("SendInform is incompatible with trimming.")]
#endif
public static void SendInform(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, int timeout, IPrivacyProvider privacy, ISnmpMessage report)
Expand Down Expand Up @@ -984,7 +984,7 @@ public static void SendInform(int requestId, VersionCode version, IPEndPoint rec
/// <c>true</c> if the specified seed has next item; otherwise, <c>false</c>.
/// </returns>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("BulkHasNext is incompatible with trimming.")]
#endif
private static bool BulkHasNext(VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, Variable seed, int timeout, int maxRepetitions, out IList<Variable> next, IPrivacyProvider? privacy, ref ISnmpMessage? report)
Expand Down Expand Up @@ -1072,7 +1072,7 @@ private static bool BulkHasNext(VersionCode version, IPEndPoint receiver, OctetS
/// <returns></returns>
/// <remarks>This method supports SNMP v2c and v3.</remarks>
[CLSCompliant(false)]
#if NET6_0 || NET5_0
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("GetTable is incompatible with trimming.")]
#endif
[Obsolete("This method only works for a few scenarios. Might be replaced by new methods in the future. If it does not work for you, parse WALK result on your own.")]
Expand Down
2 changes: 1 addition & 1 deletion SharpSnmpLib/Messaging/Net6Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace Lextm.SharpSnmpLib.Messaging

Check warning on line 26 in SharpSnmpLib/Messaging/Net6Discoverer.cs

View workflow job for this annotation

GitHub Actions / windows

Remove this empty namespace. (https://rules.sonarsource.com/csharp/RSPEC-3261)
{
#if NET6_0
#if NET6_0_OR_GREATER
/// <summary>
/// Discoverer class to discover SNMP agents in the same network.
/// </summary>
Expand Down
6 changes: 2 additions & 4 deletions SharpSnmpLib/Messaging/Net6Discovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ namespace Lextm.SharpSnmpLib.Messaging
/// </summary>
public sealed partial class Discovery
{
#if NET6_0
#if NET6_0_OR_GREATER
/// <summary>
/// Gets the response.
/// </summary>
/// <param name="receiver">The receiver.</param>
/// <param name="token">The cancellation token.</param>
/// <returns></returns>
#if NET6_0
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public async Task<ReportMessage> GetResponseAsync(IPEndPoint receiver, CancellationToken token)
{
if (receiver == null)
Expand All @@ -58,6 +56,6 @@ public async Task<ReportMessage> GetResponseAsync(IPEndPoint receiver, Cancellat
using var socket = receiver.GetSocket();
return (ReportMessage)await _discovery.GetResponseAsync(receiver, Empty, socket, token).ConfigureAwait(false);
}
#endif
#endif
}
}
2 changes: 1 addition & 1 deletion SharpSnmpLib/Messaging/Net6Messenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
#if NET6_0
#if NET6_0_OR_GREATER
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
12 changes: 1 addition & 11 deletions SharpSnmpLib/Messaging/Net6SnmpMessageExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#if NET6_0
#if NET6_0_OR_GREATER
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
#if NETSTANDARD2_0
using System.Runtime.InteropServices;
#endif
using System.Threading;
using System.Threading.Tasks;
using Lextm.SharpSnmpLib.Security;
Expand Down Expand Up @@ -115,9 +113,7 @@ public static async Task SendAsync(this ISnmpMessage message, EndPoint manager,
/// <param name="registry">User registry.</param>
/// <param name="token">The cancellation token.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
[RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, CancellationToken token)
{
// TODO: make more usage of UserRegistry.
Expand Down Expand Up @@ -148,9 +144,7 @@ public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage reques
/// <param name="receiver">Port number.</param>
/// <param name="token">The cancellation token.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
[RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, CancellationToken token)
{
if (request == null)
Expand Down Expand Up @@ -181,9 +175,7 @@ public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage reques
/// <param name="udpSocket">The UDP <see cref="Socket"/> to use to send/receive.</param>
/// <param name="token">The cancellation token.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
[RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, Socket udpSocket, CancellationToken token)
{
if (request == null)
Expand Down Expand Up @@ -219,9 +211,7 @@ public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage reques
/// <param name="registry">The user registry.</param>
/// <param name="token">The cancellation token.</param>
/// <returns></returns>
#if NET6_0 || NET5_0
[RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")]
#endif
public static async Task<ISnmpMessage> GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, Socket udpSocket, CancellationToken token)
{
if (request == null)
Expand Down
Loading

0 comments on commit c9c5c05

Please sign in to comment.