Exemplo n.º 1
0
 /// <summary>
 /// Raises the DeviceAdded event.
 /// </summary>
 /// <param name="e">The event arguments.</param>
 protected virtual void OnServiceAdded(ServiceAddedEventArgs e)
 {
     if (ServiceAdded != null)
     {
         ServiceAdded.GetInvocationList().InvokeEventGUIThreadSafe(this, e);
     }
 }
Exemplo n.º 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 already exists");
            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type));
            return(this);
        }
Exemplo n.º 3
0
        private static async void ServerBrowser_ServiceFound(object sender, NetServiceEventArgs e)
        {
            await e.Service.ResolveAsync().ConfigureAwait(false);

            _log.Info("Added service '{0}'.", e.Service.FullServiceInstanceName);

            lock (DiscoveredServers)
                DiscoveredServers[e.Service.Name] = e.Service;

            ServiceAdded.Raise(null, e);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds on-demand created service
        /// </summary>
        /// <param name="type">Service type</param>
        /// <param name="factory">Optional creator function. If not provided, reflection with default constructor will be used.</param>
        /// <param name="parameters">Factory parameters</param>
        public virtual IServiceManager AddService(Type type, Func <object> factory)
        {
            Check.ArgumentNull(nameof(type), type);
            lock (_lock) {
                Check.InvalidOperation(() => _services.ContainsKey(type));
                Check.InvalidOperation(() => _deferredServices.ContainsKey(type));
                _deferredServices[type] = factory;
            }

            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type));
            return(this);
        }
Exemplo n.º 6
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
        {
            var type = typeof(T);

            Check.ArgumentNull(nameof(service), service);
            lock (_lock) {
                Check.InvalidOperation(() => _services.ContainsKey(type));
                _services[type] = service;
            }
            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type));
            return(this);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds on-demand created service
        /// </summary>
        /// <param name="factory">Optional creator function. If not provided, reflection with default constructor will be used.</param>
        public virtual IServiceManager AddService <T>(Func <T> factory) where T : class
        {
            _disposeToken.ThrowIfDisposed();

            var type = typeof(T);
            var lazy = factory != null
                ? new Lazy <object>(() => factory())
                : new Lazy <object>(() => Activator.CreateInstance(type));

            Check.InvalidOperation(() => _s.TryAdd(type, lazy), "Service already exists");
            ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(typeof(T)));
            return(this);
        }
Exemplo n.º 8
0
        protected void AddService <T>(T serviceInstance) where T : class
        {
            var added = false;

            lock (_lock) {
                if (GetService <T>(false) == null)
                {
                    _servicesByType.Add(typeof(T), serviceInstance);
                    added = true;
                }
            }

            if (added)
            {
                ServiceAdded?.Invoke(this, new ServiceManagerEventArgs(typeof(T), serviceInstance));
            }
        }
Exemplo n.º 9
0
 private void OnServiceAdded(ServiceEventArgs e)
 {
     ServiceAdded?.Invoke(this, e);
 }
Exemplo n.º 10
0
 internal void OnServiceAdded(EntityApp app, Type serviceType, object serviceInstance)
 {
     ServiceAdded?.Invoke(this, new ServiceEventArgs(app, serviceType, serviceInstance));
 }
Exemplo n.º 11
0
 public void AddService(object service)
 {
     ImmutableInterlocked.Update(ref services, p => p.Add(service));
     ServiceAdded?.Invoke(this, service);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add a HEROsModService to the ServiceController
 /// </summary>
 /// <param name="service">Service to add</param>
 public void AddService(HEROsModService service)
 {
     _services.Add(service);
     ServiceAdded?.Invoke(service);
 }