Beispiel #1
0
        public void ThrowIfDisposed_Disposed()
        {
            _disposeToken.TryMarkDisposed();

            Action a = () => _disposeToken.ThrowIfDisposed();

            a.ShouldThrow <ObjectDisposedException>();
        }
Beispiel #2
0
        /// <summary>
        /// Add service to the service manager container
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="service">Service instance</param>
        /// <param name="type">
        /// Optional type to register the instance for. In Visual Studio
        /// some global services are registered as 'SVsService` while
        /// actual interface type is IVsService.
        /// </param>
        public virtual IServiceManager AddService <T>(T service, Type type = null) where T : class
        {
            _disposeToken.ThrowIfDisposed();

            type = type ?? typeof(T);
            Check.ArgumentNull(nameof(service), service);
            Check.InvalidOperation(() => _s.TryAdd(type, service), $"Service of type {type} already exists");

            return(this);
        }
Beispiel #3
0
        /// <summary>
        /// Add service to the service manager container
        /// </summary>
        /// <param name="service">Service instance</param>
        /// <param name="type">
        /// Optional type to register the instance for. In Visual Studio
        /// some global services are registered as 'SVsService` while
        /// actual interface type is IVsService.
        /// </param>
        public virtual IServiceManager AddService(object service, Type type = null)
        {
            _disposeToken.ThrowIfDisposed();

            type = type ?? service.GetType();
            Check.ArgumentNull(nameof(service), service);
            Check.InvalidOperation(() => _s.GetOrAdd(type, service) == service,
                                   Invariant($"Another instance of service of type {type} already added"));
            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// Add service to the service manager container
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="service">Service instance</param>
        /// <param name="type">
        /// Optional type to register the instance for. In Visual Studio
        /// some global services are registered as 'SVsService` while
        /// actual interface type is IVsService.
        /// </param>
        public virtual IServiceManager AddService <T>(T service, Type type = null) where T : class
        {
            _disposeToken.ThrowIfDisposed();

            type = type ?? typeof(T);
            Check.ArgumentNull(nameof(service), service);
            Check.InvalidOperation(() => _s.TryAdd(type, service), "Service already exists");
            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type));
            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// Add service to the service manager container
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="service">Service instance</param>
        public virtual IServiceManager AddService <T>(T service) where T : class
        {
            _disposeToken.ThrowIfDisposed();

            var type = typeof(T);

            Check.ArgumentNull(nameof(service), service);
            Check.Operation(() => _s.TryAdd(type, service));
            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type));
            return(this);
        }
Beispiel #6
0
        public Task <IRSessionInteraction> BeginInteractionAsync(bool isVisible = true, CancellationToken cancellationToken = default(CancellationToken))
        {
            _disposeToken.ThrowIfDisposed();

            if (!_isHostRunning)
            {
                return(CanceledBeginInteractionTask);
            }

            RSessionRequestSource requestSource = new RSessionRequestSource(isVisible, cancellationToken);

            _pendingRequestSources.Post(requestSource);

            return(_isHostRunning ? requestSource.CreateRequestTask : CanceledBeginInteractionTask);
        }
Beispiel #7
0
 public IRSession GetOrCreate(string sessionId)
 {
     _disposeToken.ThrowIfDisposed();
     return(_sessions.GetOrAdd(sessionId, CreateRSession));
 }
Beispiel #8
0
 public IRSession GetOrCreate(Guid guid)
 {
     _disposeToken.ThrowIfDisposed();
     return(_sessions.GetOrAdd(guid, id => new RSession(Interlocked.Increment(ref _sessionCounter), () => DisposeSession(guid))));
 }