예제 #1
0
        public static async Task <RemoteHostClient> CreateAsync(HostWorkspaceServices services, IServiceBroker serviceBroker, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.ServiceHubRemoteHostClient_CreateAsync, KeyValueLogMessage.NoProperty, cancellationToken))
            {
                Logger.Log(FunctionId.RemoteHost_Bitness, KeyValueLogMessage.Create(LogType.Trace, m => m["64bit"] = RemoteHostOptions.IsServiceHubProcess64Bit(services)));

#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);

                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);

                client.Started();
                return(client);
            }
        }
        public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            IGlobalOptionService globalOptions,
            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 client = new ServiceHubRemoteHostClient(services, globalOptions, serviceBrokerClient, hubClient, callbackDispatchers);

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

                client.Started();
                return(client);
            }
        }
예제 #3
0
        public static async ValueTask <Solution> GetSolutionAsync(ServiceBrokerClient client, object solutionInfo, CancellationToken cancellationToken)
        {
            using var rental = await client.GetProxyAsync <IRemoteWorkspaceSolutionProviderService>(RemoteWorkspaceSolutionProviderService.ServiceDescriptor, cancellationToken).ConfigureAwait(false);

            Contract.ThrowIfNull(rental.Proxy);
            return(await rental.Proxy.GetSolutionAsync((PinnedSolutionInfo)solutionInfo, cancellationToken).ConfigureAwait(false));
        }
예제 #4
0
        public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            RemoteProcessConfiguration configuration,
            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 client = new ServiceHubRemoteHostClient(services, configuration, serviceBrokerClient, hubClient, callbackDispatchers);

                var syntaxTreeConfigurationService = services.GetService <ISyntaxTreeConfigurationService>();
                if (syntaxTreeConfigurationService != null)
                {
                    await client.TryInvokeAsync <IRemoteProcessTelemetryService>(
                        (service, cancellationToken) => service.SetSyntaxTreeConfigurationOptionsAsync(syntaxTreeConfigurationService.DisableRecoverableTrees, syntaxTreeConfigurationService.DisableProjectCacheService, syntaxTreeConfigurationService.EnableOpeningSourceGeneratedFilesInWorkspace, cancellationToken),
                        cancellationToken).ConfigureAwait(false);
                }

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

                client.Started();
                return(client);
            }
        }
        private ServiceHubRemoteHostClient(
            HostWorkspaceServices services,
            IServiceBroker serviceBroker,
            ServiceBrokerClient serviceBrokerClient,
            HubClient hubClient,
            Stream stream,
            IRemoteServiceCallbackDispatcherProvider callbackDispatcherProvider)
        {
            _connectionPools = new ConnectionPools(
                connectionFactory: (serviceName, pool, cancellationToken) => CreateConnectionImplAsync(serviceName, callbackTarget: null, pool, cancellationToken),
                capacity: ConnectionPoolCapacity);

            // use the hub client logger for unexpected exceptions from devenv as well, so we have complete information in the log:
            services.GetService <IWorkspaceTelemetryService>()?.RegisterUnexpectedExceptionLogger(hubClient.Logger);

            _services                            = services;
            _serviceBroker                       = serviceBroker;
            _serviceBrokerClient                 = serviceBrokerClient;
            _hubClient                           = hubClient;
            _callbackDispatcherProvider          = callbackDispatcherProvider;
            _endPoint                            = new RemoteEndPoint(stream, hubClient.Logger, incomingCallTarget: this);
            _endPoint.Disconnected              += OnDisconnected;
            _endPoint.UnexpectedExceptionThrown += OnUnexpectedExceptionThrown;
            _endPoint.StartListening();

            _assetStorage                = services.GetRequiredService <ISolutionAssetStorageProvider>().AssetStorage;
            _serializer                  = services.GetRequiredService <ISerializerService>();
            _errorReportingService       = services.GetService <IErrorReportingService>();
            _shutdownCancellationService = services.GetService <IRemoteHostClientShutdownCancellationService>();
            _isRemoteHostServerGC        = RemoteHostOptions.IsServiceHubProcessServerGC(services);
            _isRemoteHostCoreClr         = RemoteHostOptions.IsServiceHubProcessCoreClr(services);
        }
        public ValueTask <Solution> GetSolutionAsync(ServiceBrokerClient client, PinnedSolutionInfo solutionInfo, CancellationToken cancellationToken)
        {
            var assetSource   = new SolutionAssetSource(client);
            var workspace     = GetWorkspace();
            var assetProvider = workspace.CreateAssetProvider(solutionInfo, SolutionAssetCache, assetSource);

            return(workspace.GetSolutionAsync(assetProvider, solutionInfo.SolutionChecksum, solutionInfo.FromPrimaryBranch, solutionInfo.WorkspaceVersion, solutionInfo.ProjectId, cancellationToken));
        }
        public RazorServiceBase(IServiceBroker serviceBroker)
        {
            RazorServices = new RazorServices();

#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
            ServiceBrokerClient = new ServiceBrokerClient(serviceBroker);
#pragma warning restore
        }
 public static ValueTask <Solution> GetSolutionAsync(
     this RazorPinnedSolutionInfoWrapper solutionInfo,
     ServiceBrokerClient client,
     CancellationToken cancellationToken
     ) =>
 RemoteWorkspaceManager.Default.GetSolutionAsync(
     client,
     solutionInfo.UnderlyingObject,
     cancellationToken
     );
