/// <summary>
        /// Creates and publish app resource server implementation.
        /// </summary>
        public static IAppResourceServer CreateAndPublishResourceServer(IServicePublisher publisher, string schemeName)
        {
            var srv = CreateResourceServer(publisher, schemeName);

            publisher.Publish(srv);
            return(srv);
        }
 /// <summary>
 /// Зарегистрировать все фабрики и сканировать вместе с ними.
 /// </summary>
 public static void RegisterAndScan(
     IServicePublisher publisher,
     IExtensionManager extensionManager,
     Type[] types)
 {
     extensionManager.Scan(new StrategyFactoryStrategy(publisher), types);
     ScanWithAllFactories(publisher, extensionManager, types);
 }
Ejemplo n.º 3
0
 public static IDisposable Publish <T>(
     [NotNull] this IServicePublisher publisher,
     [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class
 {
     Code.NotNull(publisher, nameof(publisher));
     Code.NotNull(instanceFactory, nameof(instanceFactory));
     return(publisher.Publish(typeof(T), instanceFactory));
 }
Ejemplo n.º 4
0
 public static IDisposable Publish <T>(
     [NotNull] this IServicePublisher publisher,
     [NotNull] T serviceInstance) where T : class
 {
     Code.NotNull(publisher, nameof(publisher));
     Code.NotNull(serviceInstance, nameof(serviceInstance));
     return(publisher.Publish(typeof(T), serviceInstance));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 protected RegElementsStrategy(IServicePublisher publisher)
 {
     if (publisher == null)
     {
         throw new ArgumentNullException(nameof(publisher));
     }
     Publisher = publisher;
 }
 /// <summary>
 /// Creates service publishing strategy.
 /// </summary>
 public static IExtensionAttachmentStrategy CreateServiceStrategy([NotNull] IServicePublisher publisher)
 {
     if (publisher == null)
     {
         throw new ArgumentNullException(nameof(publisher));
     }
     return(new ServicePublishingStrategy(publisher));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 服务订阅
        /// </summary>
        /// <param name="servicePublisher"></param>
        /// <param name="serviceTypes">服务类型</param>
        /// <param name="host">服务Host</param>
        /// <param name="port">服务端口</param>
        /// <param name="serializerName">序列化器名称</param>
        /// <returns></returns>
        public static IServicePublisher Publish(this IServicePublisher servicePublisher, IEnumerable <Type> serviceTypes, string host, int port, string serializerName)
        {
            foreach (var serviceType in serviceTypes)
            {
                servicePublisher.Publish(serviceType, host, port, serializerName);
            }

            return(servicePublisher);
        }
Ejemplo n.º 8
0
        public static IDisposable Publish <T>(
            [NotNull] this IServicePublisher publisher,
            [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class
        {
            Code.NotNull(publisher, nameof(publisher));
            Code.NotNull(instanceFactory, nameof(instanceFactory));
            // DONTTOUCH: for valid overload resolution (fails on net35).

            // ReSharper disable once RedundantCast
            return(publisher.Publish(typeof(T), instanceFactory));
        }
        /// <summary>
        /// Create and publish active parts manager.
        /// </summary>
        public static ActivePartManager CreateAndPublishManager([NotNull] IServicePublisher servicePublisher)
        {
            if (servicePublisher == null)
            {
                throw new ArgumentNullException(nameof(servicePublisher));
            }

            var mgr = new ActivePartManager(servicePublisher);

            servicePublisher.Publish <IActivePartManager>(mgr);
            return(mgr);
        }
Ejemplo n.º 10
0
 public DelegateStrategy(
     [NotNull] IServicePublisher publisher,
     [NotNull] Func <ExtensionAttachmentContext, TAttr, TInfo> creator,
     [CanBeNull] Type elementType)
     : base(publisher)
 {
     if (publisher == null)
     {
         throw new ArgumentNullException(nameof(publisher));
     }
     _creator     = creator;
     _elementType = elementType;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 使用服务发布
        /// </summary>
        /// <param name="nodeServer"></param>
        /// <param name="servicePublisher">服务发布器</param>
        /// <param name="serializerName">序列化器名称</param>
        /// <returns></returns>
        public static INodeServer UseServicePublish(this INodeServer nodeServer, IServicePublisher servicePublisher, string serializerName)
        {
            nodeServer.OnStarted += arg =>
            {
                var serviceTypes = arg.Routes.Where(r => r.Enabled).Select(r => r.ServiceType).Distinct();
                servicePublisher.Publish(serviceTypes, arg.Host, arg.Port, serializerName);
            };

            nodeServer.OnStopped += arg =>
            {
                servicePublisher.Dispose();
            };

            return(nodeServer);
        }
        public static IDisposable Publish <T>(
            [NotNull] this IServicePublisher publisher,
            [NotNull] Func <IServicePublisher, T> instanceFactory) where T : class
        {
            Code.NotNull(publisher, nameof(publisher));
            Code.NotNull(instanceFactory, nameof(instanceFactory));
            // DONTTOUCH: for valid overload resolution (fails on net35).
#if LESSTHAN_NET40
            // Hack for CS0030 Cannot convert type 'System.Func<CodeJam.Services.IServicePublisher, T>' to 'System.Func<CodeJam.Services.IServicePublisher, object>'
            return(publisher.Publish(typeof(T), new Func <IServicePublisher, object>(sp => instanceFactory(sp))));
#else
            // ReSharper disable once RedundantCast
            return(publisher.Publish(typeof(T), (Func <IServicePublisher, object>)instanceFactory));
#endif
        }
Ejemplo n.º 13
0
 public object GetInstance(IServicePublisher publisher, Type serviceType)
 {
     if (_instance == null)
     {
         lock (this)
             if (_instance == null)
             {
                 _instance = _factory(publisher);
                 if (_instance == null)
                 {
                     throw new InvalidOperationException($"Factory for service of type '{serviceType}' returns null");
                 }
             }
     }
     return(_instance);
 }
Ejemplo n.º 14
0
        public static IExtensionAttachmentStrategy CreateStrategy <TInfo, TAttr, TElement>(
            [NotNull] IServicePublisher publisher,
            [NotNull] Func <ExtensionAttachmentContext, TAttr, TInfo> infoCreator)
            where TAttr : Attribute
            where TInfo : class
        {
            if (publisher == null)
            {
                throw new ArgumentNullException(nameof(publisher));
            }
            if (infoCreator == null)
            {
                throw new ArgumentNullException(nameof(infoCreator));
            }

            return(CreateStrategy(publisher, infoCreator, typeof(TElement)));
        }
Ejemplo n.º 15
0
        public static IExtensionAttachmentStrategy CreateStrategy <TKey, TInfo, TAttr>(
            [NotNull] IServicePublisher publisher,
            [NotNull] Func <ExtensionAttachmentContext, TAttr, TInfo> infoCreator)
            where TAttr : Attribute
            where TInfo : class, IKeyedElementInfo <TKey>
            where TKey : class
        {
            if (publisher == null)
            {
                throw new ArgumentNullException(nameof(publisher));
            }
            if (infoCreator == null)
            {
                throw new ArgumentNullException(nameof(infoCreator));
            }

            return(new DelegateStrategy <TKey, TInfo, TAttr>(publisher, infoCreator, null));
        }
Ejemplo n.º 16
0
 public DBDriverRegStrategy(IServicePublisher publisher) : base(publisher)
 {
 }
 public NavigationTreeProviderStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 public RegCmdLineRulesProvidersStrategy(IServicePublisher publisher) : base(publisher)
 {
 }
 public TextMacrosProviderStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 public ServicePublishingStrategy(IServicePublisher publisher)
 {
     _publisher = publisher;
 }
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 public StrategyFactoryStrategy(IServicePublisher publisher) : base(publisher)
 {
 }
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 protected RegKeyedElementsStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
Ejemplo n.º 23
0
 public Engine(IProductDbSender mongoRepositorySender, IServicePublisher publisher)
 {
     _mongo     = mongoRepositorySender;
     _publisher = publisher;
 }
Ejemplo n.º 24
0
 public RegFruitStrategy(IServicePublisher publisher) : base(publisher)
 {
 }
 /// <include file='../CommonXmlDocs.xml' path='common-docs/def-ctor/*'/>
 public ActivePartRegStrategy(IServicePublisher publisher) : base(publisher)
 {
 }
 public NamedElementStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
Ejemplo n.º 27
0
 public MenuProviderStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
 /// <summary>
 /// Инициализирует экземпляр.
 /// </summary>
 public ConfigSectionStrategy(IServicePublisher publisher)
     : base(publisher)
 {
 }
Ejemplo n.º 29
0
 public object GetInstance(IServicePublisher publisher, Type serviceType) => _instance;
 public ExtInfoProvidersStrategy(IServicePublisher publisher) : base(publisher)
 {
 }