示例#1
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("app");
            builder.Services.AddOptions();
            builder.Services.AddAuthorizationCore(config =>
            {
                config.AddPolicy(PolicyHandler.IsAdmin, PolicyHandler.IsAdminPolicy());
                config.AddPolicy(PolicyHandler.IsUser, PolicyHandler.IsUserPolicy());
            });

            //builder.Services.AddTransient<HttpHandler>();
            builder.Services.AddTransient <LocalStorageHandler>();
            builder.Services.AddTransient <ApiMiddleware>();
            var toke = await builder.Services.BuildServiceProvider().GetRequiredService <LocalStorageHandler>().GetItem <string>(Constants.JWTKey);

            builder.Services.AddHttpClient <HttpHandler>(
                client => {
                client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {toke}");
            })
            .AddHttpMessageHandler <ApiMiddleware>();
            builder.Services.AddTransient <AuthStateHandler>();
            builder.Services.AddTransient <AuthenticationStateProvider>(provider => provider.GetRequiredService <AuthStateHandler>());
            await builder.Build().RunAsync();
        }
 public PolicyController(ILogger <PolicyController> logger,
                         PolicyHandler policyHandler, IHttpContextAccessor httpContextAccessor, GetLang _getLang)
 {
     _logger              = logger;
     _policyHandler       = policyHandler;
     _httpContextAccessor = httpContextAccessor;
     getLang              = _getLang;
     langcode             = getLang.GetLanguage();
 }
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddHealthChecks(c =>
     {
         c.AddSelfCheck("WebA is running.");
         c.AddUrlCheck("WebB is accessible.", "http://localhost:5001");
     },
                              new[] { PolicyHandler.Timeout(1) });
 }
示例#4
0
        private async Task <StringResultTask> GetSecondTask()
        {
            string filePath = @"AdventOfCode2020.Calender.Day2.Input.txt";

            PolicySet[] policies = await ParseHelper.GetInput <PolicySet>(Environment.NewLine, filePath, new PolicyParser <PositionPolicy>());

            var count = policies.Count(policy => PolicyHandler.EvaluatePassword(policy));

            return(new StringResultTask("Part 1", $"Answer: {count}"));
        }
示例#5
0
 public HomeController(ILogger <HomeController> logger, IHttpContextAccessor httpContextAccessor,
                       GetLang _getLang, PolicyHandler policy, ApprovalsHandler _approvalsHandler)
 {
     _logger = logger;
     _httpContextAccessor = httpContextAccessor;
     getLang          = _getLang;
     langcode         = getLang.GetLanguage();
     policyHandler    = policy;
     ApprovalsHandler = _approvalsHandler;
 }
 public static void AddHttpClientWithPolicyHandler(this IServiceCollection services, MazeApiSettings mazeApiSettings)
 {
     services
     .AddHttpClient <ITvMazeHttpClient, TvMazeHttpClient>(client =>
     {
         client.BaseAddress = new Uri(mazeApiSettings.BaseUrl);
     })
     .AddPolicyHandler(PolicyHandler.WaitAndRetry())
     .AddPolicyHandler(PolicyHandler.Timeout());
 }
示例#7
0
 public HomeController(IAuthService authService, IFileService fileService, ILogger <HomeController> logger, IHttpContextAccessor httpContextAccessor,
                       GetLang _getLang, PolicyHandler policy, ApprovalsHandler _approvalsHandler)
 {
     _logger = logger;
     _authenticationService = authService;
     _fileService           = fileService;
     _httpContextAccessor   = httpContextAccessor;
     getLang          = _getLang;
     langcode         = getLang.GetLanguage();
     policyHandler    = policy;
     ApprovalsHandler = _approvalsHandler;
 }
示例#8
0
 public static IServiceCollection AddHealthChecks(this IServiceCollection services, Action <IHealthCheckBuilder> configureHealthCheckBuilder)
 {
     return(AddHealthChecks(services, configureHealthCheckBuilder, new [] { PolicyHandler.WaitAndRetry(2), PolicyHandler.Timeout() }));
 }
示例#9
0
 public void MarketBuilder()
 {
     handler  = PolicyHandler.Instance;
     policies = new List <string>();
     policies.Add("Food");
 }
示例#10
0
 public void MarketBuilder()
 {
     handler = PolicyHandler.Instance;
 }