예제 #9
0
        public static async ValueTask <UnitTestingIncrementalAnalyzerProvider?> TryRegisterAnalyzerProviderAsync(
            ServiceBrokerClient client,
            string analyzerName,
            IUnitTestingIncrementalAnalyzerProviderImplementation provider,
            CancellationToken cancellationToken)
        {
            using var rental = await client.GetProxyAsync <IRemoteWorkspaceSolutionProviderService>(RemoteWorkspaceSolutionProviderService.ServiceDescriptor, cancellationToken).ConfigureAwait(false);

            Contract.ThrowIfNull(rental.Proxy);
            var workspace = await rental.Proxy.GetWorkspaceAsync(WorkspaceKind.RemoteWorkspace, cancellationToken).ConfigureAwait(false);

            return(UnitTestingIncrementalAnalyzerProvider.TryRegister(workspace, analyzerName, provider));
        }
예제 #10
0
        public async ValueTask <Solution> GetSolutionAsync(ServiceBrokerClient client, Checksum solutionChecksum, CancellationToken cancellationToken)
        {
            var assetSource   = new SolutionAssetSource(client);
            var workspace     = GetWorkspace();
            var assetProvider = workspace.CreateAssetProvider(solutionChecksum, SolutionAssetCache, assetSource);

            var(solution, _) = await workspace.RunWithSolutionAsync(
                assetProvider,
                solutionChecksum,
                static _ => ValueTaskFactory.FromResult(false),
                cancellationToken).ConfigureAwait(false);

            return(solution);
        }
예제 #11
0
        public BrokeredServiceConnection(
            object?callbackTarget,
            ServiceBrokerClient serviceBrokerClient,
            SolutionAssetStorage solutionAssetStorage,
            IErrorReportingService?errorReportingService,
            IRemoteHostClientShutdownCancellationService?shutdownCancellationService,
            bool isRemoteHost64Bit)
        {
            _serviceBrokerClient         = serviceBrokerClient;
            _solutionAssetStorage        = solutionAssetStorage;
            _errorReportingService       = errorReportingService;
            _shutdownCancellationService = shutdownCancellationService;

            _serviceDescriptor = ServiceDescriptors.GetServiceDescriptor(typeof(TService), isRemoteHost64Bit);
            _callbackHandle    = _serviceDescriptor.CallbackDispatcher?.CreateHandle(callbackTarget) ?? default;
        }
예제 #12
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))
            {
                Logger.Log(FunctionId.RemoteHost_Bitness, KeyValueLogMessage.Create(
                               LogType.Trace,
                               m =>
                {
                    m["64bit"]    = RemoteHostOptions.IsServiceHubProcess64Bit(services);
                    m["ServerGC"] = RemoteHostOptions.IsServiceHubProcessServerGC(services);
                }));

#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);

                if (AsynchronousOperationListenerProvider.IsEnabled && !IsRpsMachine())
                {
                    await client.TryInvokeAsync <IRemoteAsynchronousOperationListenerService>(
                        (service, cancellationToken) => service.EnableAsync(AsynchronousOperationListenerProvider.IsEnabled, listenerProvider.DiagnosticTokensEnabled, cancellationToken),
                        cancellationToken).ConfigureAwait(false);
                }

                client.Started();
                return(client);
            }
예제 #13
0
        public async ValueTask <T> RunServiceAsync <T>(
            ServiceBrokerClient client,
            Checksum solutionChecksum,
            Func <Solution, ValueTask <T> > implementation,
            CancellationToken cancellationToken)
        {
            var assetSource   = new SolutionAssetSource(client);
            var workspace     = GetWorkspace();
            var assetProvider = workspace.CreateAssetProvider(solutionChecksum, SolutionAssetCache, assetSource);

            var(_, result) = await workspace.RunWithSolutionAsync(
                assetProvider,
                solutionChecksum,
                implementation,
                cancellationToken).ConfigureAwait(false);

            return(result);
        }
