Esempio n. 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();
        }
Esempio n. 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;
            }
        }
        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();
        }