/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { var reportFilePatterns = Array.Empty <string>(); var targetDirectory = TargetDirectory; var sourceDirectories = Array.Empty <string>(); string historyDirectory = HistoryDirectory; var reportTypes = Array.Empty <string>(); var plugins = Array.Empty <string>(); var assemblyFilters = Array.Empty <string>(); var classFilters = Array.Empty <string>(); var fileFilters = Array.Empty <string>(); string verbosityLevel = VerbosityLevel; string tag = Tag; var config = Config.Build(ProjectDirectory).GetSection(SectionName); string value = null; if (ReportFiles.Length > 0) { reportFilePatterns = ReportFiles.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("reports", out value)) { reportFilePatterns = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { reportFilePatterns = config .GetAll("report") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (reportFilePatterns.Length == 0) { Log.LogError($"{nameof(ReportFiles)} is required."); return(false); } if (string.IsNullOrEmpty(targetDirectory) && config.TryGetString("targetdir", out value)) { targetDirectory = value; } if (string.IsNullOrEmpty(targetDirectory)) { Log.LogError($"{nameof(TargetDirectory)} is required."); return(false); } if (SourceDirectories.Length > 0) { sourceDirectories = SourceDirectories.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("sourcedirs", out value)) { sourceDirectories = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { sourceDirectories = config .GetAll("sourcedir") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (string.IsNullOrEmpty(HistoryDirectory) && config.TryGetString("historydir", out value)) { historyDirectory = value; } if (ReportTypes.Length > 0) { reportTypes = ReportTypes.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("reporttypes", out value)) { reportTypes = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { reportTypes = config .GetAll("reporttype") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (Plugins.Length > 0) { plugins = Plugins.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("plugins", out value)) { plugins = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { plugins = config .GetAll("plugin") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (AssemblyFilters.Length > 0) { assemblyFilters = AssemblyFilters.Select(r => r.ItemSpec).ToArray(); } else if (Filters.Length > 0) { assemblyFilters = Filters.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("assemblyfilters", out value)) { assemblyFilters = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { assemblyFilters = config .GetAll("assemblyfilter") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (ClassFilters.Length > 0) { classFilters = ClassFilters.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("classfilters", out value)) { classFilters = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { classFilters = config .GetAll("classfilter") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (FileFilters.Length > 0) { fileFilters = FileFilters.Select(r => r.ItemSpec).ToArray(); } else if (config.TryGetString("filefilters", out value)) { fileFilters = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } else { fileFilters = config .GetAll("filefilter") .Select(x => x.RawValue) .Where(x => !string.IsNullOrEmpty(x)) .ToArray(); } if (string.IsNullOrEmpty(verbosityLevel) && config.TryGetString("verbosity", out value)) { verbosityLevel = value; } if (string.IsNullOrEmpty(tag) && config.TryGetString("tag", out value)) { tag = value; } var configuration = new ReportConfiguration( reportFilePatterns, targetDirectory, sourceDirectories, historyDirectory, reportTypes, plugins, assemblyFilters, classFilters, fileFilters, verbosityLevel, tag); return(new Generator().GenerateReport(configuration)); }