Exemple #1
0
            public ValueTask <T?> GetProxyAsync <T>(ServiceRpcDescriptor descriptor, ServiceActivationOptions options, CancellationToken cancellationToken) where T : class
            {
                var pipePair = FullDuplexStream.CreatePipePair();

                var clientConnection = descriptor
                                       .WithTraceSource(_services.ServiceProvider.TraceSource)
                                       .ConstructRpcConnection(pipePair.Item2);

                Contract.ThrowIfFalse(options.ClientRpcTarget is null == descriptor.ClientInterface is null);

                if (descriptor.ClientInterface != null)
                {
                    Contract.ThrowIfNull(options.ClientRpcTarget);
                    clientConnection.AddLocalRpcTarget(options.ClientRpcTarget);
                }

                // Clear RPC target so that the server connection is forced to create a new proxy for the callback
                // instead of just invoking the callback object directly (this emulates the product that does
                // not serialize the callback object over).
                options.ClientRpcTarget = null;

                // Creates service instance and connects it to the pipe.
                // We don't need to store the instance anywhere.
                _ = _services.CreateBrokeredService(descriptor, pipePair.Item1, options);

                clientConnection.StartListening();

                return(ValueTaskFactory.FromResult((T?)clientConnection.ConstructRpcClient <T>()));
            }
Exemple #2
0
            internal TService Create(
                IDuplexPipe pipe,
                IServiceProvider hostProvidedServices,
                ServiceActivationOptions serviceActivationOptions,
                IServiceBroker serviceBroker
                )
            {
                var descriptor = ServiceDescriptors.Instance.GetServiceDescriptorForServiceFactory(
                    typeof(TService)
                    );
                var serviceHubTraceSource = (TraceSource)hostProvidedServices.GetService(
                    typeof(TraceSource)
                    );
                var serverConnection = descriptor
                                       .WithTraceSource(serviceHubTraceSource)
                                       .ConstructRpcConnection(pipe);

                var args    = new ServiceConstructionArguments(hostProvidedServices, serviceBroker);
                var service = CreateService(
                    args,
                    descriptor,
                    serverConnection,
                    serviceActivationOptions.ClientRpcTarget
                    );

                serverConnection.AddLocalRpcTarget(service);
                serverConnection.StartListening();

                return(service);
            }
