diff --git a/src/Acoustics.Shared/AppConfigHelper.cs b/src/Acoustics.Shared/AppConfigHelper.cs index a3df47fe3..bc2e94621 100644 --- a/src/Acoustics.Shared/AppConfigHelper.cs +++ b/src/Acoustics.Shared/AppConfigHelper.cs @@ -38,7 +38,17 @@ public static class AppConfigHelper private static readonly string ExecutingAssemblyPath = (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).Location; - private static readonly IConfigurationSection SharedSettings; + private static readonly Lazy SharedSettings = new Lazy(() => + { + var settings = AppConfiguration.Value.GetSection("appSettings"); + if (!settings.AsEnumerable().Any()) + { + throw new ConfigurationErrorsException("Could not read AP.Settings.json - no values were found in the config file"); + } + + return settings; + }); + private static readonly ILog Log = LogManager.GetLogger(nameof(AppConfigHelper)); private static readonly bool IsLinuxValue; private static readonly bool IsWindowsValue; @@ -46,21 +56,14 @@ public static class AppConfigHelper static AppConfigHelper() { - AppConfiguration = new ConfigurationBuilder() - .AddJsonFile("AP.Settings.json") - .Build(); - - SharedSettings = AppConfiguration.GetSection("appSettings"); - if (!SharedSettings.AsEnumerable().Any()) - { - throw new ConfigurationErrorsException("Could not read AP.Settings.json - no values were found in the config file"); - } - IsMono = Type.GetType("Mono.Runtime") != null; CheckOs(ref IsWindowsValue, ref IsLinuxValue, ref IsMacOsXValue); } - public static IConfigurationRoot AppConfiguration { get; } + public static Lazy AppConfiguration { get; } = new Lazy(() => + new ConfigurationBuilder() + .AddJsonFile("AP.Settings.json") + .Build()); public static int DefaultTargetSampleRate => GetInt(DefaultTargetSampleRateKey); @@ -166,7 +169,7 @@ public static DirectoryInfo AssemblyDir public static string GetString(string key) { - var value = SharedSettings[key]; + var value = SharedSettings.Value[key]; if (string.IsNullOrEmpty(value)) { @@ -333,7 +336,7 @@ private static string GetExeFile(string appConfigKey, bool required = true) key = appConfigKey; } - var path = SharedSettings[key]; + var path = SharedSettings.Value[key]; Log.Verbose($"Attempted to get exe path `{appConfigKey}`. Value: '{path}'"); diff --git a/src/AnalysisPrograms/CheckEnvironment.cs b/src/AnalysisPrograms/CheckEnvironment.cs index c3f1e6514..59efa8b58 100644 --- a/src/AnalysisPrograms/CheckEnvironment.cs +++ b/src/AnalysisPrograms/CheckEnvironment.cs @@ -1,4 +1,4 @@ -// +// // 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). // @@ -9,13 +9,14 @@ namespace AnalysisPrograms using System.Linq; using System.Reflection; using System.Text; + using System.Text.RegularExpressions; using System.Threading.Tasks; using Acoustics.Shared; using Acoustics.Tools.Audio; - using AnalyseLongRecordings; + using AnalysisPrograms.AnalyseLongRecordings; + using AnalysisPrograms.Production.Arguments; using log4net; using McMaster.Extensions.CommandLineUtils; - using Production.Arguments; public class CheckEnvironment { @@ -25,10 +26,18 @@ public class CheckEnvironment private void Execute(Arguments arguments) { + List errors = new List(); Log.Info("Checking required executables can be found"); - // master audio utlility checks for available executables - var utility = new MasterAudioUtility(); + // master audio utility checks for available executables + try + { + var utility = new MasterAudioUtility(); + } + catch (Exception ex) + { + errors.Add(ex); + } if (AppConfigHelper.IsMono) { @@ -39,17 +48,33 @@ private void Execute(Arguments arguments) if (displayName != null) { var name = displayName.Invoke(null, null); - Log.Info($"Mono version is {name}, we require at least Mono 5.5"); + var version = Regex.Match(name as string, @".*(\d+\.\d+\.\d+\.\d+).*").Groups[1].Value; + Console.WriteLine(version); + if (new Version(version) > new Version(5, 5)) + { + Log.Success($"Your mono version {name} is greater than our required Mono version 5.5"); + } + else + { + errors.Add(new Exception($"Mono version is {name}, we require at least Mono 5.5")); + } } else { - Log.Warn("Could not check Mono version"); + errors.Add(new Exception("Could not check Mono version")); } } } // don't have much more to check at the current time - Log.Success("Valid environment"); + if (errors.Count == 0) + { + Log.Success("Valid environment"); + } + else + { + throw new AggregateException(errors.ToArray()); + } } [Command(