Esempio n. 1
0
        private void addHttpsRule(object sender, MouseButtonEventArgs e)
        {
            string url = this.url.Text;

            if (url.Length == 0)
            {
                Fiddler.FiddlerApplication.DoNotifyUser("Please input the url", "Error tips");
                return;
            }

            //生产参数
            JObject param = new JObject();

            param["url"] = url;

            if (_index >= 0 && _type != "copy")
            {
                //修改数据
                Main.mainData.modifyRuleByIndex(_parentIndex, _index, param);
            }
            else
            {
                //添加Rule数据
                HttpsModel rule = Main.mainData.addRuleToItem <HttpsModel>(_parentIndex, param);
                //添加UI
                Main.container.addRuleToUI(rule);
                //获取Item数据
                ItemModel item = Main.mainData.getItemByIndex(_parentIndex);
                //显示对应区域
                item.Show = true;
            }

            //关闭弹框
            (this.Parent as Window).Close();
        }
Esempio n. 2
0
        //解析Rule数据
        private static ArrayList parseRuleData(JArray rules, int parentIndex, string type)
        {
            ArrayList result = new ArrayList();

            for (int i = 0, len = rules.Count; i < len; i++)
            {
                JObject rule = rules[i] as JObject;
                if (type == "host")
                {
                    HostModel temp = new HostModel(parentIndex, i, (bool)rule["enable"], rule["ip"].ToString(), rule["port"].ToString(), rule["url"].ToString());
                    result.Add(temp);
                }
                else if (type == "file")
                {
                    FileModel temp = new FileModel(parentIndex, i, (bool)rule["enable"], rule["url"].ToString(), rule["path"].ToString());
                    result.Add(temp);
                }
                else if (type == "https")
                {
                    HttpsModel temp = new HttpsModel(parentIndex, i, (bool)rule["enable"], rule["url"].ToString());
                    result.Add(temp);
                }
            }

            return(result);
        }
Esempio n. 3
0
        private void setInputText()
        {
            if (_parentIndex < 0 || _index < 0)
            {
                return;
            }

            //获取数据
            HttpsModel rule = Main.mainData.getRuleByIndex <HttpsModel>(_parentIndex, _index);

            //设置数据
            this.url.Text = rule.Url;
        }
Esempio n. 4
0
        //格式化Rule数据
        private static JArray formatRuleData(ArrayList rules, string type)
        {
            JArray result = new JArray();

            for (int i = 0, len = rules.Count; i < len; i++)
            {
                //生成Json数据
                JObject temp = new JObject();

                if (type == "host")
                {
                    HostModel rule = rules[i] as HostModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("ip", rule.IP);
                    temp.Add("port", rule.Port);
                    temp.Add("url", rule.Url);
                }
                else if (type == "file")
                {
                    FileModel rule = rules[i] as FileModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("url", rule.Url);
                    temp.Add("path", rule.Path);
                }
                else if (type == "https")
                {
                    HttpsModel rule = rules[i] as HttpsModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("url", rule.Url);
                }
                else if (type == "header")
                {
                    HeaderModel rule = rules[i] as HeaderModel;
                    //填充数据
                    temp.Add("enable", rule.Enable);
                    temp.Add("type", rule.Type);
                    temp.Add("url", rule.Url);
                    temp.Add("key", rule.Key);
                    temp.Add("value", rule.Value);
                }
                //填充进数组中
                result.Add(temp);
            }

            return(result);
        }
Esempio n. 5
0
        //添加Rule控件
        public void addRuleToUI(BaseModel model)
        {
            string type = Main.mainData.type;
            //创建UI对象
            Label label = new Label();
            //Item控件
            Label item = null;

            if (type == "host")
            {
                //设置UI对象属性
                HostModel rule = model as HostModel;
                label.Template    = Resources["main_content_host"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.host.Children[rule.ParentIndex] as Label;
            }
            else if (type == "file")
            {
                //设置UI对象属性
                FileModel rule = model as FileModel;
                label.Template    = Resources["main_content_file"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.file.Children[rule.ParentIndex] as Label;
            }
            else if (type == "https")
            {
                //设置UI对象属性
                HttpsModel rule = model as HttpsModel;
                label.Template    = Resources["main_content_https"] as ControlTemplate;
                label.DataContext = rule;

                //获取对应Item控件
                item = this.https.Children[rule.ParentIndex] as Label;
            }

            //首先执行一次ApplyTemplate,确保模板应用到了渲染树中
            item.ApplyTemplate();
            //获取对应的内容
            StackPanel content = item.Template.FindName("content", item) as StackPanel;

            //添加Rule控件
            content.Children.Add(label);
        }