示例#1
0
        public static async Task <EnvironmentCheckResults> ExecuteAllEnvironmentChecks(IServiceProvider services, CancellationToken token = default(CancellationToken))
        {
            var results = new EnvironmentCheckResults();


            var checks = services.discoverChecks().ToArray();

            if (!checks.Any())
            {
                return(results);
            }

            Console.WriteLine("Running Environment Checks");

            for (int i = 0; i < checks.Length; i++)
            {
                var check = checks[i];

                try
                {
                    await check.Assert(services, token);

                    ConsoleWriter.Write(ConsoleColor.Green, $"{(i + 1).ToString().PadLeft(4)}.) Success: {check.Description}");
                    results.RegisterSuccess(check.Description);
                }
                catch (Exception e)
                {
                    ConsoleWriter.Write(ConsoleColor.Red, $"{(i + 1).ToString().PadLeft(4)}.) Failed: {check.Description}");
                    ConsoleWriter.Write(ConsoleColor.Yellow, e.ToString());
                    results.RegisterFailure(check.Description, e);
                }
            }

            return(results);
        }
 public EnvironmentCheckException(EnvironmentCheckResults results) : base(results.ToString(), results.Failures.Select(x => x.Exception))
 {
     Results = results;
 }