Skip to content

Commit

Permalink
Test and patch for short-name-app-config bug
Browse files Browse the repository at this point in the history
Fixes #241

When R executes AP.exe it uses the `Sys.which` function to resolve the executable
name. This function uses the Windows 8.3 short-name functionality by defualt which
launches the application as ANALYS~1.exe. Since the application is no longer named
correctly, the AnalysisPrograms.exe.config file cannot be loaded and all of our
application binding redirects are ignored. Subsequently the fusion assembly loader
throws errors like:

```
  System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
	- Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

```

In addition to the stack overflow post that should how to update the current domain's
App.Config file and settings, I also had to force Fusion to redo it's setup. This method,
is to say the least, fragile, and we can expect it to fail in the port to .NET Core.

Additionally added a AP_DEFAULT_LOG_VERBOSITY flag that set the log level verbosity
before the command line is parsed.

Additionally added a few extension method helpers and associated tests
  • Loading branch information
atruskie committed Sep 11, 2019
1 parent 7542295 commit 92c371e
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = true:none
# Expression-bodied members
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
csharp_style_expression_bodied_methods = when_on_single_line:hint
csharp_style_expression_bodied_constructors = when_on_single_line:suggestion
csharp_style_expression_bodied_operators = true:warning
csharp_style_expression_bodied_properties = true:warning
Expand Down
2 changes: 1 addition & 1 deletion docs/developing.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
See [Contributing](https://github.com/QutEcoacoustics/audio-analysis/blob/master/CONTRIBUTING.md)
See [Contributing](https://github.com/QutEcoacoustics/audio-analysis/blob/master/CONTRIBUTING.md)
1 change: 1 addition & 0 deletions src/Acoustics.Shared/Acoustics.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<Compile Include="Csv\Csv.cs" />
<Compile Include="Csv\ISetPointConverter.cs" />
<Compile Include="Debugging\AutoAttachVs.cs" />
<Compile Include="Extensions\EnumExtensions.cs" />
<Compile Include="Enums.cs" />
<Compile Include="ExpressionVisitor.cs" />
<Compile Include="Extensions\ArrayExtensions.cs" />
Expand Down
7 changes: 1 addition & 6 deletions src/Acoustics.Shared/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Enums.cs" company="QutEcoacoustics">
// <copyright file="Enums.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>

Expand All @@ -25,9 +25,4 @@ public enum ImageChrome
Without = 0,
With = 1,
}

public static class EnumExtenstions
{
public static ImageChrome ToImageChrome(this bool chromeOrNot) => chromeOrNot ? ImageChrome.With : ImageChrome.Without;
}
}
23 changes: 23 additions & 0 deletions src/Acoustics.Shared/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <copyright file="EnumExtensions.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>

namespace System
{
using Acoustics.Shared;

public static class EnumExtensions
{
public static ImageChrome ToImageChrome(this bool chromeOrNot) => chromeOrNot ? ImageChrome.With : ImageChrome.Without;

public static string PrintEnumOptions(this Type @enum)
{
if (@enum == null || !@enum.IsEnum)
{
throw new ArgumentException($"{nameof(PrintEnumOptions)} must only be used on an enum type", nameof(@enum));
}

return Enum.GetValues(@enum).Join("|");
}
}
}
23 changes: 20 additions & 3 deletions src/Acoustics.Shared/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
// ReSharper disable once CheckNamespace
namespace System
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acoustics.Shared;
using Acoustics.Shared.Contracts;
using Collections.Generic;
using JetBrains.Annotations;
using Linq;
using Threading.Tasks;

public static class EnumerableExtensions
{
Expand Down Expand Up @@ -311,5 +313,20 @@ public static IEnumerable<T> Append<T>(this IEnumerable<T> items, T newItem)

yield return newItem;
}

public static string Join(this IEnumerable items, string delimiter = " ") => Join(items.Cast<object>(), delimiter);

public static string Join<T>(this IEnumerable<T> items, string delimiter = " ")
{
var result = new StringBuilder();
foreach (var item in items)
{
result.Append(item);
result.Append(delimiter);
}

// return one delimiter length less because we always add a delimiter on the end
return result.ToString(0, result.Length - delimiter.Length);
}
}
}
3 changes: 3 additions & 0 deletions src/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<Reference Include="Equ, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Equ.2.0.2\lib\netstandard1.5\Equ.dll</HintPath>
</Reference>
<Reference Include="Fasterflect, Version=2.1.3.0, Culture=neutral, PublicKeyToken=38d18473284c1ca7, processorArchitecture=MSIL">
<HintPath>..\..\packages\fasterflect.2.1.3\lib\net40\Fasterflect.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\FSharp.Core.4.3.4\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
Expand Down
2 changes: 2 additions & 0 deletions src/AnalysisPrograms/CheckEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AnalysisPrograms
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -30,6 +31,7 @@ public class CheckEnvironment
private int Execute(Arguments arguments)
{
var errors = new List<string>();

Log.Info("Checking required executables and libraries can be found and loaded");

// this is an important call used in analyze long recordings.
Expand Down
5 changes: 4 additions & 1 deletion src/AnalysisPrograms/MainEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public static async Task<int> Main(string[] args)
// Uses an env var to attach debugger before argument parsing
AttachDebugger(ApAutoAttach ? DebugOptions.YesSilent : DebugOptions.No);

Logging = new Logging(colorConsole: !ApPlainLogging, Level.Info, quietConsole: false);
Logging = new Logging(
colorConsole: !ApPlainLogging,
VerbosityToLevel(ApDefaultLogVerbosity ?? LogVerbosity.Info),
quietConsole: false);

Copyright();

Expand Down
Loading

0 comments on commit 92c371e

Please sign in to comment.