public ProfilePhoto(ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptionValue, IHostingEnvironment env) { this.tokenAcquisition = tokenAcquisition; this.webOptions = webOptionValue.Value; this.env = env; }
public WebOptions Resolve() { if (_options != null) { // Already cached in this request return _options; } var key = GetKey(); var documentResult = _bucket.GetDocument<WebOptions>(key); if (documentResult.Success && documentResult.Content != null) { // Loaded from Couchbase cache _options = documentResult.Content; } else { // Need to load from database, then store in Couchbase cache _options = LoadFromDatabase(); _bucket.Upsert(new Document<WebOptions>() { Id = key, Content = _options, Expiry = (uint) CacheInterval.TotalMilliseconds }); } return _options; }
public WebOptions Resolve() { if (_options != null) { // Already cached in this request return(_options); } var key = GetKey(); var documentResult = _bucket.GetDocument <WebOptions>(key); if (documentResult.Success && documentResult.Content != null) { // Loaded from Couchbase cache _options = documentResult.Content; } else { // Need to load from database, then store in Couchbase cache _options = LoadFromDatabase(); _bucket.Upsert(new Document <WebOptions>() { Id = key, Content = _options, Expiry = (uint)CacheInterval.TotalMilliseconds }); } return(_options); }
public MediaService(IOptions <WebOptions> options, IOptions <FormOptions> formOptions, ILogger <MediaService> logger, IConnectionMultiplexer connection) { _options = options.Value; _formOptions = formOptions.Value; _logger = logger; _connection = connection; }
public MailProcessingService( IBlobService blobService, IConnectionMultiplexer connectionMultiplexer, ILogger <MailProcessingService> logger, IOptions <WebOptions> options) : base(connectionMultiplexer) { _blobService = blobService; _logger = logger; _options = options.Value; }
public MsGraph ( ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptions, IAzureUserDetailCache userDetailCache ) { _tokenAcquisition = tokenAcquisition; _webOptions = webOptions.Value; _userDetailCache = userDetailCache; }
public HomeController(ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptionValue, ILogger <HomeController> logger, IConfiguration configuration) { this.tokenAcquisition = tokenAcquisition; this.webOptions = webOptionValue.Value; Secrets = new HashSet <SecretItem>(); Configuration = configuration; Keyvault = Configuration["keyvault"]; WebappClaim = new Claim("groups", Configuration["groupObject"]); // Not required UpnClaim = new Claim("name", ""); Telemetry = new TelemetryClient(config); }
public HomeController(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IMemoryCache memoryCache, IOptions <RoomsConfig> roomsConfig, ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptionValue) { _configuration = configuration; _env = hostingEnvironment; _cache = memoryCache; _roomsConfig = roomsConfig; _tokenAcquisition = tokenAcquisition; _webOptions = webOptionValue.Value; }
public async Task Test1() { var options = new WebOptions { MediaStoragePath = "./app_data/media" }; var subs = new Subtitles { Id = "0c86a6a1f91a3f806095b165b7df6673.mp4", Lines = new[] { "1", "00:00:00,100 --> 00:00:05,000", "Welkom in deze wereld!" } }; var mockRedis = new Mock <IConnectionMultiplexer>(); var modkDb = new Mock <IDatabase>(); modkDb.Setup(s => s.StringSetAsync(It.IsAny <RedisKey>(), It.IsAny <RedisValue>(), It.IsAny <TimeSpan>(), It.IsAny <When>(), It.IsAny <CommandFlags>())); modkDb.Setup(s => s.StringGetAsync(It.IsAny <RedisKey>(), It.IsAny <CommandFlags>())).ReturnsAsync((RedisValue)10); mockRedis.Setup(m => m.GetDatabase(-1, null)).Returns(modkDb.Object); var mediaService = new MediaService(Options.Create(options), Options.Create(new FormOptions()), new NullLogger <MediaService>(), mockRedis.Object); var str = mediaService.AddSubTitles(subs, CancellationToken.None); }
private Task StartWebMode(WebOptions options) { var config = new LocalWebServerConfig { Port = options.Port }; var tokenSource = new CancellationTokenSource(); var token = new CancellationToken(); /*var task = */ _localWebServer.RunAsync(config, token); UtilConsole.WriteSuccess("Local server started. Press <Enter> to stop..."); if (options.OpenWindow) { var url = $"http://localhost:{config.Port}"; UtilSystem.OpenUrl(url); } Console.ReadLine(); Console.WriteLine("Stopping local server..."); _localWebServer.Stop(); tokenSource.Cancel(); return(Task.CompletedTask); }
private static IServiceCollection AddCaching(this IServiceCollection services, WebOptions webOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (webOptions == null) { throw new ArgumentNullException(nameof(webOptions)); } var cacheOptions = webOptions.Hosting.Cache; services .AddResponseCaching(x => { x.SizeLimit = cacheOptions.MaxSize * 1024; x.MaximumBodySize = cacheOptions.MaxBodySize * 1024; }); return(services); }
private static IServiceCollection AddHealthChecking(this IServiceCollection services, WebOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (!options.Hosting.UseHealthCheck) { return(services); } services .AddHealthChecks() .AddCheck <StartupHealthCheck>("self"); if (options.Hosting.UseHealthCheckUI) { var port = options.Hosting.Ports.FirstOrDefault(); var config = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); var appOptions = config.GetSection(AppOptions.SectionName).Get <AppOptions>(); var healthz = new { HealthChecks = new[] { new { Name = appOptions.Name.ToLower(), Uri = $"http://localhost:{port}/healthz" } } }; config["HealthChecks-UI"] = JsonConvert.SerializeObject(healthz); // BUG: string.Concat("{\"HealthChecks\": [{\"Name\": \"app\",\"Uri\": \"http://localhost:", port, "/healthz\"}]}"); config[HostDefaults.ContentRootKey] = Directory.GetCurrentDirectory(); services .AddHealthChecksUI(); services.AddScoped <DbContextOptions, DbContextOptions <NullDbContext> >(); // BUG: Wihtout this line, EF-Core fails when no Data Provider / Context is registerd and 'NullDbContext' is used. } return(services); }
public HeroesController(ILogger <HeroesController> logger, IHeroesService heroesService, IOptions <WebOptions> webOptionValue) { _logger = logger; _heroesService = heroesService; webOptions = webOptionValue.Value; }
private static IServiceCollection AddHealthChecking(this IServiceCollection services, AppOptions appOptions, WebOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (!options.Hosting.HealthCheck.UseHealthCheck) { return(services); } services .AddHealthChecks() .AddCheck <StartupHealthCheck>("self"); if (options.Hosting.HealthCheck.UseHealthCheckUI) { var port = options.Hosting.Ports.FirstOrDefault(); var config = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); config[HostDefaults.ContentRootKey] = Directory.GetCurrentDirectory(); // TODO: HealthChecks UI: Doesn't poll: JS: Configured polling interval: NaN milliseconds (seems like knowm issue) services .AddHealthChecksUI(x => { x.AddHealthCheckEndpoint(appOptions.Name.ToLower(), $"http://localhost:{port}/healthz"); x.SetEvaluationTimeInSeconds(options.Hosting.HealthCheck.EvaluationInterval); x.SetMinimumSecondsBetweenFailureNotifications(options.Hosting.HealthCheck.FailureNotificationInterval); foreach (var webHook in options.Hosting.HealthCheck.WebHooks) { x.AddWebhookNotification(webHook.Name, webHook.Uri, webHook.Payload); } }) .AddInMemoryStorage(); } return(services); }
public HomeController(WebOptions options) { _options = options; }
public HomeController(ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptionValue, ResolveCaseContext context) { this.tokenAcquisition = tokenAcquisition; this.webOptions = webOptionValue.Value; _context = context; }
private static IServiceCollection AddDocumentation(this IServiceCollection services, AppOptions appOptions, WebOptions webOptions, SecurityOptions securityOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (appOptions == null) { throw new ArgumentNullException(nameof(appOptions)); } if (webOptions == null) { throw new ArgumentNullException(nameof(webOptions)); } if (securityOptions == null) { throw new ArgumentNullException(nameof(securityOptions)); } return(services .AddSwaggerGen(x => { x.IgnoreObsoleteActions(); x.IgnoreObsoleteProperties(); x.DescribeAllEnumsAsStrings(); x.CustomSchemaIds(y => y.FullName); x.OrderActionsBy(y => y.RelativePath); x.DocumentFilter <LowercaseDocumentFilter>(); x.SwaggerDoc(appOptions.Version, new Info { Title = appOptions.Name, Description = appOptions.Description, Version = appOptions.Version, TermsOfService = appOptions.TermsOfService, Contact = webOptions.Documentation.Contact, License = webOptions.Documentation.License }); if (securityOptions.IsEnabled) { x.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Type = "apiKey", Name = "Authorization", Description = "JWT Authorization header using the Bearer scheme. Format: Authorization: Bearer [token]" }); x.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[] { } } }); } AppDomain.CurrentDomain .GetAssemblies() .SelectMany(y => y.GetTypes()) .Where(y => y.IsTypeDef(typeof(BaseController))) .Select(y => y.Module) .Distinct() .ToList() .ForEach(y => { var name = y.Name.Replace(".dll", ".xml").Replace(".exe", ".xml"); var path = Path.Combine(AppContext.BaseDirectory, name); if (File.Exists(path)) { x.IncludeXmlComments(path); } var modelsName = y.Name.Replace(".dll", "").Replace(".exe", "") + ".Models.xml"; var modelsPath = Path.Combine(AppContext.BaseDirectory, modelsName); if (File.Exists(modelsPath)) { x.IncludeXmlComments(modelsPath); } y.Assembly .GetManifestResourceNames() .Where(z => z.ToLower().EndsWith(".xml")) .ToList() .ForEach(z => { var resource = y.Assembly.GetManifestResourceStream(z); if (resource != null) { x.IncludeXmlComments(() => new XPathDocument(resource)); } }); }); })); }
private static IServiceCollection AddDocumentation(this IServiceCollection services, AppOptions appOptions, WebOptions webOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (appOptions == null) { throw new ArgumentNullException(nameof(appOptions)); } if (webOptions == null) { throw new ArgumentNullException(nameof(webOptions)); } return(services .AddSwaggerGen(x => { var info = new OpenApiInfo { Title = appOptions.Name, Description = appOptions.Description, Version = appOptions.Version, Contact = webOptions.Documentation.Contact, License = webOptions.Documentation.License }; if (!string.IsNullOrEmpty(appOptions.TermsOfService)) { info.TermsOfService = new Uri(appOptions.TermsOfService); } x.SwaggerDoc(appOptions.Version, info); x.IgnoreObsoleteActions(); x.IgnoreObsoleteProperties(); x.EnableAnnotations(true, true); x.CustomSchemaIds(y => y.FullName); x.OrderActionsBy(y => y.RelativePath); x.SchemaFilter <SwaggerExcludeFilter>(); var securityScheme = new OpenApiSecurityScheme { In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Name = "Authorization", Description = "JWT Authorization header using the Bearer scheme. Format: Authorization: Bearer [token]" }; x.AddSecurityDefinition("Bearer", securityScheme); x.AddSecurityRequirement(new OpenApiSecurityRequirement { { securityScheme, new string[] { } } }); AppDomain.CurrentDomain .GetAssemblies() .SelectMany(y => y.GetTypes()) .Where(y => y.IsTypeOf(typeof(BaseController))) .Select(y => y.Module) .Distinct() .ToList() .ForEach(y => { var name = y.Name.Replace(".dll", ".xml").Replace(".exe", ".xml"); var path = Path.Combine(AppContext.BaseDirectory, name); if (File.Exists(path)) { x.IncludeXmlComments(path); } var modelsName = y.Name.Replace(".dll", "").Replace(".exe", "") + ".Models.xml"; var modelsPath = Path.Combine(AppContext.BaseDirectory, modelsName); if (File.Exists(modelsPath)) { x.IncludeXmlComments(modelsPath); } y.Assembly .GetManifestResourceNames() .Where(z => z.ToLower().EndsWith(".xml")) .ToList() .ForEach(z => { var resource = y.Assembly.GetManifestResourceStream(z); if (resource != null) { x.IncludeXmlComments(() => new XPathDocument(resource)); } }); }); }) .AddSwaggerGenNewtonsoftSupport()); }
public void ClearCache() { _options = null; _bucket.Remove(GetKey()); }
private static IServiceCollection AddHealthChecking(this IServiceCollection services, AppOptions appOptions, WebOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (!options.Hosting.HealthCheck.UseHealthCheck) { return(services); } services .AddHealthChecks() .AddCheck <StartupHealthCheck>("self"); if (options.Hosting.HealthCheck.UseHealthCheckUI) { var port = options.Hosting.Ports.FirstOrDefault(); // TODO: HealthChecks UI: Doesn't poll: JS: Configured polling interval: NaN milliseconds (https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/636) services .AddHealthChecksUI(x => { x.AddHealthCheckEndpoint(appOptions.Name.ToLower(), $"http://localhost:{port}/healthz"); x.SetApiMaxActiveRequests(1); x.SetEvaluationTimeInSeconds(options.Hosting.HealthCheck.EvaluationInterval); x.SetMinimumSecondsBetweenFailureNotifications(options.Hosting.HealthCheck.FailureNotificationInterval); x.MaximumHistoryEntriesPerEndpoint(options.Hosting.HealthCheck.MaximumHistoryEntriesPerEndpoint); foreach (var webHook in options.Hosting.HealthCheck.WebHooks) { x.AddWebhookNotification(webHook.Name, webHook.Uri, webHook.Payload); } }) .AddInMemoryStorage(); } return(services); }
/// <summary>Initializes a new instance of the <see cref="MSGraphService"/> class.</summary> /// <param name="webOptionValue">The web option value.</param> public MSGraphService(IOptions <WebOptions> webOptionValue) { webOptions = webOptionValue.Value; }
public ArmApiOperationService(HttpClient httpClient, IOptions <WebOptions> webOptionValue) { this.httpClient = httpClient; webOptions = webOptionValue.Value; }
public AccountController(ITokenAcquisition tokenAcquisition, IOptions <WebOptions> webOptionValue) { this.tokenAcquisition = tokenAcquisition; this.webOptions = webOptionValue.Value; }
public static IServiceCollection AddWebNotification(this IServiceCollection services, WebOptions options) { if (options.UsedFake()) { services.AddFakeWebNotification(); } else if (options.UsedSignalR()) { services.AddSignalRWebNotification(); } return(services); }
private static IServiceCollection AddHealthChecking(this IServiceCollection services, AppOptions appOptions, WebOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (!options.Hosting.UseHealthCheck) { return(services); } services .AddHealthChecks() .AddCheck <StartupHealthCheck>("self"); if (options.Hosting.UseHealthCheckUI) { var port = options.Hosting.Ports.FirstOrDefault(); var config = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); config[HostDefaults.ContentRootKey] = Directory.GetCurrentDirectory(); services .AddHealthChecksUI("healthchecksdb", x => { x.AddHealthCheckEndpoint(appOptions.Name.ToLower(), $"http://localhost:{port}/healthz"); x.SetEvaluationTimeInSeconds(10); x.SetMinimumSecondsBetweenFailureNotifications(60); }); services .AddScoped <DbContextOptions, DbContextOptions <NullDbContext> >(); } return(services); }