private async Task <PowerConsoleToolWindow> GetPowershellConsole()
        {
            IVsWindowFrame         window       = null;
            PowerConsoleToolWindow powerConsole = null;
            var powerConsoleToolWindowGUID      = new Guid("0AD07096-BBA9-4900-A651-0598D26F6D24");
            var stopwatch = Stopwatch.StartNew();

            var uiShell = ServiceLocator.GetInstance <IVsUIShell>();

            // Open PMC in VS
            do
            {
                if (VSConstants.S_OK == uiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, powerConsoleToolWindowGUID, out window))
                {
                    window.Show();
                }
                else
                {
                    Thread.Sleep(100);
                }
            }while (stopwatch.Elapsed < _timeout && window == null);

            // Get PowerConsoleToolWindow from the VS frame
            if (window != null)
            {
                if (VSConstants.S_OK == window.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out var toolPane))
                {
                    powerConsole = (PowerConsoleToolWindow)toolPane;
                    while (!powerConsole.IsLoaded && stopwatch.Elapsed < _timeout)
                    {
                        Thread.Sleep(100);
                    }

                    var dispatcherStarted = false;

                    while (!dispatcherStarted && stopwatch.Elapsed < _timeout)
                    {
                        try
                        {
                            await powerConsole.StartDispatcherAsync();

                            dispatcherStarted = true;
                        }
                        catch
                        {
                            // Ignore MEF cache exceptions here and retry. It is unclear why this happens
                            // but when running outside of Apex tests the same VSIX works fine.
                            Thread.Sleep(100);
                        }
                    }

                    while (!powerConsole.IsHostSuccessfullyInitialized() && stopwatch.Elapsed < _timeout)
                    {
                        Thread.Sleep(100);
                    }
                }
            }

            return(powerConsole);
        }
Example #2
0
        private PowerConsoleToolWindow GetPowershellConsole()
        {
            IVsWindowFrame         window       = null;
            PowerConsoleToolWindow powerConsole = null;
            var powerConsoleToolWindowGUID      = new Guid("0AD07096-BBA9-4900-A651-0598D26F6D24");
            var stopwatch = Stopwatch.StartNew();
            var timeout   = TimeSpan.FromMinutes(5);

            var uiShell = ServiceLocator.GetInstance <IVsUIShell>();

            // Open PMC in VS
            do
            {
                if (VSConstants.S_OK == uiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, powerConsoleToolWindowGUID, out window))
                {
                    window.Show();
                }
                else
                {
                    Thread.Sleep(100);
                }
            }while (stopwatch.Elapsed < timeout && window == null);

            // Get PowerConsoleToolWindow from the VS frame
            if (window != null)
            {
                if (VSConstants.S_OK == window.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out var toolPane))
                {
                    powerConsole = (PowerConsoleToolWindow)toolPane;
                    while (!powerConsole.IsLoaded && stopwatch.Elapsed < timeout)
                    {
                        Thread.Sleep(100);
                    }
                    powerConsole.StartDispatcher();
                    while (!powerConsole.IsHostSuccessfullyInitialized() && stopwatch.Elapsed < timeout)
                    {
                        Thread.Sleep(100);
                    }
                }
            }

            return(powerConsole);
        }
Example #3
0
 public ApexTestConsole(IWpfConsole WpfConsole, PowerConsoleToolWindow consoleWindow)
 {
     _wpfConsole    = WpfConsole ?? throw new ArgumentNullException(nameof(WpfConsole));
     _consoleWindow = consoleWindow ?? throw new ArgumentNullException(nameof(consoleWindow));
 }