* Added missing summaries
This commit is contained in:
@@ -9,11 +9,11 @@ using Telegrator.RoslynGenerators.RoslynExtensions;
|
||||
using System.Diagnostics;
|
||||
#endif
|
||||
|
||||
namespace Telegrator.RoslynGenerators
|
||||
namespace Telegrator.RoslynGenerators;
|
||||
|
||||
[Generator(LanguageNames.CSharp)]
|
||||
public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
||||
{
|
||||
[Generator(LanguageNames.CSharp)]
|
||||
public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
||||
{
|
||||
private static readonly string[] DefaultUsings =
|
||||
[
|
||||
"Telegrator.Handlers.Building",
|
||||
@@ -280,5 +280,4 @@ namespace Telegrator.RoslynGenerators
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,11 @@
|
||||
This application's logger
|
||||
</summary>
|
||||
</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>
|
||||
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class.
|
||||
</summary>
|
||||
<param name="webApplicationBuilder">The proxied instance of host builder.</param>
|
||||
<param name="handlers"></param>
|
||||
</member>
|
||||
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.CreateBuilder(Telegrator.Hosting.Web.TelegramBotWebOptions)">
|
||||
<summary>
|
||||
@@ -209,6 +208,14 @@
|
||||
Provides method to configure <see cref="T:Telegrator.Hosting.Web.ITelegramBotWebHost"/>
|
||||
</summary>
|
||||
</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.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers"/>
|
||||
</member>
|
||||
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Hosting.Web.TelegramBotWebOptions,Telegrator.Core.IHandlersCollection)">
|
||||
<summary>
|
||||
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
@@ -227,5 +234,10 @@
|
||||
<param name="services"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:Telegrator.ServicesCollectionExtensions.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers">
|
||||
<summary>
|
||||
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -396,11 +396,29 @@
|
||||
</summary>
|
||||
<returns>The configured TelegramBotClientOptions instance.</returns>
|
||||
</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.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers"/>
|
||||
</member>
|
||||
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.Hosting.TelegramBotHostBuilderSettings,Telegrator.Core.IHandlersCollection)">
|
||||
<summary>
|
||||
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Telegrator.HostBuilderExtensions.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers">
|
||||
<summary>
|
||||
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Telegrator.ServicesCollectionExtensions">
|
||||
<summary>
|
||||
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
|
||||
@@ -476,5 +494,17 @@
|
||||
<param name="routineMethod"></param>
|
||||
<returns>True if the type implements IPreBuildingRoutine; otherwise, false.</returns>
|
||||
</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>
|
||||
</doc>
|
||||
|
||||
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0290")]
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[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.
|
||||
/// </summary>
|
||||
/// <param name="webApplicationBuilder">The proxied instance of host builder.</param>
|
||||
/// <param name="handlers"></param>
|
||||
public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers)
|
||||
public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder)
|
||||
{
|
||||
// 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
|
||||
_innerApp = webApplicationBuilder.Build();
|
||||
@@ -161,15 +162,5 @@ namespace Telegrator.Hosting.Web
|
||||
GC.SuppressFinalize(this);
|
||||
_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));
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_handlers = new HostHandlersCollection(Services, _settings);
|
||||
|
||||
_innerBuilder.AddTelegratorWeb(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,7 +62,7 @@ namespace Telegrator.Hosting.Web
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_handlers = handlers ?? throw new ArgumentNullException(nameof(settings));
|
||||
|
||||
_innerBuilder.AddTelegratorWeb(settings);
|
||||
_innerBuilder.AddTelegratorWeb(settings, handlers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,38 +71,7 @@ namespace Telegrator.Hosting.Web
|
||||
/// <returns></returns>
|
||||
public TelegramBotWebHost Build()
|
||||
{
|
||||
if (_handlers is IHostHandlersCollection hostHandlers)
|
||||
{
|
||||
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);
|
||||
return new TelegramBotWebHost(_innerBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics;
|
||||
@@ -20,6 +21,19 @@ namespace Telegrator
|
||||
/// </summary>
|
||||
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>
|
||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
/// </summary>
|
||||
@@ -32,6 +46,7 @@ namespace Telegrator
|
||||
ConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
handlers ??= new HostHandlersCollection(services, settings);
|
||||
builder.Host.Properties.Add(HandlersCollectionPropertyKey, handlers);
|
||||
|
||||
if (handlers is IHostHandlersCollection hostHandlers)
|
||||
{
|
||||
@@ -53,6 +68,7 @@ namespace Telegrator
|
||||
if (!settings.DisableAutoConfigure)
|
||||
{
|
||||
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegratorWebOptions)));
|
||||
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegramBotClientOptions)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,8 +108,12 @@ namespace Telegrator
|
||||
ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
|
||||
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
|
||||
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0290")]
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||
|
||||
@@ -36,7 +36,8 @@ namespace Telegrator.Hosting
|
||||
public TelegramBotHost(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers)
|
||||
{
|
||||
// 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
|
||||
_innerHost = hostApplicationBuilder.Build();
|
||||
@@ -122,14 +123,5 @@ namespace Telegrator.Hosting
|
||||
GC.SuppressFinalize(this);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
private void RegisterHostServices(IServiceCollection services, IHandlersCollection handlers)
|
||||
{
|
||||
//services.RemoveAll<IHost>();
|
||||
//services.AddSingleton<IHost>(this);
|
||||
|
||||
services.AddSingleton<ITelegramBotHost>(this);
|
||||
services.AddSingleton<ITelegratorBot>(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,26 @@ using Telegrator.Logging;
|
||||
using Telegrator.Polling;
|
||||
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>
|
||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
/// </summary>
|
||||
@@ -37,6 +53,7 @@ namespace Telegrator
|
||||
IConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
handlers ??= new HostHandlersCollection(services, settings);
|
||||
builder.Properties.Add(HandlersCollectionPropertyKey, handlers);
|
||||
|
||||
if (handlers is IHostHandlersCollection hostHandlers)
|
||||
{
|
||||
@@ -62,10 +79,8 @@ namespace Telegrator
|
||||
}
|
||||
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!");
|
||||
*/
|
||||
|
||||
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!");
|
||||
@@ -86,14 +101,14 @@ namespace Telegrator
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="IServiceCollection"/>
|
||||
/// Provides method to configure <see cref="ITelegramBotHost"/>
|
||||
/// </summary>
|
||||
public static class ServicesCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="IServiceCollection"/>
|
||||
/// Provides method to configure <see cref="ITelegramBotHost"/>
|
||||
/// </summary>
|
||||
public static class ServicesCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers a configuration instance that strongly-typed <typeparamref name="TOptions"/> will bind against using <see cref="ConfigureOptionsProxy{TOptions}"/>.
|
||||
/// </summary>
|
||||
@@ -145,13 +160,13 @@ namespace Telegrator
|
||||
/// <returns></returns>
|
||||
private static ITelegramBotClient TypedTelegramBotClientFactory(HttpClient httpClient, IServiceProvider provider)
|
||||
=> new TelegramBotClient(provider.GetRequiredService<IOptions<TelegramBotClientOptions>>().Value, httpClient);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides useful methods to adjust <see cref="ITelegramBotHost"/>
|
||||
/// </summary>
|
||||
public static class TelegramBotHostExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides useful methods to adjust <see cref="ITelegramBotHost"/>
|
||||
/// </summary>
|
||||
public static class TelegramBotHostExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Replaces the initialization logic from TelegramBotWebHost constructor.
|
||||
/// Initializes the bot and logs handlers on application startup.
|
||||
@@ -163,8 +178,12 @@ namespace Telegrator
|
||||
ILoggerFactory loggerFactory = botHost.Services.GetRequiredService<ILoggerFactory>();
|
||||
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("Telegram Bot : {firstname}, @{usrname}, id:{id},", info.User.FirstName ?? "[NULL]", info.User.Username ?? "[NULL]", info.User.Id);
|
||||
logger.LogHandlers(handlers);
|
||||
}
|
||||
|
||||
return botHost;
|
||||
}
|
||||
@@ -197,13 +216,13 @@ namespace Telegrator
|
||||
TelegratorLogging.AddAdapter(adapter);
|
||||
return host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for reflection and type inspection.
|
||||
/// </summary>
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods for reflection and type inspection.
|
||||
/// </summary>
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if a type implements the <see cref="IPreBuildingRoutine"/> interface.
|
||||
/// </summary>
|
||||
@@ -219,12 +238,23 @@ namespace Telegrator
|
||||
routineMethod = handlerType.GetMethod(nameof(IPreBuildingRoutine.PreBuildingRoutine), BindingFlags.Static | BindingFlags.Public);
|
||||
return routineMethod != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoggerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods for logging Telegrator-related information.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
if (!logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information))
|
||||
return;
|
||||
|
||||
StringBuilder logBuilder = new StringBuilder("Registered handlers : ");
|
||||
if (!handlers.Keys.Any())
|
||||
throw new Exception();
|
||||
@@ -244,5 +274,4 @@ namespace Telegrator
|
||||
|
||||
logger.LogInformation(logBuilder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
using Telegram.Bot.Types;
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Telegrator.Localized
|
||||
{
|
||||
public interface ILocalizedMessageHandler : ILocalizedHandler<Message>
|
||||
{
|
||||
namespace Telegrator.Localized;
|
||||
|
||||
public interface ILocalizedMessageHandler : ILocalizedHandler<Message>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ using Telegrator.Logging;
|
||||
|
||||
namespace Telegrator;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a continuous chat action that runs in the background until cancelled or disposed.
|
||||
/// </summary>
|
||||
public class ContinuousAction : IDisposable
|
||||
{
|
||||
private readonly ITelegramBotClient _client;
|
||||
@@ -17,6 +20,14 @@ public class ContinuousAction : IDisposable
|
||||
|
||||
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)
|
||||
{
|
||||
_client = client;
|
||||
@@ -52,6 +63,9 @@ public class ContinuousAction : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the continuous action.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
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()
|
||||
{
|
||||
await _workerTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the instance and stops the continuous action.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _disposed, 1) == 1)
|
||||
@@ -85,5 +105,7 @@ public class ContinuousAction : IDisposable
|
||||
{
|
||||
_linkedCts.Dispose();
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Telegrator.Core.Descriptors
|
||||
private readonly ManualResetEventSlim ResetEvent = new ManualResetEventSlim(false);
|
||||
|
||||
/// <summary>
|
||||
/// descriptor from that handler was described from
|
||||
/// Descriptor from that handler was described from.
|
||||
/// </summary>
|
||||
public HandlerDescriptor From { get; }
|
||||
|
||||
@@ -71,9 +71,9 @@ namespace Telegrator.Core.Descriptors
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DescribedHandlerDescriptor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fromDescriptor">descriptor from that handler was described from</param>
|
||||
/// <param name="awaitingProvider"></param>
|
||||
/// <param name="fromDescriptor">The descriptor from which this handler was described.</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="handlerInstance">The handler instance.</param>
|
||||
/// <param name="filterContext">The filter execution context.</param>
|
||||
@@ -98,6 +98,10 @@ namespace Telegrator.Core.Descriptors
|
||||
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)
|
||||
{
|
||||
await Task.Yield();
|
||||
@@ -105,6 +109,10 @@ namespace Telegrator.Core.Descriptors
|
||||
ResetEvent.Wait(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the execution result and signals completion.
|
||||
/// </summary>
|
||||
/// <param name="result">The execution result.</param>
|
||||
public void ReportResult(Result? result)
|
||||
{
|
||||
if (result != null)
|
||||
|
||||
@@ -4,8 +4,8 @@ using Telegram.Bot.Types;
|
||||
namespace Telegrator.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Requests new <see cref="Update"/>s and processes them using provided <see cref="IUpdateHandler"/> instance<
|
||||
/// /summary>
|
||||
/// Requests new <see cref="Update"/>s and processes them using provided <see cref="IUpdateHandler"/> instance.
|
||||
/// </summary>
|
||||
public interface IUpdateReceiver
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -18,8 +18,14 @@ namespace Telegrator.Mediation
|
||||
/// </summary>
|
||||
protected readonly object SyncObj = new object();
|
||||
|
||||
/// <summary>
|
||||
/// The task responsible for reading and processing handlers from the channel.
|
||||
/// </summary>
|
||||
protected readonly Task ChannelReaderTask;
|
||||
|
||||
/// <summary>
|
||||
/// The channel used to queue handlers for execution.
|
||||
/// </summary>
|
||||
protected readonly Channel<DescribedHandlerDescriptor> ExecutionChannel;
|
||||
|
||||
/// <summary>
|
||||
@@ -27,6 +33,9 @@ namespace Telegrator.Mediation
|
||||
/// </summary>
|
||||
protected readonly SemaphoreSlim? ExecutionLimiter;
|
||||
|
||||
/// <summary>
|
||||
/// The update router associated with this pool.
|
||||
/// </summary>
|
||||
protected readonly IUpdateRouter UpdateRouter;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,20 +4,20 @@ using Telegrator.Core.Descriptors;
|
||||
using Telegrator.Core.Filters;
|
||||
using Xunit;
|
||||
|
||||
namespace Telegrator.Tests.Collections
|
||||
namespace Telegrator.Tests.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Тесты для коллекций.
|
||||
///
|
||||
/// ПАРАДИГМЫ ТЕСТИРОВАНИЯ:
|
||||
/// 1. Collection Testing - тестирование коллекций и их операций
|
||||
/// 2. List Testing - тестирование списков
|
||||
/// 3. Indexing Testing - тестирование индексации
|
||||
/// 4. Enumeration Testing - тестирование перечисления
|
||||
/// 5. Capacity Testing - тестирование емкости коллекций
|
||||
/// </summary>
|
||||
public class CollectionTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Тесты для коллекций.
|
||||
///
|
||||
/// ПАРАДИГМЫ ТЕСТИРОВАНИЯ:
|
||||
/// 1. Collection Testing - тестирование коллекций и их операций
|
||||
/// 2. List Testing - тестирование списков
|
||||
/// 3. Indexing Testing - тестирование индексации
|
||||
/// 4. Enumeration Testing - тестирование перечисления
|
||||
/// 5. Capacity Testing - тестирование емкости коллекций
|
||||
/// </summary>
|
||||
public class CollectionTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Тест для HandlerDescriptorList - создание списка.
|
||||
///
|
||||
@@ -313,5 +313,4 @@ namespace Telegrator.Tests.Collections
|
||||
{
|
||||
return new HandlerDescriptor(DescriptorType.General, typeof(TestUpdateHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,20 @@ using Telegrator.Filters;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable CS8625
|
||||
namespace Telegrator.Tests.Filters
|
||||
namespace Telegrator.Tests.Filters;
|
||||
|
||||
/// <summary>
|
||||
/// Тесты для базовых фильтров.
|
||||
///
|
||||
/// ПАРАДИГМЫ ТЕСТИРОВАНИЯ:
|
||||
/// 1. AAA (Arrange-Act-Assert) - структура теста: подготовка, действие, проверка
|
||||
/// 2. Given-When-Then - альтернативная формулировка AAA для лучшей читаемости
|
||||
/// 3. Тестирование граничных случаев и исключений
|
||||
/// 4. Использование моков для изоляции тестируемого кода
|
||||
/// 5. Тестирование как позитивных, так и негативных сценариев
|
||||
/// </summary>
|
||||
public class FilterTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Тесты для базовых фильтров.
|
||||
///
|
||||
/// ПАРАДИГМЫ ТЕСТИРОВАНИЯ:
|
||||
/// 1. AAA (Arrange-Act-Assert) - структура теста: подготовка, действие, проверка
|
||||
/// 2. Given-When-Then - альтернативная формулировка AAA для лучшей читаемости
|
||||
/// 3. Тестирование граничных случаев и исключений
|
||||
/// 4. Использование моков для изоляции тестируемого кода
|
||||
/// 5. Тестирование как позитивных, так и негативных сценариев
|
||||
/// </summary>
|
||||
public class FilterTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Тест для AnyFilter - фильтр, который всегда проходит.
|
||||
///
|
||||
@@ -173,5 +173,4 @@ namespace Telegrator.Tests.Filters
|
||||
result.Should().BeTrue();
|
||||
wasCalled.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user