Added missing XML summaries

This commit is contained in:
2025-08-08 17:15:57 +04:00
parent d8fa0b02d7
commit cee7ed3adc
8 changed files with 302 additions and 188 deletions
@@ -35,17 +35,20 @@ namespace Telegrator.Attributes.Components
/// </summary> /// </summary>
public int Priority { get; set; } public int Priority { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to form a fallback report for debugging purposes.
/// </summary>
public bool FormReport { get; set; } public bool FormReport { get; set; }
/// <summary> /// <summary>
/// Creates a new instance of <see cref="UpdateHandlerAttributeBase"/> /// Creates a new instance of <see cref="UpdateHandlerAttributeBase"/>
/// </summary> /// </summary>
/// <param name="expectingHandlerType"></param> /// <param name="expectingHandlerType">The types of handlers that this attribute can be applied to.</param>
/// <param name="updateType"></param> /// <param name="updateType">The type of update that this handler processes.</param>
/// <param name="importance"></param> /// <param name="importance">The importance level of this handler (default: 0).</param>
/// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="expectingHandlerType"/> is null.</exception>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException">Thrown when one of the handler types is not a valid handler type.</exception>
/// <exception cref="Exception"></exception> /// <exception cref="Exception">Thrown when <paramref name="updateType"/> is <see cref="UpdateType.Unknown"/>.</exception>
protected internal UpdateHandlerAttributeBase(Type[] expectingHandlerType, UpdateType updateType, int importance = 0) protected internal UpdateHandlerAttributeBase(Type[] expectingHandlerType, UpdateType updateType, int importance = 0)
{ {
if (expectingHandlerType == null) if (expectingHandlerType == null)
@@ -65,15 +68,15 @@ namespace Telegrator.Attributes.Components
/// <summary> /// <summary>
/// Gets an <see cref="DescriptorIndexer"/> of this <see cref="UpdateHandlerAttributeBase"/> from <see cref="Importance"/> and <see cref="Priority"/> /// Gets an <see cref="DescriptorIndexer"/> of this <see cref="UpdateHandlerAttributeBase"/> from <see cref="Importance"/> and <see cref="Priority"/>
/// </summary> /// </summary>
/// <returns></returns> /// <returns>A descriptor indexer for this handler attribute.</returns>
public DescriptorIndexer GetIndexer() public DescriptorIndexer GetIndexer()
=> new DescriptorIndexer(0, this); => new DescriptorIndexer(0, this);
/// <summary> /// <summary>
/// Validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process /// Validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process
/// </summary> /// </summary>
/// <param name="context"></param> /// <param name="context">The filter execution context containing the update to validate.</param>
/// <returns></returns> /// <returns>True if the update passes validation; otherwise, false.</returns>
public abstract bool CanPass(FilterExecutionContext<Update> context); public abstract bool CanPass(FilterExecutionContext<Update> context);
} }
} }
@@ -12,12 +12,15 @@ namespace Telegrator.Filters.Components
private readonly Func<Update, object?> GetFilterringTarget; private readonly Func<Update, object?> GetFilterringTarget;
private readonly string _name; private readonly string _name;
/// <summary>
/// Gets the name of this compiled filter.
/// </summary>
public virtual string Name => _name; public virtual string Name => _name;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AnonymousCompiledFilter"/> class. /// Initializes a new instance of the <see cref="AnonymousCompiledFilter"/> class.
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name">The name of the compiled filter.</param>
/// <param name="filterAction">The filter action delegate.</param> /// <param name="filterAction">The filter action delegate.</param>
/// <param name="getFilterringTarget">The function to get the filtering target from an update.</param> /// <param name="getFilterringTarget">The function to get the filtering target from an update.</param>
private AnonymousCompiledFilter(string name, Func<Update, object?> getFilterringTarget, Func<FilterExecutionContext<Update>, object, bool> filterAction) private AnonymousCompiledFilter(string name, Func<Update, object?> getFilterringTarget, Func<FilterExecutionContext<Update>, object, bool> filterAction)
@@ -43,10 +46,10 @@ namespace Telegrator.Filters.Components
} }
/// <summary> /// <summary>
/// Compiles a set of filters into an <see cref="AnonymousCompiledFilter"/> for a specific target type. /// Compiles a set of filters into an <see cref="AnonymousCompiledFilter"/> for a specific target type with a custom name.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the filtering target.</typeparam> /// <typeparam name="T">The type of the filtering target.</typeparam>
/// <param name="name"></param> /// <param name="name">The custom name for the compiled filter.</param>
/// <param name="filters">The list of filters to compile.</param> /// <param name="filters">The list of filters to compile.</param>
/// <param name="getFilterringTarget">The function to get the filtering target from an update.</param> /// <param name="getFilterringTarget">The function to get the filtering target from an update.</param>
/// <returns>The compiled filter.</returns> /// <returns>The compiled filter.</returns>
@@ -12,12 +12,15 @@ namespace Telegrator.Filters.Components
private readonly Func<Update, object?> GetFilterringTarget; private readonly Func<Update, object?> GetFilterringTarget;
private readonly string _name; private readonly string _name;
/// <summary>
/// Gets the name of this filter.
/// </summary>
public virtual string Name => _name; public virtual string Name => _name;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AnonymousTypeFilter"/> class. /// Initializes a new instance of the <see cref="AnonymousTypeFilter"/> class.
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name">The name of the filter.</param>
/// <param name="filterAction">The filter action delegate.</param> /// <param name="filterAction">The filter action delegate.</param>
/// <param name="getFilterringTarget">The function to get the filtering target from an update.</param> /// <param name="getFilterringTarget">The function to get the filtering target from an update.</param>
public AnonymousTypeFilter(string name, Func<Update, object?> getFilterringTarget, Func<FilterExecutionContext<Update>, object, bool> filterAction) public AnonymousTypeFilter(string name, Func<Update, object?> getFilterringTarget, Func<FilterExecutionContext<Update>, object, bool> filterAction)
@@ -43,10 +46,10 @@ namespace Telegrator.Filters.Components
} }
/// <summary> /// <summary>
/// Compiles a filter for a specific target type. /// Compiles a filter for a specific target type with a custom name.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the filtering target.</typeparam> /// <typeparam name="T">The type of the filtering target.</typeparam>
/// <param name="name"></param> /// <param name="name">The custom name for the compiled filter.</param>
/// <param name="filter">The filter to apply.</param> /// <param name="filter">The filter to apply.</param>
/// <param name="getFilterringTarget">The function to get the filtering target from an update.</param> /// <param name="getFilterringTarget">The function to get the filtering target from an update.</param>
/// <returns>The compiled filter.</returns> /// <returns>The compiled filter.</returns>
@@ -11,6 +11,9 @@ namespace Telegrator.Filters.Components
private readonly IFilter<T>[] Filters; private readonly IFilter<T>[] Filters;
private readonly string _name; private readonly string _name;
/// <summary>
/// Gets the name of this compiled filter.
/// </summary>
public virtual string Name => _name; public virtual string Name => _name;
/// <summary> /// <summary>
@@ -24,9 +27,9 @@ namespace Telegrator.Filters.Components
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CompiledFilter{T}"/> class. /// Initializes a new instance of the <see cref="CompiledFilter{T}"/> class with a custom name.
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name">The custom name for the compiled filter.</param>
/// <param name="filters">The filters to compose.</param> /// <param name="filters">The filters to compose.</param>
public CompiledFilter(string name, params IFilter<T>[] filters) public CompiledFilter(string name, params IFilter<T>[] filters)
{ {
+6
View File
@@ -1,7 +1,13 @@
namespace Telegrator.Filters.Components namespace Telegrator.Filters.Components
{ {
/// <summary>
/// Interface for filters that have a name for identification and debugging purposes.
/// </summary>
public interface INamedFilter public interface INamedFilter
{ {
/// <summary>
/// Gets the name of the filter.
/// </summary>
public string Name { get; } public string Name { get; }
} }
@@ -1,7 +1,6 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Handlers.Components; using Telegrator.Handlers.Components;
using Telegrator.MadiatorCore;
using Telegrator.MadiatorCore.Descriptors; using Telegrator.MadiatorCore.Descriptors;
namespace Telegrator.Handlers.Building namespace Telegrator.Handlers.Building
@@ -56,13 +55,15 @@ namespace Telegrator.Handlers.Building
return Task.FromResult(Result.Ok()); return Task.FromResult(Result.Ok());
} }
/// <summary> /// <inheritdoc/>
/// Disposes of the reset event. protected override bool Dispose(bool disposing)
/// </summary>
public void Dispose()
{ {
if (!disposing)
return true;
ResetEvent.Dispose(); ResetEvent.Dispose();
ResetEvent = null!; ResetEvent = null!;
return true;
} }
} }
} }
@@ -6,16 +6,37 @@ using Telegrator.MadiatorCore.Descriptors;
namespace Telegrator.Handlers.Components namespace Telegrator.Handlers.Components
{ {
/// <summary>
/// Represents a report of filter fallback information for debugging and error handling.
/// Contains detailed information about which filters failed and why during handler execution.
/// </summary>
/// <param name="descriptor">The handler descriptor that generated this report.</param>
/// <param name="context">The filter execution context.</param>
public class FiltersFallbackReport(HandlerDescriptor descriptor, FilterExecutionContext<Update> context) public class FiltersFallbackReport(HandlerDescriptor descriptor, FilterExecutionContext<Update> context)
{ {
/// <summary>
/// Gets the handler descriptor associated with this fallback report.
/// </summary>
public HandlerDescriptor Descriptor { get; } = descriptor; public HandlerDescriptor Descriptor { get; } = descriptor;
/// <summary>
/// Gets the filter execution context that generated this report.
/// </summary>
public FilterExecutionContext<Update> Context { get; } = context; public FilterExecutionContext<Update> Context { get; } = context;
/// <summary>
/// Gets or sets the fallback information for the update validator filter.
/// </summary>
public FilterFallbackInfo? UpdateValidator { get; set; } public FilterFallbackInfo? UpdateValidator { get; set; }
/// <summary>
/// Gets or sets the fallback information for the state keeper validator filter.
/// </summary>
public FilterFallbackInfo? StateKeeperValidator { get; set; } public FilterFallbackInfo? StateKeeperValidator { get; set; }
/// <summary>
/// Gets the list of fallback information for update filters that failed.
/// </summary>
public List<FilterFallbackInfo> UpdateFilters { get; } = []; public List<FilterFallbackInfo> UpdateFilters { get; } = [];
/* /*
@@ -35,6 +56,12 @@ namespace Telegrator.Handlers.Components
} }
*/ */
/// <summary>
/// Checks if the failure is due to a specific attribute type, excluding other failures.
/// </summary>
/// <typeparam name="T">The attribute type to check for.</typeparam>
/// <param name="index">The index of the filter to check (default: 0).</param>
/// <returns>True if the failure is exclusively due to the specified attribute type; otherwise, false.</returns>
public bool ExceptAttribute<T>(int index = 0) where T : UpdateFilterAttributeBase public bool ExceptAttribute<T>(int index = 0) where T : UpdateFilterAttributeBase
{ {
string name = typeof(T).Name; string name = typeof(T).Name;
@@ -46,21 +73,50 @@ namespace Telegrator.Handlers.Components
} }
} }
/// <summary>
/// Contains information about a filter that failed during execution.
/// Provides details about the filter, its failure status, and any associated exception.
/// </summary>
/// <param name="name">The name of the filter.</param>
/// <param name="filter">The filter instance that failed.</param>
/// <param name="failed">Whether the filter failed.</param>
/// <param name="exception">The exception that occurred during filter execution, if any.</param>
public class FilterFallbackInfo(string name, IFilter<Update> filter, bool failed, Exception? exception) public class FilterFallbackInfo(string name, IFilter<Update> filter, bool failed, Exception? exception)
{ {
/// <summary>
/// Gets the name of the filter.
/// </summary>
public string Name { get; } = name; public string Name { get; } = name;
/// <summary>
/// Gets the filter instance that failed.
/// </summary>
public IFilter<Update> Filter { get; } = filter; public IFilter<Update> Filter { get; } = filter;
/// <summary>
/// Gets a value indicating whether the filter failed.
/// </summary>
public bool Failed { get; } = failed; public bool Failed { get; } = failed;
/// <summary>
/// Gets the exception that occurred during filter execution, if any.
/// </summary>
public Exception? Exception { get; } = exception; public Exception? Exception { get; } = exception;
} }
/// <summary>
/// Specifies the reason for a filter fallback.
/// </summary>
public enum FallbackReason public enum FallbackReason
{ {
/// <summary>
/// The filter target was null.
/// </summary>
NullTarget, NullTarget,
/// <summary>
/// The filter failed to pass.
/// </summary>
FailedFilter FailedFilter
} }
} }
@@ -73,6 +73,9 @@ namespace Telegrator.MadiatorCore.Descriptors
set; set;
} }
/// <summary>
/// Gets or sets a value indicating whether to form a fallback report for debugging purposes.
/// </summary>
public bool FormReport public bool FormReport
{ {
get; get;
@@ -126,7 +129,8 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Display string for the handler (for debugging or logging). /// Gets or sets the display string for this handler descriptor.
/// Used for debugging and logging purposes.
/// </summary> /// </summary>
public string? DisplayString public string? DisplayString
{ {
@@ -135,7 +139,8 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Gets or sets a function for 'lazy' handlers initialization /// Gets or sets the lazy initialization action for this handler.
/// Called when the handler instance needs to be initialized.
/// </summary> /// </summary>
public Action<UpdateHandlerBase>? LazyInitialization public Action<UpdateHandlerBase>? LazyInitialization
{ {
@@ -144,56 +149,60 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with the specified descriptor type and handler type. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class.
/// Automatically inspects the handler type to extract attributes, filters, and configuration.
/// </summary> /// </summary>
/// <param name="descriptorType">The type of the descriptor</param> /// <param name="descriptorType">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler to describe</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="dontInspect"></param> /// <param name="dontInspect">Whether to skip inspection of the handler type.</param>
/// <exception cref="ArgumentException">Thrown when the handler type is not compatible with the expected handler type</exception>
public HandlerDescriptor(DescriptorType descriptorType, Type handlerType, bool dontInspect = false) public HandlerDescriptor(DescriptorType descriptorType, Type handlerType, bool dontInspect = false)
{ {
Type = descriptorType; Type = descriptorType;
HandlerType = handlerType; HandlerType = handlerType;
Filters = new DescriptorFiltersSet(null, null, null); Indexer = new DescriptorIndexer(0, 0, 0);
if (dontInspect) if (!dontInspect)
return; {
UpdateHandlerAttributeBase? pollingHandlerAttribute = HandlerInspector.GetPollingHandlerAttribute(handlerType);
if (pollingHandlerAttribute != null)
{
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
}
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(handlerType); IFilter<Update>[]? filters = HandlerInspector.GetFilterAttributes(handlerType, UpdateType).ToArray();
if (handlerAttribute.ExpectingHandlerType != null && !handlerAttribute.ExpectingHandlerType.Contains(handlerType.BaseType)) IFilter<Update>? stateKeepFilter = HandlerInspector.GetStateKeeperAttribute(handlerType);
throw new ArgumentException(string.Format("This handler attribute cannot be attached to this class. Attribute can be attached on next handlers : {0}", string.Join(", ", handlerAttribute.ExpectingHandlerType.AsEnumerable()))); DescriptorAspectsSet? aspects = HandlerInspector.GetAspects(handlerType);
StateKeeperAttributeBase? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(handlerType); if (filters.Length > 0 || stateKeepFilter != null)
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(handlerType, handlerAttribute.Type).ToArray(); {
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
UpdateType = handlerAttribute.Type; if (aspects != null)
Indexer = handlerAttribute.GetIndexer(); {
FormReport = handlerAttribute.FormReport; Aspects = aspects;
Filters = new DescriptorFiltersSet(handlerAttribute, stateKeeperAttribute, filters); }
Aspects = HandlerInspector.GetAspects(handlerType); }
DisplayString = HandlerInspector.GetDisplayName(handlerType);
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class as a keyed handler with the specified service key. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for keyed handlers.
/// </summary> /// </summary>
/// <param name="handlerType">The type of the handler to describe</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> is null</exception>
public HandlerDescriptor(Type handlerType, object serviceKey) : this(DescriptorType.Keyed, handlerType) public HandlerDescriptor(Type handlerType, object serviceKey) : this(DescriptorType.Keyed, handlerType)
{ {
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); ServiceKey = serviceKey;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with all basic properties. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with complete configuration.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler</param> /// <param name="filters">The set of filters associated with this handler.</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters)
{ {
Type = type; Type = type;
@@ -204,16 +213,15 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with singleton instance support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler</param> /// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler</param> /// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, UpdateHandlerBase singletonInstance) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, UpdateHandlerBase singletonInstance)
{ {
Type = type; Type = type;
@@ -221,20 +229,19 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); ServiceKey = serviceKey;
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance)); SingletonInstance = singletonInstance;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler</param> /// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
@@ -242,20 +249,19 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); InstanceFactory = instanceFactory;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key and instance factory support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key and instance factory.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler</param> /// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
@@ -263,210 +269,243 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); ServiceKey = serviceKey;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); InstanceFactory = instanceFactory;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute and filters. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param> /// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters); FormReport = pollingHandlerAttribute.FormReport;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, and singleton instance. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers with polling handler attribute.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param> /// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler</param> /// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters); FormReport = pollingHandlerAttribute.FormReport;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); ServiceKey = serviceKey;
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance)); SingletonInstance = singletonInstance;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, and instance factory. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory and polling handler attribute.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param> /// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters); FormReport = pollingHandlerAttribute.FormReport;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); InstanceFactory = instanceFactory;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, service key, and instance factory. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key, instance factory and polling handler attribute.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param> /// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters); FormReport = pollingHandlerAttribute.FormReport;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); ServiceKey = serviceKey;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); InstanceFactory = instanceFactory;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with complete configuration.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">Optional validation filter</param> /// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter and singleton instance support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers with complete configuration.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">Optional validation filter</param> /// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler</param> /// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters); ServiceKey = serviceKey;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); SingletonInstance = singletonInstance;
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter and instance factory support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory and complete configuration.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">Optional validation filter</param> /// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters); InstanceFactory = instanceFactory;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter, service key, and instance factory support. /// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key, instance factory and complete configuration.
/// </summary> /// </summary>
/// <param name="type">The type of the descriptor</param> /// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler</param> /// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The type of update this handler processes</param> /// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param> /// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">Optional validation filter</param> /// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">Optional array of filters to apply</param> /// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param> /// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for dependency injection</param> /// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">Factory for creating handler instances</param> /// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters); ServiceKey = serviceKey;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey)); InstanceFactory = instanceFactory;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <summary>
/// Sets singleton instance of this descriptor /// Sets the singleton instance for this handler descriptor.
/// Throws exception if instance already set
/// </summary> /// </summary>
/// <param name="instance"></param> /// <param name="instance">The singleton instance to set.</param>
/// <exception cref="Exception"></exception>
public void SetInstance(UpdateHandlerBase instance) public void SetInstance(UpdateHandlerBase instance)
{ {
if (SingletonInstance != null) if (Type != DescriptorType.Singleton)
throw new Exception(); throw new InvalidOperationException("Cannot set instance for non-singleton descriptor");
SingletonInstance = instance; SingletonInstance = instance;
} }
/// <summary> /// <summary>
/// Tries to set singleton instance of this descriptor /// Attempts to set the singleton instance for this handler descriptor.
/// </summary> /// </summary>
/// <param name="instance"></param> /// <param name="instance">The singleton instance to set.</param>
/// <returns></returns> /// <returns>True if the instance was set successfully; otherwise, false.</returns>
public bool TrySetInstance(UpdateHandlerBase instance) public bool TrySetInstance(UpdateHandlerBase instance)
{ {
if (SingletonInstance != null) if (Type != DescriptorType.Singleton)
return false; return false;
SingletonInstance = instance; SingletonInstance = instance;
return true; return true;
} }
/// <inheritdoc/> /// <summary>
/// Returns a string representation of this handler descriptor.
/// </summary>
/// <returns>A string representation of the handler descriptor.</returns>
public override string ToString() public override string ToString()
=> DisplayString ?? HandlerType.Name; {
return DisplayString ?? $"{Type} {HandlerType.Name}";
}
} }
} }