예제 #14
0
        public BrokeredServiceConnection(
            ServiceDescriptor serviceDescriptor,
            object?callbackTarget,
            IRemoteServiceCallbackDispatcher?callbackDispatcher,
            ServiceBrokerClient serviceBrokerClient,
            SolutionAssetStorage solutionAssetStorage,
            IErrorReportingService?errorReportingService,
            IRemoteHostClientShutdownCancellationService?shutdownCancellationService)
        {
            Contract.ThrowIfFalse((callbackDispatcher == null) == (serviceDescriptor.ClientInterface == null));

            _serviceDescriptor           = serviceDescriptor;
            _serviceBrokerClient         = serviceBrokerClient;
            _solutionAssetStorage        = solutionAssetStorage;
            _errorReportingService       = errorReportingService;
            _shutdownCancellationService = shutdownCancellationService;
            _callbackDispatcher          = callbackDispatcher;
            _callbackHandle = callbackDispatcher?.CreateHandle(callbackTarget) ?? default;
        }
        private ServiceHubRemoteHostClient(
            HostWorkspaceServices services,
            RemoteProcessConfiguration configuration,
            ServiceBrokerClient serviceBrokerClient,
            HubClient hubClient,
            IRemoteServiceCallbackDispatcherProvider callbackDispatcherProvider)
        {
            // use the hub client logger for unexpected exceptions from devenv as well, so we have complete information in the log:
            services.GetService <IWorkspaceTelemetryService>()?.RegisterUnexpectedExceptionLogger(hubClient.Logger);

            _services                   = services;
            _serviceBrokerClient        = serviceBrokerClient;
            _hubClient                  = hubClient;
            _callbackDispatcherProvider = callbackDispatcherProvider;

            _assetStorage                = services.GetRequiredService <ISolutionAssetStorageProvider>().AssetStorage;
            _errorReportingService       = services.GetService <IErrorReportingService>();
            _shutdownCancellationService = services.GetService <IRemoteHostClientShutdownCancellationService>();
            Configuration                = configuration;
        }
예제 #16
0
        public BrokeredServiceConnection(
            object?callbackTarget,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers,
            ServiceBrokerClient serviceBrokerClient,
            SolutionAssetStorage solutionAssetStorage,
            IErrorReportingService?errorReportingService,
            IRemoteHostClientShutdownCancellationService?shutdownCancellationService,
            bool isRemoteHost64Bit)
        {
            _serviceBrokerClient         = serviceBrokerClient;
            _solutionAssetStorage        = solutionAssetStorage;
            _errorReportingService       = errorReportingService;
            _shutdownCancellationService = shutdownCancellationService;

            _serviceDescriptor = ServiceDescriptors.GetServiceDescriptor(typeof(TService), isRemoteHost64Bit);

            if (_serviceDescriptor.ClientInterface != null)
            {
                _callbackDispatcher = callbackDispatchers.GetDispatcher(typeof(TService));
                _callbackHandle     = _callbackDispatcher.CreateHandle(callbackTarget);
            }
        }
예제 #17
0
        /// <summary>
        /// Use to perform a callback from ServiceHub process to an arbitrary brokered service hosted in the original process (usually devenv).
        /// </summary>
        public static async ValueTask <TResult> InvokeServiceAsync <TResult>(
            ServiceBrokerClient client,
            ServiceRpcDescriptor serviceDescriptor,
            Func <RemoteCallback <T>, CancellationToken, ValueTask <TResult> > invocation,
            CancellationToken cancellationToken)
        {
            ServiceBrokerClient.Rental <T> rental;
            try
            {
                rental = await client.GetProxyAsync <T>(serviceDescriptor, cancellationToken).ConfigureAwait(false);
            }
            catch (ObjectDisposedException e)
            {
                // When a connection is dropped ServiceHub's ServiceManager disposes the brokered service, which in turn disposes the ServiceBrokerClient.
                cancellationToken.ThrowIfCancellationRequested();
                throw new OperationCanceledIgnoringCallerTokenException(e);
            }

            Contract.ThrowIfNull(rental.Proxy);
            var callback = new RemoteCallback <T>(rental.Proxy);

            return(await invocation(callback, cancellationToken).ConfigureAwait(false));
        }
예제 #18
0
 public SolutionAssetSource(ServiceBrokerClient client)
 {
     _client = client;
 }
예제 #19
0
 public static ValueTask <T> RunServiceAsync <T>(this PythiaPinnedSolutionInfoWrapper solutionInfo, ServiceBrokerClient client, Func <Solution, ValueTask <T> > implementation, CancellationToken cancellationToken)
 => RemoteWorkspaceManager.Default.RunServiceAsync(client, solutionInfo.UnderlyingObject, implementation, cancellationToken);
예제 #20
0
 public SolutionAssetSource(ServiceBrokerClient client, CancellationTokenSource clientDisconnectedSource)
 {
     _client = client;
     _clientDisconnectedSource = clientDisconnectedSource;
 }