private string GetTargetFilterString(FilterPair filterPair)
 {
     if (Guid.Equals(new Guid(m_serverDiffEngine.Session.LeftMigrationSourceUniqueId), new Guid(filterPair.FilterItem[0].MigrationSourceUniqueId)))
     {
         return(VCTranslationService.TrimTrailingPathSeparator(filterPair.FilterItem[1].FilterString));
     }
     else
     {
         return(VCTranslationService.TrimTrailingPathSeparator(filterPair.FilterItem[0].FilterString));
     }
 }
        public override void PreAnalysis(AnalysisContext analysisContext)
        {
            m_configurationService = analysisContext.TookitServiceContainer.GetService(typeof(ConfigurationService)) as ConfigurationService;
            if (m_configurationService == null)
            {
                throw new ArgumentNullException("ConfigurationService");
            }
            m_serverPathTranslationService = (IServerPathTranslationService)((analysisContext.TookitServiceContainer.GetService(typeof(IServerPathTranslationService)) as IServerPathTranslationService));
            if (m_serverPathTranslationService == null)
            {
                throw new ArgumentNullException("IServerPathTranslationService");
            }
            m_vcTranslationService = (VCTranslationService)((analysisContext.TookitServiceContainer.GetService(typeof(ITranslationService)) as ITranslationService));
            if (m_vcTranslationService == null)
            {
                throw new ArgumentNullException("ITranslationService");
            }
            m_sourceId = new Guid(m_configurationService.MigrationSource.InternalUniqueId);

            // Get the configured output file path here (or use default) and make sure we can open it for writing

            Dictionary <string, string> addinCustomSettings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            addinCustomSettings.Add(c_symbolLinkOutputFilePathKey, c_defaultSymbolLinkOutputFilePath);
            AddinCustomSettingsHelper.GetAddinCustomSettings(m_configurationService, ReferenceNameString, addinCustomSettings);
            m_symbolLinkOutputFilePath = addinCustomSettings[c_symbolLinkOutputFilePathKey];

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(m_symbolLinkOutputFilePath, false))
                {
                }
            }
            catch (Exception e)
            {
                throw new MigrationException(string.Format(CultureInfo.InvariantCulture, ClearCaseSymbolicLinkMonitorAnalysisAddinResources.UnableToOpenOutputFile,
                                                           m_symbolLinkOutputFilePath, e.Message));
            }
        }
        public override void PreAnalysis(AnalysisContext analysisContext)
        {
            m_configurationService = analysisContext.TookitServiceContainer.GetService(typeof(ConfigurationService)) as ConfigurationService;

            if (m_configurationService != null)
            {
                // Create a HWM and set the initial value
                m_hwmSemaphoreFile = new HighWaterMark <DateTime>(c_semaphoreFileHWNName);
                m_configurationService.RegisterHighWaterMarkWithSession(m_hwmSemaphoreFile);

                Dictionary <string, string> addinCustomSettings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                addinCustomSettings.Add(c_semaphoreFilePath, null);
                addinCustomSettings.Add(c_excludeDateTimeFromLabelName, null);

                AddinCustomSettingsHelper.GetAddinCustomSettings(m_configurationService, ReferenceNameString, addinCustomSettings);
                m_semaphoreFilePath = addinCustomSettings[c_semaphoreFilePath];

                if (string.IsNullOrEmpty(m_semaphoreFilePath))
                {
                    throw new MigrationException(SemaphoreFileAnalysisAddinResources.SemaphoreFilePathNotConfigured);
                }

                if (addinCustomSettings[c_excludeDateTimeFromLabelName] != null &&
                    string.Equals(addinCustomSettings[c_excludeDateTimeFromLabelName], "true", StringComparison.OrdinalIgnoreCase))
                {
                    m_excludeDateTimeFromLabelName = true;
                }
            }
            else
            {
                Debug.Fail("SemaphoreFileAnalysisAddin unable to get ConfigurationService");
                throw new ArgumentNullException("ConfigurationService");
            }

            m_vcTranslationService = analysisContext.TookitServiceContainer.GetService(typeof(ITranslationService)) as VCTranslationService;

            m_sourceId = new Guid(m_configurationService.MigrationSource.InternalUniqueId);
        }
        public Endpoint(
            MonitorWatcher watcher,
            RuntimeEntityModel context,
            RTSession rtSession,
            RTMigrationSource rtMigrationSource,
            bool isRightMigrationSource,
            RTMigrationSource peerMigrationSource)
        {
            m_monitorWatcher = watcher;

            // TODO: Consider moving all of this initialization code to a new EndpointContext class that contains everything that the
            // Poll() method needs to do its job, and then have MonitorWatcher.GetEndpoints() pass the EndpointContext object as the single
            // arg to this constructor.

            this.Context                = context;
            this.RTMigrationSource      = rtMigrationSource;
            this.IsRightMigrationSource = isRightMigrationSource;
            this.PeerRTMigrationSource  = peerMigrationSource;

            BusinessModelManager businessModelManager = new BusinessModelManager();

            if (rtSession.SessionGroup == null)
            {
                rtSession.SessionGroupReference.Load();
            }

            Config = businessModelManager.LoadConfiguration(rtSession.SessionGroup.GroupUniqueId);
            if (Config == null)
            {
                throw new ApplicationException(
                          String.Format(CultureInfo.InvariantCulture, MigrationToolkitResources.SessionGroupNotFound,
                                        rtSession.SessionGroup.GroupUniqueId.ToString()));
            }

            // TODO: Modify ProdviderManager to take a constructor that does not require a Config and that just loads
            // all providers in the Plugins directory, then move this code up to the MonitorWatcher constructor and pass the
            // providerHandlers down as another argument to this constructor
            ProviderManager providerManager = new ProviderManager(Config);
            Dictionary <Guid, ProviderHandler> providerHandlers = providerManager.LoadProvider(new DirectoryInfo(Constants.PluginsFolderName));

            ProviderHandler providerHandler;

            if (!providerHandlers.TryGetValue(this.RTMigrationSource.UniqueId, out providerHandler))
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.ProviderHandlerNotLoadedForMigrationSouce,
                                                  this.RTMigrationSource.FriendlyName));
            }

            Debug.Assert(providerHandler.Provider != null);
            SyncMonitorProvider = providerHandler.Provider.GetService(typeof(ISyncMonitorProvider)) as ISyncMonitorProvider;
            if (SyncMonitorProvider == null)
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture,
                                                                MigrationToolkitResources.ProviderDoesNotImplementISyncMonitor,
                                                                providerHandler.ProviderName));
            }

            // Find the Session object corresponding to the RTSession
            if (Config.SessionGroup != null && Config.SessionGroup.Sessions != null)
            {
                foreach (var aSession in Config.SessionGroup.Sessions.Session)
                {
                    if (string.Equals(aSession.SessionUniqueId, rtSession.SessionUniqueId.ToString(), StringComparison.Ordinal))
                    {
                        Session = aSession;
                        break;
                    }
                }
            }
            if (Session == null)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.SessionNotFoundForMigrationSource,
                                                  rtSession.SessionGroup.GroupUniqueId.ToString(), RTMigrationSource.FriendlyName));
            }

            Guid migrationSourceGuid = new Guid(isRightMigrationSource ? Session.RightMigrationSourceUniqueId : Session.LeftMigrationSourceUniqueId);

            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSource = Config.GetMigrationSource(migrationSourceGuid);
            Session.MigrationSources.Add(migrationSourceGuid, migrationSource);

            var serviceContainer = new ServiceContainer();

            serviceContainer.AddService(typeof(ITranslationService), new SyncMonitorTranslationService(Session));
            // We pass null for the global Configuration to the ConfigurationService constructor because its not handy and not needed in this context
            serviceContainer.AddService(typeof(ConfigurationService), new ConfigurationService(null, Session, migrationSourceGuid));
            SyncMonitorProvider.InitializeServices(serviceContainer);
            SyncMonitorProvider.InitializeClient(migrationSource);

            int filterPairIndex = IsRightMigrationSource ? 1 : 0;

            foreach (var filterPair in Session.Filters.FilterPair)
            {
                if (!filterPair.Neglect)
                {
                    m_filterStrings.Add(VCTranslationService.TrimTrailingPathSeparator(filterPair.FilterItem[filterPairIndex].FilterString));
                }
            }
        }