Exemple #1
0
 /// <summary>
 /// Initialize the editor to a default state based on given test run.
 /// </summary>
 /// <param name="serviceProvider">VS Service Provider.</param>
 /// <param name="run">Obselete. Always null.</param>
 void IRunConfigurationEditor.Initialize(System.IServiceProvider serviceProvider, TestRun run)
 {
     // Initialize to something like: 7.0, 7.1, 8.0, 9.0, 10.0
     foreach (string version in VsRegistry.GetVersions())
     {
         m_hiveCombo.Items.Add(version);
     }
 }
Exemple #2
0
 /// <summary>
 /// Main editor is asking the control for the current host specific data.
 /// </summary>
 /// <returns></returns>
 IHostSpecificRunConfigurationData IRunConfigurationCustomHostEditor.GetData()
 {
     if (m_data == null)
     {
         m_data = new RunConfigData(VsRegistry.GetDefaultVersion());
     }
     return(m_data);
 }
Exemple #3
0
        /// <summary>
        /// Create a Visual Studio process.
        /// </summary>
        /// <param name="info">Startup information.</param>
        private void StartNewInstance(VsIdeStartupInfo startupInfo)
        {
            try
            {
                Debug.Assert(startupInfo != null);
                Debug.Assert(m_process == null, "VisualStudioIde.StartNewInstance: m_process should be null!");

                Process process = new Process();
                process.StartInfo.UseShellExecute = false;
                if (startupInfo.WorkingDirectory != null)
                {
                    process.StartInfo.WorkingDirectory = startupInfo.WorkingDirectory;
                }

                process.StartInfo.FileName = VsRegistry.GetVsLocation(startupInfo.RegistryHive);
                Debug.Assert(!string.IsNullOrEmpty(process.StartInfo.FileName));

                // Note that this needs to be partial (not $-terminated) as we partially match/replace.
                Regex versionRegex = new Regex(@"^[0-9]+\.[0-9]+");

                string hiveVersion = versionRegex.Match(startupInfo.RegistryHive).Value;
                string hiveSuffix  = versionRegex.Replace(startupInfo.RegistryHive, string.Empty);

                if (!string.IsNullOrEmpty(hiveSuffix))
                {
                    process.StartInfo.Arguments = "/RootSuffix " + hiveSuffix;
                }

                process.Exited += new EventHandler(ProcessExited);
                process.EnableRaisingEvents = true;

                if (!process.Start())
                {
                    throw new VsIdeTestHostException(Resources.FailedToStartVSProcess);
                }

                m_process = process;

                string progId = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", VisualStudioIde.BaseProgId, hiveVersion);
                m_dte = GetDteFromRot(progId, m_process.Id);
                if (m_dte == null)
                {
                    throw new VsIdeTestHostException(Resources.FailedToGetDte);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("VsIde.StartNewInstance: " + ex.ToString());
                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// Handle the event that core (non-host and not-test-specific) run config data are modified outside this editor.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="dirtyEventArgs">contains run config object that is changed outside</param>
        void IRunConfigurationEditor.OnCommonDataDirty(object sender, CommonRunConfigurationDirtyEventArgs dirtyEventArgs)
        {
            // Out test config does not depend on other data contained in the run config
            // but for the case when nobody modifies our config we still want to have our default section in RC,
            // that's why when the user switches hosts to VS IDE and we did not exist we say we are dirty, and get data will return our data.
            if (m_data == null)
            {
                SetDirty();

                // Select 1st item
                if (m_hiveCombo.SelectedIndex < 0)
                {
                    m_hiveCombo.SelectedItem = VsRegistry.GetDefaultVersion();
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructor. Starts new instance of VS IDE.
        /// </summary>
        public VisualStudioIde(VsIdeStartupInfo info)
        {
            Debug.Assert(info != null);

            if (string.IsNullOrEmpty(info.RegistryHive))
            {
                info.RegistryHive = VsRegistry.GetDefaultVersion();
                if (string.IsNullOrEmpty(info.RegistryHive))
                {
                    // Please no Debug.Assert. This is a valid case.
                    throw new VsIdeTestHostException(string.Format(CultureInfo.InvariantCulture, Resources.CannotFindVSInstallation, info.RegistryHive));
                }
            }

            StartNewInstance(info);
        }
Exemple #6
0
        [SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")] // Taking care of rightAlign is not important for this sample.
        void IRunConfigurationCustomHostEditor.SetData(IHostSpecificRunConfigurationData data)
        {
            string latestVersion = VsRegistry.GetDefaultVersion();  // Throws if VS is not installed.

            RunConfigData vsIdeHostData = data as RunConfigData;

            if (vsIdeHostData == null)
            {
                vsIdeHostData = new RunConfigData(VsRegistry.GetDefaultVersion());
            }
            else if (!m_hiveCombo.Items.Contains(vsIdeHostData.RegistryHive))
            {
                // If .testrunconfig file has VS version that we do not have in combobox,
                // show message box and use default version.
                MessageBox.Show(
                    this,
                    string.Format(CultureInfo.InvariantCulture, Resources.WrongVSVersionPassedToRunConfigControl,
                                  vsIdeHostData.RegistryHive, latestVersion),
                    Resources.MicrosoftVisualStudio);

                vsIdeHostData = new RunConfigData(latestVersion);
            }

            if ((object)m_data != (object)vsIdeHostData)
            {
                SetDirty();
            }

            // Set the data.
            m_data = vsIdeHostData;

            int selectedIndex = m_hiveCombo.Items.IndexOf(vsIdeHostData.RegistryHive);

            if (selectedIndex < 0)
            {
                selectedIndex = m_hiveCombo.Items.IndexOf(latestVersion);
                Debug.Assert(selectedIndex >= 0);
            }
            if (selectedIndex >= 0)
            {
                m_hiveCombo.SelectedIndex = selectedIndex;
            }
        }