<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Models
{
    public sealed class LockoutRuntime
    {
        private readonly LockoutDef[] defs;

        public LockoutRuntime(LockoutDef[] defs)
        {
            this.defs = defs;
        }

        public async Task<bool> Check(ICounterOperations counterOperations, IDictionary<string, string> context)
        {
            foreach (var d in this.defs)
            {
                var l = new Lockout(
                    new Counter(counterOperations, this.MakeKey(d.Key, context), d.Expiration),
                    d.Threshold);
                if (await l.Check())
                {
                    return true;
                }
            }

            return false;
        }

        public async Task<bool> Guard(ICounterOperations counterOperations, IDictionary<string, string> context)
        {
            var result = await Task.WhenAll(
                from d in this.defs
                select new Lockout(
                    new Counter(counterOperations, this.MakeKey(d.Key, context), d.Expiration),
                    d.Threshold).Guard());
            return result.Any(r => r);
        }

        private string MakeKey(string format, IDictionary<string, string> d)
        {
            var r = format;
            foreach (var pair in d)
            {
                r = r.Replace("{" + pair.Key + "}", pair.Value);
            }

            return r;
        }
    }
}<commit_msg>Minor method visibility cleanup in lockout runtime.<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Models
{
    public sealed class LockoutRuntime
    {
        private readonly LockoutDef[] defs;

        public LockoutRuntime(LockoutDef[] defs)
        {
            this.defs = defs;
        }

        public async Task<bool> Check(ICounterOperations counterOperations, IDictionary<string, string> context)
        {
            foreach (var d in this.defs)
            {
                var l = new Lockout(
                    new Counter(counterOperations, LockoutRuntime.MakeKey(d.Key, context), d.Expiration),
                    d.Threshold);
                if (await l.Check())
                {
                    return true;
                }
            }

            return false;
        }

        public async Task<bool> Guard(ICounterOperations counterOperations, IDictionary<string, string> context)
        {
            var result = await Task.WhenAll(
                from d in this.defs
                select new Lockout(
                    new Counter(counterOperations, LockoutRuntime.MakeKey(d.Key, context), d.Expiration),
                    d.Threshold).Guard());
            return result.Any(r => r);
        }

        private static string MakeKey(string format, IDictionary<string, string> d)
        {
            var r = format;
            foreach (var pair in d)
            {
                r = r.Replace("{" + pair.Key + "}", pair.Value);
            }

            return r;
        }
    }
}
{'fraction_non_alphanumeric': 0.08824466390570246, 'fraction_numerical': 0.0, 'mean_word_length': 1.482213438735178, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3489500', 'n_tokens_mistral': 814, 'n_tokens_neox': 788, 'n_words': 207}