Esempio n. 1
0
        public async Task <string> StartAsync(int port)
        {
            LogConfiguration.CreateLogger(LogLevel);

            var url = $"http://localhost:{port}";

            _host = Host.CreateDefaultBuilder()
                    .UseSerilog()
                    .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseUrls(url);
                webBuilder.UseStartup <Startup>();
            })
                    .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>()
                {
                    ["Boost:Port"]         = port.ToString(),
                    ["Boost:WebServerUrl"] = url
                });
            })
                    .ConfigureServices((context, services) =>
            {
                services.AddControllers()
                .PartManager.ApplicationParts.Add(new AssemblyPart(_commandContext.ToolAssembly));

                services.AddSameSiteOptions();
                services.AddHttpContextAccessor();
                services.AddSignalR();
                services.AddBoost();
                services.AddSingleton <IBoostCommandContext>(_commandContext);

                services.AddSingleton <IWebShellFactory, WebShellFactory>();
                services.AddHttpClient();
                services.AddSingleton <IAuthWebServer, AuthWebServer>();
                _commandContext.ConfigureWeb?.Invoke(services);

                services.AddSingleton(
                    _commandContext.Services !.GetRequiredService <IBoostDbContextFactory>());

                services.AddSingleton(
                    _commandContext.Services !.GetRequiredService <IUserDataProtector>());

                services.AddSingleton(
                    _commandContext.Services !.GetRequiredService <AppSettings>());
            })
                    .Build();

            await _host.StartAsync();

            _console.WriteLine($"Boost server started on {url}");

            return(url);
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            LogConfiguration.CreateLogger();

            using (ServiceProvider services = new ServiceCollection()
                                              .AddSingleton(PhysicalConsole.Singleton)
                                              .AddSingleton <IReporter>(provider =>
                                                                        new ConsoleReporter(provider.GetRequiredService <IConsole>()))
                                              .AddToolServices()
                                              .AddSingleton(new AppSettings())
                                              .AddSingleton <IWebShellFactory, ConsoleWebShellFactory>()
                                              .AddSingleton <IWebServer>(c =>
            {
                return(new BoostWebServer(
                           c.GetRequiredService <IConsole>(),
                           new BoostCommandContext(c, (services) =>
                {
                    services.AddGitHub();
                    services.AddAzureDevOps();
                    services.AddSnapshooter();

                    services.AddGraphQLServices((gql) =>
                    {
                        gql.AddSnapshooterTypes();
                        gql.AddGitHubTypes();
                        gql.AddAzureDevOpsTypes();
                    });
                }, typeof(Program).Assembly)));
            })
                                              .BuildServiceProvider())
            {
                var app = new CommandLineApplication <Program>();
                app.Conventions
                .UseDefaultConventions()
                .UseConstructorInjection(services);

                return(app.Execute(args));
            }
        }