Example #1
0
        private void CreateHostSide()
        {
            // Note: we already have try-catch-Debug.Fail in Initialize that calls this method.
            // Note: registryHive can be null when using HostType attribute. In this case we'll use default hive.
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            // Note: registryHive can be null when using the attribute. That's OK, VsIde will figure out.
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            Debug.Assert(m_hostSide == null, "HA.CreateHostSide: m_hostSide should be null (ignorable).");
            Debug.Assert(m_vsIde == null, "HA.CreateHostSide: m_vsIde should be null (ignorable).");

            // Start devenv.
            m_vsIde = new VisualStudioIde(new VsIdeStartupInfo(m_vsRegistryHive, m_additionalCommandLine, m_workingDir));
            m_vsIde.ErrorHandler += HostProcessErrorHandler;

            bool success = InvokeWithRetry(
                delegate
            {
                m_vsIde.Dte.MainWindow.Visible = true;        // TestRunConfig for this host type could have an option to set main window to visible.
            },
                s_addinWaitTimeout
                );

            if (!success)
            {
                throw new VsIdeTestHostException(Resources.TimedOutCommunicatingToIde);
            }

            m_hostSide = GetHostSideFromAddin();
        }
Example #2
0
        private void CleanupHostSide()
        {
            if (!m_isHostSideDirty)
            {
                return;
            }

            lock (m_hostSideLock)
            {
                //Debug.Assert(HostSide != null);

                if (HostSide != null)
                {
                    try
                    {
                        ((ITestAdapter)HostSide).Cleanup();
                    }
                    catch (Exception ex)    // We don't know what this can throw in advance.
                    {
                        SendResult(Resources.FailedToCallTACleanup(ex), TestOutcome.Warning);
                    }
                }

                // m_runConfig can be null if cleanup is called too early, i.e. before we completed init.
                if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger)
                {
                    // Detach debugger for VS we are going to shut down.
                    //Debug.Assert(m_hostSession != null);
                    if (m_hostSession != null)
                    {
                        try
                        {
                            // Detach debugger but keep HostSession alive for possible attach to restarted VS.
                            m_hostSession.DetachDebugger(m_vsIde.Process.Id);
                        }
                        catch (Exception ex)
                        {
                            SendResult(Resources.FailedToDetachDebugger(ex), TestOutcome.Warning);
                        }
                    }
                }

                if (m_vsIde != null)
                {
                    try
                    {
                        m_vsIde.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SendResult(Resources.ErrorShuttingDownVS(ex), TestOutcome.Warning);
                    }
                }
                m_vsIde           = null;
                m_hostSide        = null;
                m_isHostSideDirty = false;
            }
        }
Example #3
0
        private HostAdapterHostSide GetHostSideFromAddin()
        {
            // Find the Addin.
            // Note: After VS starts addin needs some time to load, so we try a few times.
            IVsIdeTestHostAddin addinLookingFor = null;

            InvokeWithRetry(
                delegate
            {
                foreach (AddIn addin in m_vsIde.Dte.AddIns)
                {
                    // Note: the name of the addin comes from XML file that registers the addin.
                    if (addin.Name == "VsIdeTestHost(EF)")
                    {
                        addinLookingFor = (IVsIdeTestHostAddin)addin.Object;
                        break;
                    }
                }
            },
                delegate
            {
                return(addinLookingFor != null);
            },
                s_addinWaitTimeout
                );

            if (addinLookingFor == null)
            {
                Debug.Fail("HA.GetHostSideFromAddin: timed out but could not get the addin from VS.");
                throw new VsIdeTestHostException(Resources.TimedOutGettingAddin);
            }

            m_testHostAddin = addinLookingFor;
            HostAdapterHostSide hostSide = m_testHostAddin.GetHostSide(); // This can be casted to ITestAdapter.

            Debug.Assert(hostSide != null);

            return(hostSide);
        }
