public static MultiPicDownloadDispatcher <T> getInst(int childThreadNum) { if (_inst == null) { _inst = new MultiPicDownloadDispatcher <T>(childThreadNum); } return(_inst); }
public static string GetSpotIdOnline(string latY, string lngX) { string result = "{\"success\": "; LatLng baiduLoc = BdCoodOffsetProvider.getInstance().StandardMercator2BaiduMercator(new LatLng(double.Parse(latY), double.Parse(lngX))); string url = "http://pcsv0.map.bdimg.com/?qt=qsdata&x=" + baiduLoc.longitude + "&y=" + baiduLoc.latitude; string spotInfo = HttpGetText(url); if (spotInfo != null) { SpotInfo info = SpotInfo.FromJson(spotInfo); if (info != null) { result = result + "true,"; LatLng correctLoc = BdCoodOffsetProvider.getInstance().BaiduMercator2StandardMercator(new LatLng(((double)info.content.y) / 100.0, ((double)info.content.x) / 100.0)); result = result + "\"pid\": \"" + info.content.id + "\"," + "\"x\": " + correctLoc.longitude + ", \"y\": " + correctLoc.latitude + "}"; for (int z = 5; z > 2; z--) { if (!File.Exists("site/" + "Pics/" + BaiDuMapManager.inst.streetudt + "/" + info.content.id + "/" + z + ".jpeg")) { new Thread((level) => { int zoom = (int)level; MultiPicDownloadDispatcher <DownloadWorker> d3 = getAttendant(zoom); d3.setPicInfo(info.content.id, zoom - 1); d3.start(); Utility.LogSimple(LogLevel.Debug, "level " + level + " pano triggered!"); byte[] pic = d3.getResult(); Utility.LogSimple(LogLevel.Debug, "level " + level + " pano returned!"); if (pic != null && pic.Length > 0) { Utility.LogSimple(LogLevel.Debug, "level " + level + " pano start to write to file!"); string path = "site/" + "Pics/" + BaiDuMapManager.inst.streetudt + "/" + info.content.id; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = path + "/" + zoom + ".jpeg"; File.WriteAllBytes(path, pic); } }).Start(z); } } } else { result = result + "true,\"pid\": null, \"x\":0, \"y\":0}"; } } else { result = result + "false,\"pid\": null, \"x\":0, \"y\":0}"; } return(result); }
public static MultiPicDownloadDispatcher <DownloadWorker> getAttendant(int level) { lock (dispatcherlock) { //PrintEntries(); List <MultiPicDownloadDispatcher <DownloadWorker> > entry = entries[level - 3]; if (entry == null) { MultiPicDownloadDispatcher <DownloadWorker> d = new MultiPicDownloadDispatcher <DownloadWorker>(threadNumbers[level - 3]); entry = new List <MultiPicDownloadDispatcher <DownloadWorker> >(); entry.Add(d); entries[level - 3] = entry; return(d); } int count = entry.Count; while (true) { for (int i = 0; i < count; i++) { if (entry[i].isIdle) { Utility.LogSimple(LogLevel.Debug, "Get dispather for zoom " + level + ", Total " + count + " dispatcher, and choosed " + i); return(entry[i]); } } if (count < 6) { MultiPicDownloadDispatcher <DownloadWorker> d = new MultiPicDownloadDispatcher <DownloadWorker>(threadNumbers[level - 3]); entry.Add(d); Utility.LogSimple(LogLevel.Debug, "Get dispather for zoom " + level + ", Total " + count + ", new dispatcher added"); return(d); } Thread.Sleep(200); } } }