Exemple #1
0
        public static async Task <KeepAliveSession?> TryCreateKeepAliveSessionAsync(
            this RemoteHostClient client, string serviceName, object?callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await client.TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

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

            return(new KeepAliveSession(client, connection, serviceName, callbackTarget));
        }
Exemple #2
0
        public static async Task <SessionWithSolution?> TryCreateSessionAsync(
            this RemoteHostClient client, string serviceName, Solution solution, object?callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await client.TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

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

            return(await SessionWithSolution.CreateAsync(connection, solution, cancellationToken).ConfigureAwait(false));
        }
Exemple #3
0
        public static async Task <T?> TryRunRemoteValueAsync <T>(
            this RemoteHostClient client, string serviceName, Solution solution, string targetName, IReadOnlyList <object> arguments, CancellationToken cancellationToken) where T : struct
        {
            using var session = await client.TryCreateSessionAsync(serviceName, solution, cancellationToken).ConfigureAwait(false);

            if (session == null)
            {
                // can't create Session. RemoteHost seems not responding for some reasons such as OOP gone.
                return(null);
            }

            return(await session.InvokeAsync <T>(targetName, arguments, cancellationToken).ConfigureAwait(false));
        }
Exemple #4
0
        public async Task <bool> TryInvokeAsync(string targetName, Solution?solution, IReadOnlyList <object?> arguments, CancellationToken cancellationToken)
        {
            using var connection = await TryGetConnectionAsync(cancellationToken).ConfigureAwait(false);

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

            await RemoteHostClient.RunRemoteAsync(connection.Target, _remotableDataService, targetName, solution, arguments, cancellationToken).ConfigureAwait(false);

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Run given service on remote host. if it fails to run on remote host, it will return default(T)
        /// </summary>
        public static async Task <T> RunOnRemoteHostAsync <T>(
            this RemoteHostClient client, string serviceName, Solution solution, string targetName, object[] arguments, CancellationToken cancellationToken)
        {
            using (var session = await client.TryCreateServiceSessionAsync(serviceName, solution, cancellationToken).ConfigureAwait(false))
            {
                if (session == null)
                {
                    // can't create Session. RemoteHost seems not responding for some reasons such as OOP gone.
                    return(default(T));
                }

                return(await session.InvokeAsync <T>(targetName, arguments).ConfigureAwait(false));
            }
        }
Exemple #6
0
        public void Shutdown()
        {
            using (_gate.DisposableWait(_cancellationToken))
            {
                if (_client != null)
                {
                    _client.StatusChanged -= OnStatusChanged;
                }

                _connection?.Dispose();

                _client     = null;
                _connection = null;
            }
        }
        public static async Task<bool> TryRunRemoteAsync(
            this RemoteHostClient client, string serviceName, string targetName, IReadOnlyList<object> arguments, CancellationToken cancellationToken)
        {
            using (var connection = await client.TryCreateConnectionAsync(serviceName, cancellationToken).ConfigureAwait(false))
            {
                if (connection == null)
                {
                    // can't create Connection. RemoteHost seems not responding for some reasons such as OOP gone.
                    return false;
                }

                await connection.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);
                return true;
            }
        }
Exemple #8
0
        public static async Task <bool> TryRunRemoteAsync(
            this RemoteHostClient client, string serviceName, Solution solution, object?callbackTarget,
            string targetName, IReadOnlyList <object> arguments, CancellationToken cancellationToken)
        {
            using var session = await client.TryCreateSessionAsync(serviceName, solution, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (session == null)
            {
                // can't create Session. RemoteHost seems not responding for some reasons such as OOP gone.
                return(false);
            }

            await session.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);

            return(true);
        }
