Skip to content

Commit

Permalink
Updated the packaging support files.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 31, 2024
1 parent fcfbe82 commit adacd85
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 151 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2008-2017 Malcolm Crowe, Lex Li, and other contributors.
Copyright (c) 2008-2024 Malcolm Crowe, Lex Li, and other contributors.
Copyright (c) 2018-2024 LeXtudio Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion SharpSnmpLib/Messaging/Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public async Task DiscoverAsync(VersionCode version, IPEndPoint broadcastAddress
}

#if NET6_0_OR_GREATER
var source = new CancellationTokenSource();
using var source = new CancellationTokenSource();
source.CancelAfter(interval);
try
{
Expand Down
4 changes: 2 additions & 2 deletions SharpSnmpLib/Messaging/Net6Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
using System.Threading;
using System.Threading.Tasks;

#if NET6_0_OR_GREATER
namespace Lextm.SharpSnmpLib.Messaging
{
#if NET6_0_OR_GREATER
/// <summary>
/// Discoverer class to discover SNMP agents in the same network.
/// </summary>
Expand Down Expand Up @@ -233,5 +233,5 @@ await Task.Factory.StartNew(() => HandleMessage(buffer, result.ReceivedBytes, (I
}
}
}
#endif
}
#endif
2 changes: 1 addition & 1 deletion SharpSnmpLib/OperationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public OperationException(string message, Exception inner) : base(message, inner
/// </summary>
/// <param name="info">Info</param>
/// <param name="context">Context</param>
internal protected OperationException(SerializationInfo info, StreamingContext context)
protected OperationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
var content = info.GetString("Agent");
Expand Down
6 changes: 5 additions & 1 deletion SharpSnmpLib/SharpSnmpLib.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>SharpSnmpLib</AssemblyName>
<RootNamespace>Lextm.SharpSnmpLib</RootNamespace>
Expand Down Expand Up @@ -31,6 +31,7 @@
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<AndroidUseIntermediateDesignerFile>False</AndroidUseIntermediateDesignerFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -59,6 +60,9 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="../readme.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net471'">
<Reference Include="System.Configuration" />
</ItemGroup>
Expand Down
52 changes: 26 additions & 26 deletions Tests/CSharpCore/Unit/DataFactoryTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,66 @@ public void TestException()
Assert.Throws<ArgumentNullException>(() => DataFactory.CreateSnmpData((byte[])null));
Assert.Throws<ArgumentNullException>(() => DataFactory.CreateSnmpData(0, null));
}

[Fact]
public void TestCreateObjectIdentifier()
{
byte[] expected = new byte[] {0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x90, 0x72, 0x87, 0x68, 0x02};
byte[] expected = new byte[] { 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x90, 0x72, 0x87, 0x68, 0x02 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.ObjectIdentifier, data.TypeCode);
ObjectIdentifier o = (ObjectIdentifier)data;
Assert.Equal(new uint[] { 1, 3, 6, 1, 4, 1, 2162, 1000, 2 }, o.ToNumerical());
}

[Fact]
public void TestCreateObjectIdentifier2()
{
byte[] expected = new Byte[] {0x06, 0x01, 0x00};
byte[] expected = new Byte[] { 0x06, 0x01, 0x00 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.ObjectIdentifier, data.TypeCode);
ObjectIdentifier o = (ObjectIdentifier)data;
Assert.Equal(new uint[] {0, 0}, o.ToNumerical());
Assert.Equal(new uint[] { 0, 0 }, o.ToNumerical());
}

[Fact]
public void TestCreateNull()
{
byte[] expected = new byte[] {0x05, 0x00};
byte[] expected = new byte[] { 0x05, 0x00 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.Null, data.TypeCode);
Null n = (Null)data;
Assert.Equal(expected, n.ToBytes());
}

[Fact]
public void TestCreateInteger()
{
byte[] expected = new byte[] {0x02, 0x01, 0x00};
byte[] expected = new byte[] { 0x02, 0x01, 0x00 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.Integer32, data.TypeCode);
Integer32 i = (Integer32)data;
Assert.Equal(0, i.ToInt32());
}

[Fact]
public void TestCreateOctetString()
{
byte[] expected = new byte[] {0x04, 0x06, 0x70, 0x75, 0x62, 0x6C, 0x69, 0x63};
byte[] expected = new byte[] { 0x04, 0x06, 0x70, 0x75, 0x62, 0x6C, 0x69, 0x63 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.OctetString, data.TypeCode);
Assert.Equal("public", data.ToString());
}

[Fact]
public void TestCreateIP()
{
byte[] expected = new byte[] { 0x40, 0x04, 0x7F, 0x00, 0x00, 0x01};
byte[] expected = new byte[] { 0x40, 0x04, 0x7F, 0x00, 0x00, 0x01 };
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.IPAddress, data.TypeCode);
IP a = (IP)data;
Assert.Equal("127.0.0.1", a.ToString());
}

