public string GetParser(string name, long type) { switch (type) // 0:xml 1:c# 2:java { case 0: return(Reach.Load(xmlDefPath + "/parsers/" + name + ".xml").text); case 1: return(SourceCode(name, type)); case 2: return(SourceCode(name, type)); } return(""); }
public Udf(string xmlFile) { xmlDefFile = xmlFile; xmlDefPath = Path.GetDirectoryName(xmlDefFile); xmlDef = Reach.Load(xmlFile); }
private string prepare(string name, string param, KeyPile <string, Tag> paramSet, Pile <Tag> rsDefSet, KeyPile <string, Conditions> rsCondSet, KeyPile <string, Tag> responseSet, KeyPile <string, Tag> results, string debug) { Tag def = new Tag(GetParser(name, 0), true); Tag requestDef = def.tags(2, new Pile <string>("", true, "[type]==request"))[1]; Tag parserDef = def.tags(2, new Pile <string>("", true, "[type]==parser"))[1]; Tag responseDef = def.tags(2, new Pile <string>("", true, "[type]==response"))[1]; KeyPile <string, Tag> resultSetDefinitions = new KeyPile <string, Tag>(); string url = parserDef.tags(2, Tag.where ("[type]==url"))[1].txt; foreach (Tag t in parserDef.tags(2, Tag.where ("[type]==resultset"))) { resultSetDefinitions.Add(t.attr["name"].Value.text, t); } foreach (string key in resultSetDefinitions.Keys) { rsDefSet.Add(resultSetDefinitions[key]); } foreach (Tag t in responseDef.tags(2, Tag.where ("[type]==param"))) { responseSet.Add(t.attr["name"].Value.text, t); } KeyPile <long, Tag> paramList = new KeyPile <long, Tag>(); foreach (Tag t in requestDef.tags(2, Tag.where ("[type]==param"))) { paramList.Add(Int32.Parse(t.attr["key"].Value.text), t); } foreach (long key in paramList.kAsc) { paramSet.Add(paramList[key].txt.after(1, "[").before(1, "]").text, paramList[key]); } Pile <Tag> qParams = new Tag(param, true).tags(2, Tag.where ("[type]==param")); string[] qp = new string[qParams.Len]; for (int i = 1; i <= qParams.Len; i++) { Tag t = qParams[i]; qp[i - 1] = t.attr["name"].Value.text + "=" + t.attr["value"].Value.text; } foreach (string worddef in qp) { string word = worddef; string key = utl.cutl(ref word, "="); long pos = 0; for (int i = 1; i <= paramSet.Len; i++) { if (paramSet.Keys[i].Equals(key)) { pos = i; break; } } url = url.Replace("[" + pos + "]", paramSet[key].txt.text.Replace("[" + key + "]", word)); } url = url.Replace("&", "&"); for (long i = 1; i <= paramSet.Len; i++) { url = url.Replace("[" + i + "]", ""); } for (int rset = 1; rset <= rsDefSet.Len; rset++) { if (debug.Equals("base")) { break; } Tag rsDef = rsDefSet[rset]; Pile <Pile <string> > rsFilters = new Pile <Pile <string> >(); foreach (Tag filterDef in rsDef.tags(2, Tag.where ("[type]==filter"))) { Pile <string> rsPatterns = new Pile <string>(); foreach (Tag patternDef in filterDef.tags(2, Tag.where ("[type]==pattern"))) { bool neg = patternDef.attr["neg"].Value.Equals("1"); bool csens = patternDef.attr["csens"].Value.Equals("1"); bool rexp = patternDef.attr["rexp"].Value.Equals("1"); string key = patternDef.attr["key"].Value.text.Replace(">", ">").Replace("<", "<"); string val = patternDef.txt; string cmp = ""; if (neg) { cmp = "!"; } if (!csens) { cmp += "°"; } if (rexp) { cmp += "~"; } else { cmp += "="; } if (csens) { cmp += cmp.Substring(cmp.Length - 1); } rsPatterns.Add(key + cmp + val); } rsFilters.Add(rsPatterns); } rsCondSet.Add(rsDef.attr["base"].Value + "-" + rsDef.attr["name"].Value, new Conditions(rsDef.attr["base"].Value, rsDef.attr["name"].Value, rsDef.tags(2, Tag.where ("[type]==sequence"))[1].attr["include"].Value.text.Trim(), rsFilters)); if (debug.Equals(rsDef.attr["name"].Value)) { break; } //rsCondSet.Add(rsDef.attr["base"].Item, new Conditions(rsDef.attr["base"].Item, rsDef.attr["name"].Item, rsDef.tags(2, Tag.where("[type]==sequence"))[1].attr["include"].Item.text.Trim(), rsFilters)); } //long Pos1 = ((string)Reach.Load("http://www.livejasmin.com/listpage.php?page=22&livejasmin_session=4678d6bb9242e4bef687d240c293b873&tags=girl&type=40&orderby=0")).IndexOf("allonline_perfnametext"); Tag doc = new Tag(Reach.Load(url), false); //long Pos2 = doc.struc(-1).IndexOf("allonline_perfnametext"); //for (long i = 1; i <= doc.Tags.Len(); i++) doc.Tags[i].Name = "base:" + i; results.Add("base", doc); return(url); }