コード例 #1
0
        /// <summary>
        ///     Runs checks on parent modules and this command.
        /// </summary>
        /// <param name="context"> The <see cref="ICommandContext"/> used for execution. </param>
        /// <param name="provider"> The <see cref="IServiceProvider"/> used for execution. </param>
        /// <returns>
        ///     A <see cref="SuccessfulResult"/> if all of the checks pass, otherwise a <see cref="ChecksFailedResult"/>.
        /// </returns>
        public async Task <IResult> RunChecksAsync(ICommandContext context, IServiceProvider provider = null)
        {
            if (provider is null)
            {
                provider = EmptyServiceProvider.Instance;
            }

            var result = await Module.RunChecksAsync(context, provider).ConfigureAwait(false);

            if (!result.IsSuccessful)
            {
                return(result);
            }

            if (Checks.Count > 0)
            {
                var checkResults = (await Task.WhenAll(Checks.Select(x => RunCheckAsync(x, context, provider))).ConfigureAwait(false));
                var failedGroups = checkResults.GroupBy(x => x.Check.Group).Where(x => x.Key == null ? x.Any(y => y.Error != null) : x.All(y => y.Error != null)).ToArray();
                if (failedGroups.Length > 0)
                {
                    return(new ChecksFailedResult(this, failedGroups.SelectMany(x => x).Where(x => x.Error != null).ToImmutableList()));
                }
            }

            return(new SuccessfulResult());
        }
コード例 #2
0
ファイル: CommandHelper.cs プロジェクト: Ultz/Volte
 public static async ValueTask <bool> CanShowModuleAsync(VolteContext ctx, Module module) =>
 await module.RunChecksAsync(ctx) is SuccessfulResult;