Example #4
0
        /// <summary>
        /// This can be called from OnConnect by Addin AND from GetHostSide by HA.
        /// </summary>
        private void InitHostSide()
        {
            try
            {
                lock (m_hostLock)
                {
                    if (m_hostSide == null)
                    {
                        Debug.Assert(m_applicationObject != null, "HostSide.InitHostSide: m_applicationObject is null!");

                        m_serviceProvider = new ServiceProvider((IOleServiceProvider)m_applicationObject);
                        Debug.Assert(m_serviceProvider != null, "VsIdeTestHostAddin.InitHostSide: failed to init service provider!");

                        m_hostSide = new HostAdapterHostSide(m_serviceProvider);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("HA.InitHostSide: " + ex.ToString());
                throw;
            }
        }
        private void CleanupHostSide()
        {
            if (!m_isHostSideDirty)
                return;

            lock (m_hostSideLock)
            {
                //Debug.Assert(HostSide != null);

                if (HostSide != null)
                {
                    try
                    {
                        ((ITestAdapter)HostSide).Cleanup();
                    }
                    catch (Exception ex)    // We don't know what this can throw in advance.
                    {
                        SendResult(Resources.FailedToCallTACleanup(ex), TestOutcome.Warning);
                    }
                }

                // m_runConfig can be null if cleanup is called too early, i.e. before we comleted init.
                if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger)
                {
                    // Detach debugger for VS we are going to shut down.
                    //Debug.Assert(m_hostSession != null);
                    if (m_hostSession != null)
                    {
                        try
                        {
                            // Detach debugger but keep HostSession alive for possible attach to restarted VS.
                            m_hostSession.DetachDebugger(m_vsIde.Process.Id);
                        }
                        catch (Exception ex)
                        {
                            SendResult(Resources.FailedToDetachDebugger(ex), TestOutcome.Warning);
                        }
                    }
                }

                if (m_vsIde != null)
                {
                    try
                    {
                        m_vsIde.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SendResult(Resources.ErrorShuttingDownVS(ex), TestOutcome.Warning);
                    }
                }
                m_vsIde = null;
                m_hostSide = null;
                m_isHostSideDirty = false;
            }
        }
        private void CreateHostSide()
        {
            // Note: we already have try-catch-Debug.Fail in Initialize that calls this method.
            // Note: registryHive can be null when using HostType attribute. In this case we'll use default hive.
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            // Note: registryHive can be null when using the attribute. That's OK, VsIde will figure out.
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            Debug.Assert(m_hostSide == null, "HA.CreateHostSide: m_hostSide should be null (ignorable).");
            Debug.Assert(m_vsIde == null, "HA.CreateHostSide: m_vsIde should be null (ignorable).");

            // Start devenv.
            m_vsIde = new VisualStudioIde(new VsIdeStartupInfo(m_vsRegistryHive, m_additionalCommandLine, m_workingDir));
            m_vsIde.ErrorHandler += HostProcessErrorHandler;

            bool success = InvokeWithRetry(
                delegate
                {
                    m_vsIde.Dte.MainWindow.Visible = true;    // TestRunConfig for this host type could have an option to set main window to visible.
                },
                s_addinWaitTimeout
            );

            if (!success)
            {
                throw new VsIdeTestHostException(Resources.TimedOutCommunicatingToIde);
            }

            m_hostSide = GetHostSideFromAddin();
        }
        /// <summary>
        /// This can be called from OnConnect by Addin AND from GetHostSide by HA.
        /// </summary>
        private void InitHostSide()
        {
            try
            {
                lock (m_hostLock)
                {
                    if (m_hostSide == null)
                    {
                        Debug.Assert(m_applicationObject != null, "HostSide.InitHostSide: m_applicationObject is null!");

                        m_serviceProvider = new ServiceProvider((IOleServiceProvider)m_applicationObject);
                        Debug.Assert(m_serviceProvider != null, "VsIdeTestHostAddin.InitHostSide: failed to init service provider!");

                        m_hostSide = new HostAdapterHostSide(m_serviceProvider);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("HA.InitHostSide: " + ex.ToString());
                throw;
            }
        }