public string Translate(Guid srcMigrationSourceId, string srcServerPath)
        {
            IServerPathTranslationService srcTranslationService = LookupService(srcMigrationSourceId);
            string canonicalPath = srcTranslationService.TranslateToCanonicalPathCaseSensitive(srcServerPath);

            if (!m_pathValidator.IsSyntaxCorrect(canonicalPath))
            {
                throw new InvalidServerPathException(string.Format(
                                                         MigrationToolkitResources.VCPathTranslationErrVCPathTranslationError_InvalidCanonicalPath,
                                                         canonicalPath));
            }

            string canonicalFilterPath;

            canonicalPath = ApplyFilterMapping(srcMigrationSourceId, canonicalPath, out canonicalFilterPath);

            foreach (Guid sourceId in m_adapterPathTranslationServices.Keys)
            {
                if (!sourceId.Equals(srcMigrationSourceId))
                {
                    IServerPathTranslationService destTranslationService = LookupService(sourceId);
                    return(destTranslationService.TranslateFromCanonicalPath(canonicalPath, canonicalFilterPath));
                }
            }

            throw new ServerPathTranslationException(
                      string.Format(
                          MigrationToolkitResources.Culture,
                          MigrationToolkitResources.VCPathTranslationError_CannotFindFilterString,
                          srcServerPath));
        }
コード例 #2
0
        private bool IsPathMapped(string path, AnalysisContext analysisContext)
        {
            // TraceManager.TraceInformation("IsPathMapped: Entering with path: " + path);
            string translatedPath = m_serverPathTranslationService.TranslateToCanonicalPathCaseSensitive(path);

            // TraceManager.TraceInformation("IsPathMapped: translatedPath: " + translatedPath);
            foreach (MappingEntry mapping in m_configurationService.Filters)
            {
                // TraceManager.TraceInformation("IsPathMapped: mapping.Path: " + mapping.Path);
                string canonicalFilterString = m_serverPathTranslationService.TranslateToCanonicalPathCaseSensitive(mapping.Path);
                // TraceManager.TraceInformation("IsPathMapped: canonicalFilterString: " + canonicalFilterString);
                if (translatedPath.StartsWith(canonicalFilterString, StringComparison.OrdinalIgnoreCase))
                {
                    // TraceManager.TraceInformation("IsPathMapped: returning true");
                    return(true);
                }
            }

            // TraceManager.TraceInformation("IsPathMapped: returning false");
            return(false);
        }
        public override void PostAnalysis(AnalysisContext analysisContext)
        {
            HashSet <string> symbolicLinks = new HashSet <string>();

            // Find symbolic links in all VOB used
            foreach (string vob in m_vobNames)
            {
                FindSymbolicLinks(vob, symbolicLinks);
            }

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(m_symbolLinkOutputFilePath, false))
                {
                    foreach (string symbolicLinkPath in symbolicLinks)
                    {
                        // Translate the symbolLinkPath to the path format used on the target side
                        try
                        {
                            string canonicalPath  = m_serverPathTranslationService.TranslateToCanonicalPathCaseSensitive(symbolicLinkPath);
                            string translatedPath = m_vcTranslationService.GetMappedPath(canonicalPath, m_sourceId);
                            streamWriter.WriteLine(translatedPath);
                        }
                        catch (Exception ex)
                        {
                            TraceManager.TraceWarning(String.Format(CultureInfo.InvariantCulture, "Unable to translate ClearCase Path '{0}': {1}",
                                                                    symbolicLinkPath, ex.ToString()));
                            TraceManager.TraceWarning(String.Format(CultureInfo.InvariantCulture, "Writing untranslated ClearCase Path to '{0}'",
                                                                    m_symbolLinkOutputFilePath));
                            streamWriter.WriteLine(symbolicLinkPath);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new MigrationException(string.Format(CultureInfo.InvariantCulture, ClearCaseSymbolicLinkMonitorAnalysisAddinResources.UnableToOpenOutputFile,
                                                           m_symbolLinkOutputFilePath, e.Message));
            }
        }
        private void TranslateFilterStringPairs(
            Collection <FilterPair> filterStrings,
            Guid leftMigrationSourceId,
            Guid rightMigrationSourceId)
        {
            m_canonicalFilterStringsCloakedOnly.Add(leftMigrationSourceId, new List <string>());
            m_canonicalFilterStringsCloakedOnly.Add(rightMigrationSourceId, new List <string>());

            IServerPathTranslationService leftPathTranslationService  = LookupService(leftMigrationSourceId);
            IServerPathTranslationService rightPathTranslationService = LookupService(rightMigrationSourceId);

            foreach (FilterPair filterPair in filterStrings)
            {
                Debug.Assert(filterPair.FilterItem.Count == 2, "FilterPairs must have exactly two items");
                string leftCanonicalFilter  = null;
                string rightCanonicalFilter = null;

                for (int i = 0; i < 2; ++i)
                {
                    FilterItem filterItem = filterPair.FilterItem[i];
                    string     adapterSpecificFilterStr     = filterItem.FilterString;
                    Guid       filterOwnerMigrationSourceId = new Guid(filterItem.MigrationSourceUniqueId);

                    if (leftMigrationSourceId.Equals(filterOwnerMigrationSourceId))
                    {
                        leftCanonicalFilter = leftPathTranslationService.TranslateToCanonicalPathCaseSensitive(adapterSpecificFilterStr);

                        if (m_pathValidator.IsSyntaxCorrect(leftCanonicalFilter))
                        {
                            leftCanonicalFilter = RemoveTailingDelimiter(leftCanonicalFilter);
                        }

                        if (filterPair.Neglect)
                        {
                            m_canonicalFilterStringsCloakedOnly[leftMigrationSourceId].Add(leftCanonicalFilter);
                        }
                    }
                    else if (rightMigrationSourceId.Equals(filterOwnerMigrationSourceId))
                    {
                        rightCanonicalFilter = rightPathTranslationService.TranslateToCanonicalPathCaseSensitive(adapterSpecificFilterStr);

                        if (m_pathValidator.IsSyntaxCorrect(rightCanonicalFilter))
                        {
                            rightCanonicalFilter = RemoveTailingDelimiter(rightCanonicalFilter);
                        }

                        if (filterPair.Neglect)
                        {
                            m_canonicalFilterStringsCloakedOnly[rightMigrationSourceId].Add(rightCanonicalFilter);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(leftCanonicalFilter) && !string.IsNullOrEmpty(rightCanonicalFilter))
                {
                    if (!m_canonicalFilterStrings.ContainsKey(leftMigrationSourceId))
                    {
                        m_canonicalFilterStrings.Add(leftMigrationSourceId, new Dictionary <string, string>());
                    }

                    if (!m_canonicalFilterStrings.ContainsKey(rightMigrationSourceId))
                    {
                        m_canonicalFilterStrings.Add(rightMigrationSourceId, new Dictionary <string, string>());
                    }

                    // there should be no 1:M filter mapping in the config
                    if (!m_canonicalFilterStrings[leftMigrationSourceId].ContainsKey(leftCanonicalFilter) &&
                        !m_canonicalFilterStrings[rightMigrationSourceId].ContainsKey(rightCanonicalFilter))
                    {
                        m_canonicalFilterStrings[leftMigrationSourceId].Add(leftCanonicalFilter, rightCanonicalFilter);
                        m_canonicalFilterStrings[rightMigrationSourceId].Add(rightCanonicalFilter, leftCanonicalFilter);
                    }
                }
            }
        }