/// <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; } }
/// <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); }
/// <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)); }
/// <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); }
/// <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);
/// <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);
/// <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) { }
/// <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);