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); }