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.
            // This call effectively check is we can load types and if files are present (I think)
            try
            {
                AnalysisCoordinator.GetAnalyzers <IAnalyser2>(typeof(MainEntry).Assembly);
            }
            catch (ReflectionTypeLoadException rtlex)
            {
                errors.Add(ExceptionLookup.FormatReflectionTypeLoadException(rtlex, true));
            }

            // master audio utility checks for available executables
            try
            {
                var utility = new MasterAudioUtility();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
            }

            if (MainEntry.CheckForDataAnnotations() is string message)
            {
                errors.Add(message);
            }


            Type type = Type.GetType("Mono.Runtime");

            if (type != null)
            {
                errors.Add($"We no longer use Mono with ${Meta.Name}. DO NOT prefix the {Meta.Name} prefix with `mono`.");
            }


            // don't have much more to check at the current time
            if (errors.Count == 0)
            {
                Log.Success("Valid environment");

                return(ExceptionLookup.Ok);
            }
            else
            {
                foreach (var error in errors)
                {
                    Log.Error(error);
                }

                // not using exception lookup on purpose - it's static constructor loads more types
                return(ExceptionLookup.UnhandledExceptionErrorCode);
            }
        }
예제 #2
0
        private StringBuilder GetAnalyzersTable()
        {
            var analysers = AnalysisCoordinator
                            .GetAnalyzers <IAnalyser2>(typeof(MainEntry).Assembly)
                            .OrderBy(x => x.Identifier)
                            .ToArray();

            const string identifier       = "Identifier";
            var          indentifierWidth = Math.Max(identifier.Length, analysers.Max((analyser2) => analyser2.Identifier.Length)) + 1;
            var          typeLength       = 16 + 1;
            int          bufferWidth;

            try
            {
                bufferWidth = Console.BufferWidth;
            }
            catch (Exception)
            {
                bufferWidth = 80;
            }

            var consoleWidth     = Math.Max((10 * (bufferWidth / 10)) - Environment.NewLine.Length, 80);
            var descrptionLength = consoleWidth - indentifierWidth - typeLength;

            string tableFormat = "{0, " + -indentifierWidth + "}{1, " + -typeLength + "}{2," + -descrptionLength + "}";
            string header      = string.Format(tableFormat, identifier, "Type", "Description");

            StringBuilder table = new StringBuilder((analysers.Length + 3) * consoleWidth);

            table.AppendLine(header);
            table.AppendLine(string.Empty.PadRight(header.Length, '-'));
            foreach (IAnalyser2 analyser in analysers)
            {
                var isEventRecognizer = analyser is IEventRecognizer;

                var description = analyser.Description;
                if (string.IsNullOrWhiteSpace(description))
                {
                    description = "<No description>";
                }

                if (description.Length > descrptionLength)
                {
                    description = description.WordWrap(descrptionLength, indentifierWidth + typeLength);
                }

                table.AppendLine(string.Format(tableFormat, analyser.Identifier, isEventRecognizer ? "Event Recognizer" : "Type unknown", description));
            }

            return(table);
        }
예제 #3
0
        public static T FindAndCheckAnalyzer <T>(string analysisIdentifier, string partialIdentifier)
            where T : class, IAnalyser2
        {
            string searchName;

            if (analysisIdentifier.IsNotWhitespace())
            {
                searchName = analysisIdentifier;
                Log.Debug($"Searching for exact analysis identifier name {searchName} (from a CLI option)");
            }
            else
            {
                // split name (e.g. "Towsey.Acoustics.Zooming.yml") on periods
                var fragments = partialIdentifier.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);

                Contract.Requires <CommandLineArgumentException>(
                    fragments.Length >= 2,
                    $"We need at least two segments to search for an analyzer, supplied name `{partialIdentifier}` is insufficient.");

                // assume identifier (e.g. "Towsey.Acoustic") in first two segments
                searchName = fragments[0] + "." + fragments[1];
                Log.Debug($"Searching for partial analysis identifier name. `{searchName}` extracted from `{partialIdentifier}`");
            }

            var analyzers = AnalysisCoordinator.GetAnalyzers <T>(typeof(MainEntry).Assembly).ToList();
            T   analyzer  = analyzers.FirstOrDefault(a => a.Identifier == searchName);

            if (analyzer == null)
            {
                var error = $"We cannot determine what analysis you want to run. We tried to search for \"{searchName}\"";
                LoggedConsole.WriteErrorLine(error);
                var knownAnalyzers = analyzers.Aggregate(string.Empty, (a, i) => a + $"  {i.Identifier}\n");
                LoggedConsole.WriteLine("Available analyzers are:\n" + knownAnalyzers);

                throw new ValidationException($"Cannot find an IAnalyser2 with the name `{searchName}`");
            }

            Log.Info($"Using analyzer {analyzer.Identifier}");

            return(analyzer);
        }
예제 #4
0
        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.
            // This call effectively check is we can load types and if files are present (I think)
            try
            {
                AnalysisCoordinator.GetAnalyzers <IAnalyser2>(typeof(MainEntry).Assembly);
            }
            catch (ReflectionTypeLoadException rtlex)
            {
                errors.Add(ExceptionLookup.FormatReflectionTypeLoadException(rtlex, true));
            }

            // master audio utility checks for available executables
            try
            {
                var utility = new MasterAudioUtility();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
            }

            if (MainEntry.CheckForDataAnnotations() is string message)
            {
                errors.Add(message);
            }

            if (AppConfigHelper.IsMono)
            {
                Type type = Type.GetType("Mono.Runtime");
                if (type != null)
                {
                    MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);

                    if (displayName?.Invoke(null, null) is string name)
                    {
                        var version = Regex.Match(name, @".*(\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($"Mono version is {name}, we require at least Mono 5.5");
                        }
                    }
                    else
                    {
                        errors.Add("Could not get Mono display name");
                    }
                }
            }

            // don't have much more to check at the current time
            if (errors.Count == 0)
            {
                Log.Success("Valid environment");

                return(ExceptionLookup.Ok);
            }
            else
            {
                foreach (var error in errors)
                {
                    Log.Error(error);
                }

                // not using exception lookup on purpose - it's static constructor loads more types
                return(ExceptionLookup.UnhandledExceptionErrorCode);
            }
        }