public override async Task <bool> Execute(CheckEnvironmentInput input)
        {
            AnsiConsole.Render(
                new FigletText("Oakton")
                .LeftAligned());


            using (var host = input.BuildHost())
            {
                var results = await EnvironmentChecker.ExecuteAllEnvironmentChecks(host.Services);

                if (input.FileFlag.IsNotEmpty())
                {
                    results.WriteToFile(input.FileFlag);
                    Console.WriteLine("Writing environment checks to " + input.FileFlag);
                }

                if (results.Failures.Any())
                {
                    ConsoleWriter.Write(ConsoleColor.Red, "Some environment checks failed!");
                    return(false);
                }
                else
                {
                    ConsoleWriter.Write(ConsoleColor.Green, "All environment checks are good!");
                    return(true);
                }
            }
        }
示例#2
0
        public override bool Execute(RunInput input)
        {
            Host = input.BuildHost();

            if (input.CheckFlag)
            {
                EnvironmentChecker.ExecuteAllEnvironmentChecks(Host.Services)
                .GetAwaiter().GetResult()
                .Assert();
            }


            var assembly = typeof(RunCommand).GetTypeInfo().Assembly;

            AssemblyLoadContext.GetLoadContext(assembly).Unloading += context => Shutdown();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Shutdown();
                eventArgs.Cancel = true;
            };

            using (Host)
            {
                Host.Start();

                Started.Set();

                var shutdownMessage = "Press CTRL + C to quit";

                // TODO -- do this with a flag
                //Console.WriteLine("Running all environment checks...");
                //host.ExecuteAllEnvironmentChecks();

                IHostingEnvironment service = Host.Services.GetService <IHostingEnvironment>();

                Console.WriteLine("Hosting environment: " + service.EnvironmentName);
                Console.WriteLine("Content root path: " + service.ContentRootPath);
                ICollection <string> addresses = Host.ServerFeatures.Get <IServerAddressesFeature>()?.Addresses;
                if (addresses != null)
                {
                    foreach (string str in addresses)
                    {
                        Console.WriteLine("Now listening on: " + str);
                    }
                }
                if (!string.IsNullOrEmpty(shutdownMessage))
                {
                    Console.WriteLine(shutdownMessage);
                }


                Reset.Wait();
            }


            return(true);
        }
示例#3
0
        public override async Task <bool> Execute(RunInput input)
        {
            using (Host = input.BuildHost())
            {
                if (input.CheckFlag)
                {
                    var report = await EnvironmentChecker.ExecuteAllEnvironmentChecks(Host.Services);

                    report.Assert();
                }

                await Host.RunAsync();
            }


            return(true);
        }
示例#4
0
        public override async Task <bool> Execute(CheckEnvironmentInput input)
        {
            using (var host = input.BuildHost())
            {
                var results = await EnvironmentChecker.ExecuteAllEnvironmentChecks(host.Services);

                if (input.FileFlag.IsNotEmpty())
                {
                    results.WriteToFile(input.FileFlag);
                    Console.WriteLine("Writing environment checks to " + input.FileFlag);
                }

                results.Assert();

                ConsoleWriter.Write(ConsoleColor.Green, "All environment checks are good!");
            }

            return(true);
        }
示例#5
0
        public override async Task <bool> Execute(RunInput input)
        {
            input.ApplyHostBuilderInput();
            input.HostBuilder.ConfigureServices(services => services.AddHostedService <Job1>());

            using (Host = input.BuildHost())
            {
                if (input.CheckFlag)
                {
                    var report = await EnvironmentChecker.ExecuteAllEnvironmentChecks(Host.Services);

                    report.Assert();
                }

                await Host.RunAsync();
            }


            return(true);
        }
示例#6
0
        public async override Task <bool> Execute(RunInput input)
        {
            using (var host = input.BuildHost())
            {
                if (input.CheckFlag)
                {
                    (await EnvironmentChecker.ExecuteAllEnvironmentChecks(host.Services)).Assert();
                }

                var reset = new ManualResetEventSlim();
                AssemblyLoadContext.GetLoadContext(typeof(RunCommand).GetTypeInfo().Assembly).Unloading += (Action <AssemblyLoadContext>)(context => reset.Set());
                Console.CancelKeyPress += (ConsoleCancelEventHandler)((sender, eventArgs) =>
                {
                    reset.Set();
                    eventArgs.Cancel = true;
                });

                await host.StartAsync();

                reset.Wait();
                await host.StopAsync();
            }
            return(true);
        }