Exemplo n.º 1
0
 private void PrepareKeyContext(
     QosPolicyKeyContext context,
     HttpContext httpContext,
     QosPolicy policy,
     RouteTemplate routeTemplate,
     RouteValueDictionary routeValues)
 {
     context.HttpContext   = httpContext;
     context.Policy        = policy;
     context.RouteTemplate = routeTemplate;
     context.RouteValues   = routeValues;
 }
Exemplo n.º 2
0
        private async Task <(QosPolicy RejectedPolicy, int RejectedPolicyIndex)> EnterAsync(
            HttpContext context,
            ExecutionData[] execData)
        {
            var keyContext   = new QosPolicyKeyContext(); // Perfs: allocate it only one time
            var enterContext = new QosGateEnterContext(); // Perfs: allocate it only one time

            for (var i = 0; i < _policies.Length; i++)
            {
                var policy = _policies[i];

                var           routeValues = new RouteValueDictionary();
                RouteTemplate routeTemplate;
                if (policy.TryUrlMatching(context.Request.Method, context.Request.Path, routeValues, out routeTemplate))
                {
                    PrepareKeyContext(keyContext, context, policy.Policy, routeTemplate, routeValues);

                    var key = policy.Policy.Key.GetKey(keyContext);
                    if (!string.IsNullOrEmpty(key))
                    {
                        PrepareGateEnterContext(enterContext, context, key);

                        var enterResult = await policy.Policy.Gate.TryEnterAsync(enterContext);

                        if (!enterResult.Success)
                        {
                            return(policy.Policy, i);
                        }

                        execData[i] = new ExecutionData()
                        {
                            Key      = key,
                            GateData = enterResult.Data
                        };
                    }
                }
            }

            return(null, 0);
        }
Exemplo n.º 3
0
 public string GetKey(QosPolicyKeyContext context)
 {
     return(_keyEvaluator(context));
 }