コード例 #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="chainedCondition"></param>
 public NegativeCondition(IRewriteCondition chainedCondition)
 {
     if (chainedCondition == null)
     {
         throw new ArgumentNullException("chainedCondition");
     }
     _chainedCondition = chainedCondition;
 }
コード例 #2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="chainedCondition"></param>
 public NegativeCondition(IRewriteCondition chainedCondition)
 {
     if (chainedCondition == null)
     {
         throw new ArgumentNullException("chainedCondition");
     }
     _chainedCondition = chainedCondition;
 }
コード例 #3
0
        /// <summary>
        /// Parses conditions from the node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="conditions">Conditions list to add new conditions to.</param>
        /// <param name="negative">Whether the conditions should be negated.</param>
        /// <param name="config">Rewriter configuration</param>
        protected void ParseConditions(XmlNode node, IList conditions, bool negative, object config)
        {
            if (config == null)
            {
                return;
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (conditions == null)
            {
                throw new ArgumentNullException("conditions");
            }

            RewriterConfiguration rewriterConfig = config as RewriterConfiguration;

            // Parse attribute-based conditions.
            foreach (IRewriteConditionParser parser in rewriterConfig.ConditionParserPipeline)
            {
                IRewriteCondition condition = parser.Parse(node);
                if (condition != null)
                {
                    if (negative)
                    {
                        condition = new NegativeCondition(condition);
                    }

                    conditions.Add(condition);
                }
            }

            // Now, process the nested <and> conditions.
            XmlNode childNode = node.FirstChild;

            while (childNode != null)
            {
                if (childNode.NodeType == XmlNodeType.Element)
                {
                    if (childNode.LocalName == Constants.ElementAnd)
                    {
                        ParseConditions(childNode, conditions, negative, config);

                        XmlNode childNode2 = childNode.NextSibling;
                        node.RemoveChild(childNode);
                        childNode = childNode2;
                        continue;
                    }
                }

                childNode = childNode.NextSibling;
            }
        }
コード例 #4
0
        private void ProcessRules(RewriteContext context)
        {
            const int MaxRestart = 10;             // Controls the number of restarts so we don't get into an infinite loop

            IList rewriteRules = _configuration.Rules;
            int   restarts     = 0;

            for (int i = 0; i < rewriteRules.Count; i++)
            {
                // If the rule is conditional, ensure the conditions are met.
                IRewriteCondition condition = rewriteRules[i] as IRewriteCondition;
                if (condition == null || condition.IsMatch(context))
                {
                    // Execute the action.
                    IRewriteAction    action     = rewriteRules[i] as IRewriteAction;
                    RewriteProcessing processing = action.Execute(context);

                    //if (!TygaSoft.TygaSoftRuntime.ValidateRuntime())
                    //{
                    //    context.Location = "~/NotAccess.aspx";
                    //    break;
                    //}

                    // If the action is Stop, then break out of the processing loop
                    if (processing == RewriteProcessing.StopProcessing)
                    {
                        _configuration.Logger.Debug(MessageProvider.FormatString(Message.StoppingBecauseOfRule));
                        break;
                    }
                    else if (processing == RewriteProcessing.RestartProcessing)
                    {
                        _configuration.Logger.Debug(MessageProvider.FormatString(Message.RestartingBecauseOfRule));

                        // Restart from the first rule.
                        i = 0;

                        if (++restarts > MaxRestart)
                        {
                            throw new InvalidOperationException(MessageProvider.FormatString(Message.TooManyRestarts));
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Executes the rule.
        /// </summary>
        /// <param name="context"></param>
        public virtual RewriteProcessing Execute(RewriteContext context)
        {
            // Execute the actions.
            for (int i = 0; i < Actions.Count; i++)
            {
                IRewriteCondition condition = Actions[i] as IRewriteCondition;
                if (condition == null || condition.IsMatch(context))
                {
                    IRewriteAction    action     = Actions[i] as IRewriteAction;
                    RewriteProcessing processing = action.Execute(context);
                    if (processing != RewriteProcessing.ContinueProcessing)
                    {
                        return(processing);
                    }
                }
            }

            return(RewriteProcessing.ContinueProcessing);
        }
コード例 #6
0
        private void ProcessRules(IRewriteContext context, IList <IRewriteAction> rewriteRules, int restarts)
        {
            foreach (IRewriteAction action in rewriteRules)
            {
                // If the rule is conditional, ensure the conditions are met.
                IRewriteCondition condition = action as IRewriteCondition;
                if (condition == null || condition.IsMatch(context))
                {
                    // Execute the action.
                    RewriteProcessing processing = action.Execute(context);

                    // If the action is Stop, then break out of the processing loop
                    if (processing == RewriteProcessing.StopProcessing)
                    {
                        _configuration.Logger.Debug(MessageProvider.FormatString(Message.StoppingBecauseOfRule));

                        // Exit the loop.
                        break;
                    }

                    // If the action is Restart, then start again.
                    if (processing == RewriteProcessing.RestartProcessing)
                    {
                        _configuration.Logger.Debug(MessageProvider.FormatString(Message.RestartingBecauseOfRule));

                        // Increment the number of restarts and check that we have not exceeded our max.
                        restarts++;
                        if (restarts > MaxRestarts)
                        {
                            throw new InvalidOperationException(MessageProvider.FormatString(Message.TooManyRestarts));
                        }

                        // Restart again from the first rule by calling this method recursively.
                        ProcessRules(context, rewriteRules, restarts);

                        // Exit the loop.
                        break;
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Executes the rule.
        /// </summary>
        /// <param name="context">The rewrite context</param>
        public virtual RewriteProcessing Execute(IRewriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Execute the actions.
            for (int i = 0; i < Actions.Count; i++)
            {
                IRewriteCondition condition = Actions[i] as IRewriteCondition;
                if (condition == null || condition.IsMatch(context))
                {
                    IRewriteAction    action     = Actions[i];
                    RewriteProcessing processing = action.Execute(context);
                    if (processing != RewriteProcessing.ContinueProcessing)
                    {
                        return(processing);
                    }
                }
            }

            return(RewriteProcessing.ContinueProcessing);
        }
コード例 #8
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="chainedCondition"></param>
 public NegativeCondition(IRewriteCondition chainedCondition)
 {
     this._chainedCondition = chainedCondition ?? throw new ArgumentNullException(nameof(chainedCondition));
 }