Esempio n. 1
0
        public void EditRule()
        {
            string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "EditRule.xml"));
            var    request  = new EditRule
            {
                SessionId    = "sid",
                Who          = "*****@*****.**",
                RuleID       = 1,
                RuleSettings = new TRuleSettings
                {
                    Title      = "Test",
                    Active     = true,
                    RuleID     = 1,
                    Conditions = new TRuleConditions
                    {
                        Items = new List <TRuleCondition>
                        {
                            new TRuleSomeWordsCondition
                            {
                                ConditionType = TRuleConditionType.CustomHeader,
                                OperatorAnd   = true,
                                MatchFunction = TRuleSomeWordsFunctionType.Regex,
                                MatchValue    = "X-Priority: 2"
                            }
                        }
                    },
                    Actions = new TRuleActions
                    {
                        Items = new List <TRuleAction>
                        {
                            new TRuleMessageActionAction
                            {
                                Actiontype        = TRuleActionType.MessageAction,
                                MessageActionType = TRuleMessageActionType.Reject
                            },
                            new TRulePriorityAction
                            {
                                Actiontype = TRuleActionType.Priority,
                                Priority   = TRulePriorityType.Highest
                            }
                        }
                    }
                }
            };
            var xml = request.ToXml().InnerXmlFormatted();

            Assert.AreEqual(expected, xml);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "EditRule.xml")));
            var response = request.FromHttpRequestResult(new HttpRequestResult {
                Response = doc.InnerXml
            });

            Assert.AreEqual("result", response.Type);
            Assert.True(response.Success);
        }
Esempio n. 2
0
 public void Setup(EditRule rule)
 {
     editRule = rule;
     // Create the lines describing the rule.
     // First the condition
     conditionToken = UIRuleTokenManager.Instance.CreateConditionToken(rule.condition, tokenRoot);
     actionTokens.Clear();
     for (int i = 0; i < rule.actions.Count; ++i)
     {
         var action = rule.actions[i];
         actionTokens.Add(UIRuleTokenManager.Instance.CreateActionToken(action, i == 0, tokenRoot));
     }
     Expand(false);
 }
Esempio n. 3
0
 void OnActionChange(EditRule rule, EditAction action)
 {
     base.pageDirty = true;
 }
Esempio n. 4
0
 void OnConditionChange(EditRule rule, EditCondition condition)
 {
     base.pageDirty = true;
 }
Esempio n. 5
0
 private void rulesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     var elem = rulesList.InputHitTest(e.GetPosition(rulesList));
     ListBoxItem item = Helper.FindParent<ListBoxItem>(elem as DependencyObject);
     if (item != null)
     {
         PrjRule rule = item.Content as PrjRule;
         var win = new EditRule("Edit rule", rule, host) { Owner = host as Window };
         if (win.ShowDialog() ?? false)
         {
             int idx = host.Project.Rules.IndexOf(rule);
             host.Project.Rules.RemoveAt(idx);
             host.Project.Rules.Insert(idx, win.Rule.Clone(host.Project));
             rulesList.SelectedIndex = idx;
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Create a Set of edits from a raw INI-like source
        /// </summary>
        /// <param name="RawEdits">INI-like list of edits (from webone.conf)</param>
        public EditSet(List <string> RawEdits)
        {
            UrlMasks         = new List <string>();
            UrlIgnoreMasks   = new List <string>();
            ContentTypeMasks = new List <string>();
            HeaderMasks      = new List <string>();
            Edits            = new List <KeyValuePair <string, string> >();
            IsForRequest     = false;

            bool MayBeForResponse = false; //does this set containing tasks for HTTP response processing?

            foreach (string EditRule in RawEdits)
            {
                int BeginValue = EditRule.IndexOf("=");
                if (BeginValue < 1)
                {
                    continue;                 //ignore bad lines
                }
                string ParamName  = EditRule.Substring(0, BeginValue);
                string ParamValue = EditRule.Substring(BeginValue + 1);

                switch (ParamName)
                {
                case "OnUrl":
                    UrlMasks.Add(ParamValue);
                    continue;

                case "OnCode":
                    OnCode = int.Parse(ParamValue);
                    continue;

                case "IgnoreUrl":
                    UrlIgnoreMasks.Add(ParamValue);
                    continue;

                case "OnContentType":
                    ContentTypeMasks.Add(ParamValue);
                    continue;

                case "OnHeader":
                    HeaderMasks.Add(ParamValue);
                    continue;

                default:
                    if (ParamName.StartsWith("Add"))
                    {
                        Edits.Add(new KeyValuePair <string, string>(ParamName, ParamValue));
                    }
                    else
                    {
                        Console.WriteLine("Warning: unknown mask \"{0}\" will be ignored.", ParamName);
                    }

                    if (ParamName.StartsWith("AddConvert"))
                    {
                        MayBeForResponse = true;
                    }
                    if (ParamName == "AddContentType")
                    {
                        MayBeForResponse = true;
                    }
                    if (ParamName == "AddFind")
                    {
                        MayBeForResponse = true;
                    }
                    if (ParamName == "AddReplace")
                    {
                        MayBeForResponse = true;
                    }
                    if (ParamName == "AddInternalRedirect")
                    {
                        MayBeForResponse = false;
                    }

                    continue;
                }
            }

            //check if the edit set can be runned on HTTP-request time
            if (ContentTypeMasks.Count == 0 && !MayBeForResponse)
            {
                IsForRequest = true;
            }

            if (UrlMasks.Count == 0)
            {
                UrlMasks.Add(".*");
            }
        }