Example #1
0
        /// <summary>
        /// internal ctor - allows hooking out the ProcessLauncher for testing
        /// </summary>
        internal OutputFileLocation(string file, A11yElement element, Func <ProcessStartInfo, Process> processLauncher)
        {
            file.ArgumentIsNotTrivialString(nameof(file));
            element.ArgumentIsNotNull(nameof(element));

            try
            {
                _file = Path.GetFullPath(file);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                throw new ArgumentException("Unable to get full path to file: " + file, nameof(file), e);
            }
#pragma warning restore CA1031 // Do not catch general exception types

            if (!File.Exists(_file))
            {
                throw new ArgumentException("File does not exist: " + _file, nameof(file));
            }

            _elementId    = element.UniqueId;
            _processStart = processLauncher;
            Source        = _file;
            Id            = _elementId.ToString(CultureInfo.InvariantCulture);
        }
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="element">The element being fingerprinted</param>
        /// <param name="ruleId">The RuleIds value associated with this rule</param>
        /// <param name="status">The status of this rule for this element</param>
        public ScanResultFingerprint(A11yElement element, RuleId ruleId, ScanStatus status)
        {
            element.ArgumentIsNotNull(nameof(element));

            List <FingerprintContribution> contributions = new List <FingerprintContribution>
            {
                new FingerprintContribution("RuleId", ruleId.ToString()),
                new FingerprintContribution("Level", status.ToResultLevelString()),
            };

            AddRuleSpecificContributions(contributions, ruleId, element);

            A11yElement parent        = element.Parent;
            A11yElement grandparent   = parent?.Parent;
            int         ancestorLevel = 0;

            while (true)
            {
                bool ignoreNameProperty = (ancestorLevel > 0) && (grandparent == null);

                AddRuleAgnosticContributions(contributions, element, ancestorLevel++, ignoreNameProperty);

                if (grandparent == null)
                {
                    break;
                }

                element     = parent;
                parent      = grandparent;
                grandparent = parent?.Parent;
            }

            // Sort the list to help with comparisons
            contributions.Sort();
            Contributions = contributions;
        }