public HttpMessage(SdNode cfg, String url) { this.config = cfg; this.url = url; rebuild(null); }
public void loadByJson(SdNode c, params string[] jsons) { if (jsons == null || jsons.Length == 0) return; foreach (String json in jsons) { //支持多个数据块加载 ONode data = ONode.tryLoad(json); if (data.isArray) { foreach (ONode n in data) { String name = n.get("name").getString(); if (Session.isVip == 0 && SourceApi.isFilter(name)) //非vip进行过滤 continue; BookUpdateModel b = new BookUpdateModel(); b.name = name; b.url = n.get("url").getString(); b.logo = n.get("logo").getString(); b.author = n.get("author").getString(); b.newSection = n.get("newSection").getString(); b.updateTime = n.get("updateTime").getString(); b.status = n.get("status").getString(); list.Add(b); } } } }
protected String parseUrl(SdNode config, String url, String html) { Log.v("parseUrl", url); Log.v("parseUrl", html == null ? "null" : html); return(js.callJs(config.parseUrl, url, html)); }
//add (不继承父节点) private SdNode buildForAdd(XElement cfg, SdNode p) //add不能有自己独立的url //定义为同一个page的数据获取(可能需要多个ajax) { foreach (var att in cfg.Attributes()) { attrs.set(att.Name.LocalName, att.Value); } this.name = cfg.Name.LocalName;//默认为标签名 this.url = attrs.getString("url"); this.txt = attrs.getString("txt");// this.method = attrs.getString("method"); this.header = attrs.getString("header"); this._encode = attrs.getString("encode"); this._ua = attrs.getString("ua"); //-------- this.title = attrs.getString("title");//可能为null this.parse = attrs.getString("parse"); this.buildUrl = attrs.getString("buildUrl"); this.buildRef = attrs.getString("buildRef"); this.buildHeader = attrs.getString("buildHeader"); return(this); }
public virtual void loadByConfig(SdNode c) { DdNode config = (DdNode)c; if (doFilter(c.title)) { return; } BookSearchModel b = new BookSearchModel(); DdNode cfg = config.s().search; b._dtype = cfg.dtype(); b.btype = cfg.btype(); b.name = c.title; b.url = c.url; b.logo = c.logo; b.updateTime = ""; b.newSection = ""; b.author = ""; b.status = ""; b.source = config.source.title; doAddItem(b); }
public void rebuild(SdNode cfg) { if (cfg != null) { this.config = cfg; } ua = config.ua(); encode = config.encode(); method = config.method; if (config.isInCookie()) { String cookies = config.cookies(url); if (cookies != null) { header.Add("Cookie", cookies); } } if (config.isInReferer()) { header.Add("Referer", config.getReferer(url)); } if (config.isEmptyHeader() == false) { foreach (String kv in config.getHeader(url).Split(';')) { String[] kv2 = kv.Split('='); if (kv2.Length == 2) { header.Add(kv2[0], kv2[1]); } } } }
public String parse(SdNode config, String url, String html) { Log.v("parse", url); Log.v("parse", html == null ? "null" : html); if (string.IsNullOrEmpty(config.parse)) { return(html); } if ("@null".Equals(config.parse)) //如果是@null,说明不需要通过js解析 { return(html); } else { String temp = js.callJs(config.parse, url, html); if (temp == null) { Log.v("parse.rst", "null" + "\r\n\n"); } else { Log.v("parse.rst", temp + "\r\n\n"); } return(temp); } }
private static async void doHttp(SdSource source, String url, Dictionary<String, String> args, SdNode config, __CacheBlock cache, HttpCallback callback) { var encoding = Encoding.GetEncoding(config.encode()); AsyncHttpClient client = new AsyncHttpClient(); if (config.isInCookie() && string.IsNullOrEmpty(source.cookies()) == false) { client.Cookies(source.cookies()); } client.Header("User-Agent", source.ua()); client.Encoding(config.encode()); string newUrl = null; if (url.IndexOf(" ") >= 0) newUrl = Uri.EscapeUriString(url); else newUrl = url; if (config.isInReferer()) { client.Header("Referer", source.buildReferer(config, url)); } if (string.IsNullOrEmpty(config.accept) == false) { client.Header("Accept", config.accept); client.Header("X-Requested-With", "XMLHttpRequest"); } client.Url(newUrl); string temp = null; try { AsyncHttpResponse rsp = null; if ("post".Equals(config.method)) rsp = await client.Post(args); else rsp = await client.Get(); if (rsp.StatusCode == HttpStatusCode.Ok) { source.setCookies(rsp.Cookies); temp = rsp.GetString(); } } catch(Exception ex) { Util.log(source, "HTTP", ex.Message); } if (temp == null) { if (cache == null) callback(-2, null); else callback(1, cache.value); } else callback(1, temp); }
public bool isEquals(SdNode node) { if (name == null) { return(false); } return(name.Equals(node.name)); }
public virtual void loadByJson(SdNode config, params String[] jsons) { if (jsons == null || jsons.Length == 0) return; foreach (String json in jsons) { loadByJsonData(config, json); } }
internal SdNodeSet buildForNode(XElement element) { if (element == null) { return(this); } name = element.Name.LocalName; _items.Clear(); attrs.clear(); { foreach (var p in element.Attributes()) { attrs.set(p.Name.LocalName, p.Value); } foreach (var p in element.Elements()) { if (p.HasAttributes == false) { if (new List <XNode>(p.Nodes()).Count == 1) { var p2 = p.FirstNode; if (p2 != null && p2.NodeType == System.Xml.XmlNodeType.Text) { attrs.set(p.Name.LocalName, p.Value); } } } } } _dtype = attrs.getInt("dtype"); foreach (XElement e1 in element.Elements()) { if (e1.HasAttributes) { SdNode temp = Util.createNode(source).buildForNode(e1); this.add(temp); } else if (e1.HasElements) { SdNodeSet temp = Util.createNodeSet(source).buildForNode(e1); this.add(temp); } } OnDidInit(); return(this); }
public static String urlEncode(String str, SdNode config) { try { return Uri.EscapeUriString(str); } catch (Exception) { return ""; } }
internal SdJscript(SdSource source, XElement node) { s = source; if (node == null) { code = ""; require = new SdNode(source, null); } else { code = node.Element("code").Value.Trim(); require = new SdNode(source, node.Element("require")); } }
public HttpMessage(SdNode cfg, String url, int tag, Dictionary<String, String> args) { this.config = cfg; this.url = url; this.tag = tag; if (args != null) { form = args; } rebuild(null); }
/* 支持 ["","",""] 或 {bg:"",list:["","",""]} 或 {bg:"",list:[{url:"",time:"mm::ss.xx"},{...}]} 或 {bg:"",logo:"",name:"",list:[{url:"",time:"mm::ss.xx"},{...}]} */ public virtual void loadByJson(SdNode config, params String[] jsons) { if (jsons == null || jsons.Length == 0) return; foreach (String json in jsons) { StateTag state = new StateTag(); loadByJsonData(config, json, state); } }
public SdNode nodeMatch(String url) { foreach (ISdNode n in nodes()) { SdNode n1 = (SdNode)n; if (n1.isMatch(url)) { return(n1); } } return(Util.createNode(source).buildForNode(null)); }
public HttpMessage(SdNode cfg, String url, int tag, Dictionary <String, String> args) { this.config = cfg; this.url = url; this.tag = tag; if (args != null) { form = args; } rebuild(null); }
//---------- public static String urlEncode(String str, SdNode config) { try { if(config.encode().ToLower() == "utf-8") return Uri.EscapeUriString(str); else return __Escape.JsEscape(str); } catch (Exception) { return ""; } }
private void doParse_noAddin(ISdViewModel viewModel, SdNode config, String url, String text) { String json = this.parse(config, url, text); if (isDebug) { Util.log(this, config, url, json, 0); } if (json != null) { viewModel.loadByJson(config, json); } }
public bool isOuttime(SdNode config) { if (time == null || value == null) { return true; } else { if (config.cache == 1) return false; else { long seconds = ( DateTime.Now - time ).Seconds; return seconds > config.cache; } } }
private void doParse_noAddinForTmp(Dictionary <int, String> dataList, SdNode config, String url, String text, int tag) { String json = this.parse(config, url, text); if (isDebug) { Util.log(this, config, url, json, tag); } if (json != null) { dataList.Add(tag, json); } }
// //--------------------------------------- // public void getNodeViewModel(ISdViewModel viewModel, SdNodeSet nodeSet, bool isUpdate, SdSourceCallback callback) { __AsyncTag tag = new __AsyncTag(); foreach (ISdNode node in nodeSet.nodes()) { SdNode n = (SdNode)node; doGetNodeViewModel(viewModel, isUpdate, tag, n.url, null, n, callback); } if (tag.total == 0) { callback(1); } }
internal void loadByElement(XElement element) { if (element == null) return; _items.Clear(); foreach (XElement e1 in element.Elements()) { if (e1.HasAttributes) { SdNode temp = new SdNode(_source, e1); this.add(e1.Name.LocalName, temp); } else { SdNodeSet temp = new SdNodeSet(_source, e1); this.add(e1.Name.LocalName, temp); } } }
//---------- public static String urlEncode(String str, SdNode config) { try { if (config.encode().ToLower() == "utf-8") { return(Uri.EscapeUriString(str)); } else { return(__Escape.JsEscape(str)); } } catch (Exception) { return(""); } }
private void doParseUrl_Aft(ISdViewModel viewModel, SdNode config, bool isUpdate, List <String> newUrls, Dictionary <String, String> args, __AsyncTag tag, Dictionary <int, String> dataList, SdSourceCallback callback) { foreach (String newUrl2 in newUrls) { tag.total++; HttpMessage msg = new HttpMessage(config, newUrl2, tag.total, args); msg.callback = (code2, sender, text2, url302) => { tag.value++; if (code2 == 1) { if (string.IsNullOrEmpty(url302)) { url302 = newUrl2; } doParse_noAddinForTmp(dataList, config, url302, text2, sender.tag); } if (tag.total == tag.value) { List <String> jsonList = new List <String>(); for (int i = 1; i <= tag.total; i++) //安排序加载内容 { if (dataList.ContainsKey(i)) { jsonList.Add(dataList[i]); } } String[] strAry = jsonList.ToArray(); viewModel.loadByJson(config, strAry); callback(code2); } }; Util.http(this, isUpdate, msg); } }
public bool isOuttime(SdNode config) { if (time == null || value == null) { return(true); } else { if (config.cache == 1) { return(false); } else { long seconds = (DateTime.Now - time).Seconds; return(seconds > config.cache); } } }
//item(继承父节点) private SdNode buildForItem(XElement cfg, SdNode p) { foreach (var att in cfg.Attributes()) { attrs.set(att.Name.LocalName, att.Value); } this.name = p.name; this.title = attrs.getString("title"); //可能为null this.group = attrs.getString("group"); this.url = attrs.getString("url"); // this.txt = attrs.getString("txt"); // this.lib = attrs.getString("lib"); this.logo = attrs.getString("logo"); this._encode = attrs.getString("encode"); return(this); }
protected void loadByJsonData(SdNode config, String json) { ONode list = null; ONode obj = ONode.tryLoad(json); if (obj.isObject) { list = obj.get("list").asArray(); if (TextUtils.isEmpty(name)) { name = obj.get("name").getString(); logo = obj.get("logo").getString(); } } else { list = obj; } foreach (ONode n in list) { TxtModel txt = new TxtModel(referer, n.get("d").getString(), n.get("t").getInt(), n.get("c").getString()); items.Add(txt); } }
public virtual void loadByJson(SdNode c, params string[] jsons) { if (jsons == null || jsons.Length == 0) return; DdNode config = (DdNode)c; foreach (String json in jsons) { //支持多个数据块加载 ONode data = ONode.tryLoad(json); if (data.isArray) { foreach (ONode n in data) { String name = n.get("name").getString(); if (doFilter(name)) { continue; } BookSearchModel b = new BookSearchModel(); b.name = name; b.url = n.get("url").getString(); b.logo = n.get("logo").getString(); b.updateTime = n.get("updateTime").getString(); b.newSection = n.get("newSection").getString(); b.author = n.get("author").getString(); b.status = n.get("status").getString(); b.source = config.source.title; b.btag = n.get("btag").getString(); DdNode cfg = config.s().book(b.url); b._dtype = cfg.dtype(); b.btype = cfg.btype(); doAddItem(b); } } } }
// //-------------------------------- // public static void log(SdSource source, SdNode node, String url, String json, int tag) { log(source, node.name, "tag=" + tag); if (url == null) { log(source, node.name, "url=null"); } else { log(source, node.name, url); } if (json == null) { log(source, node.name, "json=null"); } else { log(source, node.name, json); } }
public async static void http(SdSource source, bool isUpdate, String url, Dictionary<String, String> args, SdNode config, HttpCallback callback) { __CacheBlock block = null; if (isUpdate == false && config.cache > 0) { block = cache.get(url); } if (block != null) { if (config.cache == 1 || block.seconds() <= config.cache) { await Task.Delay(100); callback(1, block.value); return; } } doHttp(source, url, args, config, block,(code, data) => { if (code == 1 && config.cache > 0) { cache.save(url, data); } callback(code, data); }); }
public virtual void loadByJson(SdNode config, params string[] jsons) { if (jsons == null || jsons.Length == 0) return; foreach (String json in jsons) { if (json.StartsWith("{") || json.StartsWith("[")) { ONode jList = null; ONode obj = ONode.tryLoad(json); if (obj.isObject) { jList = obj.get("list").asArray(); if (TextUtils.isEmpty(name)) { name = obj.get("name").getString(); logo = obj.get("logo").getString(); } } else { jList = obj; } foreach (ONode n1 in jList) { items.Add(new MediaModel(n1.get("url").getString(), n1.get("type").getString(), n1.get("mime").getString(), n1.get("logo").getString())); } } else { foreach (String url in json.Split(';')) { if (url.Length > 6) { items.Add(new MediaModel(url)); } } } } }
private void doParse_hasAddin(ISdViewModel viewModel, SdNode config, String url, String text) { String json = this.parse(config, url, text); if (isDebug) { Util.log(this, config, url, json, 0); } if (json != null) { viewModel.loadByJson(config, json); if (config.hasAdds()) //没有url的add { foreach (SdNode n1 in config.adds()) { if (string.IsNullOrEmpty(n1.buildUrl) == false || string.IsNullOrEmpty(n1.url) == false) { continue; } String json2 = this.parse(n1, url, text); if (isDebug) { Util.log(this, n1, url, json2, 0); } if (json2 != null) { viewModel.loadByJson(n1, json2); } } } } }
//------------------- // public void loadByConfig(SdNode c) { }
public SdNode(SdSource source, XElement cfg) { this.source = source; _isEmpty = (cfg == null); if (cfg != null) { this.name = cfg.Name.LocalName; this.title = cfg.Attribute("title")?.Value; this.method = cfg.Attribute("method")?.Value; this.parse = cfg.Attribute("parse")?.Value; this.parseUrl = cfg.Attribute("parseUrl")?.Value; this.url = cfg.Attribute("url")?.Value; this.expr = cfg.Attribute("expr")?.Value; this._run = cfg.Attribute("run")?.Value; this._encode = cfg.Attribute("encode")?.Value; this._ua = cfg.Attribute("ua")?.Value; if (string.IsNullOrEmpty(this.method)) { this.method = "get"; } { string temp = cfg.Attribute("cache")?.Value; if (string.IsNullOrEmpty(temp) == false) { int len = temp.Length; if (len == 1) { cache = int.Parse(temp); } else if (len > 1) { cache = int.Parse(temp.Substring(0, len - 1)); string p = temp.Substring(len - 1); switch (p) { case "d": cache = cache * 24 * 60 * 60; break; case "h": cache = cache * 60 * 60; break; case "m": cache = cache * 60; break; } } } } this.accept = cfg.Attribute("accept")?.Value; this.header = cfg.Attribute("header")?.Value; if (this.header == null) this.header = ""; string w = cfg.Attribute("w")?.Value; if (string.IsNullOrEmpty(w) == false) { string h = cfg.Attribute("h")?.Value; WHp = float.Parse(w) / float.Parse(h); } this.buildRef = cfg.Attribute("buildRef")?.Value; this.buildUrl = cfg.Attribute("buildUrl")?.Value; this.buildKey = cfg.Attribute("buildKey")?.Value; this.buildWeb = cfg.Attribute("buildWeb")?.Value; this.addKey = cfg.Attribute("addKey")?.Value; string _addPage = cfg.Attribute("addPage")?.Value; if (string.IsNullOrEmpty(_addPage) == false) { this.addPage = int.Parse(_addPage); } //搜索物有 this.args = cfg.Attribute("args")?.Value; if (cfg.HasElements) { _items = new List<SdNode>(); _adds = new List<SdNode>(); foreach (XElement e1 in cfg.Elements()) { if (e1.Name.LocalName.Equals("item")) { SdNode temp = new SdNode(source).buildForItem(e1, this); _items.Add(temp); } else { SdNode temp = new SdNode(source).buildForAdd(e1, this); _adds.Add(temp); } } } } }
// //-------------------------------- // public static void log(SdSource source, SdNode node, String url, String json) { if (url == null) log(source, node.name, "url=null"); else log(source, node.name, url); if (json == null) log(source, node.name, "json=null"); else log(source, node.name, json); }
//item(继承父节点) private SdNode buildForItem(XElement cfg, SdNode p) { foreach(var att in cfg.Attributes()) { attrs.set(att.Name.LocalName, att.Value); } this.name = p.name; this.title = attrs.getString("title");//可能为null this.group = attrs.getString("group"); this.url = attrs.getString("url");// this.txt = attrs.getString("txt");// this.lib = attrs.getString("lib"); this.logo = attrs.getString("logo"); this._encode = attrs.getString("encode"); return this; }
//add (不继承父节点) private SdNode buildForAdd(XElement cfg, SdNode p) { //add不能有自己独立的url //定义为同一个page的数据获取(可能需要多个ajax) foreach (var att in cfg.Attributes()) { attrs.set(att.Name.LocalName, att.Value); } this.name = cfg.Name.LocalName;//默认为标签名 this.url = attrs.getString("url"); this.txt = attrs.getString("txt");// this.method = attrs.getString("method"); this.header = attrs.getString("header"); this._encode = attrs.getString("encode"); this._ua = attrs.getString("ua"); //-------- this.title = attrs.getString("title");//可能为null this.parse = attrs.getString("parse"); this.buildUrl = attrs.getString("buildUrl"); this.buildRef = attrs.getString("buildRef"); this.buildHeader = attrs.getString("buildHeader"); return this; }
private void doGetNodeViewModel(ISdViewModel viewModel, bool isUpdate, __AsyncTag tag, String url, Dictionary <String, String> args, SdNode config, SdSourceCallback callback) { //需要对url进行转换成最新的格式(可能之前的旧的格式缓存) if (config.isEmpty()) { return; } if (config.hasItems()) { viewModel.loadByConfig(config); return; } if ("@null".Equals(config.method)) { viewModel.loadByJson(config, config.getUrl(url)); return; } if (string.IsNullOrEmpty(config.parse) == false && string.IsNullOrEmpty(url) == false) //如果没有url 和 parse,则不处理 { HttpMessage msg = new HttpMessage(); if (args != null) { msg.form = args; } var dataList = new Dictionary <int, String>();//如果有多个地址,需要排序 //2.获取主内容 tag.total++; msg.url = config.getUrl(url); msg.callback = (code, sender, text, url302) => { tag.value++; if (code == 1) { if (string.IsNullOrEmpty(url302)) { url302 = sender.url; } if (string.IsNullOrEmpty(config.parseUrl) == false) //url需要解析出来(多个用;隔开) { List <String> newUrls = new List <String>(); String[] rstUrls = parseUrl(config, url302, text).Split(';'); foreach (String url1 in rstUrls) { if (url1.Length == 0) { continue; } if (url1.StartsWith(Util.NEXT_CALL)) { Util.log(this, "CALL::url=", url1); HttpMessage msg0 = new HttpMessage(); msg0.url = url1.Replace(Util.NEXT_CALL, "") .Replace("GET::", "") .Replace("POST::", ""); msg0.rebuild(config); if (url1.IndexOf("POST::") > 0) { msg0.method = "post"; msg0.rebuildForm(); } else { msg0.method = "get"; } msg0.callback = msg.callback; tag.total++; Util.http(this, isUpdate, msg0); } else { newUrls.Add(url1); } } if (newUrls.Count > 0) { doParseUrl_Aft(viewModel, config, isUpdate, newUrls, args, tag, dataList, callback); } return;//下面的代码被停掉 } else { doParse_hasAddin(viewModel, config, url302, text); } } if (tag.total == tag.value) { callback(code); } }; //有缓存的话,可能会变成同步了 msg.rebuild(config); Util.http(this, isUpdate, msg); } if (config.hasAdds()) { //2.2 获取副内容(可能有多个) foreach (SdNode n1 in config.adds()) { if (n1.isEmptyUrl()) { continue; } tag.total++; HttpMessage msg = new HttpMessage(); //如果自己有url,则使用自己的url;;如果没有,则通过父级的url进行buildUrl(url) msg.url = (string.IsNullOrEmpty(n1.url) ? n1.getUrl(url) : n1.url); msg.callback = (code, sender, text, url302) => { if (code == 1) { if (string.IsNullOrEmpty(url302)) { url302 = msg.url; } String json = this.parse(n1, url302, text); if (isDebug) { Util.log(this, n1, url302, json, 0); } if (json != null) { viewModel.loadByJson(n1, json); } } tag.value++; if (tag.total == tag.value) { callback(code); } }; msg.rebuild(config); Util.http(this, isUpdate, msg); } } }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, int page, String url, SdNode config, SdSourceCallback callback) { config.url = url; getNodeViewModel(viewModel, isUpdate, null, page, config, callback); }
protected override void DoTraceUrl(String url, String args, SdNode config) { if (TextUtils.isEmpty(trace_url) == false) { if (TextUtils.isEmpty(url) == false) { try { var data = new Dictionary<String, String>(); data.Add("_uid", Session.userID + ""); data.Add("_uname", Session.nickname); data.Add("_days", Session.dayNum + ""); data.Add("_vip", Session.isVip + ""); data.Add("url", url); data.Add("args", args); data.Add("node", config.name); HttpUtil.post(trace_url, data, (code, text) => { }); } catch (Exception) { } } } }
//add (不继承父节点) private SdNode buildForAdd(XElement cfg, SdNode p) { //add不能有自己独立的url //定义为同一个page的数据获取(可能需要多个ajax) this.name = cfg.Name.LocalName;//默认为标签名 this.method = cfg.Attribute("method")?.Value; this.accept = cfg.Attribute("accept")?.Value; this._encode = cfg.Attribute("encode")?.Value; this._ua = cfg.Attribute("ua")?.Value; //-------- this.title = cfg.Attribute("title")?.Value;//可能为null this.parse = cfg.Attribute("parse")?.Value; this.buildUrl = cfg.Attribute("buildUrl")?.Value; this.buildRef = cfg.Attribute("buildRef")?.Value; return this; }
protected void loadByJsonData(SdNode config, String json, StateTag state) { ONode list = null; ONode obj = ONode.tryLoad(json); if (obj.isObject) { list = obj.get("list").asArray(); String bg = obj.get("bg").getString(); if (TextUtils.isEmpty(bg) == false) { bgUrl = bg; } if (TextUtils.isEmpty(name)) { name = obj.get("name").getString(); logo = obj.get("logo").getString(); } } else { list = obj; } foreach (ONode n in list) { PicModel pic = null; if (n.isObject) { pic = new PicModel(section(), n.get("url").getString(), n.get("time").getInt(), state.value); } else { pic = new PicModel(section(), n.getString(), 0, state.value); } pic.cacheID = items.Count; doAddItem(pic, state); state.value++; } }
protected internal virtual void DoTraceUrl(String url, String args, SdNode config) { }
public String callJs(SdNode config, String funAttr, params String[] args) { return(js.callJs(config.attrs.getString(funAttr), args)); }
public virtual void loadByConfig(SdNode config) { }
public static bool isUpdates(SdNode node) { return "updates".Equals(node.name); }
//item(继承父节点) private SdNode buildForItem(XElement cfg, SdNode p) { this.name = p.name; this.title = cfg.Attribute("title")?.Value;//可能为null this.url = cfg.Attribute("url")?.Value;// this.logo = cfg.Attribute("logo")?.Value; this.group = cfg.Attribute("group")?.Value; this._encode = cfg.Attribute("encode")?.Value; return this; }
internal SdNode buildForNode(XElement cfg) { _isEmpty = (cfg == null); if (cfg != null) { this.name = cfg.Name.LocalName; foreach (XAttribute att in cfg.Attributes()) { attrs.set(att.Name.LocalName, att.Value); } _dtype = attrs.getInt("dtype"); _btype = attrs.getInt("btype"); this.title = attrs.getString("title"); this.method = attrs.getString("method", "get"); this.parse = attrs.getString("parse"); this.parseUrl = attrs.getString("parseUrl"); this.url = attrs.getString("url"); this.lib = attrs.getString("lib"); this.expr = attrs.getString("expr"); this._encode = attrs.getString("encode"); this._ua = attrs.getString("ua"); //book,section 特有 this.header = attrs.getString("header", ""); this.buildArgs = attrs.getString("buildArgs"); this.buildRef = attrs.getString("buildRef"); this.buildUrl = attrs.getString("buildUrl"); this.buildHeader = attrs.getString("buildHeader"); this.args = attrs.getString("args"); this.addCookie = attrs.getString("addCookie"); this.addKey = attrs.getString("addKey"); this.addPage = attrs.getInt("addPage"); { string temp = cfg.Attribute("cache")?.Value; if (string.IsNullOrEmpty(temp) == false) { int len = temp.Length; if (len == 1) { cache = int.Parse(temp); } else if (len > 1) { cache = int.Parse(temp.Substring(0, len - 1)); string p = temp.Substring(len - 1); switch (p) { case "d": cache = cache * 24 * 60 * 60; break; case "h": cache = cache * 60 * 60; break; case "m": cache = cache * 60; break; } } } } if (cfg.HasElements) { _items = new List <SdNode>(); _adds = new List <SdNode>(); foreach (XElement e1 in cfg.Elements()) { if (e1.Name.LocalName.Equals("item")) { SdNode temp = Util.createNode(source).buildForItem(e1, this); _items.Add(temp); } else if (e1.HasAttributes) { SdNode temp = Util.createNode(source).buildForAdd(e1, this); _adds.Add(temp); } else { attrs.set(e1.Name.LocalName, e1.Value); } } } } OnDidInit(); return(this); }
public bool isEquals(SdNode node) { if (name == null) return false; return name.Equals(node.name); }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, String key, int page, SdNode config, SdSourceCallback callback) { try { doGetNodeViewModel(viewModel, isUpdate, key, page, config, callback); } catch (Exception) { callback(1); } }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, String url, SdNode config, SdSourceCallback callback) { //需要对url进行转换成最新的格式(可能之前的旧的格式缓存) try { if (DoCheck(url, cookies(), true) == false) { callback(99); return; } __AsyncTag tag = new __AsyncTag(); doGetNodeViewModel(viewModel, isUpdate, tag, url, null, config, callback); if (tag.total == 0) { callback(1); } } catch { callback(1); } }
public virtual void loadByJson(SdNode config, params String[] jsons) { if (jsons == null || jsons.Length == 0) return; if (DdSource.isBook(config)) { String json = jsons[0]; //不支持多个数据块加载 ONode data = ONode.tryLoad(json); name = data.get("name").getString(); author = data.get("author").getString(); intro = data.get("intro").getString(); logo = data.get("logo").getString(); updateTime = data.get("updateTime").getString(); isSectionsAsc = data.get("isSectionsAsc").getInt() > 0;//默认为倒排 } foreach (String json in jsons) //支持多个数据块加载 { ONode data = ONode.tryLoad(json); ONode sl = data.get("sections").asArray(); foreach (ONode n in sl) { SectionModel sec = newSection(); sec.name = n.get("name").getString(); sec.url = n.get("url").getString(); sec.bookName = name; sec.bookUrl = bookUrl; sec.orgIndex = total(); sections.Add(sec); onAddItem(sec); } } }
private void doGetNodeViewModel(ISdViewModel viewModel, bool isUpdate, String key, int page, SdNode config, SdSourceCallback callback) { HttpMessage msg = new HttpMessage(); page += config.addPage; //加上增减量 if (key != null && string.IsNullOrEmpty(config.addKey) == false) //如果有补充关键字 { key = key + " " + config.addKey; } if (key == null) { msg.url = config.getUrl(config.url, page); } else { msg.url = config.getUrl(config.url, key, page); } if (string.IsNullOrEmpty(msg.url)) { callback(-3); return; } msg.rebuild(config); if ("post".Equals(config.method)) { msg.rebuildForm(page, key); } else { msg.url = msg.url.Replace("@page", page + ""); if (key != null) { msg.url = msg.url.Replace("@key", Util.urlEncode(key, config)); } } //为doParseUrl_Aft服务(要在外围) var dataList = new Dictionary <int, String>();//如果有多个地址,需要排序 var tag = new __AsyncTag(); int pageX = page; String keyX = key; tag.total++; msg.callback = (code, sender, text, url302) => { tag.value++; if (code == 1) { if (string.IsNullOrEmpty(url302)) { url302 = sender.url; } if (string.IsNullOrEmpty(config.parseUrl) == false) //url需要解析出来(多个用;隔开) { List <String> newUrls = new List <String>(); String[] rstUrls = parseUrl(config, url302, text).Split(';'); foreach (String url1 in rstUrls) { if (url1.Length == 0) { continue; } if (url1.StartsWith(Util.NEXT_CALL)) { HttpMessage msg0 = new HttpMessage(); msg0.url = url1.Replace(Util.NEXT_CALL, "") .Replace("GET::", "") .Replace("POST::", ""); msg0.rebuild(config); if (url1.IndexOf("POST::") > 0) { msg0.method = "post"; msg0.rebuildForm(pageX, keyX); } else { msg0.method = "get"; } msg0.callback = msg.callback; tag.total++; Util.http(this, isUpdate, msg0); } else { newUrls.Add(url1); } } if (newUrls.Count > 0) { doParseUrl_Aft(viewModel, config, isUpdate, newUrls, sender.form, tag, dataList, callback); } return; } else { doParse_noAddin(viewModel, config, url302, text); } } callback(code); }; Util.http(this, isUpdate, msg); }