public void With_sla_attribute() { TimeSpan sla; GenericHost.TryGetSlaFromEndpointConfigType(typeof(ClassWithHostSlaAttribute), out sla); Assert.AreEqual(TimeSpan.FromHours(2), sla); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> public WindowsHost(Type endpointType, string[] args, string endpointName, IEnumerable <string> scannableAssembliesFullName) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); genericHost = new GenericHost(specifier, args, new List <Type> { typeof(Production) }, endpointName, scannableAssembliesFullName); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> /// <param name="scannableAssembliesFullName"></param> public WindowsHost(Type endpointType, string[] args, IEnumerable<string> scannableAssembliesFullName) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); genericHost = new GenericHost(specifier, args, new List<Type> { typeof(Development) }, scannableAssembliesFullName); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> public WindowsHost(Type endpointType, string[] args) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); genericHost = new GenericHost(specifier, args, new[] { typeof(Lite) }); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> public WindowsHost(Type endpointType, string[] args) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); genericHost = new GenericHost(specifier, args, new[] { typeof(Development) }); }
protected AppServiceBaseTest(ITestOutputHelper outputHelper) { var host = GenericHost.CreateHostBuilder(null) .ConfigureLogging(builder => builder.AddXUnit(outputHelper)) .Build(); ServiceProvider = host.Services; OutputHelper = outputHelper; }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> /// <param name="scannableAssembliesFullName"></param> public WindowsHost(Type endpointType, string[] args, IEnumerable <string> scannableAssembliesFullName) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); genericHost = new GenericHost(specifier, args, new List <Type> { typeof(Development) }, scannableAssembliesFullName); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> public WindowsHost(Type endpointType, string[] args) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); args = AddProfilesFromConfiguration(args); genericHost = new GenericHost(specifier, args, new[] { typeof(Development), typeof(OnAzureTableStorage) }, Program.EndpointId); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> public WindowsHost(Type endpointType, string[] args) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); Program.EndpointId = Program.GetEndpointId(specifier); args = AddProfilesFromConfiguration(args); genericHost = new GenericHost(specifier, args, new[] { typeof(Development), typeof(OnAzureTableStorage) }); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> /// <param name="endpointName"></param> /// <param name="runOtherInstallers"></param> /// <param name="runInfrastructureInstallers"></param> public WindowsHost(Type endpointType, string[] args, string endpointName, bool runOtherInstallers, bool runInfrastructureInstallers) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); genericHost = new GenericHost(specifier, args, new[] { typeof(Production) }, endpointName); Configure.Instance.DefineCriticalErrorAction(OnCriticalError); if (runOtherInstallers || Debugger.IsAttached) this.runOtherInstallers = true; this.runInfrastructureInstallers = runInfrastructureInstallers; }
public async Task Test1() { var host = new GenericHost(); host.OnConfigure += app => app.Run(ctx => { ctx.Response.StatusCode = 204; return(Task.CompletedTask); }); await host.InitializeAsync(); var response = await host.HttpClient.GetAsync("/test"); response.StatusCode.Should().Be(204); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> /// <param name="endpointName"></param> /// <param name="runOtherInstallers"></param> /// <param name="runInfrastructureInstallers"></param> public WindowsHost(Type endpointType, string[] args, string endpointName, bool runOtherInstallers, bool runInfrastructureInstallers) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); genericHost = new GenericHost(specifier, args, new[] { typeof(Production) }, endpointName); Configure.Instance.DefineCriticalErrorAction(OnCriticalError); if (runOtherInstallers || Debugger.IsAttached) { this.runOtherInstallers = true; } this.runInfrastructureInstallers = runInfrastructureInstallers; }
static void Main(string[] args) { global::Gtk.Application.Init(); var hostBuilder = GenericHost.CreateHostBuilder(args); hostBuilder.ConfigureServices(RegisterServices); using var host = hostBuilder.Build(); host.Start(); var app = host.Services.GetService <Startup>(); app.Run(); }
public int Run() { UserInteraction.Message($"SCALUS is starting up..."); using (GenericHost = CreateHost()) { var serverTask = GenericHost.RunAsync(CancellationTokenSource.Token).ContinueWith(x => { Log.Debug($"Web server stopped: {x.Status}"); return(x); }); OsServices.OpenDefault($"http://localhost:{WebPort}/index.html"); UserInteraction.Message($"SCALUS is running at http://localhost:{WebPort}. Close the browser window to quit."); GenericHost.WaitForShutdown(); } return(0); }
static async Task Main(string[] args) => await GenericHost.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Debug)) .ConfigureServices((hostContext, services) => { // options services.AddOptions(); services.Configure <ConnectionStrings>(hostContext.Configuration.GetSection("ConnectionStrings")); // hosted service = entrypoint services.AddHostedService <TimerHostedService>(); // add dependency injection services.AddSingleton <IFugaService, FugaService>(); }) .RunConsoleAsync();
static async Task <IWantToRunContext> RunHost() { var defaultProfiles = new List <Type> { typeof(Production) }; string[] args = {}; var context = new IWantToRunContext(); var configurer = new GenericEndpointConfig(context); var host = new GenericHost(configurer, args, defaultProfiles, GenericEndpointConfig.EndpointName); await host.Start(); await host.Stop(); return(context); }
public static IHostBuilder CreateHostBuilder(string[] args) => GenericHost .CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, config) => config.AddSecrets()) .UseStartup(config => new Startup(config));
public DynamicProvidersTests() { _idp1 = new GenericHost("https://idp1"); _idp1.OnConfigureServices += services => { services.AddRouting(); services.AddAuthorization(); services.AddIdentityServer() .AddInMemoryClients(new Client[] { new Client { ClientId = "client", ClientSecrets = { new Secret("secret".Sha256()) }, AllowedGrantTypes = GrantTypes.Code, RedirectUris = { "https://server/federation/idp1/signin" }, PostLogoutRedirectUris = { "https://server/federation/idp1/signout-callback" }, FrontChannelLogoutUri = "https://server/federation/idp1/signout", AllowedScopes = { "openid" } } }) .AddInMemoryIdentityResources(new IdentityResource[] { new IdentityResources.OpenId(), }) .AddDeveloperSigningCredential(persistKey: false); services.AddLogging(options => { options.AddFilter("Duende", LogLevel.Debug); }); }; _idp1.OnConfigure += app => { app.UseRouting(); app.UseIdentityServer(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapGet("/signin", async ctx => { await ctx.SignInAsync(new IdentityServerUser("1").CreatePrincipal()); }); endpoints.MapGet("/account/logout", async ctx => { var isis = ctx.RequestServices.GetRequiredService <IIdentityServerInteractionService>(); var logoutCtx = await isis.GetLogoutContextAsync(ctx.Request.Query["logoutId"]); Idp1FrontChannelLogoutUri = logoutCtx.SignOutIFrameUrl; await ctx.SignOutAsync(); }); }); }; _idp1.InitializeAsync().Wait(); _idp2 = new GenericHost("https://idp2"); _idp2.OnConfigureServices += services => { services.AddRouting(); services.AddAuthorization(); services.AddIdentityServer() .AddInMemoryClients(new Client[] { new Client { ClientId = "client", ClientSecrets = { new Secret("secret".Sha256()) }, AllowedGrantTypes = GrantTypes.Code, RedirectUris = { "https://server/signin-oidc" }, PostLogoutRedirectUris = { "https://server/signout-callback-oidc" }, FrontChannelLogoutUri = "https://server/signout-oidc", AllowedScopes = { "openid" } } }) .AddInMemoryIdentityResources(new IdentityResource[] { new IdentityResources.OpenId(), }) .AddDeveloperSigningCredential(persistKey: false); services.AddLogging(options => { options.AddFilter("Duende", LogLevel.Debug); }); }; _idp2.OnConfigure += app => { app.UseRouting(); app.UseIdentityServer(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapGet("/signin", async ctx => { await ctx.SignInAsync(new IdentityServerUser("2").CreatePrincipal()); }); }); }; _idp2.InitializeAsync().Wait(); _host = new GenericHost("https://server"); _host.OnConfigureServices += services => { services.AddRouting(); services.AddAuthorization(); services.AddIdentityServer() .AddInMemoryClients(new Client[] { }) .AddInMemoryIdentityResources(new IdentityResource[] { }) .AddInMemoryOidcProviders(_oidcProviders) .AddInMemoryCaching() .AddIdentityProviderStoreCache <InMemoryOidcProviderStore>() .AddDeveloperSigningCredential(persistKey: false); services.ConfigureAll <OpenIdConnectOptions>(options => { options.BackchannelHttpHandler = _idp1.Server.CreateHandler(); }); services.AddAuthentication() .AddOpenIdConnect("idp2", options => { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; options.Authority = "https://idp2"; options.ClientId = "client"; options.ClientSecret = "secret"; options.ResponseType = "code"; options.ResponseMode = "query"; options.Scope.Clear(); options.Scope.Add("openid"); options.SecurityTokenValidator = new JwtSecurityTokenHandler { MapInboundClaims = false }; options.BackchannelHttpHandler = _idp2.Server.CreateHandler(); }); services.AddLogging(options => { options.AddFilter("Duende", LogLevel.Debug); }); }; _host.OnConfigure += app => { app.UseRouting(); app.UseIdentityServer(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapGet("/user", async ctx => { var session = await ctx.AuthenticateAsync(IdentityServerConstants.DefaultCookieAuthenticationScheme); if (session.Succeeded) { await ctx.Response.WriteAsync(session.Principal.FindFirst("sub").Value); } else { ctx.Response.StatusCode = 401; } }); endpoints.MapGet("/callback", async ctx => { var session = await ctx.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); if (session.Succeeded) { await ctx.SignInAsync(session.Principal, session.Properties); await ctx.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); await ctx.Response.WriteAsync(session.Principal.FindFirst("sub").Value); } else { ctx.Response.StatusCode = 401; } }); endpoints.MapGet("/challenge", async ctx => { await ctx.ChallengeAsync(ctx.Request.Query["scheme"], new AuthenticationProperties { RedirectUri = "/callback" }); }); endpoints.MapGet("/logout", async ctx => { await ctx.SignOutAsync(ctx.Request.Query["scheme"]); }); }); }; _host.InitializeAsync().Wait(); }
public WindowsHost(Type endpointType) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); genericHost = new GenericHost(specifier); }
public void Shutdown() { GenericHost.StopAsync(); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint"/>. /// </summary> /// <param name="endpointType"></param> /// <param name="args"></param> /// <param name="endpointName"></param> public WindowsHost(Type endpointType, string[] args, string endpointName) { var specifier = (IConfigureThisEndpoint)Activator.CreateInstance(endpointType); genericHost = new GenericHost(specifier, args, new[] { typeof(Lite) }, endpointName); }
static async Task Main(string[] args) { await GenericHost.CreateHostBuilder(args) .ConfigureServices(RegisterServices) .RunConsoleAsync(); }