private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = new ResiliencePolicies { CalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderVersionRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedFundingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProfilingApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), FundingFeedSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), PublishedFundingBlobRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), PublishedIndexSearchResiliencePolicy = PublishedIndexSearchResiliencePolicy.GeneratePublishedIndexSearch(), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
public static IServiceCollection RegisterRetryPolicies(this IServiceCollection services, IConfiguration configuration) { var policySettings = new PolicySettings(); configuration.Bind(PolicySettings.PoliciesConfigurationSectionName, policySettings); var policyRegistry = services.AddPolicyRegistry(); TimeSpan SleepDurationProvider(int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(policySettings.HttpRetry.SleepDurationPower, retryAttempt)); policyRegistry.Add( PolicyNames.HttpRetry, HttpPolicyExtensions .HandleTransientHttpError() .WaitAndRetryAsync( retryCount: policySettings.HttpRetry.RetryCount, sleepDurationProvider: SleepDurationProvider)); policyRegistry.Add( PolicyNames.HttpCircuitBreaker, HttpPolicyExtensions .HandleTransientHttpError() .CircuitBreakerAsync( handledEventsAllowedBeforeBreaking: policySettings.HttpCircuitBreaker.HandledEventsAllowedBeforeBreaking, durationOfBreak: policySettings.HttpCircuitBreaker.DurationOfBreak)); return(services); }
private static void ValidateExpectedConnectPolicies(PolicySettings expectedConnectPolicies, JToken securityPoliciesSentToConnectApi) { if (expectedConnectPolicies.AllowRawExceptionMessages != null) { Assert.AreEqual(expectedConnectPolicies.AllowRawExceptionMessages.Enabled, securityPoliciesSentToConnectApi["allow_raw_exception_messages"]["enabled"].Value <bool>()); } if (expectedConnectPolicies.AttributesInclude != null) { Assert.AreEqual(expectedConnectPolicies.AttributesInclude.Enabled, securityPoliciesSentToConnectApi["attributes_include"]["enabled"].Value <bool>()); } if (expectedConnectPolicies.CustomEvents != null) { Assert.AreEqual(expectedConnectPolicies.CustomEvents.Enabled, securityPoliciesSentToConnectApi["custom_events"]["enabled"].Value <bool>()); } if (expectedConnectPolicies.CustomInstrumentationEditor != null) { Assert.AreEqual(expectedConnectPolicies.CustomInstrumentationEditor.Enabled, securityPoliciesSentToConnectApi["custom_instrumentation_editor"]["enabled"].Value <bool>()); } if (expectedConnectPolicies.CustomParameters != null) { Assert.AreEqual(expectedConnectPolicies.CustomParameters.Enabled, securityPoliciesSentToConnectApi["custom_parameters"]["enabled"].Value <bool>()); } if (expectedConnectPolicies.RecordSql != null) { Assert.AreEqual(expectedConnectPolicies.RecordSql.Enabled, securityPoliciesSentToConnectApi["record_sql"]["enabled"].Value <bool>()); } }
internal IServiceCollection ConfigureServices(IServiceCollection builder) { builder.AddTransient <IPublishedProviderContentsGenerator, PublishedProviderContentsGenerator>(); builder.AddTransient <IPublishedFundingContentsGenerator, PublishedFundingContentsGenerator>(); builder.AddTransient <Providers.v1.ProviderDocumentGenerator>(); builder.AddTransient <Providers.v2.ProviderDocumentGenerator>(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Generators.NavFeed"); builder.AddLogging("CalculateFunding.Generators.NavFeed"); builder.AddProvidersInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <IOrganisationGroupResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new OrganisationGroupResiliencePolicies { ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); return(builder); }
public static IServiceProvider BuildServiceProvider() { IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddApplicationInsightsTelemetryClient(_configuration, "CalculateFunding.Migrations.PublishedProviderPopulateReleased"); serviceCollection.AddLogging(serviceName: "CalculateFunding.Migrations.PublishedProviderPopulateReleased"); serviceCollection.AddPolicySettings(_configuration); serviceCollection.AddSingleton <ICosmosRepository>(ctx => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); _configuration.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "publishedfunding"; return(new CosmosRepository(cosmosDbSettings)); }); serviceCollection.AddSingleton <IPublishingResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers .GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { PublishedProviderVersionRepository = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); serviceCollection.AddTransient <IPublishedProviderMigration, PublishedProviderMigration>(); return(serviceCollection.BuildServiceProvider()); }
public void SaveActionExecution(Int32 idUser, Int32 idRole, long idPath, long idSubActivity, dtoEvaluation evaluation, DateTime?referenceTime) { try { Boolean save = true; Path path = GetPath(idPath); PolicySettings settings = null; if (path != null) { settings = path.Policy; } if (settings != null) { switch (settings.Statistics) { case CompletionPolicy.UpdateAlways: break; default: List <SubActivityStatistic> items = GetUserStatistics(idSubActivity, idUser, ((referenceTime != null && referenceTime.HasValue) ? referenceTime.Value : DateTime.Now)); SubActivityStatistic last = (items == null ? null : items.FirstOrDefault()); switch (settings.Statistics) { case CompletionPolicy.NoUpdateIfCompleted: if (evaluation.isPassed && evaluation.isCompleted) { save = !items.Any(i => ServiceStat.CheckStatusStatistic(i.Status, StatusStatistic.CompletedPassed)); } else { save = !items.Any(i => ServiceStat.CheckStatusStatistic(i.Status, StatusStatistic.Completed) || ServiceStat.CheckStatusStatistic(i.Status, StatusStatistic.CompletedPassed)); } break; //case CompletionPolicy.UpdateOnlyIfBetter: // if (last != null) // save = (last.Completion < evaluation.Completion || ( // ((!ServiceStat.CheckStatusStatistic(last.Status, StatusStatistic.Completed) && !ServiceStat.CheckStatusStatistic(last.Status, StatusStatistic.CompletedPassed)) // && (evaluation.Status == Core.FileRepository.Domain.PackageStatus.completed // || evaluation.Status == Core.FileRepository.Domain.PackageStatus.completedpassed)) // )); // break; //case CompletionPolicy.UpdateOnlyIfWorst: // break; } break; } } if (save) { Manager.BeginTransaction(); ServiceStat.InitOrUpdateSubActivityNoTransaction(idSubActivity, idUser, idRole, idUser, UC.IpAddress, UC.ProxyIpAddress, evaluation.Completion, (short)evaluation.Completion, evaluation.isStarted, evaluation.isCompleted, evaluation.isPassed); Manager.Commit(); } } catch (Exception ex) { } }
private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = new ResiliencePolicies() { CalculationProviderResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderProfilingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderCalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PublishedProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderCalculationResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderChangesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder .AddSingleton <OnNotificationEventTrigger>(); builder .AddSingleton <INotificationService, NotificationService>(); builder.AddFeatureToggling(config); builder.AddServiceBus(config); builder.AddApplicationInsights(config, "CalculateFunding.Functions.Notifications"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Notifications"); builder.AddLogging("CalculateFunding.Functions.Notifications"); builder.AddTelemetry(); builder.AddPolicySettings(config); builder.AddSingleton <INotificationsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new NotificationsResiliencePolicies { MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), }); }); return(builder.BuildServiceProvider()); }
public static IServiceCollection AddCalcsResiliencePolicies(this IServiceCollection serviceCollection) { serviceCollection.AddSingleton <ICalcsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); return(serviceCollection); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var proxy = Configuration.GetValue <string>("Proxy"); if (string.IsNullOrEmpty(proxy)) { _logger.LogWarning("Невозможно получить URL прокси. Ананимный парсинг невозможен."); } services.AddControllers().AddNewtonsoftJson(); // services.AddHostedService<SchedulerService>(); services.AddHostedService <MyWorker>(); services.AddSingleton <IMyQueue, MyQueue>(); services.AddHttpClient <ICheckPackagesService, CheckPackagesService>(x => { }) .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, Proxy = new WebProxy() }) .AddPolicyHandler(PolicySettings.GetRetryPolicy()) .AddPolicyHandler(PolicySettings.GetTimeoutPolicy()); Policy.BulkheadAsync(10); services.AddHttpClient <ISendCallbackService, SendCallbackService>(x => { x.Timeout = TimeSpan.FromSeconds(90); }); services.AddTransient <IRevisionJob, RevisionJob>(); }
private void Workbook_SheetCalculate(object Sh) { // Run a scan if necessary if (PolicySettings.hasAutomaticScans() && Settings.Default.AutomaticScans) { this.Inspect(InspectionType.LIVE); } }
private void Workbook_AfterSave(bool Success) { // Run a scan if necessary if (PolicySettings.hasAutomaticScans() && Settings.Default.AutomaticScans) { this.Inspect(InspectionType.LIVE); } }
public static PolicySettings GetPolicySettings(IConfiguration config) { PolicySettings policySettings = new PolicySettings(); config.Bind("policy", policySettings); return(policySettings); }
/// <summary> /// Initializes a new instance of the <see cref="RalphJansen.StyleCopCheckInPolicy.VisualStudio.ViolationTaskProvider"/> class. /// </summary> /// <param name="provider">The underlying provider for the error task provider.</param> /// <param name="settings">The policy settings.</param> public ViolationTaskProvider(IServiceProvider provider, PolicySettings settings) : base(provider) { this.ProviderGuid = new Guid("{1A896300-D69E-427c-A6A1-9EA4A279A060}"); this.ProviderName = DefaultProviderName; this.Settings = settings; this.Provider = provider; }
public static IServiceCollection AddPolicySettings(this IServiceCollection builder, IConfiguration config) { PolicySettings policySettings = GetPolicySettings(builder, config); builder.AddSingleton <PolicySettings>(policySettings); return(builder); }
public static PolicySettings GetPolicySettings(this IServiceCollection builder, IConfiguration config) { PolicySettings policySettings = new PolicySettings(); config.Bind("policy", policySettings); return(policySettings); }
private static OrganisationGroupResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); OrganisationGroupResiliencePolicies resiliencePolicies = new OrganisationGroupResiliencePolicies { ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
internal CdnWebApplicationFirewallPolicyData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, string etag, Models.Sku sku, PolicySettings policySettings, RateLimitRuleList rateLimitRules, CustomRuleList customRules, ManagedRuleSetList managedRules, IReadOnlyList <SubResource> endpointLinks, ProvisioningState?provisioningState, PolicyResourceState?resourceState) : base(id, name, type, systemData, tags, location) { Etag = etag; Sku = sku; PolicySettings = policySettings; RateLimitRules = rateLimitRules; CustomRules = customRules; ManagedRules = managedRules; EndpointLinks = endpointLinks; ProvisioningState = provisioningState; ResourceState = resourceState; }
internal WebApplicationFirewallPolicyData(string id, string name, string resourceType, string location, IDictionary <string, string> tags, string etag, PolicySettings policySettings, IList <WebApplicationFirewallCustomRule> customRules, IReadOnlyList <ApplicationGatewayData> applicationGateways, ProvisioningState?provisioningState, WebApplicationFirewallPolicyResourceState?resourceState, ManagedRulesDefinition managedRules, IReadOnlyList <WritableSubResource> httpListeners, IReadOnlyList <WritableSubResource> pathBasedRules) : base(id, name, resourceType, location, tags) { Etag = etag; PolicySettings = policySettings; CustomRules = customRules; ApplicationGateways = applicationGateways; ProvisioningState = provisioningState; ResourceState = resourceState; ManagedRules = managedRules; HttpListeners = httpListeners; PathBasedRules = pathBasedRules; }
/// <summary> /// Occurs after any workbook is recalculated or after any changed data is plotted on a chart. /// </summary> /// <param name="sh"></param> private void workbook_SheetCalculate(object sh) { // Run a scan if necessary if (!PolicySettings.HasAutomaticScans() || !Settings.Default.AutomaticScans) { return; } if (!Globals.Ribbons.Ribbon.scanButton.Enabled) { return; } DataModel.Instance.CurrentWorkbook.Inspect(); }
private static CalculatorResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); CalculatorResiliencePolicies resiliencePolicies = new CalculatorResiliencePolicies() { ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderSourceDatasetsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), Messenger = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static PolicyResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new PolicyResiliencePolicies { PolicyRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), FundingSchemaRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), FundingTemplateRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TemplatesSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TemplatesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static DatasetsResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new DatasetsResiliencePolicies { SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProviderRepository = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetSearchService = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), DatasetDefinitionSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { builder .AddSingleton <OnNotificationEventTrigger>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <INotificationService, NotificationService>(); builder.AddFeatureToggling(config); builder.AddServiceBus(config, "notifications"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Notifications"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Notifications"); builder.AddLogging("CalculateFunding.Functions.Notifications"); builder.AddTelemetry(); builder.AddPolicySettings(config); builder.AddSingleton <INotificationsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new NotificationsResiliencePolicies { MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), }); }); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
public static IServiceProvider BuildServiceProvider(IApiOptions options) { IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddLogging("CalculateFunding.Migrations.ProviderVersionDefectCorrection"); serviceCollection.AddPolicySettings(Configuration); serviceCollection.AddSingleton <ICalculationsEtlResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers .GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsApiClient = GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationApiClient = GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DataSetsApiClient = GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); AddHttpClientForClientKey(HttpClientKeys.Specifications, options.SpecificationsApiUri, options.SpecificationsApiKey, serviceCollection); AddHttpClientForClientKey(HttpClientKeys.Calculations, options.CalculationsApiUri, options.CalculationsApiKey, serviceCollection); AddHttpClientForClientKey(HttpClientKeys.Datasets, options.DataSetsApiUri, options.DataSetsApiKey, serviceCollection); serviceCollection.AddSingleton <ICalculationsApiClient, CalculationsApiClient>(); serviceCollection.AddTransient <ISpecificationsApiClient, SpecificationsApiClient>(); serviceCollection.AddTransient <IDatasetsApiClient, DatasetsApiClient>(); return(serviceCollection.BuildServiceProvider()); }
/// <summary> /// Show dialog for editing the settings of the checkin policy. /// </summary> /// <param name="policyEditArgs">An <see cref="IPolicyEditArgs"/> containing policy edit arguments.</param> /// <returns><b>true</b> if the policy has been edited successfully, otherwise <b>false</b>.</returns> public override bool Edit(IPolicyEditArgs policyEditArgs) { if (policyEditArgs == null) { ThrowHelper.ThrowArgumentNullException("policyEditArgs"); } bool retval = false; using (EditPolicyDialog dialog = new EditPolicyDialog()) { // Clone the settings to prevent modifying the settings currently in use. dialog.Settings = (PolicySettings)this.Settings.Clone(); if (dialog.ShowDialog(policyEditArgs.Parent) == DialogResult.OK) { this.Settings = dialog.Settings; retval = true; } } return(retval); }
void Verify(PolicySettings settings) { Assert.NotNull(settings.Resolvers); Assert.Equal(3, settings.Resolvers.Count()); IPolicyResolver trustResolver = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.TrustPolicyName).CreateResolver(); IPolicyResolver privateResolver = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.PrivatePolicyName).CreateResolver(); IPolicyResolver publicResolver = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.PublicPolicyName).CreateResolver(); Assert.NotNull(trustResolver); Assert.NotNull(privateResolver); Assert.NotNull(publicResolver); TrustPolicyServiceResolverSettings trustSettings = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.TrustPolicyName) as TrustPolicyServiceResolverSettings; Assert.True(trustSettings.CacheSettings.Cache); Assert.True(trustSettings.CacheSettings.NegativeCache); Assert.Equal(60, trustSettings.CacheSettings.CacheTTLSeconds); PrivatePolicyServiceResolverSettings privateSettings = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.PrivatePolicyName) as PrivatePolicyServiceResolverSettings; Assert.True(privateSettings.CacheSettings.Cache); Assert.True(privateSettings.CacheSettings.NegativeCache); Assert.Equal(60, privateSettings.CacheSettings.CacheTTLSeconds); PublicPolicyServiceResolverSettings publicSettings = settings.Resolvers.FirstOrDefault(r => r.Name == CertPolicyResolvers.PublicPolicyName) as PublicPolicyServiceResolverSettings; Assert.True(publicSettings.CacheSettings.Cache); Assert.True(publicSettings.CacheSettings.NegativeCache); Assert.Equal(60, publicSettings.CacheSettings.CacheTTLSeconds); }
public static void ConfigureAuthorization(this IServiceCollection services, PolicySettings policySettings) { services.AddAuthorization(options => { foreach (var policySetting in policySettings.Policies) { options.AddPolicy(policySetting.Name, policy => { if (policySetting.Claims.Count() == 1) { var claim = policySetting.Claims.Single(); policy.RequireClaim(claim.ClaimType.GetDescription(), claim.ClaimValues); } else { policy.RequireAssertion(context => { return(context.User.Claims.Any(x => policySetting.Claims.Select(y => y.ClaimType.GetDescription()).Contains(x.Type))); }); } }); } }); }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <ISpecificationsService, SpecificationsService>() .AddSingleton <IHealthChecker, SpecificationsService>(); builder.AddSingleton <IValidator <PolicyCreateModel>, PolicyCreateModelValidator>(); builder.AddSingleton <IValidator <PolicyEditModel>, PolicyEditModelValidator>(); builder.AddSingleton <IValidator <CalculationCreateModel>, CalculationCreateModelValidator>(); builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>(); builder.AddSingleton <IValidator <CalculationEditModel>, CalculationEditModelValidator>(); builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>(); builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>(); builder .AddSingleton <ISpecificationsSearchService, SpecificationsSearchService>() .AddSingleton <IHealthChecker, SpecificationsSearchService>(); builder.AddSingleton <IResultsRepository, ResultsRepository>(); builder.AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <IFundingService, FundingService>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <IVersionRepository <SpecificationVersion>, VersionRepository <SpecificationVersion> >((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.CollectionName = "specs"; CosmosRepository resultsRepostory = new CosmosRepository(specsVersioningDbSettings); return(new VersionRepository <SpecificationVersion>(resultsRepostory)); }); MapperConfiguration mappingConfig = new MapperConfiguration(c => c.AddProfile <SpecificationsMappingProfile>()); builder.AddFeatureToggling(Configuration); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddUserProviderFromRequest(); builder.AddCosmosDb(Configuration); builder.AddServiceBus(Configuration); builder.AddSearch(Configuration); builder.AddCaching(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddCalcsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <ISpecificationsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Polly.Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new SpecificationsResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Specs"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Apis.Specs"); builder.AddLogging("CalculateFunding.Apis.Specs"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); }