internal LogicalLocation CreateLogicalLocation(LogicalLocationVersionOne v1LogicalLocation, string fullyQualifiedName, string logicalLocationKey)
        {
            LogicalLocation logicalLocation = null;

            int parentIndex = -1;

            if (!string.IsNullOrEmpty(v1LogicalLocation.ParentKey) &&
                _v1KeyToV2LogicalLocationMap.TryGetValue(v1LogicalLocation.ParentKey, out LogicalLocation parentLogicalLocation))
            {
                _v2LogicalLocationToIndexMap.TryGetValue(parentLogicalLocation, out parentIndex);
            }

            _v1LogicalLocationKeyToDecoratedNameMap.TryGetValue(logicalLocationKey, out string decoratedName);

            if (v1LogicalLocation != null)
            {
                logicalLocation = new LogicalLocation
                {
                    Kind = v1LogicalLocation.Kind,
                    Name = v1LogicalLocation.Name,
                    FullyQualifiedName = fullyQualifiedName != v1LogicalLocation.Name ? fullyQualifiedName : null,
                    DecoratedName      = decoratedName,
                    ParentIndex        = parentIndex
                };
            }

            return(logicalLocation);
        }
        private void PopulateLogicalLocation(
            Run v2Run,
            IDictionary <string, LogicalLocationVersionOne> v1LogicalLocations,
            IDictionary <string, string> fullyQualifiedNameToDecoratedNameMap,
            IDictionary <string, string> keyToFullyQualifiedNameMap,
            string logicalLocationKey,
            LogicalLocationVersionOne v1LogicalLocation,
            HashSet <string> populatedKeys)
        {
            // We saw and populated this one previously, because it was a parent to
            // a logical location that we encountered earlier
            if (populatedKeys.Contains(logicalLocationKey))
            {
                return;
            }

            if (v1LogicalLocation.ParentKey != null && !populatedKeys.Contains(v1LogicalLocation.ParentKey))
            {
                // Ensure that any parent has been populated
                PopulateLogicalLocation(
                    v2Run, v1LogicalLocations,
                    fullyQualifiedNameToDecoratedNameMap,
                    keyToFullyQualifiedNameMap,
                    v1LogicalLocation.ParentKey,
                    v1LogicalLocations[v1LogicalLocation.ParentKey],
                    populatedKeys);
            }

            if (!keyToFullyQualifiedNameMap.TryGetValue(logicalLocationKey, out string fullyQualifiedName))
            {
                // If we don't find a remapping, the dictionary key itself comprises
                // the fully qualified name.
                fullyQualifiedName = logicalLocationKey;
            }

            // Create the logical location from the v1 version
            LogicalLocation logicalLocation = CreateLogicalLocation(v1LogicalLocation, fullyQualifiedName, logicalLocationKey);

            // Remember the index that is associated with the new logical location
            _v2LogicalLocationToIndexMap[logicalLocation] = v2Run.LogicalLocations.Count;

            // Store the old v1 look-up key for the new logical location
            // We will use this to generate the index when we walk results
            // v1 key -> logical location -> logical location index
            _v1KeyToV2LogicalLocationMap[logicalLocationKey] = logicalLocation;

            v2Run.LogicalLocations.Add(logicalLocation);

            populatedKeys.Add(logicalLocationKey);
        }
        internal LogicalLocation CreateLogicalLocation(LogicalLocationVersionOne v1LogicalLocation)
        {
            LogicalLocation logicalLocation = null;

            if (v1LogicalLocation != null)
            {
                logicalLocation = new LogicalLocation
                {
                    Kind      = v1LogicalLocation.Kind,
                    Name      = v1LogicalLocation.Name,
                    ParentKey = v1LogicalLocation.ParentKey
                };
            }

            return(logicalLocation);
        }
        internal LogicalLocationVersionOne CreateLogicalLocationVersionOne(LogicalLocation v2LogicalLocation)
        {
            LogicalLocationVersionOne logicalLocation = null;
            string parentKey = null;

            if (_currentV2Run.LogicalLocations != null && v2LogicalLocation.ParentIndex > -1)
            {
                parentKey = _currentV2Run.LogicalLocations[v2LogicalLocation.ParentIndex].FullyQualifiedName;
            }

            if (v2LogicalLocation != null)
            {
                logicalLocation = new LogicalLocationVersionOne
                {
                    Kind      = v2LogicalLocation.Kind,
                    Name      = v2LogicalLocation.Name,
                    ParentKey = parentKey
                };
            }

            return(logicalLocation);
        }