コード例 #1
0
    /// <summary>
    /// Processes.
    /// </summary>
    /// <param name="args">The command arguments.</param>
    /// <param name="context">The conversation context during the command processing.</param>
    /// <param name="cancellationToken">An optional cancellation token.</param>
    /// <returns>true if process succeeded; otherwise, false.</returns>
    async Task ICommandHandler.ProcessAsync(CommandArguments args, CommandConversationContext context, CancellationToken cancellationToken)
    {
        if (IsDisabled)
        {
            return;
        }
        await Task.Run(() => { }, cancellationToken);

        try
        {
            OnProcess(args, context);
        }
        catch (Exception ex)
        {
            var exConverted = ExceptionHandler.GetException(ex);
            if (exConverted == null)
            {
                return;
            }
            if (exConverted == ex)
            {
                throw;
            }
            throw exConverted;
        }
    }
コード例 #2
0
    /// <summary>
    /// Gets help information.
    /// </summary>
    /// <param name="args">The arguments.</param>
    /// <param name="context">The conversation context during the command processing.</param>
    void ICommandHandler.GetHelp(CommandArguments args, CommandConversationContext context)
    {
        var instance = factory();

        if (instance is null)
        {
            return;
        }
        instance.GetHelp(args ?? new CommandArguments(string.Empty), context);
    }
コード例 #3
0
    /// <summary>
    /// Processes.
    /// </summary>
    /// <param name="args">The command arguments.</param>
    /// <param name="context">The conversation context during the command processing.</param>
    /// <param name="cancellationToken">An optional cancellation token.</param>
    /// <returns>true if process succeeded; otherwise, false.</returns>
    Task ICommandHandler.ProcessAsync(CommandArguments args, CommandConversationContext context, CancellationToken cancellationToken)
    {
        var instance = factory();

        if (instance is null)
        {
            return(Task.Run(() => { }, cancellationToken));
        }
        return(instance.ProcessAsync(args ?? new CommandArguments(string.Empty), context, cancellationToken));
    }
コード例 #4
0
 /// <summary>
 /// Occurs on getting help of the handler.
 /// </summary>
 /// <param name="args">The arguments data.</param>
 /// <param name="context">The conversation context during the command processing.</param>
 protected virtual void OnGetHelp(CommandArguments args, CommandConversationContext context)
 {
     Console.WriteLine(Description);
 }
コード例 #5
0
 /// <summary>
 /// Occurs on processing.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="context">The conversation context during the command processing.</param>
 protected abstract void OnProcess(CommandArguments args, CommandConversationContext context);
コード例 #6
0
 /// <summary>
 /// Gets help information.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="context">The conversation context during the command processing.</param>
 void ICommandHandler.GetHelp(CommandArguments args, CommandConversationContext context)
 => OnGetHelp(args, context);
コード例 #7
0
 /// <summary>
 /// Occurs on getting help of the handler.
 /// </summary>
 /// <param name="args">The arguments data.</param>
 /// <param name="context">The conversation context during the command processing.</param>
 protected virtual void OnGetHelp(CommandArguments args, CommandConversationContext context)
 {
 }
コード例 #8
0
 /// <summary>
 /// Occurs on processing.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="context">The conversation context during the command processing.</param>
 /// <param name="cancellationToken">An optional cancellation token.</param>
 /// <returns>A task that represents the completion of all of the invoking action tasks.</returns>
 protected abstract Task OnProcessAsync(CommandArguments args, CommandConversationContext context, CancellationToken cancellationToken = default);