//新增Rule数据 public T addRuleToItem <T>(int parentIndex, JObject param) { object rule = null; ArrayList items = data[type] as ArrayList; ArrayList rules = (items[parentIndex] as ItemModel).Rules as ArrayList; if (type == "host") { //获取所有的参数 string ip = param["ip"].ToString(); string port = param["port"].ToString(); string url = param["url"].ToString(); //新建数据 rule = new HostModel(parentIndex, rules.Count, true, ip, port, url); } else if (type == "file") { //获取所有的参数 string url = param["url"].ToString(); string path = param["path"].ToString(); //新建数据 rule = new FileModel(parentIndex, rules.Count, true, url, path); } else if (type == "https") { //获取所有的参数 string url = param["url"].ToString(); //新建数据 rule = new HttpsModel(parentIndex, rules.Count, true, url); } else if (type == "header") { //获取所有的参数 string type = param["type"].ToString(); string url = param["url"].ToString(); string key = param["key"].ToString(); string value = param["value"].ToString(); //新建数据 rule = new HeaderModel(parentIndex, rules.Count, true, type, url, key, value); } //添加数据 rules.Add(rule); //重新写入文件 DataTool.writeConfigToFile(); return((T)rule); }
//修改Item数据 public void modifyRuleByIndex(int parentIndex, int index, JObject param) { ArrayList items = data[type] as ArrayList; ArrayList rules = (items[parentIndex] as ItemModel).Rules as ArrayList; if (type == "host") { //获取规则 HostModel rule = rules[index] as HostModel; //更新数据 rule.IP = param["ip"].ToString(); rule.Port = param["port"].ToString(); rule.Url = param["url"].ToString(); } else if (type == "file") { //获取规则 FileModel rule = rules[index] as FileModel; //更新数据 rule.Url = param["url"].ToString(); rule.Path = param["path"].ToString(); } else if (type == "https") { //获取规则 HttpsModel rule = rules[index] as HttpsModel; //更新数据 rule.Url = param["url"].ToString(); } else if (type == "header") { //获取规则 HeaderModel rule = rules[index] as HeaderModel; //更新数据 rule.Type = param["type"].ToString(); rule.Url = param["url"].ToString(); rule.Key = param["key"].ToString(); rule.Value = param["value"].ToString(); } //重新写入文件 DataTool.writeConfigToFile(); }