Exemplo n.º 1
0
 protected void VerifyConfigurationsIfNeeded(
     MicrodotHostingConfig hostingConfig, ConfigurationVerificator configurationVerificator)
 {
     if (FailServiceStartOnConfigError??hostingConfig.FailServiceStartOnConfigError)
     {
         var badConfigs = configurationVerificator.Verify().Where(c => !c.Success).ToList();
         if (badConfigs.Any())
             throw new EnvironmentException("Bad configuration(s) detected. Stopping service startup. You can disable this behavior through the Microdot.Hosting.FailServiceStartOnConfigError configuration. Errors:\n"
                 + badConfigs.Aggregate(new StringBuilder(), (sb, bc) => sb.Append(bc).Append("\n")));
     }
 }
Exemplo n.º 2
0
        protected void VerifyConfiguration(ConfigurationVerificator ConfigurationVerificator)
        {
            if (ConfigurationVerificator == null)
            {
                System.Environment.ExitCode = 2;
                Console.Error.WriteLine("ERROR: The configuration verification is not properly implemented. " +
                                        "To implement you need to override OnVerifyConfiguration base method and call to base.");
            }
            else
            {
                try
                {
                    var results = ConfigurationVerificator.Verify();
                    System.Environment.ExitCode = results.All(r => r.Success) ? 0 : 1;

                    if (Arguments.ConsoleOutputMode == ConsoleOutputMode.Color)
                    {
                        var(restoreFore, restoreBack) = (Console.ForegroundColor, Console.BackgroundColor);
                        foreach (var result in results)
                        {
                            Console.BackgroundColor = result.Success ? ConsoleColor.Black : ConsoleColor.White;
                            Console.ForegroundColor = result.Success ? ConsoleColor.White : ConsoleColor.Red;
                            Console.WriteLine(result);
                        }
                        Console.BackgroundColor = restoreBack;
                        Console.ForegroundColor = restoreFore;
                    }
                    else
                    {
                        foreach (var result in results)
                        {
                            Console.WriteLine(result);
                        }
                    }
                    // Avoid extra messages in machine to machine mode or when disabled
                    if (!(Console.IsOutputRedirected || Arguments.ConsoleOutputMode == ConsoleOutputMode.Disabled))
                    {
                        Console.WriteLine("   ***   Shutting down [configuration verification mode].   ***   ");
                    }
                }
                catch (Exception ex)
                {
                    System.Environment.ExitCode = 3;
                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine(ex.StackTrace);
                }
            }
        }