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 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); } }
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); } } }
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); }
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); }
// //--------------------------------------- // 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); } }
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); } }
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 (string.IsNullOrEmpty(config.parse)) //没有解析的不处理 return; //------------ if (string.IsNullOrEmpty(url)) //url为空的不处理 return; { //2.获取主内容 tag.total++; String newUrl = buildUrl(config, url); //有缓存的话,可能会变成同步了 Util.http(this, isUpdate, newUrl, args, config, (code, text) => { if (code == 1) { if (string.IsNullOrEmpty(config.parseUrl) == false) { //url需要解析出来 String newUrl2 = parseUrl(config, newUrl, text); Util.http(this, isUpdate, newUrl2, args, config, (code2, text2) => { if (code2 == 1) { doParse_hasAddin(viewModel, config, newUrl2, text2); } tag.value++; if (tag.total == tag.value) { callback(code); } }); return;//下面的代码被停掉 } doParse_hasAddin(viewModel, config, newUrl, text); } tag.value++; if (tag.total == tag.value) { callback(code); } }); } if (config.hasAdds()) { //2.2 获取副内容(可能有多个) foreach (SdNode n1 in config.adds()) { if (string.IsNullOrEmpty(n1.buildUrl)) continue; tag.total++; String newUrl = buildUrl(n1, url); //有url的add //add 不能有自己的独立url Util.http(this, isUpdate, newUrl, args, n1, (code, text) => { if (code == 1) { String json = this.parse(n1, newUrl, text); if (isDebug) { Util.log(this, n1, newUrl, json); } if (json != null) { viewModel.loadByJson(n1, json); } } tag.value++; if (tag.total == tag.value) { callback(code); } }); } } }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, String url, SdNode config, SdSourceCallback callback) { //需要对url进行转换成最新的格式(可能之前的旧的格式缓存) __AsyncTag tag = new __AsyncTag(); doGetNodeViewModel(viewModel, isUpdate, tag, url, null, config, callback); if (tag.total == 0) { callback(1); } }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, int page, SdNode config, SdSourceCallback callback) { getNodeViewModel(viewModel, isUpdate, null, page, config, callback); }
public void getNodeViewModel(ISdViewModel viewModel, bool isUpdate, String key, int page, SdNode config, SdSourceCallback callback) { page += config.addPage; //加上增减量 String newUrl = buildUrl(config, config.url, page); if (key != null && string.IsNullOrEmpty(config.addKey) == false) {//如果有补充关键字 key = key + " " + config.addKey; } Dictionary<String, String> args = null; if ("post".Equals(config.method)) { args = new Dictionary<string, string>(); if (string.IsNullOrEmpty(config.args) == false) { foreach (String kv in config.args.Split(';')) { if (kv.Length > 3) { String name = kv.Split('=')[0]; String value = kv.Split('=')[1]; if (value.Equals("@key")) args.Add(name, Util.urlEncode(key, config)); else if (value.Equals("@page")) args.Add(name, page + ""); else args.Add(name, Util.urlEncode(value, config)); } } } } else { newUrl = newUrl.Replace("@page", page + ""); if (key != null) newUrl = newUrl.Replace("@key", Util.urlEncode(key, config)); } String newUrl0 = newUrl; Dictionary< String, String > args0 = args; Util.http(this, isUpdate, newUrl, args0, config, (code, text) => { if (code == 1) { if (string.IsNullOrEmpty(config.parseUrl) == false) { //url需要解析出来 String newUrl2 = parseUrl(config, newUrl0, text); Util.http(this, isUpdate, newUrl2, args0, config, (code2, text2) => { if (code2 == 1) { doParse_noAddin(viewModel, config, newUrl2, text2); } callback(code); }); return;//下面的代码被停掉 } doParse_noAddin(viewModel, config, newUrl0, text); } callback(code); }); }