Exemple #9
0
        private async Task SynchronizePrimaryWorkspaceAsync(CancellationToken cancellationToken)
        {
            var solution = _workspace.CurrentSolution;

            if (solution.BranchId != _workspace.PrimaryBranchId)
            {
                return;
            }

            var client = await RemoteHostClient
                         .TryGetClientAsync(_workspace, cancellationToken)
                         .ConfigureAwait(false);

            if (client == null)
            {
                return;
            }

            using (
                Logger.LogBlock(
                    FunctionId.SolutionChecksumUpdater_SynchronizePrimaryWorkspace,
                    cancellationToken
                    )
                )
            {
                var checksum = await solution.State
                               .GetChecksumAsync(cancellationToken)
                               .ConfigureAwait(false);

                await client
                .TryInvokeAsync <IRemoteAssetSynchronizationService>(
                    solution,
                    (service, solution, cancellationToken) =>
                    service.SynchronizePrimaryWorkspaceAsync(
                        solution,
                        checksum,
                        solution.WorkspaceVersion,
                        cancellationToken
                        ),
                    cancellationToken
                    )
                .ConfigureAwait(false);
            }
        }
        public void Shutdown(CancellationToken cancellationToken)
        {
            ReferenceCountedDisposable <RemoteHostClient.Connection> connection;

            lock (_gate)
            {
                if (_client != null)
                {
                    _client.StatusChanged -= OnStatusChanged;
                }

                connection = _connectionDoNotAccessDirectly;

                _client = null;
                _connectionDoNotAccessDirectly = null;
            }

            connection?.Dispose();
        }
        private async Task <GlobalNotificationState> SendStartNotificationAsync(Task <GlobalNotificationState> previousTask)
        {
            // Can only transition from NotStarted->Started.  If we hear about
            // anything else, do nothing.
            if (previousTask.Result != GlobalNotificationState.NotStarted)
            {
                return(previousTask.Result);
            }

            var client = await RemoteHostClient.TryGetClientAsync(_services, _cancellationToken).ConfigureAwait(false);

            if (client == null)
            {
                return(previousTask.Result);
            }

            _ = await client.TryInvokeAsync <IRemoteGlobalNotificationDeliveryService>(
                (service, cancellationToken) => service.OnGlobalOperationStartedAsync(cancellationToken),
                _cancellationToken).ConfigureAwait(false);

            return(GlobalNotificationState.Started);
        }
Exemple #12
0
        private async Task <GlobalNotificationState> SendStoppedNotificationAsync(Task <GlobalNotificationState> previousTask, GlobalOperationEventArgs e)
        {
            // Can only transition from Started->NotStarted.  If we hear about
            // anything else, do nothing.
            if (previousTask.Result != GlobalNotificationState.Started)
            {
                return(previousTask.Result);
            }

            var client = await RemoteHostClient.TryGetClientAsync(_services, _cancellationToken).ConfigureAwait(false);

            if (client == null)
            {
                return(previousTask.Result);
            }

            _ = await client.TryInvokeAsync <IRemoteGlobalNotificationDeliveryService>(
                (service, cancellationToken) => service.OnGlobalOperationStoppedAsync(e.Operations, e.Cancelled, cancellationToken),
                callbackTarget : null,
                _cancellationToken).ConfigureAwait(false);

            // Mark that we're stopped now.
            return(GlobalNotificationState.NotStarted);
        }
Exemple #13
0
 /// <summary>
 /// Create <see cref="RemoteHostClient.Connection"/> for the <paramref name="serviceName"/> if possible.
 /// otherwise, return null.
 ///
 /// Creating connection could fail if remote host is not available. one of example will be user killing
 /// remote host.
 /// </summary>
 public static Task <RemoteHostClient.Connection> TryCreateConnectionAsync(
     this RemoteHostClient client, string serviceName, CancellationToken cancellationToken)
 => client.TryCreateConnectionAsync(serviceName, callbackTarget: null, cancellationToken: cancellationToken);
