/// <summary> /// Initializes a new instance of <c>HandlerConfigurator</c> class. /// </summary> /// <param name="context">The configuration context.</param> /// <param name="name">The name of the message handler.</param> /// <param name="handlerKind">The <see cref="HandlerKind"/> which specifies the kind of the handler, can either be a Command or an Event.</param> /// <param name="sourceType">The <see cref="HandlerSourceType"/> which specifies the type of the source, can either be an Assembly or a Type.</param> /// <param name="source">The source name, if <paramref name="sourceType"/> is Assembly, the source name should be the assembly full name, if /// <paramref name="sourceType"/> is Type, the source name should be the assembly qualified name of the type.</param> public HandlerConfigurator(IConfigSourceConfigurator context, string name, HandlerKind handlerKind, HandlerSourceType sourceType, string source) : base(context) { this.name = name; this.handlerKind = handlerKind; this.sourceType = sourceType; this.source = source; }
/// <summary> /// 初始化<c> HandlerConfigurator </ c>类的新实例. /// </summary> /// <param name="context">配置上下文.</param> /// <param name="name">消息处理程序的名称.</param> /// <param name="handlerKind">指定处理程序类型的<see cref ="HandlerKind"/>可以是Command或Event.</param> /// <param name="sourceType">指定源的类型的<see cref ="HandlerSourceType"/>可以是程序集或类型.</param> /// <param name="source">The source name, if <paramref name="sourceType"/> is Assembly, the source name should be the assembly full name, if /// <paramref name="sourceType"/> is Type, the source name should be the assembly qualified name of the type.</param> public HandlerConfigurator(IConfigSourceConfigurator context, string name, HandlerKind handlerKind, HandlerSourceType sourceType, string source) : base(context) { this.name = name; this.handlerKind = handlerKind; this.sourceType = sourceType; this.source = source; }
/// <summary> /// Adds a command or event handler to the ConfigSource. /// </summary> /// <param name="name">Name of the handler to be added.</param> /// <param name="kind">The <see cref="Apworks.Config.HandlerKind"/> value which /// represents the kind of the message.</param> /// <param name="sourceType">The <see cref="Apworks.Config.HandlerSourceType"/> value /// which indicates where the handler exists. This could be either a type or an assembly.</param> /// <param name="source">The identifier of the source, for <c>sourceType==HandlerSourceType.Type</c>, /// this value should be the name of the type; for <c>sourceType==HandlerSourceType.Assembly</c>, /// this value should be the name of the assembly.</param> public void AddHandler(string name, HandlerKind kind, HandlerSourceType sourceType, string source) { if (this.config.Handlers == null) { this.config.Handlers = new HandlerElementCollection(); } foreach (HandlerElement he in this.config.Handlers) { if ((he.Name == name) || (he.Kind == kind && he.SourceType == sourceType && he.Source == source)) { return; } } this.config.Handlers.Add(new HandlerElement { Name = name, Kind = kind, SourceType = sourceType, Source = source }); }
/// <summary> /// 初始化<c> HandlerConfigurator </ c>类的新实例. /// </summary> /// <param name="context">配置上下文.</param> /// <param name="handlerKind">The <see cref="HandlerKind"/> which specifies the kind of the handler, can either be a Command or an Event.</param> /// <param name="sourceType">The <see cref="HandlerSourceType"/> which specifies the type of the source, can either be an Assembly or a Type.</param> /// <param name="source">The source name, if <paramref name="sourceType"/> is Assembly, the source name should be the assembly full name, if /// <paramref name="sourceType"/> is Type, the source name should be the assembly qualified name of the type.</param> public HandlerConfigurator(IConfigSourceConfigurator context, HandlerKind handlerKind, HandlerSourceType sourceType, string source) : this(context, Guid.NewGuid().ToString(), handlerKind, sourceType, source) { }
/// <summary> /// Adds a message handler to the Apworks framework. (This operation only applies on CQRS architecture). /// </summary> /// <param name="configurator">The <see cref="IHandlerConfigurator"/> instance to be extended.</param> /// <param name="handlerKind">The <see cref="HandlerKind"/> which specifies the kind of the handler, can either be a Command or an Event.</param> /// <param name="sourceType">The <see cref="HandlerSourceType"/> which specifies the type of the source, can either be an Assembly or a Type.</param> /// <param name="source">The source name, if <paramref name="sourceType"/> is Assembly, the source name should be the assembly full name, if /// <paramref name="sourceType"/> is Type, the source name should be the assembly qualified name of the type.</param> /// <param name="name">The name of the message handler.</param> /// <returns>The <see cref="IHandlerConfigurator"/> instance.</returns> public static IHandlerConfigurator AddMessageHandler(this IHandlerConfigurator configurator, HandlerKind handlerKind, HandlerSourceType sourceType, string source, string name = null) { if (string.IsNullOrEmpty(name)) { return(new HandlerConfigurator(configurator, handlerKind, sourceType, source)); } else { return(new HandlerConfigurator(configurator, name, handlerKind, sourceType, source)); } }
/// <summary> /// Adds a command or event handler to the ConfigSource. /// </summary> /// <param name="name">Name of the handler to be added.</param> /// <param name="kind">The <see cref="Apworks.Config.HandlerKind"/> value which /// represents the kind of the message.</param> /// <param name="sourceType">The <see cref="Apworks.Config.HandlerSourceType"/> value /// which indicates where the handler exists. This could be either a type or an assembly.</param> /// <param name="source">The identifier of the source, for <c>sourceType==HandlerSourceType.Type</c>, /// this value should be the name of the type; for <c>sourceType==HandlerSourceType.Assembly</c>, /// this value should be the name of the assembly.</param> public void AddHandler(string name, HandlerKind kind, HandlerSourceType sourceType, string source) { if (this.config.Handlers == null) this.config.Handlers = new HandlerElementCollection(); foreach (HandlerElement he in this.config.Handlers) { if ((he.Name == name) || (he.Kind == kind && he.SourceType == sourceType && he.Source == source)) return; } this.config.Handlers.Add(new HandlerElement { Name = name, Kind = kind, SourceType = sourceType, Source = source }); }
/// <summary> /// Initializes a new instance of <c>HandlerConfigurator</c> class. /// </summary> /// <param name="context">The configuration context.</param> /// <param name="handlerKind">The <see cref="HandlerKind"/> which specifies the kind of the handler, can either be a Command or an Event.</param> /// <param name="sourceType">The <see cref="HandlerSourceType"/> which specifies the type of the source, can either be an Assembly or a Type.</param> /// <param name="source">The source name, if <paramref name="sourceType"/> is Assembly, the source name should be the assembly full name, if /// <paramref name="sourceType"/> is Type, the source name should be the assembly qualified name of the type.</param> public HandlerConfigurator(IConfigSourceConfigurator context, HandlerKind handlerKind, HandlerSourceType sourceType, string source) : this(context, Guid.NewGuid().ToString(), handlerKind, sourceType, source) { }
/// <summary> /// Adds a command or event handler to the ConfigSource. /// </summary> /// <param name="name">Name of the handler to be added.</param> /// <param name="kind">The <see cref="Apworks.Config.HandlerKind"/> value which /// represents the kind of the message.</param> /// <param name="sourceType">The <see cref="Apworks.Config.HandlerSourceType"/> value /// which indicates where the handler exists. This could be either a type or an assembly.</param> /// <param name="source">The identifier of the source, for <c>sourceType==HandlerSourceType.Type</c>, /// this value should be the name of the type; for <c>sourceType==HandlerSourceType.Assembly</c>, /// this value should be the name of the assembly.</param> public void AddHandler(string name, HandlerKind kind, HandlerSourceType sourceType, string source) { this.config.Handlers.Add(new HandlerElement { Name = name, Kind = kind, SourceType = sourceType, Source = source }); }