Exemple #3
0
 public ValueTask <IDuplexPipe> GetPipeAsync(
     ServiceMoniker serviceMoniker,
     ServiceActivationOptions options    = default,
     CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
            public Task <object> CreateAsync(
                Stream stream,
                IServiceProvider hostProvidedServices,
                ServiceActivationOptions serviceActivationOptions,
                IServiceBroker serviceBroker,
                AuthorizationServiceClient?authorizationServiceClient)
            {
                // Exception from IServiceHubServiceFactory.CreateAsync are not propagated to the client.
                // Intercept the exception here and report it to the log.
                // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1410923
                try
                {
                    // Dispose the AuthorizationServiceClient since we won't be using it
                    authorizationServiceClient?.Dispose();

                    // First request determines the default culture:
                    // TODO: Flow culture explicitly where needed https://github.com/dotnet/roslyn/issues/43670
                    if (Interlocked.CompareExchange(ref s_cultureInitialized, 1, 0) == 0)
                    {
                        CultureInfo.DefaultThreadCurrentUICulture = serviceActivationOptions.ClientUICulture;
                        CultureInfo.DefaultThreadCurrentCulture   = serviceActivationOptions.ClientCulture;
                    }

                    return(Task.FromResult((object)Create(
                                               stream.UsePipe(),
                                               hostProvidedServices,
                                               serviceActivationOptions,
                                               serviceBroker)));
                }
                catch (Exception e) when(FatalError.ReportAndPropagateUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Exemple #5
0
 public ValueTask <T> GetProxyAsync <T>(
     ServiceRpcDescriptor serviceDescriptor,
     ServiceActivationOptions options    = default,
     CancellationToken cancellationToken = default)
     where T : class
 {
     throw new NotImplementedException();
 }
Exemple #6
0
        private ValueTask <object> CreateSourceProviderServiceAsync(
            ServiceMoniker moniker,
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            CancellationToken cancellationToken)
        {
#pragma warning disable CA2000 // Dispose objects before losing scope
            return(new ValueTask <object>(new NuGetSourcesService(options, serviceBroker, authorizationServiceClient)));

#pragma warning restore CA2000 // Dispose objects before losing scope
        }
Exemple #7
0
        public Task <object> CreateAsync(
            Stream stream,
            IServiceProvider hostProvidedServices,
            ServiceActivationOptions serviceActivationOptions,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient?authorizationServiceClient)
        {
            // Dispose the AuthorizationServiceClient since we won't be using it
            authorizationServiceClient?.Dispose();

            return(Task.FromResult((object)Create(stream.UsePipe(), serviceBroker)));
        }
        private async ValueTask <object> CreateNuGetProjectServiceV1(
            ServiceMoniker moniker,
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            CancellationToken cancellationToken)
        {
            await _lazyInitializer.InitializeAsync(cancellationToken);

            IVsSolutionManager solutionManager = await _lazySolutionManager.GetValueAsync(cancellationToken);

            ISettings settings = await _lazySettings.GetValueAsync(cancellationToken);

            return(new NuGetProjectService(solutionManager, settings));
        }
        public NuGetPackageSearchService(ServiceActivationOptions options, IServiceBroker sb, AuthorizationServiceClient ac, ISharedServiceState state)
        {
            _options       = options;
            _serviceBroker = sb;
            _authorizationServiceClient = ac;
            _sharedServiceState         = state;

            _packagesFolderLocalRepositoryLazy = new Microsoft.VisualStudio.Threading.AsyncLazy <SourceRepository>(
                GetPackagesFolderSourceRepositoryAsync,
                NuGetUIThreadHelper.JoinableTaskFactory);
            _globalPackageFolderRepositoriesLazy = new Microsoft.VisualStudio.Threading.AsyncLazy <IReadOnlyList <SourceRepository> >(
                GetGlobalPackageFolderRepositoriesAsync,
                NuGetUIThreadHelper.JoinableTaskFactory);
        }
Exemple #10
0
 public NuGetPackageFileService(
     ServiceActivationOptions options,
     IServiceBroker serviceBroker,
     AuthorizationServiceClient authorizationServiceClient,
     INuGetTelemetryProvider nuGetTelemetryProvider)
 {
     _options       = options;
     _serviceBroker = serviceBroker;
     _authorizationServiceClient = authorizationServiceClient;
     _nuGetTelemetryProvider     = nuGetTelemetryProvider;
     Assumes.NotNull(_serviceBroker);
     Assumes.NotNull(_authorizationServiceClient);
     Assumes.NotNull(_nuGetTelemetryProvider);
 }
        private async ValueTask <object> CreateSolutionManagerServiceAsync(
            ServiceMoniker moniker,
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            CancellationToken cancellationToken)
        {
            NuGetSolutionManagerService service = await NuGetSolutionManagerService.CreateAsync(
                options,
                serviceBroker,
                authorizationServiceClient,
                cancellationToken);

            return(service);
        }
Exemple #12
0
        public NuGetProjectUpgraderService(
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            ISharedServiceState state)
        {
            Assumes.NotNull(serviceBroker);
            Assumes.NotNull(authorizationServiceClient);
            Assumes.NotNull(state);

            _options       = options;
            _serviceBroker = serviceBroker;
            _authorizationServiceClient = authorizationServiceClient;
            _state = state;
        }
        public NuGetSourcesService(
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            ISharedServiceState state)
        {
            Assumes.NotNull(serviceBroker);
            Assumes.NotNull(authorizationServiceClient);
            Assumes.NotNull(state);

            _options       = options;
            _serviceBroker = serviceBroker;
            _authorizationServiceClient = authorizationServiceClient;
            _sharedServiceState         = state;
            _sharedServiceState.SourceRepositoryProvider.PackageSourceProvider.PackageSourcesChanged += PackageSourceProvider_PackageSourcesChanged;
        }
Exemple #14
0
        public static async ValueTask <NuGetSolutionManagerService> CreateAsync(
            ServiceActivationOptions options,
            IServiceBroker sb,
            AuthorizationServiceClient ac,
            CancellationToken cancellationToken)
        {
            Assumes.NotNull(sb);
            Assumes.NotNull(ac);

            cancellationToken.ThrowIfCancellationRequested();

            IComponentModel componentModel = await ServiceLocator.GetGlobalServiceFreeThreadedAsync <SComponentModel, IComponentModel>();

            Assumes.NotNull(componentModel);

            return(new NuGetSolutionManagerService(options, sb, ac, componentModel));
        }
        private async ValueTask <Rental> RentServiceAsync(CancellationToken cancellationToken)
        {
            // Make sure we are on the thread pool to avoid UI thread dependencies if external code uses ConfigureAwait(true)
            await TaskScheduler.Default;

            var options = new ServiceActivationOptions
            {
                ClientRpcTarget = _serviceDescriptor.CallbackDispatcher
            };

            var proxyRental = await _serviceBrokerClient.GetProxyAsync <TService>(_serviceDescriptor, options, cancellationToken).ConfigureAwait(false);

            var service = proxyRental.Proxy;

            Contract.ThrowIfNull(service);
            return(new Rental(proxyRental, service));
        }
Exemple #16
0
            internal TService Create(
                IDuplexPipe pipe,
                IServiceProvider hostProvidedServices,
                ServiceActivationOptions serviceActivationOptions,
                IServiceBroker serviceBroker)
            {
                var descriptor       = ServiceDescriptors.GetServiceDescriptor(typeof(TService), isRemoteHost64Bit: IntPtr.Size == 8);
                var serverConnection = descriptor.ConstructRpcConnection(pipe);

                var args    = new ServiceConstructionArguments(hostProvidedServices, serviceBroker, new CancellationTokenSource());
                var service = CreateService(args, descriptor, serverConnection, serviceActivationOptions.ClientRpcTarget);

                serverConnection.AddLocalRpcTarget(service);
                serverConnection.StartListening();

                return(service);
            }
        private async ValueTask <object> CreateSourceProviderServiceAsync(
            ServiceMoniker moniker,
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            CancellationToken cancellationToken)
        {
            await _lazyInitializer.InitializeAsync(cancellationToken);

#pragma warning disable CA2000 // Dispose objects before losing scope
            var service = new NuGetSourcesService(
                options,
                serviceBroker,
                authorizationServiceClient,
                _sharedServiceState);
#pragma warning restore CA2000 // Dispose objects before losing scope

            return(service);
        }
Exemple #18
0
        private NuGetSolutionManagerService(
            ServiceActivationOptions options,
            IServiceBroker sb,
            AuthorizationServiceClient ac,
            IComponentModel componentModel)
        {
            Assumes.NotNull(sb);
            Assumes.NotNull(ac);

            _options       = options;
            _serviceBroker = sb;
            _authorizationServiceClient = ac;

            componentModel.DefaultCompositionService.SatisfyImportsOnce(this);

            Assumes.NotNull(SolutionManager);

            RegisterEventHandlers();
        }
        public override async ValueTask <RemoteServiceConnection <T> > CreateConnectionAsync <T>(object?callbackTarget, CancellationToken cancellationToken)
        {
            var options = new ServiceActivationOptions();

            if (callbackTarget is not null)
            {
                options.ClientRpcTarget = callbackTarget;
            }

            var assetStorage = _workspaceServices.GetRequiredService <ISolutionAssetStorageProvider>().AssetStorage;
            var descriptor   = ServiceDescriptors.GetServiceDescriptor(typeof(T), isRemoteHost64Bit: IntPtr.Size == 8);

#pragma warning disable ISB001 // Dispose of proxies - caller disposes
            var proxy = await _inprocServices.ServiceBroker.GetProxyAsync <T>(descriptor, options, cancellationToken).ConfigureAwait(false);

#pragma warning restore

            Contract.ThrowIfNull(proxy);
            return(new BrokeredServiceConnection <T>(proxy, assetStorage, errorReportingService: null));
        }
        private async ValueTask <object> CreatePackageFileServiceAsync(
            ServiceMoniker moniker,
            ServiceActivationOptions options,
            IServiceBroker serviceBroker,
            AuthorizationServiceClient authorizationServiceClient,
            CancellationToken cancellationToken)
        {
            await _lazyInitializer.InitializeAsync(cancellationToken);

            INuGetTelemetryProvider telemetryProvider = await _lazyTelemetryProvider.GetValueAsync(cancellationToken);

#pragma warning disable CA2000 // Dispose objects before losing scope
            var service = new NuGetPackageFileService(
                options,
                serviceBroker,
                authorizationServiceClient,
                telemetryProvider);
#pragma warning restore CA2000 // Dispose objects before losing scope

            return(service);
        }
Exemple #21
0
            internal TService Create(
                IDuplexPipe pipe,
                IServiceProvider hostProvidedServices,
                ServiceActivationOptions serviceActivationOptions,
                IServiceBroker serviceBroker)
            {
                // Register this service broker globally (if it's the first we encounter) so it can be used by other
                // global services that need it.
                GlobalServiceBroker.RegisterServiceBroker(serviceBroker);

                var descriptor            = ServiceDescriptors.Instance.GetServiceDescriptorForServiceFactory(typeof(TService));
                var serviceHubTraceSource = (TraceSource)hostProvidedServices.GetService(typeof(TraceSource));
                var serverConnection      = descriptor.WithTraceSource(serviceHubTraceSource).ConstructRpcConnection(pipe);

                var args    = new ServiceConstructionArguments(hostProvidedServices, serviceBroker);
                var service = CreateService(args, descriptor, serverConnection, serviceActivationOptions.ClientRpcTarget);

                serverConnection.AddLocalRpcTarget(service);
                serverConnection.StartListening();

                return(service);
            }
Exemple #22
0
            public Task <object> CreateAsync(
                Stream stream,
                IServiceProvider hostProvidedServices,
                ServiceActivationOptions serviceActivationOptions,
                IServiceBroker serviceBroker,
                AuthorizationServiceClient?authorizationServiceClient)
            {
                // Dispose the AuthorizationServiceClient since we won't be using it
                authorizationServiceClient?.Dispose();

                // First request determines the default culture:
                // TODO: Flow culture explicitly where needed https://github.com/dotnet/roslyn/issues/43670
                if (Interlocked.CompareExchange(ref s_cultureInitialized, 1, 0) == 0)
                {
                    CultureInfo.DefaultThreadCurrentUICulture = serviceActivationOptions.ClientUICulture;
                    CultureInfo.DefaultThreadCurrentCulture   = serviceActivationOptions.ClientCulture;
                }

                return(Task.FromResult((object)Create(
                                           stream.UsePipe(),
                                           hostProvidedServices,
                                           serviceActivationOptions,
                                           serviceBroker)));
            }
 object IFactory.Create(IDuplexPipe pipe, IServiceProvider hostProvidedServices, ServiceActivationOptions serviceActivationOptions, IServiceBroker serviceBroker)
 => Create(pipe, hostProvidedServices, serviceActivationOptions, serviceBroker);
Exemple #24
0
        public async ValueTask <object> CreateNuGetProjectServiceV1(ServiceMoniker moniker, ServiceActivationOptions options, IServiceBroker serviceBroker, CancellationToken cancellationToken)
        {
            var solutionManager = await _solutionManager.GetValueAsync(cancellationToken);

            var settings = await _settings.GetValueAsync(cancellationToken);

            return(new NuGetProjectService(solutionManager, settings));
        }
Exemple #25
0
 // This method is currently not needed for our IServiceBroker usage patterns.
 public ValueTask <IDuplexPipe?> GetPipeAsync(ServiceMoniker serviceMoniker, ServiceActivationOptions options, CancellationToken cancellationToken)
 => throw ExceptionUtilities.Unreachable;
Exemple #26
0
 public NuGetSourcesService(ServiceActivationOptions options, IServiceBroker serviceBroker, AuthorizationServiceClient authorizationServiceClient)
 {
     _options       = options;
     _serviceBroker = serviceBroker;
     _authorizationServiceClient = authorizationServiceClient;
 }
            public async ValueTask <T?> GetProxyAsync <T>(ServiceRpcDescriptor serviceDescriptor, ServiceActivationOptions options = default, CancellationToken cancellationToken = default)
                where T : class
            {
                if (this.container.profferedServices.TryGetValue(serviceDescriptor.Moniker, out object?factory))
                {
                    if (factory is BrokeredServiceFactory fac1)
                    {
                        T?service = (T?) await fac1(serviceDescriptor.Moniker, options, this, cancellationToken).ConfigureAwait(false);

                        if (service is object)
                        {
                            return(serviceDescriptor.ConstructLocalProxy <T>(service));
                        }
                    }
                    else if (factory is AuthorizingBrokeredServiceFactory fac2)
                    {
#pragma warning disable CA2000 // Dispose objects before losing scope
                        T?service = (T?) await fac2(serviceDescriptor.Moniker, options, this, new AuthorizationServiceClient(new MockAuthorizationService()), cancellationToken).ConfigureAwait(false);

#pragma warning restore CA2000 // Dispose objects before losing scope
                        if (service is object)
                        {
                            return(serviceDescriptor.ConstructLocalProxy <T>(service));
                        }
                    }
                    else
                    {
                        throw Assumes.NotReachable();
                    }
                }

                return(default);