Exemple #14
0
 public static Task <bool> TryRunRemoteAsync(
     this RemoteHostClient client, string serviceName, Solution solution, string targetName, object argument, CancellationToken cancellationToken)
 => TryRunRemoteAsync(client, serviceName, solution, targetName, new object[] { argument }, cancellationToken);
 public static Task <RemoteHostClient.Session> CreateCodeAnalysisServiceSessionAsync(
     this RemoteHostClient client, Solution solution, object callbackTarget, CancellationToken cancellationToken)
 {
     return(client.CreateServiceSessionAsync(
                WellKnownServiceHubServices.CodeAnalysisService, solution, callbackTarget, cancellationToken));
 }
Exemple #16
0
 public static Task <KeepAliveSession> TryCreateCodeAnalysisKeepAliveSessionAsync(
     this RemoteHostClient client, CancellationToken cancellationToken)
 => TryCreateCodeAnalysisKeepAliveSessionAsync(client, callbackTarget: null, cancellationToken: cancellationToken);
Exemple #17
0
 public static Task <SessionWithSolution> TryCreateCodeAnalysisSessionAsync(
     this RemoteHostClient client, Solution solution, CancellationToken cancellationToken)
 => TryCreateCodeAnalysisSessionAsync(client, solution, callbackTarget: null, cancellationToken: cancellationToken);
Exemple #18
0
 public static Task RunCodeAnalysisServiceOnRemoteHostAsync(
     this RemoteHostClient client, Solution solution, object callbackTarget, string targetName, object argument, CancellationToken cancellationToken)
 {
     return(RunCodeAnalysisServiceOnRemoteHostAsync(client, solution, callbackTarget, targetName, new object[] { argument }, cancellationToken));
 }
Exemple #19
0
 public static Task RunOnRemoteHostAsync(
     this RemoteHostClient client, string serviceName, Solution solution, string targetName, object argument, CancellationToken cancellationToken)
 {
     return(RunOnRemoteHostAsync(client, serviceName, solution, targetName, new object[] { argument }, cancellationToken));
 }
Exemple #20
0
 public static Task <RemoteHostClient.Session> TryCreateCodeAnalysisServiceSessionAsync(
     this RemoteHostClient client, Solution solution, CancellationToken cancellationToken)
 {
     return(TryCreateCodeAnalysisServiceSessionAsync(
                client, solution, callbackTarget: null, cancellationToken: cancellationToken));
 }
Exemple #21
0
 /// <summary>
 /// Run given service on remote host. if it fails to run on remote host, it will return default(T)
 /// </summary>
 public static Task <T> RunCodeAnalysisServiceOnRemoteHostAsync <T>(
     this RemoteHostClient client, Solution solution, string targetName, object[] arguments, CancellationToken cancellationToken)
 {
     return(RunOnRemoteHostAsync <T>(client, WellKnownServiceHubServices.CodeAnalysisService, solution, targetName, arguments, cancellationToken));
 }
 public static Task<bool> TryRunCodeAnalysisRemoteAsync(
     this RemoteHostClient client, string targetName, object[] arguments, CancellationToken cancellationToken)
     => TryRunRemoteAsync(client, WellKnownServiceHubServices.CodeAnalysisService, targetName, arguments, cancellationToken);
 /// <summary>
 /// Run given service on remote host. if it fails to run on remote host, it will return default(T)
 /// </summary>
 public static Task<T> TryRunCodeAnalysisRemoteAsync<T>(
     this RemoteHostClient client, Solution solution, string targetName, object argument, CancellationToken cancellationToken)
     => TryRunCodeAnalysisRemoteAsync<T>(client, solution, targetName, new object[] { argument }, cancellationToken);
Exemple #24
0
 /// <summary>
 /// Create <see cref="SessionWithSolution"/> for the <paramref name="serviceName"/> if possible.
 /// otherwise, return null.
 ///
 /// Creating session could fail if remote host is not available. one of example will be user killing
 /// remote host.
 /// </summary>
 public static Task <SessionWithSolution> TryCreateSessionAsync(
     this RemoteHostClient client, string serviceName, Solution solution, CancellationToken cancellationToken)
 => client.TryCreateSessionAsync(serviceName, solution, callbackTarget: null, cancellationToken: cancellationToken);
