* Version incremented
* Added ability to handle errors during filters validation inside Handlers * Moved Result class to root directory * Added FilterOrigin enum
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegrator.MadiatorCore;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.MadiatorCore.Descriptors;
|
||||
using Telegrator.Polling;
|
||||
|
||||
namespace Telegrator.Handlers.Components
|
||||
{
|
||||
@@ -102,5 +100,20 @@ namespace Telegrator.Handlers.Components
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
protected abstract Task<Result> ExecuteInternal(IHandlerContainer container, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles failed filters during handler describing.
|
||||
/// Use <see cref="Result"/> to control how router should treat this fail.
|
||||
/// <see cref="Result.Ok"/> to silently continue decribing.
|
||||
/// <see cref="Result.Fault"/> to stop\break decribing sequence.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="failedFilter"></param>
|
||||
/// <param name="origin"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task<Result> FiltersFallback(FilterExecutionContext<Update> context, IFilter<Update> failedFilter, FilterOrigin origin)
|
||||
{
|
||||
return Task.FromResult(Result.Ok());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
namespace Telegrator.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents handler results, allowing to communicate with router and control aspect execution
|
||||
/// </summary>
|
||||
public sealed class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// Is result positive
|
||||
/// </summary>
|
||||
public bool Positive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Should router search for next matching handler
|
||||
/// </summary>
|
||||
public bool RouteNext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Exact type that router should search
|
||||
/// </summary>
|
||||
public Type? NextType { get; }
|
||||
|
||||
internal Result(bool positive, bool routeNext, Type? nextType)
|
||||
{
|
||||
Positive = positive;
|
||||
RouteNext = routeNext;
|
||||
NextType = nextType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "OK" result
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Result Ok()
|
||||
=> new Result(true, false, null);
|
||||
|
||||
/// <summary>
|
||||
/// "Somethong went wrong" result
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Result Fault()
|
||||
=> new Result(false, false, null);
|
||||
|
||||
/// <summary>
|
||||
/// "Search next handler" result
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Result Next()
|
||||
=> new Result(true, true, null);
|
||||
|
||||
/// <summary>
|
||||
/// "Search next handler of type" result
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static Result Next<T>()
|
||||
=> new Result(true, true, typeof(T));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user