/// <summary> /// Execute the scan /// </summary> /// <param name="config">A set of configuration options</param> /// <param name="scanTools">A set of tools for writing output files, /// creating the expected results format, and finding the target element to scan</param> /// <returns>A SnapshotCommandResult that describes the result of the command</returns> public static ScanResults Execute(Config config, IScanTools scanTools) { return(ExecutionWrapper.ExecuteCommand <ScanResults>(() => { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.TargetElementLocator == null) { throw new ArgumentNullException(nameof(scanTools.TargetElementLocator)); } if (scanTools.Actions == null) { throw new ArgumentNullException(nameof(scanTools.Actions)); } var rootElement = scanTools.TargetElementLocator.LocateRootElement(config.ProcessId); if (rootElement == null) { throw new InvalidOperationException(nameof(rootElement)); } return scanTools.Actions.Scan(rootElement, (element, elementId) => { return ProcessResults(element, elementId, config, scanTools); }); })); }
/// <summary> /// Execute the scan /// </summary> /// <param name="config">A set of configuration options</param> /// <param name="scanTools">A set of tools for writing output files, /// creating the expected results format, and finding the target element to scan</param> /// <returns>A SnapshotCommandResult that describes the result of the command</returns> public static ScanResults Execute(Config config, IScanTools scanTools) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.TargetElementLocator == null) { throw new ArgumentException(ErrorMessages.ScanToolsTargetElementLocatorNull, nameof(scanTools)); } if (scanTools.Actions == null) { throw new ArgumentException(ErrorMessages.ScanToolsActionsNull, nameof(scanTools)); } if (scanTools.NativeMethods == null) { throw new ArgumentException(ErrorMessages.ScanToolsNativeMethodsNull, nameof(scanTools)); } // We must turn on DPI awareness so we get physical, not logical, UIA element bounding rectangles scanTools.NativeMethods.SetProcessDPIAware(); var rootElement = scanTools.TargetElementLocator.LocateRootElement(config.ProcessId); return(scanTools.Actions.Scan(rootElement, (element, elementId) => { return ProcessResults(element, elementId, config, scanTools); })); }
/// <summary> /// Execute the scan /// </summary> /// <param name="config">A set of configuration options</param> /// <param name="scanTools">A set of tools for writing output files, /// creating the expected results format, and finding the target element to scan</param> /// <returns>A SnapshotCommandResult that describes the result of the command</returns> public static IReadOnlyCollection <ScanResults> Execute(Config config, IScanTools scanTools) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.TargetElementLocator == null) { throw new ArgumentException(ErrorMessages.ScanToolsTargetElementLocatorNull, nameof(scanTools)); } if (scanTools.Actions == null) { throw new ArgumentException(ErrorMessages.ScanToolsActionsNull, nameof(scanTools)); } if (scanTools.NativeMethods == null) { throw new ArgumentException(ErrorMessages.ScanToolsNativeMethodsNull, nameof(scanTools)); } // We must turn on DPI awareness so we get physical, not logical, UIA element bounding rectangles scanTools.NativeMethods.SetProcessDPIAware(); if (config.CustomUIAConfigPath != null) { scanTools.Actions.RegisterCustomUIAPropertiesFromConfig(config.CustomUIAConfigPath); } List <ScanResults> resultList = new List <ScanResults>(); var rootElements = scanTools.TargetElementLocator.LocateRootElements(config.ProcessId); if (rootElements is null || !rootElements.Any()) { return(resultList); } int targetIndex = 1; foreach (var rootElement in rootElements) { resultList.Add(scanTools.Actions.Scan(rootElement, (element, elementId) => { return(ProcessResults(element, elementId, config, scanTools, targetIndex++, rootElements.Count())); })); if (!config.AreMultipleScanRootsEnabled) { // We only want to scan the first window so just break for loop here break; } } return(resultList); }
internal Scanner(Config config, IScanTools scanTools) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } _config = config; _scanTools = scanTools; }
internal Scanner(Config config, IScanTools scanTools) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.OutputFileHelper == null) { throw new ArgumentException(ErrorMessages.ScanToolsOutputFileHelperNull, nameof(scanTools)); } _config = config; _scanTools = scanTools; }
private static OutputFile WriteOutputFiles(OutputFileFormat outputFileFormat, IScanTools scanTools, A11yElement element, Guid elementId) { if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.OutputFileHelper == null) { throw new ArgumentException(ErrorMessages.ScanToolsOutputFileHelperNull, nameof(scanTools)); } string a11yTestOutputFile = null; if (outputFileFormat.HasFlag(OutputFileFormat.A11yTest)) { scanTools.Actions.CaptureScreenshot(elementId); a11yTestOutputFile = scanTools.OutputFileHelper.GetNewA11yTestFilePath(); if (a11yTestOutputFile == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.VariableNull, nameof(a11yTestOutputFile))); } scanTools.Actions.SaveA11yTestFile(a11yTestOutputFile, element, elementId); } return(OutputFile.BuildFromA11yTestFile(a11yTestOutputFile)); }
private static ScanResults ProcessResults(A11yElement element, Guid elementId, Config config, IScanTools scanTools) { if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.ResultsAssembler == null) { throw new ArgumentException(ErrorMessages.ScanToolsResultsAssemblerNull, nameof(scanTools)); } var results = scanTools.ResultsAssembler.AssembleScanResultsFromElement(element); if (results.ErrorCount > 0) { results.OutputFile = WriteOutputFiles(config.OutputFileFormat, scanTools, element, elementId); } return(results); }
private static OutputFile WriteOutputFiles(OutputFileFormat outputFileFormat, IScanTools scanTools, A11yElement element, Guid elementId) { if (scanTools?.OutputFileHelper == null) { throw new ArgumentNullException(nameof(scanTools.OutputFileHelper)); } string a11yTestOutputFile = null; if (outputFileFormat.HasFlag(OutputFileFormat.A11yTest)) { scanTools.Actions.CaptureScreenshot(elementId); a11yTestOutputFile = scanTools.OutputFileHelper.GetNewA11yTestFilePath(); if (a11yTestOutputFile == null) { throw new InvalidOperationException(nameof(a11yTestOutputFile)); } scanTools.Actions.SaveA11yTestFile(a11yTestOutputFile, element, elementId); } #if NOT_CURRENTLY_SUPPORTED if (locationHelper.IsSarifExtension()) // SaveAction.SaveSarifFile(outputFileHelper.GetNewSarifFilePath(), ec2.Id, !locationHelper.IsAllOption()); #endif return(OutputFile.BuildFromA11yTestFile(a11yTestOutputFile)); }
private static ScanResults ProcessResults(A11yElement element, Guid elementId, Config config, IScanTools scanTools, int targetIndex, int targetCount) { if (scanTools == null) { throw new ArgumentNullException(nameof(scanTools)); } if (scanTools.ResultsAssembler == null) { throw new ArgumentException(ErrorMessages.ScanToolsResultsAssemblerNull, nameof(scanTools)); } var results = scanTools.ResultsAssembler.AssembleScanResultsFromElement(element); if (config.AreMultipleScanRootsEnabled) { results.OutputFile = WriteOutputFiles(config.OutputFileFormat, scanTools, element, elementId, (name) => $"{name}_{targetIndex}_of_{targetCount}"); } else { if (results.ErrorCount > 0) { results.OutputFile = WriteOutputFiles(config.OutputFileFormat, scanTools, element, elementId, null); } } return(results); }