Beispiel #1
0
        private void LinkResultsWithIdenticalWhere()
        {
            // Walk Results sorted by where, linking those with identical positions and a matching category.
            int beforeIndex = 0, afterIndex = 0;

            while (beforeIndex < Before.Count && afterIndex < After.Count)
            {
                ExtractedResult left  = Before[beforeIndex];
                ExtractedResult right = After[afterIndex];

                int whereCmp = WhereComparer.CompareWhere(left, right);
                if (whereCmp < 0)
                {
                    // Left is in a 'Where' before Right - look at the next Result in 'Before'.
                    beforeIndex++;
                }
                else if (whereCmp > 0)
                {
                    // Right is in a 'Where' before Left - look at the next Result in 'After'.
                    afterIndex++;
                }
                else
                {
                    // The Results have a matching where. If the category matches, link them.
                    if (left.MatchesCategory(right))
                    {
                        LinkIfSimilar(beforeIndex, afterIndex);
                    }

                    // Look at the next pair of Results.
                    beforeIndex++;
                    afterIndex++;
                }
            }
        }
Beispiel #2
0
        private ExtractedResult LastWithUri(ExtractedResult desiredUri, IList <ExtractedResult> set, ref int fromIndex)
        {
            ExtractedResult lastMatch = null;

            // Find the first Result  at fromIndex or later with a Uri *after* the desired one, saving the last Result that matched as we go
            for (; fromIndex < set.Count; ++fromIndex)
            {
                int whereCmp = WhereComparer.CompareFirstArtifactUri(set[fromIndex], desiredUri);

                if (whereCmp == 0)
                {
                    lastMatch = set[fromIndex];
                }
                else if (whereCmp > 0)
                {
                    break;
                }
            }

            // Ensure the index ends at the last match
            if (fromIndex > 0)
            {
                fromIndex--;
            }

            return(lastMatch);
        }
Beispiel #3
0
        private void Add(ExtractedResult result, HashSet <string> otherRunLocations, int index)
        {
            // Find the LocationSpecifier for the Result (the first Uri or FQN also in the other Run)
            string locationSpecifier = WhereComparer.LocationSpecifier(result, otherRunLocations);

            // Add Result attributes used as matching hints in a "bucket" for the Rule x LocationSpecifier x AttributeName
            foreach (WhatComponent component in result.WhatProperties(locationSpecifier))
            {
                Add(component, index);
            }
        }
Beispiel #4
0
        private void BuildMaps()
        {
            // Identify all locations used in each log
            HashSet <string> beforeLocationIdentifiers = new HashSet <string>();

            _before.ForEach((result) => WhereComparer.AddLocationIdentifiers(result, beforeLocationIdentifiers));

            HashSet <string> afterLocationIdentifiers = new HashSet <string>();

            _after.ForEach((result) => WhereComparer.AddLocationIdentifiers(result, afterLocationIdentifiers));

            // Populate WhatMap and TrustMap to guide subsequent matching
            BuildMap(_before, _beforeWhatMap, _beforeTrustMap, otherRunLocations: afterLocationIdentifiers);
            BuildMap(_after, _afterWhatMap, _afterTrustMap, otherRunLocations: beforeLocationIdentifiers);

            // Match the TrustMaps to finish determining trust
            _afterTrustMap.CountMatchesWith(_beforeTrustMap);
        }
Beispiel #5
0
        private ExtractedResult FirstWithUri(ExtractedResult desiredUri, IList <ExtractedResult> set, ref int fromIndex)
        {
            // Find the first Result at fromIndex or later with a Uri *matching* the desired one, or null if there aren't any
            for (; fromIndex < set.Count; ++fromIndex)
            {
                int whereCmp = WhereComparer.CompareFirstArtifactUri(set[fromIndex], desiredUri);

                if (whereCmp == 0)
                {
                    return(set[fromIndex]);
                }
                else if (whereCmp > 0)
                {
                    break;
                }
            }

            return(null);
        }
Beispiel #6
0
        private static void BuildMap(List <ExtractedResult> results, WhatMap whatMap, TrustMap trustMap, HashSet <string> otherRunLocations)
        {
            // Populate the WhatMap and TrustMap
            for (int i = 0; i < results.Count; ++i)
            {
                ExtractedResult result = results[i];

                // Find the LocationSpecifier for the Result (the first Uri or FQN also in the other Run)
                string locationSpecifier = WhereComparer.LocationSpecifier(result, otherRunLocations);

                foreach (WhatComponent component in WhatComparer.WhatProperties(result, locationSpecifier))
                {
                    // Add Result attributes used as matching hints in a "bucket" for the Rule x LocationSpecifier x AttributeName
                    whatMap.Add(component, i);

                    // Track attribute usage to determine per-attribute trust
                    trustMap.Add(component);
                }
            }
        }