public DebugInfoPageMiddleware(RequestDelegate next, IServerAddressesFeature serverAddresses, IHostingEnvironment hostingEnv, Scenarios scenarios)
 {
     _next = next;
     _hostingEnv = hostingEnv;
     _scenarios = scenarios;
     _serverAddresses = serverAddresses;
 }
Пример #2
0
        public Startup(IHostingEnvironment hostingEnv, Scenarios scenarios)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(PlatformServices.Default.Application.ApplicationBasePath)
                .AddCommandLine(Program.Args)
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{hostingEnv.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();

            Configuration = builder.Build();

            Scenarios = scenarios;
        }
        public void ConfigureScenarios(Scenarios scenarios)
        {
            var scenarioConfig = new ConfigurationBuilder()
                .AddJsonFile("scenarios.json", optional: true)
                .AddCommandLine(_args)
                .Build();

            var enabledCount = 0;
            var configuredScenarios = scenarioConfig["scenarios"];
            if (!string.IsNullOrWhiteSpace(configuredScenarios))
            {
                Console.WriteLine("Scenario configuration found in scenarios.json and/or command line args");
                var choices = configuredScenarios.Split(',');
                foreach (var choice in choices)
                {
                    enabledCount += scenarios.Enable(choice);
                }
            }
            else
            {
                Console.WriteLine("Which scenarios would you like to enable?:");
                Console.WriteLine();
                foreach (var scenario in Scenarios.GetNames())
                {
                    Console.WriteLine("  " + scenario);
                }
                Console.WriteLine();
                Console.WriteLine("Type full or partial scenario names separated by commas and hit [Enter]");
                Console.Write("> ");

                var choices = Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (choices.Length > 0)
                {
                    foreach (var choice in choices)
                    {
                        enabledCount += scenarios.Enable(choice);
                    }
                }
            }

            if (enabledCount == 0)
            {
                Console.WriteLine();
                Console.WriteLine("No matching scenarios found, enabling defaults");
                scenarios.EnableDefault();
            }

            PrintEnabledScenarios(scenarios.GetEnabled());
        }