<commit_before>﻿using System;
using System.Collections.Generic;
using Microsoft.Framework.DependencyInjection;
using System.Threading.Tasks;

namespace Glimpse.Web
{
    public class MasterRequestRuntime
    {
        private readonly IDiscoverableCollection<IRequestRuntime> _requestRuntimes;
        private readonly IDiscoverableCollection<IRequestHandler> _requestHandlers;
        private readonly IEnumerable<IRequestAuthorizer> _requestAuthorizers;

        public MasterRequestRuntime(IRequestAuthorizerProvider requestAuthorizerProvider, IDiscoverableCollection<IRequestRuntime> requestRuntimes, IDiscoverableCollection<IRequestHandler> requestHandlers)
        {
            _requestAuthorizers = requestAuthorizerProvider.Authorizers;

            _requestRuntimes = requestRuntimes;
            _requestRuntimes.Discover();

            _requestHandlers = requestHandlers;
            _requestHandlers.Discover();
        }

        public bool Authorized(IHttpContext context)
        {
            foreach (var requestAuthorizer in _requestAuthorizers)
            {
                var allowed = requestAuthorizer.AllowUser(context);
                if (!allowed)
                {
                    return false;
                }
            }

            return true;
        }

        public async Task Begin(IHttpContext context)
        {
            foreach (var requestRuntime in _requestRuntimes)
            {
                await requestRuntime.Begin(context);<commit_msg>Setup runtime to use request handler provider<commit_after>﻿using System;
using System.Collections.Generic;
using Microsoft.Framework.DependencyInjection;
using System.Threading.Tasks;

namespace Glimpse.Web
{
    public class MasterRequestRuntime
    {
        private readonly IDiscoverableCollection<IRequestRuntime> _requestRuntimes;
        private readonly IEnumerable<IRequestHandler> _requestHandlers;
        private readonly IEnumerable<IRequestAuthorizer> _requestAuthorizers;

        public MasterRequestRuntime(IRequestAuthorizerProvider requestAuthorizerProvider, IDiscoverableCollection<IRequestRuntime> requestRuntimes, IRequestHandlerProvider requestHandlersProvider)
        {
            _requestAuthorizers = requestAuthorizerProvider.Authorizers;

            _requestRuntimes = requestRuntimes;
            _requestRuntimes.Discover();

            _requestHandlers = requestHandlersProvider.Handlers; 
        }

        public bool Authorized(IHttpContext context)
        {
            foreach (var requestAuthorizer in _requestAuthorizers)
            {
                var allowed = requestAuthorizer.AllowUser(context);
                if (!allowed)
                {
                    return false;
                }
            }

            return true;
        }

        public async Task Begin(IHttpContext context)
        {
            foreach (var requestRuntime in _requestRuntimes)
            {
                await requestRuntime.Begin(context);
{'fraction_non_alphanumeric': 0.05243820975283901, 'fraction_numerical': 0.0, 'mean_word_length': 2.486612339930151, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033888', 'n_tokens_mistral': 702, 'n_tokens_neox': 682, 'n_words': 144}