Skip to content

Commit

Permalink
Merge pull request #289 from atc-net/feature/AssemblyHelper-and-exe-f…
Browse files Browse the repository at this point in the history
…iles

Improve AssemblyHelper
  • Loading branch information
davidkallesen authored Oct 8, 2023
2 parents 613e230 + e38fb11 commit e8764f5
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.70" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.92" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.5.0.73987" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.11.0.78383" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Atc.CodeAnalysis.CSharp/Atc.CodeAnalysis.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Atc.OpenApi/Atc.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.6" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Atc.XUnit/Atc.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPPlus" Version="6.2.7" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7345" />
<PackageReference Include="EPPlus" Version="6.2.10" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.1.1.7464" />
<PackageReference Include="Mono.Reflection" Version="2.0.0">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 14 additions & 5 deletions src/Atc/Helpers/AssemblyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public static Assembly Load(
throw new IOException("File not found");
}

if (!assemblyFile.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
if (!assemblyFile.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase) &&
!assemblyFile.Extension.Equals(".exe", StringComparison.OrdinalIgnoreCase))
{
throw new IOException("File is not a dll");
throw new IOException("File is not a dll or a executable file");
}

var bytes = ReadAsBytes(assemblyFile);
Expand All @@ -43,7 +44,14 @@ public static Assembly Load(
throw new IOException("File has a 0 byte length");
}

return Assembly.Load(bytes);
try
{
return Assembly.Load(bytes);
}
catch (BadImageFormatException)
{
throw new IOException("File is not a valid Assembly");
}
}

/// <summary>
Expand All @@ -64,9 +72,10 @@ public static byte[] ReadAsBytes(
throw new IOException("File not found");
}

if (!assemblyFile.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
if (!assemblyFile.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase) &&
!assemblyFile.Extension.Equals(".exe", StringComparison.OrdinalIgnoreCase))
{
throw new IOException("File is not a dll");
throw new IOException("File is not a dll or a executable file");
}

try
Expand Down
2 changes: 2 additions & 0 deletions src/Atc/Helpers/Enums/CardinalDirectionTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static CardinalDirectionType GetWhenRotateRight(CardinalDirectionType car
/// <param name="cardinalDirectionTypeToInclude">The cardinal direction type to include.</param>
/// <param name="cardinalDirectionType">Type of the cardinal direction.</param>
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")]
[SuppressMessage("Bug", "S2589:Conditionally executed code should be reachable", Justification = "OK.")]
public static CardinalDirectionType GetWhenRotateRight(CardinalDirectionType cardinalDirectionTypeToInclude, CardinalDirectionType cardinalDirectionType)
{
var returnValue = CardinalDirectionType.None;
Expand Down Expand Up @@ -265,6 +266,7 @@ public static CardinalDirectionType GetWhenRotate180(CardinalDirectionType cardi
/// <param name="angle">The angle.</param>
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")]
[SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "OK.")]
[SuppressMessage("Bug", "S2589:Conditionally executed code should be reachable", Justification = "OK.")]
public static CardinalDirectionType GetTheClosestByAngle(CardinalDirectionType combinedCardinalDirectionType, double angle)
{
if (angle < 0 || angle > 360)
Expand Down
1 change: 1 addition & 0 deletions src/Atc/Helpers/NetworkInformationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static bool HasTcpConnection(IPAddress ipAddress, int port)
}
}

[SuppressMessage("Bug", "S2583:Conditionally executed code should be reachable", Justification = "OK.")]
public static IPAddress? GetPublicIpAddress()
{
string? response = null;
Expand Down
3 changes: 3 additions & 0 deletions src/Atc/Helpers/TaskHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static async Task<TResult> Execute<TResult>(
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1031:Do not catch general exception types", Justification = "OK.")]
[SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "OK.")]
[SuppressMessage("Code Smell", "S112:General exceptions should never be thrown", Justification = "OK.")]
public static async Task WhenAll(IEnumerable<Task> tasks)
{
var allTasks = Task.WhenAll(tasks);
Expand Down Expand Up @@ -82,6 +83,7 @@ public static async Task WhenAll(IEnumerable<Task> tasks)
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1031:Do not catch general exception types", Justification = "OK.")]
[SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "OK.")]
[SuppressMessage("Code Smell", "S112:General exceptions should never be thrown", Justification = "OK.")]
public static async Task<IEnumerable<T>> WhenAll<T>(IEnumerable<Task<T>> tasks)
{
var allTasks = Task.WhenAll(tasks);
Expand Down Expand Up @@ -110,6 +112,7 @@ public static async Task<IEnumerable<T>> WhenAll<T>(IEnumerable<Task<T>> tasks)
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1031:Do not catch general exception types", Justification = "OK.")]
[SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "OK.")]
[SuppressMessage("Code Smell", "S112:General exceptions should never be thrown", Justification = "OK.")]
public static async Task<IEnumerable<T>> WhenAll<T>(params Task<T>[] tasks)
{
var allTasks = Task.WhenAll(tasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions test/Atc.Rest.Tests/Atc.Rest.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<ItemGroup>
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.Tests/Atc.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.XUnit.Tests/Atc.XUnit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Test" Version="1.0.77" />
<PackageReference Include="Atc.Test" Version="1.0.79" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16" PrivateAssets="All" />
</ItemGroup>

Expand Down

0 comments on commit e8764f5

Please sign in to comment.