[Fact]
public void TestTimeticks()
{
Expand All @@ -92,7 +92,7 @@ public void TestTimeticks()
TimeTicks t = (TimeTicks)data;
Assert.Equal(16352U, t.ToUInt32());
}

[Fact]
public void TestVarbind()
{
Expand All @@ -103,17 +103,17 @@ public void TestVarbind()
Assert.Equal(SnmpType.Sequence, data.TypeCode);
Sequence a = (Sequence)data;
Assert.Equal(2, a.Length);

ISnmpData oid = a[0];
ISnmpData name = a[1];
Assert.Equal(SnmpType.ObjectIdentifier, oid.TypeCode);
Assert.Equal(SnmpType.OctetString, name.TypeCode);
ObjectIdentifier o = (ObjectIdentifier)oid;
Assert.Equal(new uint[] {1,3,6,1,4,1,2162,1001,21,0}, o.ToNumerical());
Assert.Equal(new uint[] { 1, 3, 6, 1, 4, 1, 2162, 1001, 21, 0 }, o.ToNumerical());
OctetString s = (OctetString)name;
Assert.Equal("TrapTest", s.ToString());
}

[Fact]
public void TestVarbindSection()
{
Expand All @@ -123,13 +123,13 @@ public void TestVarbindSection()
0x04, 0x08, 0x54, 0x72, 0x61, 0x70, 0x54, 0x65, 0x73, 0x74};
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.Sequence, data.TypeCode);

Sequence a = (Sequence)data;
Assert.Equal(1, a.Length);
ISnmpData varbind = a[0];
Assert.Equal(SnmpType.Sequence, varbind.TypeCode);
}

[Fact]
public void TestTrapv1Pdu()
{
Expand All @@ -145,16 +145,16 @@ public void TestTrapv1Pdu()
0x04, 0x08, 0x54, 0x72, 0x61, 0x70, 0x54, 0x65, 0x73, 0x74};
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.TrapV1Pdu, data.TypeCode);

TrapV1Pdu t = (TrapV1Pdu)data;
Assert.Equal(new uint[] {1,3,6,1,4,1,2162,1000,2}, t.Enterprise.ToNumerical());
Assert.Equal(new uint[] { 1, 3, 6, 1, 4, 1, 2162, 1000, 2 }, t.Enterprise.ToNumerical());
Assert.Equal("127.0.0.1", t.AgentAddress.ToIPAddress().ToString());
Assert.Equal(GenericCode.EnterpriseSpecific, t.Generic);
Assert.Equal(12, t.Specific);
Assert.Equal(16352U, t.TimeStamp.ToUInt32());
Assert.Equal(1, t.Variables.Count);
Assert.Single(t.Variables);
}

[Fact]
public void TestTrapPacket()
{
Expand All @@ -174,7 +174,7 @@ public void TestTrapPacket()
0x04, 0x08, 0x54, 0x72, 0x61, 0x70, 0x54, 0x65, 0x73, 0x74};
ISnmpData data = DataFactory.CreateSnmpData(expected);
Assert.Equal(SnmpType.Sequence, data.TypeCode);

Sequence t = (Sequence)data;
Assert.Equal(3, t.Length);
ISnmpData version = t[0];
Expand All @@ -200,4 +200,4 @@ public void TestInformDiscovery()
Assert.Equal(0U, newPdu.TimeStamp);
}
}
}
}
2 changes: 1 addition & 1 deletion Tests/CSharpCore/Unit/MalformedPduTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Test()
Assert.Throws<NotSupportedException>(() => { var test = pdu.ErrorIndex; });
Assert.Throws<NotSupportedException>(() => { var test = pdu.ErrorStatus; });
Assert.Throws<NotSupportedException>(() => pdu.AppendBytesTo(null));
Assert.Equal(0, pdu.Variables.Count);
Assert.Empty(pdu.Variables);
Assert.Equal(Integer32.Zero, pdu.RequestId);
Assert.Equal(SnmpType.Unknown, pdu.TypeCode);
Assert.Equal("Malformed PDU", pdu.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Test()
ISnmpMessage message = MessageFactory.ParseMessages(expected, new UserRegistry())[0];
Assert.Equal(SnmpType.GetRequestPdu, message.TypeCode());
GetRequestPdu pdu = (GetRequestPdu)message.Pdu();
Assert.Equal(1, pdu.Variables.Count);
Assert.Single(pdu.Variables);
Variable v = pdu.Variables[0];
Assert.Equal(new uint[] { 1, 3, 6, 1, 2, 1, 1, 6, 0 }, v.Id.ToNumerical());
Assert.Equal(typeof(Null), v.Data.GetType());
Expand Down
Loading

0 comments on commit adacd85

Please sign in to comment.