Parse the cmdlet help file
        /// <summary>
        /// Given a set of directory paths containing PowerShell module folders, analyze the help
        /// in the module folders and report any issues
        /// </summary>
        /// <param name="scopes"></param>
        public void Analyze(IEnumerable <string> scopes)
        {
            var savedDirectory     = Directory.GetCurrentDirectory();
            var processedHelpFiles = new List <string>();
            var helpLogger         = Logger.CreateLogger <HelpIssue>("HelpIssues.csv");

            foreach (var baseDirectory in scopes.Where(s => Directory.Exists(Path.GetFullPath(s))))
            {
                foreach (var directory in Directory.EnumerateDirectories(Path.GetFullPath(baseDirectory)))
                {
                    var commandAssemblies = Directory.EnumerateFiles(directory, "*.Commands.*.dll")
                                            .Where(f => IsAssemblyFile(f) && !File.Exists(f + "-Help.xml"));
                    foreach (var orphanedAssembly in commandAssemblies)
                    {
                        helpLogger.LogRecord(new HelpIssue()
                        {
                            Assembly    = orphanedAssembly,
                            Description = string.Format("{0} has no matching help file", orphanedAssembly),
                            Severity    = 0,
                            Remediation = string.Format("Make sure a dll Help file for {0} exists and it is " +
                                                        "being copied to the output directory.", orphanedAssembly),
                            Target    = orphanedAssembly,
                            HelpFile  = orphanedAssembly + "-Help.xml",
                            ProblemId = MissingHelpFile
                        });
                    }

                    var helpFiles = Directory.EnumerateFiles(directory, "*.dll-Help.xml")
                                    .Where(f => !processedHelpFiles.Contains(Path.GetFileName(f),
                                                                             StringComparer.OrdinalIgnoreCase)).ToList();
                    if (helpFiles.Any())
                    {
                        Directory.SetCurrentDirectory(directory);
                        foreach (var helpFile in helpFiles)
                        {
                            var cmdletFile     = helpFile.Substring(0, helpFile.Length - "-Help.xml".Length);
                            var helpFileName   = Path.GetFileName(helpFile);
                            var cmdletFileName = Path.GetFileName(cmdletFile);
                            if (File.Exists(cmdletFile))
                            {
                                processedHelpFiles.Add(helpFileName);
                                helpLogger.Decorator.AddDecorator((h) =>
                                {
                                    h.HelpFile = helpFileName;
                                    h.Assembly = cmdletFileName;
                                }, "Cmdlet");
                                var proxy       = EnvironmentHelpers.CreateProxy <CmdletLoader>(directory, out _appDomain);
                                var cmdlets     = proxy.GetCmdlets(cmdletFile);
                                var helpRecords = CmdletHelpParser.GetHelpTopics(helpFile, helpLogger);
                                ValidateHelpRecords(cmdlets, helpRecords, helpLogger);
                                helpLogger.Decorator.Remove("Cmdlet");
                                AppDomain.Unload(_appDomain);
                            }
                        }

                        Directory.SetCurrentDirectory(savedDirectory);
                    }
                }
            }
        }
        /// <summary>
        /// Given a set of directory paths containing PowerShell module folders, analyze the help
        /// in the module folders and report any issues
        /// </summary>
        /// <param name="scopes"></param>
        public void Analyze(IEnumerable <string> scopes)
        {
            var savedDirectory     = Directory.GetCurrentDirectory();
            var processedHelpFiles = new List <string>();
            var helpLogger         = Logger.CreateLogger <HelpIssue>("HelpIssues.csv");

            foreach (var baseDirectory in scopes.Where(s => Directory.Exists(Path.GetFullPath(s))))
            {
                foreach (var directory in Directory.EnumerateDirectories(Path.GetFullPath(baseDirectory)))
                {
                    var helpFiles = Directory.EnumerateFiles(directory, "*.dll-Help.xml")
                                    .Where(f => !processedHelpFiles.Contains(Path.GetFileName(f),
                                                                             StringComparer.OrdinalIgnoreCase)).ToList();
                    if (helpFiles.Any())
                    {
                        Directory.SetCurrentDirectory(directory);
                        foreach (var helpFile in helpFiles)
                        {
                            var cmdletFile     = helpFile.Substring(0, helpFile.Length - "-Help.xml".Length);
                            var helpFileName   = Path.GetFileName(helpFile);
                            var cmdletFileName = Path.GetFileName(cmdletFile);
                            if (File.Exists(cmdletFile))
                            {
                                processedHelpFiles.Add(helpFileName);
                                helpLogger.Decorator.AddDecorator((h) =>
                                {
                                    h.HelpFile = helpFileName;
                                    h.Assembly = cmdletFileName;
                                }, "Cmdlet");
                                var proxy       = AppDomainHelpers.CreateProxy <CmdletLoader>(directory, out _appDomain);
                                var cmdlets     = proxy.GetCmdlets(cmdletFile);
                                var helpRecords = CmdletHelpParser.GetHelpTopics(helpFile, helpLogger);
                                ValidateHelpRecords(cmdlets, helpRecords, helpLogger);
                                helpLogger.Decorator.Remove("Cmdlet");
                                AppDomain.Unload(_appDomain);
                            }
                        }

                        Directory.SetCurrentDirectory(savedDirectory);
                    }
                }
            }
        }
        private void AnalyzeMamlHelp(
            IEnumerable <string> scopes,
            string directory,
            ReportLogger <HelpIssue> helpLogger,
            List <string> processedHelpFiles,
            string savedDirectory)
        {
            var commandAssemblies = Directory.EnumerateFiles(directory, "*.Commands.*.dll")
                                    .Where(f => IsAssemblyFile(f) && !File.Exists(f + "-Help.xml"));

            foreach (var orphanedAssembly in commandAssemblies)
            {
                helpLogger.LogRecord(new HelpIssue()
                {
                    Assembly    = orphanedAssembly,
                    Description = string.Format("{0} has no matching help file", orphanedAssembly),
                    Severity    = 0,
                    Remediation = string.Format("Make sure a dll Help file for {0} exists and it is " +
                                                "being copied to the output directory.", orphanedAssembly),
                    Target    = orphanedAssembly,
                    HelpFile  = orphanedAssembly + "-Help.xml",
                    ProblemId = MissingHelpFile
                });
            }

            var helpFiles = Directory.EnumerateFiles(directory, "*.dll-Help.xml")
                            .Where(f => !processedHelpFiles.Contains(Path.GetFileName(f),
                                                                     StringComparer.OrdinalIgnoreCase)).ToList();

            if (!helpFiles.Any())
            {
                return;
            }

            Directory.SetCurrentDirectory(directory);
            foreach (var helpFile in helpFiles)
            {
                var cmdletFile     = helpFile.Substring(0, helpFile.Length - "-Help.xml".Length);
                var helpFileName   = Path.GetFileName(helpFile);
                var cmdletFileName = Path.GetFileName(cmdletFile);
                if (!File.Exists(cmdletFile))
                {
                    continue;
                }

                processedHelpFiles.Add(helpFileName);
                helpLogger.Decorator.AddDecorator(h =>
                {
                    h.HelpFile = helpFileName;
                    h.Assembly = cmdletFileName;
                }, "Cmdlet");

                // TODO: Remove IfDef
#if NETSTANDARD
                var proxy = new CmdletLoader();
#else
                var proxy = EnvironmentHelpers.CreateProxy <CmdletLoader>(directory, out _appDomain);
#endif
                var module      = proxy.GetModuleMetadata(cmdletFile);
                var cmdlets     = module.Cmdlets;
                var helpRecords = CmdletHelpParser.GetHelpTopics(helpFile, helpLogger);
                ValidateHelpRecords(cmdlets, helpRecords, helpLogger);
                helpLogger.Decorator.Remove("Cmdlet");
                // TODO: Remove IfDef code
#if !NETSTANDARD
                AppDomain.Unload(_appDomain);
#endif
            }

            Directory.SetCurrentDirectory(savedDirectory);
        }