Example #1
0
        /// <summary>
        /// Clean up the host side.
        /// We do the following steps. Each step is important and must be done whenever previous step throws or not.
        /// - Call HostSide.Cleanup.
        /// - Ask Runner IDE to detach debugger (if attached).
        /// - Dispose m_vsIde.
        /// This should not throw.
        /// </summary>
        private void CleanupHostSide()
        {
            lock (_hostSideLock)
            {
                Contract.Assert(HostSide != null);

                if (HostSide != null)
                {
                    try
                    {
                        HostSide.Cleanup();
                    }
                    catch (Exception ex)    // We don't know what this can throw in advance.
                    {
                        SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter failed to call ITestAdapter.Cleanup: {0}", ex), TestOutcome.Warning);
                    }
                }

                try
                {
                    Contract.Assert(_vsIde != null);
                    _vsIde.Dispose();
                }
                catch (Exception ex)
                {
                    SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter: error shutting down VS IDE: {0}", ex), TestOutcome.Warning);
                }

                _vsIde    = null;
                _hostSide = null;  // Note: host side lifetime is controlled by the addin.
            }
        }
Example #2
0
        /// <summary>
        /// Starts new Visual Studio process and obtains host side from it.
        /// </summary>
        private void CreateHostSide()
        {
            Contract.Assert(!string.IsNullOrEmpty(_workingDir));
            Contract.Assert(_hostSide == null);
            Contract.Assert(_vsIde == null);

            // Start devenv.
            _vsIde = new VisualStudioIde(new VsIdeStartupInfo(_vsRegistryHive, _workingDir));
            _vsIde.ErrorHandler += HostProcessErrorHandler;

            Stopwatch timer = Stopwatch.StartNew();

            do
            {
                try
                {
                    _vsIde.Dte.MainWindow.Visible = true;    // This could be in TestRunConfig options for this host type.
                    break;
                }
                catch (Exception)
                {
                }
                System.Threading.Thread.Sleep(_baseSleepDuration);
            } while (timer.Elapsed < _ideStartupTimeout);

            _hostSide = GetHostSideFromAddin();
        }
        protected override IScopeAnalyzer GetScopeAnalyzer()
        {
            var selectedCSharpDocuments = VisualStudioIde
                                          .GetSelectedVisualStudioProjectItemsWithSubItems()
                                          .Where(item => item.IsCSharpDocument());

            var documents = Workspace.GetRoslynDocumentsFromVisualStudioProjectItems(selectedCSharpDocuments);

            return(new MultipleDocumentsScopeAnalyzer(documents));
        }
Example #4
0
        protected override IScopeAnalyzer GetScopeAnalyzer()
        {
            var selectedCSharpProjects = VisualStudioIde
                                         .GetSelectedVisualStudioProjects()
                                         .Where(project => project.IsCSharpProject());

            var projects = Workspace.GetRoslynProjectsFromVisualStudioProjects(selectedCSharpProjects);

            return(new MultipleProjectsScopeAnalyzer(true, projects.ToArray()));
        }
        /// <summary>
        /// Clean up the host side.
        /// We do the following steps. Each step is important and must be done whenever previous step throws or not.
        /// - Call HostSide.Cleanup.
        /// - Ask Runner IDE to detach debugger (if attached).
        /// - Dispose m_vsIde.
        /// This should not throw.
        /// </summary>
        private void CleanupHostSide()
        {
            lock (_hostSideLock)
            {
                Contract.Assert(HostSide != null);

                if (HostSide != null)
                {
                    try
                    {
                        HostSide.Cleanup();
                    }
                    catch (Exception ex)    // We don't know what this can throw in advance.
                    {
                        SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter failed to call ITestAdapter.Cleanup: {0}", ex), TestOutcome.Warning);
                    }
                }

                try
                {
                    Contract.Assert(_vsIde != null);
                    _vsIde.Dispose();
                }
                catch (InvalidComObjectException)
                {
                    // This exception is always thrown when quitting VS. Nothing
                    // is gained by reporting it for every run.
                }
                catch (Exception ex)
                {
                    SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter: error shutting down VS IDE: {0}", ex), TestOutcome.Warning);
                }

                _vsIde = null;
                _hostSide = null;  // Note: host side lifetime is controlled by the addin.
            }
        }
        /// <summary>
        /// Starts new Visual Studio process and obtains host side from it.
        /// </summary>
        private void CreateHostSide()
        {
            Contract.Assert(!string.IsNullOrEmpty(_workingDir));
            Contract.Assert(_hostSide == null);
            Contract.Assert(_vsIde == null);

            // Start devenv.
            _vsIde = new VisualStudioIde(new VsIdeStartupInfo(_vsRegistryHive, _workingDir));
            _vsIde.ErrorHandler += HostProcessErrorHandler;

            Stopwatch timer = Stopwatch.StartNew();
            do
            {
                try
                {
                    _vsIde.Dte.MainWindow.Visible = true;    // This could be in TestRunConfig options for this host type.
                    break;
                }
                catch (Exception)
                {
                }
                System.Threading.Thread.Sleep(_baseSleepDuration);
            } while (timer.Elapsed < _ideStartupTimeout);

            _hostSide = GetHostSideFromAddin();
        }
Example #7
0
        protected override void IsCommandVisibleAndEnabled(out bool isVisible, out bool isEnabled)
        {
            var selectedItems = VisualStudioIde.GetSelectedVisualStudioItems();

            isVisible = isEnabled = selectedItems.Any(item => item.IsCSharpDocument());
        }
Example #8
0
        protected override void IsCommandVisibleAndEnabled(out bool isVisible, out bool isEnabled)
        {
            var selectedProjects = VisualStudioIde.GetSelectedVisualStudioProjects();

            isVisible = isEnabled = selectedProjects.Any(project => project.IsCSharpProject());
        }