public static async Task <Stream> RequestServiceAsync(
            HostWorkspaceServices services,
            HubClient client,
            RemoteServiceName serviceName,
            CancellationToken cancellationToken)
        {
            var isServerGC = RemoteHostOptions.IsServiceHubProcessServerGC(services);
            var isCoreClr  = RemoteHostOptions.IsServiceHubProcessCoreClr(services);

            // Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
            await TaskScheduler.Default;

            var descriptor = new ServiceHub.Client.ServiceDescriptor(serviceName.ToString(isServerGC, isCoreClr));

            try
            {
                return(await client.RequestServiceAsync(descriptor, cancellationToken).ConfigureAwait(false));
            }
            catch (Exception e) when(ReportNonFatalWatson(e, cancellationToken))
            {
                // TODO: Once https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1040692.
                // ServiceHub may throw non-cancellation exceptions if it is called after VS started to shut down,
                // even if our cancellation token is signaled. Cancel the operation and do not report an error in these cases.
                //
                // If ServiceHub did not throw non-cancellation exceptions when cancellation token is signaled,
                // we can assume that these exceptions indicate a failure and should be reported to the user.
                cancellationToken.ThrowIfCancellationRequested();

                services.GetService <IErrorReportingService>()?.ShowRemoteHostCrashedErrorInfo(e);

                // TODO: Propagate the original exception (see https://github.com/dotnet/roslyn/issues/40476)
                throw new SoftCrashException("Unexpected exception from HubClient", e, cancellationToken);
            }
Example #2
0
        public async Task <Optional <T> > TryRunRemoteAsync <T>(RemoteServiceName serviceName, string targetName, Solution?solution, IReadOnlyList <object?> arguments, object?callbackTarget, Func <Stream, CancellationToken, Task <T> >?dataReader, CancellationToken cancellationToken)
        {
            using var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (connection == null)
            {
                return(default);
Example #3
0
            public async Task <RemoteServiceConnection> GetOrCreateConnectionAsync(RemoteServiceName serviceName, CancellationToken cancellationToken)
            {
                var pool = _pools.GetOrAdd(serviceName, _ => new Pool(this));

                if (pool.TryAcquire(out var connection))
                {
                    return(connection);
                }

                return(await _connectionFactory(serviceName, pool, cancellationToken).ConfigureAwait(false));
            }
Example #4
0
        public async Task <KeepAliveSession?> TryCreateKeepAliveSessionAsync(RemoteServiceName serviceName, object?callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (connection == null)
            {
                return(null);
            }

            return(new KeepAliveSession(connection, RemotableDataService));
        }
Example #5
0
        public async Task <bool> TryRunRemoteAsync(RemoteServiceName serviceName, string targetName, Solution?solution, IReadOnlyList <object?> arguments, object?callbackTarget, CancellationToken cancellationToken)
        {
            using var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (connection == null)
            {
                return(false);
            }

            await RunRemoteAsync(connection, RemotableDataService, targetName, solution, arguments, cancellationToken).ConfigureAwait(false);

            return(true);
        }
Example #6
0
 public Task <T> RunRemoteAsync <T>(
     RemoteServiceName serviceName,
     string targetName,
     Solution?solution,
     IReadOnlyList <object?> arguments,
     object?callbackTarget,
     CancellationToken cancellationToken
     ) =>
 RunRemoteAsync <T>(
     serviceName,
     targetName,
     solution,
     arguments,
     callbackTarget,
     dataReader: null,
     cancellationToken
     );
Example #7
0
        // legacy services:

        public async Task RunRemoteAsync(
            RemoteServiceName serviceName,
            string targetName,
            Solution?solution,
            IReadOnlyList <object?> arguments,
            object?callbackTarget,
            CancellationToken cancellationToken
            )
        {
            using var connection = await CreateConnectionAsync(
                      serviceName,
                      callbackTarget,
                      cancellationToken
                      )
                                   .ConfigureAwait(false);

            await connection
            .RunRemoteAsync(targetName, solution, arguments, cancellationToken)
            .ConfigureAwait(false);
        }
Example #8
0
        public async Task <T> RunRemoteAsync <T>(
            RemoteServiceName serviceName,
            string targetName,
            Solution?solution,
            IReadOnlyList <object?> arguments,
            object?callbackTarget,
            Func <Stream, CancellationToken, Task <T> >?dataReader,
            CancellationToken cancellationToken
            )
        {
            using var connection = await CreateConnectionAsync(
                      serviceName,
                      callbackTarget,
                      cancellationToken
                      )
                                   .ConfigureAwait(false);

            return(await connection
                   .RunRemoteAsync(targetName, solution, arguments, dataReader, cancellationToken)
                   .ConfigureAwait(false));
        }
 public abstract Task <RemoteServiceConnection> CreateConnectionAsync(RemoteServiceName serviceName, object?callbackTarget, CancellationToken cancellationToken);
Example #10
0
 protected abstract Task <Connection?> TryCreateConnectionAsync(RemoteServiceName serviceName, object?callbackTarget, CancellationToken cancellationToken);