Beispiel #1
0
        private ITestAdapter GetHostSideFromAddin()
        {
            // Find the Addin.
            // Note: After VS starts addin needs some time to load, so we try a few times.
            AddIn addinLookingFor = null;

            Stopwatch timer = Stopwatch.StartNew();

            try
            {
                do
                {
                    try
                    {
                        // There is no index-by-name API, so we have to check all addins.
                        foreach (AddIn addin in m_vsIde.Dte.AddIns)
                        {
                            if (addin.Name == Constants.VsAddinName)
                            {
                                addinLookingFor = addin;
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // Catch all exceptions to prevent intermittent failures such as COMException (0x8001010A)
                        // while VS has not started yet. Just retry again until we timeout.
                    }

                    if (addinLookingFor != null)
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(RegistrySettings.BaseSleepDuration);
                } while (timer.Elapsed < s_addinWaitTimeout);
            }
            finally
            {
                timer.Stop();
            }

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

            m_testHostAddin = (IVsIdeTestHostAddin)addinLookingFor.Object;
            ITestAdapter hostSide = m_testHostAddin.GetHostSide();

            Debug.Assert(hostSide != null);

            return(hostSide);
        }
Beispiel #2
0
        /// <summary>
        /// Obtain host side from the addin.
        /// </summary>
        /// <returns></returns>
        private ITestAdapter GetHostSideFromAddin()
        {
            // Find the Addin.
            // Note: After VS starts addin needs some time to load, so we try a few times.
            AddIn addinLookingFor = null;

            Stopwatch timer = Stopwatch.StartNew();

            try
            {
                do
                {
                    try
                    {
                        // There is no index-by-name API, so we have to check all addins.
                        foreach (AddIn addin in _vsIde.Dte.AddIns)
                        {
                            if (addin.Name == VsAddinName)
                            {
                                addinLookingFor = addin;
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // Catch all exceptions to prevent intermittent failures such as COMException (0x8001010A)
                        // while VS has not started yet. Just retry again until we timeout.
                    }

                    if (addinLookingFor != null)
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(_baseSleepDuration);
                } while (timer.Elapsed < _addinWaitTimeout);
            }
            finally
            {
                timer.Stop();
            }

            if (addinLookingFor == null)
            {
                throw new VsIdeTestHostException("Timed out getting Vs Ide Test Host Add-in from Visual Studio. Please make sure that the Add-in is installed and started when VS starts (use Tools->Add-in Manager).");
            }

            _testHostAddin = (IVsIdeTestHostAddin)addinLookingFor.Object;
            ITestAdapter hostSide = _testHostAddin.GetHostSide();

            Contract.Assert(hostSide != null);

            return(hostSide);
        }
Beispiel #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);
        }
        /// <summary>
        /// Obtain host side from the addin.
        /// </summary>
        /// <returns></returns>
        private void GetHostSideFromAddin()
        {
            // Find the Addin.
            // Note: After VS starts addin needs some time to load, so we try a few times.
            AddIn addinLookingFor = null;

            Stopwatch timer = Stopwatch.StartNew();
            try
            {
                do
                {
                    try
                    {
                        // There is no index-by-name API, so we have to check all addins.
                        foreach (AddIn addin in dte.AddIns)
                        {
                            if (addin.Name == VSAddInName)
                            {
                                addinLookingFor = addin;
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // Catch all exceptions to prevent intermittent failures such as COMException (0x8001010A)
                        // while VS has not started yet. Just retry again until we timeout.
                    }

                    if (addinLookingFor != null)
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(_baseSleepDuration);
                } 
                while (timer.Elapsed < _addinWaitTimeout);
            }
            finally
            {
                timer.Stop();
            }

            if (addinLookingFor == null)
            {
                throw new VsIdeTestHostException("Timed out getting Vs Ide Test Host Add-in from Visual Studio. Please make sure that the Add-in is installed and started when VS starts (use Tools->Add-in Manager).");
            }

            _testHostAddin = (IVsIdeTestHostAddin)addinLookingFor.Object;
            ITestAdapter hostSide = _testHostAddin.GetHostSide();
            Contract.Assert(hostSide != null);
        }       
        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;
        }