Esempio n. 1
0
        private bool EnsureConnected(VsixTestCase testCase, IMessageBus messageBus)
        {
            if (!EnsureStarted(testCase, messageBus))
            {
                return(false);
            }

            if (_runner == null)
            {
                var hostUrl        = RemotingUtil.GetHostUri(_pipeName);
                var clientPipeName = Guid.NewGuid().ToString("N");

                _clientChannel = RemotingUtil.CreateChannel(Constants.ClientChannelName + clientPipeName, clientPipeName);
                _runner        = (IVsRemoteRunner)RemotingServices.Connect(typeof(IVsRemoteRunner), hostUrl);
            }

            var retries   = 0;
            var connected = false;
            var sleep     = _settings.RetrySleepInterval;

            while (retries++ <= _settings.RemoteConnectionRetries && !(connected = TryPing(_runner)))
            {
                Stop();
                if (!EnsureStarted(testCase, messageBus))
                {
                    return(false);
                }

                if (_runner == null)
                {
                    var hostUrl        = RemotingUtil.GetHostUri(_pipeName);
                    var clientPipeName = Guid.NewGuid().ToString("N");

                    _clientChannel = RemotingUtil.CreateChannel(Constants.ClientChannelName + clientPipeName, clientPipeName);
                    _runner        = (IVsRemoteRunner)RemotingServices.Connect(typeof(IVsRemoteRunner), hostUrl);
                }

                Thread.Sleep(sleep);
                sleep = sleep * retries;
            }

            if (!connected)
            {
                Stop();
                var message = Strings.VsClient.FailedToConnect(testCase.VisualStudioVersion, testCase.RootSuffix);
                messageBus.QueueMessage(new TestFailed(new XunitTest(testCase, testCase.DisplayName), 0, message, new InvalidOperationException(message)));
                return(false);
            }

            var remoteVars = _runner.GetEnvironment();

            Constants.Tracer.TraceEvent(TraceEventType.Verbose, 0, Strings.VsClient.RemoteEnvVars(string.Join(Environment.NewLine,
                                                                                                              remoteVars.Select(x => "    " + x[0] + "=" + x[1]))));

            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Invoked by the <see cref="VsStartup.Start"/> injected managed method in the
 /// VS process.
 /// </summary>
 public void Start()
 {
     _channel = RemotingUtil.CreateChannel(Constants.ServerChannelName, _pipeName);
 }