Ejemplo n.º 1
0
        public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            AsynchronousOperationListenerProvider listenerProvider,
            IServiceBroker serviceBroker,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers,
            CancellationToken cancellationToken
            )
        {
            using (
                Logger.LogBlock(
                    FunctionId.ServiceHubRemoteHostClient_CreateAsync,
                    KeyValueLogMessage.NoProperty,
                    cancellationToken
                    )
                )
            {
#pragma warning disable ISB001    // Dispose of proxies
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
                var serviceBrokerClient = new ServiceBrokerClient(serviceBroker);
#pragma warning restore

                var hubClient = new HubClient("ManagedLanguage.IDE.RemoteHostClient");

                var remoteHostStream = await RequestServiceAsync(
                    services,
                    hubClient,
                    WellKnownServiceHubService.RemoteHost,
                    cancellationToken
                    )
                                       .ConfigureAwait(false);

                var client = new ServiceHubRemoteHostClient(
                    services,
                    serviceBroker,
                    serviceBrokerClient,
                    hubClient,
                    remoteHostStream,
                    callbackDispatchers
                    );

                var uiCultureLCID = CultureInfo.CurrentUICulture.LCID;
                var cultureLCID   = CultureInfo.CurrentCulture.LCID;

                // initialize the remote service
                await client._endPoint
                .InvokeAsync <string>(
                    nameof(IRemoteHostService.InitializeGlobalState),
                    new object?[] { uiCultureLCID, cultureLCID },
                    cancellationToken
                    )
                .ConfigureAwait(false);

                await client
                .TryInvokeAsync <IRemoteAsynchronousOperationListenerService>(
                    (service, cancellationToken) =>
                    service.EnableAsync(
                        AsynchronousOperationListenerProvider.IsEnabled,
                        listenerProvider.DiagnosticTokensEnabled,
                        cancellationToken
                        ),
                    cancellationToken
                    )
                .ConfigureAwait(false);

                client.Started();
                return(client);
            }
        }