* Added missing summaries

This commit is contained in:
2026-03-07 00:17:31 +04:00
parent 1ebf4ec22a
commit 3cdc058fb5
18 changed files with 1045 additions and 964 deletions
@@ -9,8 +9,8 @@ using Telegrator.RoslynGenerators.RoslynExtensions;
using System.Diagnostics; using System.Diagnostics;
#endif #endif
namespace Telegrator.RoslynGenerators namespace Telegrator.RoslynGenerators;
{
[Generator(LanguageNames.CSharp)] [Generator(LanguageNames.CSharp)]
public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
{ {
@@ -281,4 +281,3 @@ namespace Telegrator.RoslynGenerators
} }
} }
} }
}
+14 -2
View File
@@ -34,12 +34,11 @@
This application's logger This application's logger
</summary> </summary>
</member> </member>
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
<summary> <summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class. Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class.
</summary> </summary>
<param name="webApplicationBuilder">The proxied instance of host builder.</param> <param name="webApplicationBuilder">The proxied instance of host builder.</param>
<param name="handlers"></param>
</member> </member>
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.CreateBuilder(Telegrator.Hosting.Web.TelegramBotWebOptions)"> <member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.CreateBuilder(Telegrator.Hosting.Web.TelegramBotWebOptions)">
<summary> <summary>
@@ -209,6 +208,14 @@
Provides method to configure <see cref="T:Telegrator.Hosting.Web.ITelegramBotWebHost"/> Provides method to configure <see cref="T:Telegrator.Hosting.Web.ITelegramBotWebHost"/>
</summary> </summary>
</member> </member>
<member name="F:Telegrator.ServicesCollectionExtensions.HandlersCollectionPropertyKey">
<summary>
The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties.
</summary>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.get_Handlers(Microsoft.Extensions.Hosting.IHostApplicationBuilder)">
<inheritdoc cref="P:Telegrator.ServicesCollectionExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers"/>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Hosting.Web.TelegramBotWebOptions,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Hosting.Web.TelegramBotWebOptions,Telegrator.Core.IHandlersCollection)">
<summary> <summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
@@ -227,5 +234,10 @@
<param name="services"></param> <param name="services"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="P:Telegrator.ServicesCollectionExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers">
<summary>
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
</summary>
</member>
</members> </members>
</doc> </doc>
+30
View File
@@ -396,11 +396,29 @@
</summary> </summary>
<returns>The configured TelegramBotClientOptions instance.</returns> <returns>The configured TelegramBotClientOptions instance.</returns>
</member> </member>
<member name="T:Telegrator.HostBuilderExtensions">
<summary>
Provides extension methods for <see cref="T:Microsoft.Extensions.Hosting.IHostApplicationBuilder"/> to configure Telegrator.
</summary>
</member>
<member name="F:Telegrator.HostBuilderExtensions.HandlersCollectionPropertyKey">
<summary>
The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties.
</summary>
</member>
<member name="M:Telegrator.HostBuilderExtensions.get_Handlers(Microsoft.Extensions.Hosting.IHostApplicationBuilder)">
<inheritdoc cref="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers"/>
</member>
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.Hosting.TelegramBotHostBuilderSettings,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.Hosting.TelegramBotHostBuilderSettings,Telegrator.Core.IHandlersCollection)">
<summary> <summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary> </summary>
</member> </member>
<member name="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers">
<summary>
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
</summary>
</member>
<member name="T:Telegrator.ServicesCollectionExtensions"> <member name="T:Telegrator.ServicesCollectionExtensions">
<summary> <summary>
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
@@ -476,5 +494,17 @@
<param name="routineMethod"></param> <param name="routineMethod"></param>
<returns>True if the type implements IPreBuildingRoutine; otherwise, false.</returns> <returns>True if the type implements IPreBuildingRoutine; otherwise, false.</returns>
</member> </member>
<member name="T:Telegrator.LoggerExtensions">
<summary>
Provides extension methods for logging Telegrator-related information.
</summary>
</member>
<member name="M:Telegrator.LoggerExtensions.LogHandlers(Microsoft.Extensions.Logging.ILogger,Telegrator.Core.IHandlersCollection)">
<summary>
Logs the registered handlers to the specified logger.
</summary>
<param name="logger">The logger to write to.</param>
<param name="handlers">The collection of handlers to log.</param>
</member>
</members> </members>
</doc> </doc>
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0290")] [assembly: SuppressMessage("Style", "IDE0290")]
[assembly: SuppressMessage("Style", "IDE0090")] [assembly: SuppressMessage("Style", "IDE0090")]
[assembly: SuppressMessage("Usage", "CA2254")] [assembly: SuppressMessage("Usage", "CA2254")]
[assembly: SuppressMessage("Maintainability", "CA1510")]
@@ -49,11 +49,12 @@ namespace Telegrator.Hosting.Web
/// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class. /// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class.
/// </summary> /// </summary>
/// <param name="webApplicationBuilder">The proxied instance of host builder.</param> /// <param name="webApplicationBuilder">The proxied instance of host builder.</param>
/// <param name="handlers"></param> public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder)
public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers)
{ {
// Registering this host in services for easy access // Registering this host in services for easy access
RegisterHostServices(webApplicationBuilder.Services, handlers); webApplicationBuilder.Services.AddSingleton<ITelegramBotHost>(this);
webApplicationBuilder.Services.AddSingleton<ITelegramBotWebHost>(this);
webApplicationBuilder.Services.AddSingleton<ITelegratorBot>(this);
// Building proxy application // Building proxy application
_innerApp = webApplicationBuilder.Build(); _innerApp = webApplicationBuilder.Build();
@@ -161,15 +162,5 @@ namespace Telegrator.Hosting.Web
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
_disposed = true; _disposed = true;
} }
private void RegisterHostServices(IServiceCollection services, IHandlersCollection handlers)
{
//service.RemoveAll<IHost>();
//service.AddSingleton<IHost>(this);
services.AddSingleton<ITelegramBotHost>(this);
services.AddSingleton<ITelegramBotWebHost>(this);
services.AddSingleton<ITelegratorBot>(this);
}
} }
} }
@@ -46,6 +46,8 @@ namespace Telegrator.Hosting.Web
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
_handlers = new HostHandlersCollection(Services, _settings); _handlers = new HostHandlersCollection(Services, _settings);
_innerBuilder.AddTelegratorWeb(settings);
} }
/// <summary> /// <summary>
@@ -60,7 +62,7 @@ namespace Telegrator.Hosting.Web
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
_handlers = handlers ?? throw new ArgumentNullException(nameof(settings)); _handlers = handlers ?? throw new ArgumentNullException(nameof(settings));
_innerBuilder.AddTelegratorWeb(settings); _innerBuilder.AddTelegratorWeb(settings, handlers);
} }
/// <summary> /// <summary>
@@ -69,38 +71,7 @@ namespace Telegrator.Hosting.Web
/// <returns></returns> /// <returns></returns>
public TelegramBotWebHost Build() public TelegramBotWebHost Build()
{ {
if (_handlers is IHostHandlersCollection hostHandlers) return new TelegramBotWebHost(_innerBuilder);
{
foreach (PreBuildingRoutine preBuildRoutine in hostHandlers.PreBuilderRoutines)
{
try
{
preBuildRoutine.Invoke(this);
}
catch (NotImplementedException)
{
_ = 0xBAD + 0xC0DE;
}
}
}
if (!_settings.DisableAutoConfigure)
{
Services.Configure<TelegratorWebOptions>(Configuration.GetSection(nameof(TelegratorWebOptions)));
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy());
}
else
{
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegratorWebOptions>)))
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegratorWebOptions' wasn't registered. This configuration is runtime required!");
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegramBotClientOptions>)))
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!");
}
Services.AddSingleton<IConfigurationManager>(Configuration);
Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings));
return new TelegramBotWebHost(_innerBuilder, _handlers);
} }
} }
} }
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Diagnostics; using System.Diagnostics;
@@ -20,6 +21,19 @@ namespace Telegrator
/// </summary> /// </summary>
public static class ServicesCollectionExtensions public static class ServicesCollectionExtensions
{ {
/// <summary>
/// The key used to store the <see cref="IHandlersCollection"/> in the builder properties.
/// </summary>
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
extension(IHostApplicationBuilder builder)
{
/// <summary>
/// Gets the <see cref="IHandlersCollection"/> from the builder properties.
/// </summary>
public IHandlersCollection Handlers => (IHandlersCollection)builder.Properties[HandlersCollectionPropertyKey];
}
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
@@ -32,6 +46,7 @@ namespace Telegrator
ConfigurationManager configuration = builder.Configuration; ConfigurationManager configuration = builder.Configuration;
handlers ??= new HostHandlersCollection(services, settings); handlers ??= new HostHandlersCollection(services, settings);
builder.Host.Properties.Add(HandlersCollectionPropertyKey, handlers);
if (handlers is IHostHandlersCollection hostHandlers) if (handlers is IHostHandlersCollection hostHandlers)
{ {
@@ -53,6 +68,7 @@ namespace Telegrator
if (!settings.DisableAutoConfigure) if (!settings.DisableAutoConfigure)
{ {
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegratorWebOptions))); services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegratorWebOptions)));
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegramBotClientOptions)));
} }
else else
{ {
@@ -92,8 +108,12 @@ namespace Telegrator
ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>(); ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost"); ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Telegrator Bot ASP.NET WebHost started"); logger.LogInformation("Telegrator Bot ASP.NET WebHost started");
logger.LogInformation("Telegram Bot : {firstname}, @{usrname}, id:{id},", info.User.FirstName ?? "[NULL]", info.User.Username ?? "[NULL]", info.User.Id);
logger.LogHandlers(handlers); logger.LogHandlers(handlers);
}
return app; return app;
} }
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0290")] [assembly: SuppressMessage("Style", "IDE0290")]
[assembly: SuppressMessage("Style", "IDE0090")] [assembly: SuppressMessage("Style", "IDE0090")]
[assembly: SuppressMessage("Usage", "CA2254")] [assembly: SuppressMessage("Usage", "CA2254")]
[assembly: SuppressMessage("Maintainability", "CA1510")]
@@ -36,7 +36,8 @@ namespace Telegrator.Hosting
public TelegramBotHost(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers) public TelegramBotHost(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers)
{ {
// Registering this host in services for easy access // Registering this host in services for easy access
RegisterHostServices(hostApplicationBuilder.Services, handlers); hostApplicationBuilder.Services.AddSingleton<ITelegramBotHost>(this);
hostApplicationBuilder.Services.AddSingleton<ITelegratorBot>(this);
// Building proxy hoster // Building proxy hoster
_innerHost = hostApplicationBuilder.Build(); _innerHost = hostApplicationBuilder.Build();
@@ -122,14 +123,5 @@ namespace Telegrator.Hosting
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
_disposed = true; _disposed = true;
} }
private void RegisterHostServices(IServiceCollection services, IHandlersCollection handlers)
{
//services.RemoveAll<IHost>();
//services.AddSingleton<IHost>(this);
services.AddSingleton<ITelegramBotHost>(this);
services.AddSingleton<ITelegratorBot>(this);
}
} }
} }
+35 -6
View File
@@ -21,10 +21,26 @@ using Telegrator.Logging;
using Telegrator.Polling; using Telegrator.Polling;
using Telegrator.Providers; using Telegrator.Providers;
namespace Telegrator namespace Telegrator;
{
/// <summary>
/// Provides extension methods for <see cref="IHostApplicationBuilder"/> to configure Telegrator.
/// </summary>
public static class HostBuilderExtensions public static class HostBuilderExtensions
{ {
/// <summary>
/// The key used to store the <see cref="IHandlersCollection"/> in the builder properties.
/// </summary>
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
extension (IHostApplicationBuilder builder)
{
/// <summary>
/// Gets the <see cref="IHandlersCollection"/> from the builder properties.
/// </summary>
public IHandlersCollection Handlers => (IHandlersCollection)builder.Properties[HandlersCollectionPropertyKey];
}
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
@@ -37,6 +53,7 @@ namespace Telegrator
IConfigurationManager configuration = builder.Configuration; IConfigurationManager configuration = builder.Configuration;
handlers ??= new HostHandlersCollection(services, settings); handlers ??= new HostHandlersCollection(services, settings);
builder.Properties.Add(HandlersCollectionPropertyKey, handlers);
if (handlers is IHostHandlersCollection hostHandlers) if (handlers is IHostHandlersCollection hostHandlers)
{ {
@@ -62,10 +79,8 @@ namespace Telegrator
} }
else else
{ {
/* if (null == services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<ReceiverOptions>)))
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<ReceiverOptions>)))
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'ReceiverOptions' wasn't registered. This configuration is runtime required!"); throw new MissingMemberException("Auto configuration disabled, yet no options of type 'ReceiverOptions' wasn't registered. This configuration is runtime required!");
*/
if (null == services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegramBotClientOptions>))) if (null == services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegramBotClientOptions>)))
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!"); throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!");
@@ -163,8 +178,12 @@ namespace Telegrator
ILoggerFactory loggerFactory = botHost.Services.GetRequiredService<ILoggerFactory>(); ILoggerFactory loggerFactory = botHost.Services.GetRequiredService<ILoggerFactory>();
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost"); ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
if (logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information))
{
logger.LogInformation("Telegrator Bot .NET Host started"); logger.LogInformation("Telegrator Bot .NET Host started");
logger.LogInformation("Telegram Bot : {firstname}, @{usrname}, id:{id},", info.User.FirstName ?? "[NULL]", info.User.Username ?? "[NULL]", info.User.Id);
logger.LogHandlers(handlers); logger.LogHandlers(handlers);
}
return botHost; return botHost;
} }
@@ -221,10 +240,21 @@ namespace Telegrator
} }
} }
/// <summary>
/// Provides extension methods for logging Telegrator-related information.
/// </summary>
public static class LoggerExtensions public static class LoggerExtensions
{ {
/// <summary>
/// Logs the registered handlers to the specified logger.
/// </summary>
/// <param name="logger">The logger to write to.</param>
/// <param name="handlers">The collection of handlers to log.</param>
public static void LogHandlers(this ILogger logger, IHandlersCollection handlers) public static void LogHandlers(this ILogger logger, IHandlersCollection handlers)
{ {
if (!logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information))
return;
StringBuilder logBuilder = new StringBuilder("Registered handlers : "); StringBuilder logBuilder = new StringBuilder("Registered handlers : ");
if (!handlers.Keys.Any()) if (!handlers.Keys.Any())
throw new Exception(); throw new Exception();
@@ -245,4 +275,3 @@ namespace Telegrator
logger.LogInformation(logBuilder.ToString()); logger.LogInformation(logBuilder.ToString());
} }
} }
}
@@ -2,10 +2,9 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Localized namespace Telegrator.Localized;
{
public interface ILocalizedHandler<T> : IAbstractUpdateHandler<Message> where T : class public interface ILocalizedHandler<T> : IAbstractUpdateHandler<Message> where T : class
{ {
public IStringLocalizer LocalizationProvider { get; } public IStringLocalizer LocalizationProvider { get; }
} }
}
@@ -1,9 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace Telegrator.Localized namespace Telegrator.Localized;
{
public interface ILocalizedMessageHandler : ILocalizedHandler<Message> public interface ILocalizedMessageHandler : ILocalizedHandler<Message>
{ {
} }
}
+22
View File
@@ -5,6 +5,9 @@ using Telegrator.Logging;
namespace Telegrator; namespace Telegrator;
/// <summary>
/// Represents a continuous chat action that runs in the background until cancelled or disposed.
/// </summary>
public class ContinuousAction : IDisposable public class ContinuousAction : IDisposable
{ {
private readonly ITelegramBotClient _client; private readonly ITelegramBotClient _client;
@@ -17,6 +20,14 @@ public class ContinuousAction : IDisposable
private int _disposed; private int _disposed;
/// <summary>
/// Initializes a new instance of the <see cref="ContinuousAction"/> class.
/// </summary>
/// <param name="client">The Telegram bot client.</param>
/// <param name="chat">The target chat.</param>
/// <param name="action">The action to perform continuously.</param>
/// <param name="delay">The delay between actions. Defaults to 4 seconds.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public ContinuousAction(ITelegramBotClient client, ChatId chat, ChatAction action, TimeSpan? delay = null, CancellationToken cancellationToken = default) public ContinuousAction(ITelegramBotClient client, ChatId chat, ChatAction action, TimeSpan? delay = null, CancellationToken cancellationToken = default)
{ {
_client = client; _client = client;
@@ -52,6 +63,9 @@ public class ContinuousAction : IDisposable
} }
} }
/// <summary>
/// Cancels the continuous action.
/// </summary>
public void Cancel() public void Cancel()
{ {
if (Interlocked.CompareExchange(ref _disposed, 0, 0) == 0) if (Interlocked.CompareExchange(ref _disposed, 0, 0) == 0)
@@ -67,11 +81,17 @@ public class ContinuousAction : IDisposable
} }
} }
/// <summary>
/// Waits for the background worker task to complete.
/// </summary>
public async Task WaitAsync() public async Task WaitAsync()
{ {
await _workerTask.ConfigureAwait(false); await _workerTask.ConfigureAwait(false);
} }
/// <summary>
/// Disposes the instance and stops the continuous action.
/// </summary>
public void Dispose() public void Dispose()
{ {
if (Interlocked.Exchange(ref _disposed, 1) == 1) if (Interlocked.Exchange(ref _disposed, 1) == 1)
@@ -85,5 +105,7 @@ public class ContinuousAction : IDisposable
{ {
_linkedCts.Dispose(); _linkedCts.Dispose();
} }
GC.SuppressFinalize(this);
} }
} }
@@ -14,7 +14,7 @@ namespace Telegrator.Core.Descriptors
private readonly ManualResetEventSlim ResetEvent = new ManualResetEventSlim(false); private readonly ManualResetEventSlim ResetEvent = new ManualResetEventSlim(false);
/// <summary> /// <summary>
/// descriptor from that handler was described from /// Descriptor from that handler was described from.
/// </summary> /// </summary>
public HandlerDescriptor From { get; } public HandlerDescriptor From { get; }
@@ -71,9 +71,9 @@ namespace Telegrator.Core.Descriptors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DescribedHandlerDescriptor"/> class. /// Initializes a new instance of the <see cref="DescribedHandlerDescriptor"/> class.
/// </summary> /// </summary>
/// <param name="fromDescriptor">descriptor from that handler was described from</param> /// <param name="fromDescriptor">The descriptor from which this handler was described.</param>
/// <param name="awaitingProvider"></param>
/// <param name="updateRouter">The update router.</param> /// <param name="updateRouter">The update router.</param>
/// <param name="awaitingProvider">The awaiting provider.</param>
/// <param name="client">The Telegram bot client.</param> /// <param name="client">The Telegram bot client.</param>
/// <param name="handlerInstance">The handler instance.</param> /// <param name="handlerInstance">The handler instance.</param>
/// <param name="filterContext">The filter execution context.</param> /// <param name="filterContext">The filter execution context.</param>
@@ -98,6 +98,10 @@ namespace Telegrator.Core.Descriptors
DisplayString = displayString ?? fromDescriptor.HandlerType.Name; DisplayString = displayString ?? fromDescriptor.HandlerType.Name;
} }
/// <summary>
/// Waits for the handler execution result.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
public async Task AwaitResult(CancellationToken cancellationToken) public async Task AwaitResult(CancellationToken cancellationToken)
{ {
await Task.Yield(); await Task.Yield();
@@ -105,6 +109,10 @@ namespace Telegrator.Core.Descriptors
ResetEvent.Wait(cancellationToken); ResetEvent.Wait(cancellationToken);
} }
/// <summary>
/// Reports the execution result and signals completion.
/// </summary>
/// <param name="result">The execution result.</param>
public void ReportResult(Result? result) public void ReportResult(Result? result)
{ {
if (result != null) if (result != null)
+2 -2
View File
@@ -4,8 +4,8 @@ using Telegram.Bot.Types;
namespace Telegrator.Core; namespace Telegrator.Core;
/// <summary> /// <summary>
/// Requests new <see cref="Update"/>s and processes them using provided <see cref="IUpdateHandler"/> instance< /// Requests new <see cref="Update"/>s and processes them using provided <see cref="IUpdateHandler"/> instance.
/// /summary> /// </summary>
public interface IUpdateReceiver public interface IUpdateReceiver
{ {
/// <summary> /// <summary>
@@ -18,8 +18,14 @@ namespace Telegrator.Mediation
/// </summary> /// </summary>
protected readonly object SyncObj = new object(); protected readonly object SyncObj = new object();
/// <summary>
/// The task responsible for reading and processing handlers from the channel.
/// </summary>
protected readonly Task ChannelReaderTask; protected readonly Task ChannelReaderTask;
/// <summary>
/// The channel used to queue handlers for execution.
/// </summary>
protected readonly Channel<DescribedHandlerDescriptor> ExecutionChannel; protected readonly Channel<DescribedHandlerDescriptor> ExecutionChannel;
/// <summary> /// <summary>
@@ -27,6 +33,9 @@ namespace Telegrator.Mediation
/// </summary> /// </summary>
protected readonly SemaphoreSlim? ExecutionLimiter; protected readonly SemaphoreSlim? ExecutionLimiter;
/// <summary>
/// The update router associated with this pool.
/// </summary>
protected readonly IUpdateRouter UpdateRouter; protected readonly IUpdateRouter UpdateRouter;
/// <summary> /// <summary>
@@ -4,8 +4,8 @@ using Telegrator.Core.Descriptors;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Xunit; using Xunit;
namespace Telegrator.Tests.Collections namespace Telegrator.Tests.Collections;
{
/// <summary> /// <summary>
/// Тесты для коллекций. /// Тесты для коллекций.
/// ///
@@ -314,4 +314,3 @@ namespace Telegrator.Tests.Collections
return new HandlerDescriptor(DescriptorType.General, typeof(TestUpdateHandler)); return new HandlerDescriptor(DescriptorType.General, typeof(TestUpdateHandler));
} }
} }
}
@@ -5,8 +5,8 @@ using Telegrator.Filters;
using Xunit; using Xunit;
#pragma warning disable CS8625 #pragma warning disable CS8625
namespace Telegrator.Tests.Filters namespace Telegrator.Tests.Filters;
{
/// <summary> /// <summary>
/// Тесты для базовых фильтров. /// Тесты для базовых фильтров.
/// ///
@@ -174,4 +174,3 @@ namespace Telegrator.Tests.Filters
wasCalled.Should().BeTrue(); wasCalled.Should().BeTrue();
} }
} }
}