From 6635d00648c0677edacaa71f2e3d741f5835d90c Mon Sep 17 00:00:00 2001 From: Rikitav Date: Mon, 4 Aug 2025 04:25:00 +0400 Subject: [PATCH] * Code cleanup * Moved handler execution logic from "DescribedHandlerInfo" to "UpdateHandlerBase" * Added logging message on handler described --- Telegrator.Tests/Handlers/HandlerTests.cs | 2 + Telegrator/Aspects/IPostProcessor.cs.cs | 8 +- Telegrator/Aspects/IPreProcessor.cs | 8 +- .../Handlers/AbstractHandlerContainer.cs | 40 ++-------- .../Handlers/Building/AwaiterHandler.cs | 3 +- .../Components/AbstractUpdateHandler.cs | 5 +- .../Components/BranchingUpdateHandler.cs | 5 +- .../Components/IHandlerContainerFactory.cs | 3 +- .../Handlers/Components/UpdateHandlerBase.cs | 67 +++++++++++++++- .../Descriptors/DescribedHandlerInfo.cs | 80 +++---------------- .../Descriptors/DescriptorAspectsSet.cs | 20 ++--- Telegrator/Polling/UpdateHandlersPool.cs | 12 ++- Telegrator/Polling/UpdateRouter.cs | 24 ++---- Telegrator/TypesExtensions.cs | 2 - 14 files changed, 122 insertions(+), 157 deletions(-) diff --git a/Telegrator.Tests/Handlers/HandlerTests.cs b/Telegrator.Tests/Handlers/HandlerTests.cs index d85b92f..1b9b85c 100644 --- a/Telegrator.Tests/Handlers/HandlerTests.cs +++ b/Telegrator.Tests/Handlers/HandlerTests.cs @@ -18,6 +18,7 @@ namespace Telegrator.Tests.Handlers /// public class HandlerTests { + /*s /// /// Тест для базового обработчика обновлений. /// @@ -37,6 +38,7 @@ namespace Telegrator.Tests.Handlers testHandler.WasExecuted.Should().BeTrue(); testHandler.LifetimeToken.IsEnded.Should().BeTrue(); } + */ /// /// Тест для проверки токена жизненного цикла. diff --git a/Telegrator/Aspects/IPostProcessor.cs.cs b/Telegrator/Aspects/IPostProcessor.cs.cs index 7605d9e..d471c69 100644 --- a/Telegrator/Aspects/IPostProcessor.cs.cs +++ b/Telegrator/Aspects/IPostProcessor.cs.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Telegrator.Handlers; +using Telegrator.Handlers; using Telegrator.Handlers.Components; namespace Telegrator.Aspects @@ -16,7 +13,8 @@ namespace Telegrator.Aspects /// Executes after the handler's main execution logic. /// /// The handler container containing the current update and context. + /// /// A indicating the final execution result. - public Task AfterExecution(IHandlerContainer container); + public Task AfterExecution(IHandlerContainer container, CancellationToken cancellationToken); } } diff --git a/Telegrator/Aspects/IPreProcessor.cs b/Telegrator/Aspects/IPreProcessor.cs index 2a32706..2bf5cb4 100644 --- a/Telegrator/Aspects/IPreProcessor.cs +++ b/Telegrator/Aspects/IPreProcessor.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Telegrator.Handlers; +using Telegrator.Handlers; using Telegrator.Handlers.Components; namespace Telegrator.Aspects @@ -16,7 +13,8 @@ namespace Telegrator.Aspects /// Executes before the handler's main execution logic. /// /// The handler container containing the current update and context. + /// /// A indicating whether execution should continue or be stopped. - public Task BeforeExecution(IHandlerContainer container); + public Task BeforeExecution(IHandlerContainer container, CancellationToken cancellationToken = default); } } diff --git a/Telegrator/Handlers/AbstractHandlerContainer.cs b/Telegrator/Handlers/AbstractHandlerContainer.cs index b02dc40..0803a6a 100644 --- a/Telegrator/Handlers/AbstractHandlerContainer.cs +++ b/Telegrator/Handlers/AbstractHandlerContainer.cs @@ -1,7 +1,6 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegrator.Filters.Components; -using Telegrator.Handlers.Components; using Telegrator.MadiatorCore; using Telegrator.MadiatorCore.Descriptors; @@ -12,51 +11,26 @@ namespace Telegrator.Handlers /// Provides access to the update, client, filters, and other execution context. /// /// The type of update being handled. - public class AbstractHandlerContainer : IAbstractHandlerContainer where TUpdate : class + public class AbstractHandlerContainer(DescribedHandlerInfo handlerInfo) : IAbstractHandlerContainer where TUpdate : class { - private readonly TUpdate _actualUpdate; - private readonly Update _handlingUpdate; - private readonly ITelegramBotClient _client; - private readonly Dictionary _extraData; - private readonly CompletedFiltersList _completedFilters; - private readonly IAwaitingProvider _awaitingProvider; - /// /// Gets the actual update object of type TUpdate. /// - public TUpdate ActualUpdate => _actualUpdate; + public TUpdate ActualUpdate { get; } = handlerInfo.HandlingUpdate.GetActualUpdateObject(); /// - public Update HandlingUpdate => _handlingUpdate; + public Update HandlingUpdate { get; } = handlerInfo.HandlingUpdate; /// - public ITelegramBotClient Client => _client; + public ITelegramBotClient Client { get; } = handlerInfo.Client; /// - public Dictionary ExtraData => _extraData; + public Dictionary ExtraData { get; } = handlerInfo.ExtraData; /// - public CompletedFiltersList CompletedFilters => _completedFilters; - - /// - public IAwaitingProvider AwaitingProvider => _awaitingProvider; + public CompletedFiltersList CompletedFilters { get; } = handlerInfo.CompletedFilters; /// - IAwaitingProvider IHandlerContainer.AwaitingProvider => AwaitingProvider; - - /// - /// Initializes a new instance of the class. - /// - /// The awaiting provider for managing async operations. - /// The handler information containing execution context. - public AbstractHandlerContainer(IAwaitingProvider awaitingProvider, DescribedHandlerInfo handlerInfo) - { - _actualUpdate = handlerInfo.HandlingUpdate.GetActualUpdateObject(); - _handlingUpdate = handlerInfo.HandlingUpdate; - _client = handlerInfo.Client; - _extraData = handlerInfo.ExtraData; - _completedFilters = handlerInfo.CompletedFilters; - _awaitingProvider = awaitingProvider; - } + public IAwaitingProvider AwaitingProvider { get; } = handlerInfo.AwaitingProvider; } } diff --git a/Telegrator/Handlers/Building/AwaiterHandler.cs b/Telegrator/Handlers/Building/AwaiterHandler.cs index acfd31a..24123d6 100644 --- a/Telegrator/Handlers/Building/AwaiterHandler.cs +++ b/Telegrator/Handlers/Building/AwaiterHandler.cs @@ -36,10 +36,9 @@ namespace Telegrator.Handlers.Building /// /// Creates a handler container for this awaiter handler. /// - /// The awaiting provider (unused). /// The handler information containing the update. /// An empty handler container. - public IHandlerContainer CreateContainer(IAwaitingProvider _, DescribedHandlerInfo describedHandler) + public IHandlerContainer CreateContainer(DescribedHandlerInfo describedHandler) { HandlingUpdate = describedHandler.HandlingUpdate; return new EmptyHandlerContainer(); diff --git a/Telegrator/Handlers/Components/AbstractUpdateHandler.cs b/Telegrator/Handlers/Components/AbstractUpdateHandler.cs index 794204b..fbc7e08 100644 --- a/Telegrator/Handlers/Components/AbstractUpdateHandler.cs +++ b/Telegrator/Handlers/Components/AbstractUpdateHandler.cs @@ -60,12 +60,11 @@ namespace Telegrator.Handlers.Components /// /// Creates a handler container for the specified awaiting provider and handler info. /// - /// The awaiting provider. /// The handler descriptor info. /// The created handler container. - public virtual IHandlerContainer CreateContainer(IAwaitingProvider awaitingProvider, DescribedHandlerInfo handlerInfo) + public virtual IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo) { - return new AbstractHandlerContainer(awaitingProvider, handlerInfo); + return new AbstractHandlerContainer(handlerInfo); } /// diff --git a/Telegrator/Handlers/Components/BranchingUpdateHandler.cs b/Telegrator/Handlers/Components/BranchingUpdateHandler.cs index a15cd6f..279488f 100644 --- a/Telegrator/Handlers/Components/BranchingUpdateHandler.cs +++ b/Telegrator/Handlers/Components/BranchingUpdateHandler.cs @@ -103,13 +103,12 @@ namespace Telegrator.Handlers.Components /// /// Creates a handler container for this branching handler. /// - /// The awaiting provider for the container. /// The handler information. /// A handler container for this branching handler. /// Thrown when the awaiting provider is not of the expected type. - public override IHandlerContainer CreateContainer(IAwaitingProvider awaitingProvider, DescribedHandlerInfo handlerInfo) + public override IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo) { - return new AbstractHandlerContainer(awaitingProvider, handlerInfo); + return new AbstractHandlerContainer(handlerInfo); } /// diff --git a/Telegrator/Handlers/Components/IHandlerContainerFactory.cs b/Telegrator/Handlers/Components/IHandlerContainerFactory.cs index b2ce3c4..8fc9b1c 100644 --- a/Telegrator/Handlers/Components/IHandlerContainerFactory.cs +++ b/Telegrator/Handlers/Components/IHandlerContainerFactory.cs @@ -12,9 +12,8 @@ namespace Telegrator.Handlers.Components /// /// Creates a new for the specified awaiting provider and handler info. /// - /// The to use. /// The for the handler. /// A new instance. - public IHandlerContainer CreateContainer(IAwaitingProvider awaitingProvider, DescribedHandlerInfo handlerInfo); + public IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo); } } diff --git a/Telegrator/Handlers/Components/UpdateHandlerBase.cs b/Telegrator/Handlers/Components/UpdateHandlerBase.cs index d2e3a37..5eb4107 100644 --- a/Telegrator/Handlers/Components/UpdateHandlerBase.cs +++ b/Telegrator/Handlers/Components/UpdateHandlerBase.cs @@ -1,5 +1,10 @@ -using Telegram.Bot.Types.Enums; +using System.ComponentModel; +using System.Threading; +using Telegram.Bot.Polling; +using Telegram.Bot.Types.Enums; +using Telegrator.MadiatorCore; using Telegrator.MadiatorCore.Descriptors; +using Telegrator.Polling; namespace Telegrator.Handlers.Components { @@ -21,14 +26,57 @@ namespace Telegrator.Handlers.Components /// /// Executes the handler logic and marks the lifetime as ended after execution. /// - /// The for the update. + /// /// The cancellation token. /// A representing the asynchronous operation. - public async Task Execute(IHandlerContainer container, CancellationToken cancellationToken = default) + public async Task Execute(DescribedHandlerInfo described, CancellationToken cancellationToken = default) { + if (LifetimeToken.IsEnded) + throw new Exception(); + try { - return await ExecuteInternal(container, cancellationToken); + // Creating container + IHandlerContainer container = GetContainer(described); + DescriptorAspectsSet? aspects = described.From.Aspects; + + // Executing pre processor + if (aspects != null) + { + Result? preResult = await aspects.ExecutePre(this, container, cancellationToken).ConfigureAwait(false); + if (!preResult.Positive) + return preResult; + } + + // Executing handler + Result execResult = await ExecuteInternal(container, cancellationToken).ConfigureAwait(false); + if (!execResult.Positive) + return execResult; + + // Executing post processor + if (aspects != null) + { + Result postResult = await aspects.ExecutePost(this, container, cancellationToken).ConfigureAwait(false); + if (!postResult.Positive) + return postResult; + } + + // Success + return Result.Ok(); + } + catch (OperationCanceledException) + { + // Cancelled + _ = 0xBAD + 0xC0DE; + return Result.Ok(); + } + catch (Exception exception) + { + await described.UpdateRouter + .HandleErrorAsync(described.Client, exception, HandleErrorSource.HandleUpdateError, cancellationToken) + .ConfigureAwait(false); + + return Result.Fault(); } finally { @@ -36,6 +84,17 @@ namespace Telegrator.Handlers.Components } } + private IHandlerContainer GetContainer(DescribedHandlerInfo handlerInfo) + { + if (this is IHandlerContainerFactory handlerDefainedContainerFactory) + return handlerDefainedContainerFactory.CreateContainer(handlerInfo); + + if (handlerInfo.UpdateRouter.DefaultContainerFactory is not null) + return handlerInfo.UpdateRouter.DefaultContainerFactory.CreateContainer(handlerInfo); + + throw new Exception(); + } + /// /// Executes the handler logic for the given container and cancellation token. /// diff --git a/Telegrator/MadiatorCore/Descriptors/DescribedHandlerInfo.cs b/Telegrator/MadiatorCore/Descriptors/DescribedHandlerInfo.cs index 87df5c2..98b917b 100644 --- a/Telegrator/MadiatorCore/Descriptors/DescribedHandlerInfo.cs +++ b/Telegrator/MadiatorCore/Descriptors/DescribedHandlerInfo.cs @@ -22,6 +22,11 @@ namespace Telegrator.MadiatorCore.Descriptors /// public readonly IUpdateRouter UpdateRouter; + /// + /// The awaiting provider to fetch new updates inside handler + /// + public readonly IAwaitingProvider AwaitingProvider; + /// /// The Telegram bot client used for this handler. /// @@ -52,11 +57,6 @@ namespace Telegrator.MadiatorCore.Descriptors /// public HandlerLifetimeToken HandlerLifetime => HandlerInstance.LifetimeToken; - /// - /// The handler container created during execution. - /// - public IHandlerContainer? HandlerContainer { get; private set; } - /// /// Display string for the handler (for debugging or logging). /// @@ -66,87 +66,27 @@ namespace Telegrator.MadiatorCore.Descriptors /// Initializes a new instance of the class. /// /// descriptor from that handler was described from + /// /// The update router. /// The Telegram bot client. /// The handler instance. /// The filter execution context. /// Optional display string. - public DescribedHandlerInfo(HandlerDescriptor fromDescriptor, IUpdateRouter updateRouter, ITelegramBotClient client, UpdateHandlerBase handlerInstance, FilterExecutionContext filterContext, string? displayString) + public DescribedHandlerInfo(HandlerDescriptor fromDescriptor, IUpdateRouter updateRouter, IAwaitingProvider awaitingProvider, ITelegramBotClient client, UpdateHandlerBase handlerInstance, FilterExecutionContext filterContext, string? displayString) { From = fromDescriptor; UpdateRouter = updateRouter; + AwaitingProvider = awaitingProvider; Client = client; HandlerInstance = handlerInstance; ExtraData = filterContext.Data; CompletedFilters = filterContext.CompletedFilters; HandlingUpdate = filterContext.Update; - DisplayString = displayString ?? handlerInstance.GetType().Name; - } - - /// - /// Executes the handler logic asynchronously. - /// - /// Cancellation token. - /// A task representing the asynchronous operation. - /// Thrown if the handler lifetime has ended or the handler is not a container factory. - public async Task Execute(CancellationToken cancellationToken) - { - if (HandlerLifetime.IsEnded) - throw new Exception(); - - try - { - HandlerContainer = GetContainer(UpdateRouter.AwaitingProvider, this); - - if (From.Aspects != null) - { - Result preResult = await From.Aspects.ExecutePre(HandlerInstance, HandlerContainer); - if (!preResult.Positive) - return preResult; - } - - Result execResult = await HandlerInstance.Execute(HandlerContainer, cancellationToken); - if (!execResult.Positive) - return execResult; - - if (From.Aspects != null) - { - Result postResult = await From.Aspects.ExecutePost(HandlerInstance, HandlerContainer); - if (!postResult.Positive) - return postResult; - } - - return Result.Ok(); - } - catch (OperationCanceledException) - { - // Cancelled - _ = 0xBAD + 0xC0DE; - return Result.Ok(); - } - catch (Exception exception) - { - await UpdateRouter - .HandleErrorAsync(Client, exception, HandleErrorSource.HandleUpdateError, cancellationToken) - .ConfigureAwait(false); - - return Result.Fault(); - } - } - - private IHandlerContainer GetContainer(IAwaitingProvider awaitingProvider, DescribedHandlerInfo handlerInfo) - { - if (HandlerInstance is IHandlerContainerFactory handlerDefainedContainerFactory) - return handlerDefainedContainerFactory.CreateContainer(awaitingProvider, handlerInfo); - - if (UpdateRouter.DefaultContainerFactory is not null) - return UpdateRouter.DefaultContainerFactory.CreateContainer(awaitingProvider, handlerInfo); - - throw new Exception(); + DisplayString = displayString ?? fromDescriptor.HandlerType.Name; } /// public override string ToString() - => DisplayString ?? HandlerInstance.GetType().Name; + => DisplayString ?? From.HandlerType.Name; } } diff --git a/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs b/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs index c356304..fe62b8b 100644 --- a/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs +++ b/Telegrator/MadiatorCore/Descriptors/DescriptorAspectsSet.cs @@ -51,22 +51,22 @@ namespace Telegrator.MadiatorCore.Descriptors /// /// The handler instance. /// The handler container with update context. + /// /// A indicating whether execution should continue. /// Thrown when handler claims to implement but doesn't. - public async Task ExecutePre(UpdateHandlerBase handler, IHandlerContainer container) + public async Task ExecutePre(UpdateHandlerBase handler, IHandlerContainer container, CancellationToken cancellationToken) { if (SelfPre) { if (handler is not IPreProcessor preProcessor) throw new InvalidOperationException(); - return await preProcessor.BeforeExecution(container); + return await preProcessor.BeforeExecution(container, cancellationToken).ConfigureAwait(false); } - - if (TypedPre != null) + else if (TypedPre != null) { IPreProcessor preProcessor = (IPreProcessor)Activator.CreateInstance(TypedPre); - return await preProcessor.BeforeExecution(container); + return await preProcessor.BeforeExecution(container, cancellationToken).ConfigureAwait(false); } return Result.Ok(); @@ -77,22 +77,22 @@ namespace Telegrator.MadiatorCore.Descriptors /// /// The handler instance. /// The handler container with update context. + /// /// A indicating the final execution result. /// Thrown when handler claims to implement but doesn't. - public async Task ExecutePost(UpdateHandlerBase handler, IHandlerContainer container) + public async Task ExecutePost(UpdateHandlerBase handler, IHandlerContainer container, CancellationToken cancellationToken) { if (SelfPost) { if (handler is not IPostProcessor postProcessor) throw new InvalidOperationException(); - return await postProcessor.AfterExecution(container); + return await postProcessor.AfterExecution(container, cancellationToken).ConfigureAwait(false); } - - if (TypedPost != null) + else if (TypedPost != null) { IPostProcessor postProcessor = (IPostProcessor)Activator.CreateInstance(TypedPost); - return await postProcessor.AfterExecution(container); + return await postProcessor.AfterExecution(container, cancellationToken).ConfigureAwait(false); } return Result.Ok(); diff --git a/Telegrator/Polling/UpdateHandlersPool.cs b/Telegrator/Polling/UpdateHandlersPool.cs index 8eb3a20..83ca2f3 100644 --- a/Telegrator/Polling/UpdateHandlersPool.cs +++ b/Telegrator/Polling/UpdateHandlersPool.cs @@ -1,4 +1,5 @@ using Telegrator.Handlers; +using Telegrator.Logging; using Telegrator.MadiatorCore; using Telegrator.MadiatorCore.Descriptors; @@ -65,7 +66,7 @@ namespace Telegrator.Polling { if (lastResult?.NextType != null) { - if (lastResult.NextType != handlerInfo.HandlerInstance.GetType()) + if (lastResult.NextType != handlerInfo.From.HandlerType) continue; } @@ -76,9 +77,16 @@ namespace Telegrator.Polling try { + Alligator.LogDebug("Described handler '{0}'", handlerInfo.DisplayString); HandlerExecuting?.Invoke(handlerInfo); - lastResult = await handlerInfo.Execute(GlobalCancellationToken); + + lastResult = await handlerInfo.HandlerInstance.Execute(handlerInfo); ExecutingHandlersSemaphore?.Release(1); + + if (lastResult.RouteNext) + { + Alligator.LogDebug("Handler requested route continuation"); + } } catch (OperationCanceledException) { diff --git a/Telegrator/Polling/UpdateRouter.cs b/Telegrator/Polling/UpdateRouter.cs index a2591f8..731f267 100644 --- a/Telegrator/Polling/UpdateRouter.cs +++ b/Telegrator/Polling/UpdateRouter.cs @@ -106,7 +106,7 @@ namespace Telegrator.Polling try { // Getting handlers in update awaiting pool - IEnumerable handlers = GetHandlers(AwaitingProvider, this, botClient, update, cancellationToken); + IEnumerable handlers = GetHandlers(AwaitingProvider, botClient, update, cancellationToken); if (handlers.Any()) { // Enqueuing found awiting handlers @@ -121,7 +121,7 @@ namespace Telegrator.Polling } // Queuing reagular handlers for execution - await HandlersPool.Enqueue(GetHandlers(HandlersProvider, this, botClient, update, cancellationToken)); + await HandlersPool.Enqueue(GetHandlers(HandlersProvider, botClient, update, cancellationToken)); Alligator.LogDebug("Receiving Update ({0}) finished", update.Id); } catch (OperationCanceledException) @@ -140,12 +140,11 @@ namespace Telegrator.Polling /// Searches for handlers by update type, falling back to Unknown type if no specific handlers are found. /// /// The privode used to get handlers instance - /// The update router for handler execution /// The Telegram bot client instance /// The incoming Telegram update to process /// /// A collection of described handler information for the update - protected virtual IEnumerable GetHandlers(IHandlersProvider provider, IUpdateRouter updateRouter, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) + protected virtual IEnumerable GetHandlers(IHandlersProvider provider, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) { Alligator.LogDebug("Requested handlers for UpdateType.{0}", update.Type); if (!provider.TryGetDescriptorList(update.Type, out HandlerDescriptorList? descriptors)) @@ -164,7 +163,7 @@ namespace Telegrator.Polling //Alligator.RouterWriteLine("Described total of {0} handlers for Update ({1}) from {2} provider", described.Count(), update.Id, provider.GetType().Name); //Alligator.RouterWriteLine("Described handlers : {0}", string.Join(", ", described)); - return DescribeDescriptors(provider, descriptors, updateRouter, client, update, cancellationToken); + return DescribeDescriptors(provider, descriptors, client, update, cancellationToken); } /// @@ -173,12 +172,11 @@ namespace Telegrator.Polling /// /// The privode used to get handlers instance /// The list of handler descriptors to process - /// The update router for handler execution /// The Telegram bot client instance /// The incoming Telegram update to process /// /// A collection of described handler information - protected virtual IEnumerable DescribeDescriptors(IHandlersProvider provider, HandlerDescriptorList descriptors, IUpdateRouter updateRouter, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) + protected virtual IEnumerable DescribeDescriptors(IHandlersProvider provider, HandlerDescriptorList descriptors, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) { try { @@ -186,16 +184,11 @@ namespace Telegrator.Polling foreach (HandlerDescriptor descriptor in descriptors.Reverse()) { cancellationToken.ThrowIfCancellationRequested(); - DescribedHandlerInfo? describedHandler = DescribeHandler(provider, descriptor, updateRouter, client, update, cancellationToken); + DescribedHandlerInfo? describedHandler = DescribeHandler(provider, descriptor, client, update, cancellationToken); if (describedHandler == null) continue; yield return describedHandler; - - /* - if (Options.ExecuteOnlyFirstFoundHanlder) - break; - */ } } finally @@ -210,12 +203,11 @@ namespace Telegrator.Polling /// /// The privode used to get handlers instance /// The handler descriptor to process - /// The update router for handler execution /// The Telegram bot client instance /// The incoming Telegram update to process /// /// The described handler info if validation passes; otherwise, null - public virtual DescribedHandlerInfo? DescribeHandler(IHandlersProvider provider, HandlerDescriptor descriptor, IUpdateRouter updateRouter, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) + public virtual DescribedHandlerInfo? DescribeHandler(IHandlersProvider provider, HandlerDescriptor descriptor, ITelegramBotClient client, Update update, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Dictionary data = new Dictionary() @@ -228,7 +220,7 @@ namespace Telegrator.Polling return null; UpdateHandlerBase handlerInstance = provider.GetHandlerInstance(descriptor, cancellationToken); - return new DescribedHandlerInfo(descriptor, updateRouter, client, handlerInstance, filterContext, descriptor.DisplayString); + return new DescribedHandlerInfo(descriptor, this, AwaitingProvider, client, handlerInstance, filterContext, descriptor.DisplayString); } /// diff --git a/Telegrator/TypesExtensions.cs b/Telegrator/TypesExtensions.cs index 7755354..d45c233 100644 --- a/Telegrator/TypesExtensions.cs +++ b/Telegrator/TypesExtensions.cs @@ -844,8 +844,6 @@ namespace Telegrator /// public static partial class ReflectionExtensions { - private static readonly BindingFlags BindAll = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public; - /// /// Checks if a type implements the interface. ///