Exemplo n.º 1
0
        public static async Task <SessionWithSolution> CreateAsync(RemoteHostClient.Connection connection, Solution solution, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(connection);
            Contract.ThrowIfNull(solution);

            var service = solution.Workspace.Services.GetRequiredService <IRemotableDataService>();
            var scope   = await service.CreatePinnedRemotableDataScopeAsync(solution, cancellationToken).ConfigureAwait(false);

            SessionWithSolution?session = null;

            try
            {
                // set connection state for this session.
                // we might remove this in future. see https://github.com/dotnet/roslyn/issues/24836
                await connection.InvokeAsync(
                    WellKnownServiceHubServices.ServiceHubServiceBase_Initialize,
                    new object[] { scope.SolutionInfo },
                    cancellationToken).ConfigureAwait(false);

                // transfer ownership of connection and scope to the session object:
                session = new SessionWithSolution(connection, scope);
            }
            finally
            {
                if (session == null)
                {
                    scope.Dispose();
                }
            }

            return(session);
        }
Exemplo n.º 2
0
        public static async Task <SessionWithSolution> CreateAsync(RemoteHostClient.Connection connection, Solution solution, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(connection);
            Contract.ThrowIfNull(solution);

            PinnedRemotableDataScope scope = null;

            try
            {
                scope = await solution.GetPinnedScopeAsync(cancellationToken).ConfigureAwait(false);

                // set connection state for this session.
                // we might remove this in future. see https://github.com/dotnet/roslyn/issues/24836
                await connection.InvokeAsync(
                    WellKnownServiceHubServices.ServiceHubServiceBase_Initialize,
                    new object[] { scope.SolutionInfo },
                    cancellationToken).ConfigureAwait(false);

                return(new SessionWithSolution(connection, scope));
            }
            catch
            {
                // make sure disposable objects are disposed when
                // exceptions are thrown
                connection.Dispose();
                scope?.Dispose();

                // we only expect this to happen on cancellation. otherwise, rethrow
                cancellationToken.ThrowIfCancellationRequested();
                throw;
            }
        }
Exemplo n.º 3
0
        public KeepAliveSession(RemoteHostClient client, RemoteHostClient.Connection connection, string serviceName, object callbackTarget)
        {
            _gate = new object();

            Initialize(client, connection);

            _remoteHostClientService = client.Workspace.Services.GetService <IRemoteHostClientService>();
            _serviceName             = serviceName;
            _callbackTarget          = callbackTarget;
        }
Exemplo n.º 4
0
        public KeepAliveSession(RemoteHostClient client, RemoteHostClient.Connection connection, string serviceName, object callbackTarget)
        {
            Initialize_NoLock(client, connection);

            _gate = new SemaphoreSlim(initialCount: 1);
            _remoteHostClientService = client.Workspace.Services.GetService <IRemoteHostClientService>();

            _serviceName    = serviceName;
            _callbackTarget = callbackTarget;
        }
Exemplo n.º 5
0
        public void Shutdown()
        {
            using (_gate.DisposableWait(_cancellationToken))
            {
                if (_client != null)
                {
                    _client.StatusChanged -= OnStatusChanged;
                }

                _connection?.Dispose();

                _client     = null;
                _connection = null;
            }
        }
Exemplo n.º 6
0
        public static async Task <SessionWithSolution> CreateAsync(RemoteHostClient.Connection connection, PinnedRemotableDataScope scope, CancellationToken cancellationToken)
        {
            var sessionWithSolution = new SessionWithSolution(connection, scope);

            try
            {
                await connection.RegisterPinnedRemotableDataScopeAsync(scope).ConfigureAwait(false);

                return(sessionWithSolution);
            }
            catch
            {
                sessionWithSolution.Dispose();

                // we only expect this to happen on cancellation. otherwise, rethrow
                cancellationToken.ThrowIfCancellationRequested();
                throw;
            }
        }
Exemplo n.º 7
0
        public static async Task <SessionWithSolution> CreateAsync(RemoteHostClient.Connection connection, Solution solution, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(connection);
            Contract.ThrowIfNull(solution);

            PinnedRemotableDataScope?scope = null;

            try
            {
                var service = solution.Workspace.Services.GetRequiredService <IRemotableDataService>();
                scope = await service.CreatePinnedRemotableDataScopeAsync(solution, cancellationToken).ConfigureAwait(false);

                // set connection state for this session.
                // we might remove this in future. see https://github.com/dotnet/roslyn/issues/24836
                await connection.InvokeAsync(
                    WellKnownServiceHubServices.ServiceHubServiceBase_Initialize,
                    new object[] { scope.SolutionInfo },
                    cancellationToken).ConfigureAwait(false);

                return(new SessionWithSolution(connection, scope));
            }
            catch
            {
                // Make sure disposable objects are disposed when exceptions are thrown. The try/finally is used to
                // ensure 'scope' is disposed even if an exception is thrown while disposing 'connection'.
                try
                {
                    connection.Dispose();
                }
                finally
                {
                    scope?.Dispose();
                }

                // we only expect this to happen on cancellation. otherwise, rethrow
                cancellationToken.ThrowIfCancellationRequested();
                throw;
            }
        }
Exemplo n.º 8
0
        public static async Task <SessionWithSolution> CreateAsync(RemoteHostClient.Connection connection, PinnedRemotableDataScope scope, CancellationToken cancellationToken)
        {
            var sessionWithSolution = new SessionWithSolution(connection, scope);

            try
            {
                // set connection state for this session.
                // we might remove this in future. see https://github.com/dotnet/roslyn/issues/24836
                await connection.InvokeAsync(
                    WellKnownServiceHubServices.ServiceHubServiceBase_Initialize,
                    new object[] { scope.SolutionInfo },
                    cancellationToken).ConfigureAwait(false);

                return(sessionWithSolution);
            }
            catch
            {
                sessionWithSolution.Dispose();

                // we only expect this to happen on cancellation. otherwise, rethrow
                cancellationToken.ThrowIfCancellationRequested();
                throw;
            }
        }
Exemplo n.º 9
0
 private SessionWithSolution(RemoteHostClient.Connection connection, PinnedRemotableDataScope scope)
 {
     _connection = connection;
     _scope      = scope;
 }
Exemplo n.º 10
0
 private SessionWithSolution(RemoteHostClient.Connection connection, PinnedRemotableDataScope scope, CancellationToken cancellationToken)
 {
     _connection        = connection;
     _scope             = scope;
     _cancellationToken = cancellationToken;
 }
Exemplo n.º 11
0
 public KeepAliveSession(RemoteHostClient.Connection connection, IRemotableDataService remotableDataService)
 {
     _remotableDataService = remotableDataService;
     _connection           = connection;
 }