Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottleProcesser"/> class.
        /// By default, the <see cref="QuotaExceededResponseCode"/> property
        /// is set to 429 (Too Many Requests).
        /// </summary>
        public ThrottleProcesser(
            ThrottlePolicy policy,
            IIpAddressParser ipAddressParser,
            IPolicyRepository policyRepo     = null,
            IThrottleRepository throttleRepo = null)
        {
            Logger = new DefaultThrottleLogger();
            QuotaExceededResponseCode = (HttpStatusCode)429;
            processResult             = new ThrottleProcessResult {
                IsPass = true
            };

            ThrottleRepo = throttleRepo;
            if (ThrottleRepo == null)
            {
                ThrottleRepo = new WebCacheThrottleRepository();
            }
            ThrottlingCore = new ThrottlingCore(ipAddressParser);
            ThrottlingCore.ThrottleRepo = ThrottleRepo;

            PolicyRepo = policyRepo;
            if (PolicyRepo == null)
            {
                PolicyRepo = new WebCachePolicyRepository();
            }
            Policy = policy;
            PolicyRepo.Save(ThrottleManager.GetPolicyKey(), policy);
        }
Esempio n. 2
0
 public ThrottleProcessResult Process(RequestIdentity identity, IEnableThrottlingAttribute attrPolicy = null)
 {
     Identity = identity;
     Policy   = PolicyRepo.FirstOrDefault(ThrottleManager.GetPolicyKey());
     if (Policy != null)
     {
         Checking(attrPolicy);
     }
     return(processResult);
 }