Exemple #25
0
 /// <summary>
 /// Create <see cref="KeepAliveSession"/> for the <paramref name="serviceName"/> if possible.
 /// otherwise, return null.
 ///
 /// Creating session could fail if remote host is not available. one of example will be user killing
 /// remote host.
 /// </summary>
 public static Task <KeepAliveSession> TryCreateKeepAliveSessionAsync(
     this RemoteHostClient client, string serviceName, CancellationToken cancellationToken)
 => TryCreateKeepAliveSessionAsync(client, serviceName, callbackTarget: null, cancellationToken: cancellationToken);
Exemple #26
0
        private void PushTextChanges(Document oldDocument, Document newDocument)
        {
            // this pushes text changes to the remote side if it can.
            // this is purely perf optimization. whether this pushing text change
            // worked or not doesn't affect feature's functionality.
            //
            // this basically see whether it can cheaply find out text changes
            // between 2 snapshots, if it can, it will send out that text changes to
            // remote side.
            //
            // the remote side, once got the text change, will again see whether
            // it can use that text change information without any high cost and
            // create new snapshot from it.
            //
            // otherwise, it will do the normal behavior of getting full text from
            // VS side. this optimization saves times we need to do full text
            // synchronization for typing scenario.

            if ((oldDocument.TryGetText(out var oldText) == false) ||
                (newDocument.TryGetText(out var newText) == false))
            {
                // we only support case where text already exist
                return;
            }

            // get text changes
            var textChanges = newText.GetTextChanges(oldText);

            if (textChanges.Count == 0)
            {
                // no changes
                return;
            }

            // whole document case
            if (textChanges.Count == 1 && textChanges[0].Span.Length == oldText.Length)
            {
                // no benefit here. pulling from remote host is more efficient
                return;
            }

            // only cancelled when remote host gets shutdown
            _textChangeQueue.ScheduleTask(nameof(PushTextChanges), async() =>
            {
                var client = await RemoteHostClient.TryGetClientAsync(_workspace, CancellationToken).ConfigureAwait(false);
                if (client == null)
                {
                    return;
                }

                var state = await oldDocument.State.GetStateChecksumsAsync(CancellationToken).ConfigureAwait(false);

                await client.RunRemoteAsync(
                    WellKnownServiceHubService.RemoteHost,
                    nameof(IRemoteHostService.SynchronizeTextAsync),
                    solution: null,
                    new object[] { oldDocument.Id, state.Text, textChanges },
                    callbackTarget: null,
                    CancellationToken).ConfigureAwait(false);
            }, CancellationToken);
        }
Exemple #27
0
 public static Task <SessionWithSolution> TryCreateCodeAnalysisSessionAsync(
     this RemoteHostClient client, Solution solution, object callbackTarget, CancellationToken cancellationToken)
 => client.TryCreateSessionAsync(WellKnownServiceHubServices.CodeAnalysisService, solution, callbackTarget, cancellationToken);
Exemple #28
0
 public static Task <T?> TryRunCodeAnalysisRemoteValueAsync <T>(
     this RemoteHostClient client, Solution solution, string targetName, object[] arguments, CancellationToken cancellationToken) where T : struct
 => TryRunRemoteValueAsync <T>(client, WellKnownServiceHubServices.CodeAnalysisService, solution, targetName, arguments, cancellationToken);
Exemple #29
0
 public static Task <KeepAliveSession> TryCreateCodeAnalysisKeepAliveSessionAsync(
     this RemoteHostClient client, object callbackTarget, CancellationToken cancellationToken)
 => client.TryCreateKeepAliveSessionAsync(WellKnownServiceHubServices.CodeAnalysisService, callbackTarget, cancellationToken);
 public static Task<bool> TryRunRemoteAsync(
     this RemoteHostClient client, string serviceName, Solution solution, string targetName, object[] arguments, CancellationToken cancellationToken)
 {
     object callbackTarget = null;
     return TryRunRemoteAsync(client, serviceName, solution, callbackTarget, targetName, arguments, cancellationToken);
 }