Ejemplo n.º 1
0
        public override void PerformAction(
            IRequestInfo requestInfo,
            IRuleResult ruleResult,
            out bool stopProcessing,
            out bool endRequest)
        {
            switch (_scope)
            {
            case Scope.Header:
                foreach (var header in requestInfo.GetHeaderNames())
                {
                    if (!_scopeIndex.Contains(header.ToLower()))
                    {
                        requestInfo.SetHeader(header, null);
                    }
                }
                break;

            case Scope.Parameter:
                var parameters = new Dictionary <string, IList <string> >();
                foreach (var parameterName in _scopeIndex)
                {
                    IList <string> parameterValue;
                    if (requestInfo.NewParameters.TryGetValue(parameterName, out parameterValue))
                    {
                        if (parameterValue != null && parameterValue.Count > 0)
                        {
                            parameters[parameterName] = parameterValue;
                        }
                    }
                }
                requestInfo.NewParameters = parameters;
                break;

            case Scope.PathElement:
                // Note that _scopeIndexValue is sorted into ascending order and always includes 0
                var newPath = _scopeIndexValue
                              .Where(i => i >= 0 && i < requestInfo.NewPath.Count)
                              .Select(index => requestInfo.NewPath[index])
                              .ToList();
                if (newPath.Count < 2)
                {
                    newPath.Add(string.Empty);
                }
                requestInfo.NewPath = newPath;
                break;
            }

            stopProcessing = _stopProcessing;
            endRequest     = _endRequest;
        }