Beispiel #1
0
 /// <summary>
 /// Tries to find the issue repository connector identified by yhe <paramref name="name"/>.
 /// </summary>
 /// <returns>true if the connector exists, false otherwise</returns>
 public bool TryGetConnector(string name, out IssueRepositoryConnector connector)
 {
     connector = null;
     if (_nameConnectorMap != null
         && _nameConnectorMap.Count > 0)
     {
         return _nameConnectorMap.TryGetValue(name, out connector);
     }
     return false;
 }
 private IssueRepositoryConfigurationPage GetConfigurationPageFor(IssueRepositoryConnector connector, ref bool needsCurrentSettings)
 {
     if (connector == null)
     {
         return null;
     }
     if (_connectorPageMap == null)
     {
         _connectorPageMap = new Dictionary<string, IssueRepositoryConfigurationPage>();
     }
     IssueRepositoryConfigurationPage configPage = null;
     if (_connectorPageMap.ContainsKey(connector.Name))
     {
         configPage = _connectorPageMap[connector.Name];
     }
     else
     {
         Exception exception = null;
         try
         {
             // triggers connector package initialization
             configPage = connector.ConfigurationPage;
         }
         catch (Exception exc)
         {
             exception = exc;
         }
         if (configPage == null)
         {
             // use a dummy configuration page in case where connector does not provide a configuration page or
             // if an exception is thrown while initializing the connector.
             configPage = exception == null ?
                 new DummyIssueRepositoryConfigurationPage(string.Format("'{0}' does not provide a configuration page.", connector.Name))
                 : new DummyIssueRepositoryConfigurationPage(exception);
         }
         _connectorPageMap.Add(connector.Name, configPage);
         needsCurrentSettings = true;
     }
     return configPage;
 }
        private void UpdatePageFor(IssueRepositoryConnector connector)
        {
            configPagePanel.Controls.Clear();

            bool needsCurrentSettings = false;
            _configPage = GetConfigurationPageFor(connector, ref needsCurrentSettings);

            if (_connectorPageControlMap == null)
            {
                _connectorPageControlMap = new Dictionary<string, Control>();
            }

            Control newControl = null;
            if (!_connectorPageControlMap.TryGetValue(connector.Name, out newControl))
            {
                newControl = GetControlFor(_configPage);
                newControl.Dock = DockStyle.Fill;
                _connectorPageControlMap.Add(connector.Name, newControl);
            }

            // setup config page
            if (_configPage != null)
            {
                _configPage.OnPageEvent += new EventHandler<ConfigPageEventArgs>(_configPage_OnPageEvent);
            }

            configPagePanel.Controls.Add(newControl);

            if (_configPage != null && needsCurrentSettings)
            {
                BeginInvoke((DoSomething)delegate()
                {
                    IssueRepositorySettings currentSettings = CurrentSolutionSettings;
                    if (currentSettings != null
                        && string.Equals(currentSettings.ConnectorName, connector.Name))
                    {
                        _configPage.Settings = currentSettings;
                    }
                });
            }
        }
        private void connectorComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            connectorComboBox.Enabled = false;

            try
            {
                if (_configPage != null)
                {
                    // remove the page event handler from the current page
                    _configPage.OnPageEvent -= new EventHandler<ConfigPageEventArgs>(_configPage_OnPageEvent);
                }

                _connector = connectorComboBox.SelectedItem as IssueRepositoryConnector;

                // if the dummy connector is selected and current settings are not null
                // enable ok button to enable removing existing settings
                // otherwise, disable ok button. it will be enabled when the selected connector page raises "page complete" event
                okButton.Enabled = CurrentSolutionSettings != null
                    && _connector is DummyConnector;

                UpdatePageFor(_connector);
            }
            finally
            {
                connectorComboBox.Enabled = true;
            }
        }