public WebItemManager(IContainer container, IConfiguration configuration, IOptionsMonitor <ILog> options) { Container = container; Configuration = configuration; log = options.Get("ASC.Web"); disableItem = (Configuration["web:disabled-items"] ?? "").Split(",").ToList(); LoadItems(); }
private CallInvoker CreateInvoker(EntryKey key) { var(name, type) = (key.Name, key.Type); var scope = _scopeFactory.CreateScope(); var services = scope.ServiceProvider; try { var httpClientFactoryOptions = _httpClientFactoryOptionsMonitor.Get(name); if (httpClientFactoryOptions.HttpClientActions.Count > 0) { throw new InvalidOperationException($"The ConfigureHttpClient method is not supported when creating gRPC clients. Unable to create client with name '{name}'."); } var clientFactoryOptions = _grpcClientFactoryOptionsMonitor.Get(name); var httpHandler = _messageHandlerFactory.CreateHandler(name); if (httpHandler == null) { throw new ArgumentNullException(nameof(httpHandler)); } var channelOptions = new GrpcChannelOptions(); channelOptions.HttpHandler = httpHandler; channelOptions.LoggerFactory = _loggerFactory; channelOptions.ServiceProvider = services; if (clientFactoryOptions.ChannelOptionsActions.Count > 0) { foreach (var applyOptions in clientFactoryOptions.ChannelOptionsActions) { applyOptions(channelOptions); } } var address = clientFactoryOptions.Address; if (address == null) { throw new InvalidOperationException($@"Could not resolve the address for gRPC client '{name}'. Set an address when registering the client: services.AddGrpcClient<{type.Name}>(o => o.Address = new Uri(""https://localhost:5001""))"); } var channel = GrpcChannel.ForAddress(address, channelOptions); var httpClientCallInvoker = channel.CreateCallInvoker(); var resolvedCallInvoker = GrpcClientFactoryOptions.BuildInterceptors( httpClientCallInvoker, services, clientFactoryOptions, InterceptorScope.Channel); return(resolvedCallInvoker); } catch { // If something fails while creating the handler, dispose the services. scope?.Dispose(); throw; } }
public async Task <ProductsApiResult> GetProducts() { const string cacheKey = "Products"; if (_cache.TryGetValue <ProductsApiResult>(cacheKey, out var forecast)) { return(forecast); } const string path = "api/products"; try { var request = new HttpRequestMessage(HttpMethod.Get, path); request.Headers.Add("ApiKey", _productsApiConfig.Get(ExternalServicesConfig.ProductsApi) .ApiKey); var response = await _httpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { return(null); } var content = await response.Content.ReadAsAsync <ProductsApiResult>(); if (content != null) { var cacheOptions = new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(_productsApiConfig.Get(ExternalServicesConfig.ProductsApi).MinsToCache) }; _cache.Set(cacheKey, content, cacheOptions); } return(content); } catch (HttpRequestException e) { _logger.LogError(e, "Failed to get products data from API"); } return(null); }
public DaprClient CreateClient(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var client = _daprClients.GetOrAdd(name, _daprClientFactory).Value; var options = _optionsMonitor.Get(name); for (int i = 0; i < options.DaprClientActions.Count; i++) { options.DaprClientActions[i](client); } return(client); }
internal static TOptions GetOptions <TOptions>(this IOptionsMonitor <TOptions> optionsMonitor, string name, Action <TOptions>?configureOptions) where TOptions : class, new() { var options = optionsMonitor?.Get(name) ?? new TOptions(); configureOptions?.Invoke(options); return(options); }
protected static CosmosCollectionConfiguration GetCosmosCollectionConfiguration( IOptionsMonitor <CosmosCollectionConfiguration> namedCosmosCollectionConfigurationAccessor, string collectionConfigurationName) { EnsureArg.IsNotNull(namedCosmosCollectionConfigurationAccessor, nameof(namedCosmosCollectionConfigurationAccessor)); EnsureArg.IsNotNullOrWhiteSpace(collectionConfigurationName, nameof(collectionConfigurationName)); return(namedCosmosCollectionConfigurationAccessor.Get(collectionConfigurationName)); }
public virtual string GetAuthCookieNameOrNull() { if (_abpAntiForgeryOptions.AuthCookieSchemaName == null) { return(null); } return(_namedOptionsAccessor.Get(_abpAntiForgeryOptions.AuthCookieSchemaName)?.Cookie?.Name); }
public CrossModuleTransferUtility(IOptionsMonitor <ILog> option, IDataStore source, IDataStore destination) { Log = option.Get("ASC.CrossModuleTransferUtility"); Option = option; this.source = source ?? throw new ArgumentNullException("source"); this.destination = destination ?? throw new ArgumentNullException("destination"); maxChunkUploadSize = 10 * 1024 * 1024; chunksize = 5 * 1024 * 1024; }
public Worker( IServiceProvider serviceProvider, IOptionsMonitor <ILog> options, Common.Utils.ConfigurationExtension configurationExtension) { this.serviceProvider = serviceProvider; this.thumbnailSettings = ThumbnailSettings.GetInstance(configurationExtension); logger = options.Get("ASC.Files.ThumbnailBuilder"); }
public async Task InvokeAsync(HttpContext context) { if (context.Request.Path.Value.ToLower() == "/refresh_auth_config") { var op = _optionsMonitor.Get("Bearer"); op.ConfigurationManager.RequestRefresh(); } await _next.Invoke(context); }
/// <inheritdoc/> public async Task <HttpResponseMessage> CallWebApiForUserAsync( string serviceName, string?authenticationScheme = null, Action <DownstreamWebApiOptions>?calledDownstreamWebApiOptionsOverride = null, ClaimsPrincipal?user = null, StringContent?content = null) { DownstreamWebApiOptions effectiveOptions = MergeOptions(serviceName, calledDownstreamWebApiOptionsOverride); if (string.IsNullOrEmpty(effectiveOptions.Scopes)) { throw new ArgumentException(IDWebErrorMessage.ScopesNotConfiguredInConfigurationOrViaDelegate); } MicrosoftIdentityOptions microsoftIdentityOptions = _microsoftIdentityOptionsMonitor .Get(_tokenAcquisition.GetEffectiveAuthenticationScheme(authenticationScheme)); string apiUrl = effectiveOptions.GetApiUrl(); CreateProofOfPossessionConfiguration(effectiveOptions, apiUrl); string?userflow; if (microsoftIdentityOptions.IsB2C && string.IsNullOrEmpty(effectiveOptions.UserFlow)) { userflow = microsoftIdentityOptions.DefaultUserFlow; } else { userflow = effectiveOptions.UserFlow; } AuthenticationResult authResult = await _tokenAcquisition.GetAuthenticationResultForUserAsync( effectiveOptions.GetScopes(), authenticationScheme, effectiveOptions.Tenant, userflow, user, effectiveOptions.TokenAcquisitionOptions) .ConfigureAwait(false); using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage( effectiveOptions.HttpMethod, apiUrl)) { if (content != null) { httpRequestMessage.Content = content; } httpRequestMessage.Headers.Add( Constants.Authorization, authResult.CreateAuthorizationHeader()); effectiveOptions.CustomizeHttpRequestMessage?.Invoke(httpRequestMessage); return(await _httpClient.SendAsync(httpRequestMessage).ConfigureAwait(false)); } }
public BranchClient(IOptionsMonitor <BranchConfig> options, string name) { var opts = options.Get(name); var httpOptions = new HttpOptions(); httpOptions.Headers.Add("Authorization", $"bearer {opts.Key}"); Client = new JsonClient(opts.Url, httpOptions); }
public IActionResult SignIn( ) { var scheme = AzureADB2CDefaults.AuthenticationScheme; // 本来はここでいろんなIDaaSの種類が選べるということ? var options = _options.Get(scheme); var redirectUrl = Url.Content("~/Home/Index"); var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; properties.Items[AzureADB2CDefaults.PolicyKey] = options.SignUpSignInPolicyId; return(Challenge( new AuthenticationProperties { RedirectUri = redirectUrl }, scheme)); }
/// <summary> /// By default, build url for Aspnet hosting url. Url building based on UrlOptions configure in appsettings /// </summary> /// <param name="webApiPath"></param> /// <returns></returns> public Uri BuildConfirmationUrl(string userId, string token) { var builder = new UriBuilder(); UrlOptions urlOptions; if (SpaHostUrl) { urlOptions = urlSettings.Get("Angular-AccountConfirmationUrl"); } else { urlOptions = urlSettings.Get("Aspnet-AccountConfirmationUrl"); } BuildBaseAddress(builder, urlOptions); builder.Query = $"userID={userId}&token={token}"; return(uri = builder.Uri); }
public TClient CreateClient(string name) { if (!_clientRegistrations.TryGetValue(name, out ClientRegistration <TClient, TOptions> registration)) { throw new InvalidOperationException($"Unable to find client registration with type '{typeof(TClient).Name}' and name '{name}'."); } return(registration.GetClient(_monitor.Get(name), _clientsOptions.Get(name).CredentialFactory(_serviceProvider))); }
/// <summary> /// Initializes a new instance of the <see cref="TorahQuoteJob"/> class. /// </summary> /// <param name="options"></param> /// <param name="service"></param> /// <param name="torahVerses"></param> public TorahQuoteJob( IOptionsMonitor <TorahQuoteJobOptions> options, TorahService service, TorahVerses torahVerses) { _options = options.Get(Name); _service = service ?? throw new ArgumentNullException(nameof(service)); _torahVerses = torahVerses ?? throw new ArgumentNullException(nameof(torahVerses)); }
public RackspaceCloudStorage( TenantManager tenantManager, PathUtils pathUtils, EmailValidationKeyProvider emailValidationKeyProvider, IOptionsMonitor <ILog> options) : base(tenantManager, pathUtils, emailValidationKeyProvider, options) { _logger = options.Get("ASC.Data.Storage.Rackspace.RackspaceCloudStorage"); }
public GoogleDriveStorage( ConsumerFactory consumerFactory, FileUtility fileUtility, IOptionsMonitor <ILog> monitor) { ConsumerFactory = consumerFactory; FileUtility = fileUtility; Log = monitor.Get("ASC.Files"); }
public HttpClientFactoryOptions Get(string name) { string client = _handlerRegistry.GetClientNameFromKey(name); _logger.LogDebug($"{nameof(ClientHandlerResolutionDecorator)} - Resolving options for {client} based on key lookup for {name}"); var options = _optionsMonitor.Get(client); return(options); }
public GlobalNotify(ICacheNotify <AscCacheItem> notify, IOptionsMonitor <ILog> options, CoreBaseSettings coreBaseSettings) { Notify = notify; Logger = options.Get("ASC.Files"); if (coreBaseSettings.Standalone) { ClearCache(); } }
public BundleDefaultsOptions GetDefaults(string bundleType) { if (bundleType == null) { throw new ArgumentNullException(nameof(bundleType)); } return(_defaultsOptions.Get(bundleType)); }
public BnaHandler( IHttpClientFactory httpClientFactory, HttpClientPoliciesSettings bnaClientPoliciesSettings, IOptionsMonitor <CurrencySettings> bnaSettings, ISlackHooksService slackHooksService, ILogger <CurrencyHandler> logger) : base(httpClientFactory, bnaClientPoliciesSettings, bnaSettings.Get("BnaService"), slackHooksService, logger) { }
public AppWorkFlowWithOptionsMonitor(IOptionsMonitor <AppSetting1> appSettingOption, IOptionsMonitor <Player1> playerOption) { this._player = playerOption.Get("Player"); this._appSetting = appSettingOption?.CurrentValue; Console.WriteLine($"AppSetting.Player.AppId = {this._appSetting.Player.AppId}"); Console.WriteLine($"Player.AppId = {this._player.AppId}"); }
public FilesMessageService( IOptionsMonitor <ILog> options, MessageTarget messageTarget, MessageService messageService) { log = options.Get("ASC.Messaging"); MessageTarget = messageTarget; MessageService = messageService; }
public SettingsController( CommonMethods commonMethods, CoreSettings coreSettings, IOptionsMonitor <ILog> option) { CommonMethods = commonMethods; CoreSettings = coreSettings; Log = option.Get("ASC.ApiSystem"); }
public WeatherApiClient(HttpClient httpClient, IOptionsMonitor <ExternalServicesConfig> options, ILogger <WeatherApiClient> logger) { var externalServiceConfig = options.Get(ExternalServicesConfig.WeatherApi); httpClient.BaseAddress = new Uri(externalServiceConfig.Url); _httpClient = httpClient; _logger = logger; }
public OrganisationLogoManager(WebImageSupplier webImageSupplier, Global global, IOptionsMonitor <ILog> logger, DaoFactory daoFactory) { _webImageSupplier = webImageSupplier; _global = global; _logger = logger.Get("ASC.CRM"); _daoFactory = daoFactory; }
public HttpClient CreateClient(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var handler = _cache.GetOrAdd(name, _valueFactory); var client = new HttpClient(handler.Value, disposeHandler: false); var options = _optionsMonitor.Get(name); for (var i = 0; i < options.HttpClientActions.Count; i++) { options.HttpClientActions[i](client); } return(client); }
public AccountDomainService(ILogger <AccountDomainService> logger, IDailyTaskApi dailyTaskApi, IOptionsMonitor <BiliBiliCookieOptions> cookie, IOptionsMonitor <Dictionary <string, int> > dicOptions) { _logger = logger; _dailyTaskApi = dailyTaskApi; _cookie = cookie.CurrentValue; _expDic = dicOptions.Get(Constants.OptionsNames.ExpDictionaryName); }
public TariffController( CommonMethods commonMethods, IOptionsSnapshot <HostedSolution> hostedSolutionOptions, IOptionsMonitor <ILog> option ) { CommonMethods = commonMethods; HostedSolution = hostedSolutionOptions.Value; Log = option.Get("ASC.ApiSystem"); }