static public Bitmap LoadThumbnailFromWeb(string url, string filename) { try { DataSetManager.DownloadFile(CacheProxy.GetCacheUrl(url), Properties.Settings.Default.CahceDirectory + @"thumbnails\" + filename, true, true); return(UiTools.LoadBitmap(Properties.Settings.Default.CahceDirectory + @"thumbnails\" + filename)); } catch { return(null); } }
public static void GetDemTileFromWeb(Tile retTile) { string directory = retTile.DemDirectory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.DemFilename; FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 2178 && fi.Length != 1026 && fi.Length != 2052 && (retTile.Dataset.Projection != ProjectionType.Mercator)) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { WebClient Client = new WebClient(); Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string dlFile = string.Format("{0}.tmp{1}", filename, NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(retTile.DemURL), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { } fi = new FileInfo(filename); exists = fi.Exists; } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Dem Download: Exception"); } exists = false; } } retTile.DemReady = true; retTile.demFileExists = exists; return; }
public static Tile GetTileFromWeb(Tile retTile, bool Initialize) { WebClient Client = null; if (retTile.Dataset.Projection == ProjectionType.SkyImage && retTile.Dataset.Url.EndsWith("/screenshot.png")) { SkyImageTile tile = retTile as SkyImageTile; Client = new WebClient(); string url = tile.URL; tile.ImageData = Client.DownloadData(url); retTile.DemReady = true; retTile.FileExists = true; retTile.ReadyToRender = true; retTile.TextureReady = true; //retTile.CreateGeometry(Tile.prepDevice); Client.Dispose(); return(retTile); } Tile parent = retTile.Parent; if (retTile.DemEnabled && (parent == null || (parent != null && parent.DemGeneration == 0))) { GetDemTileFromWeb(retTile); } else { retTile.DemReady = true; } if (retTile.Dataset.WcsImage != null && retTile.Dataset.WcsImage is FitsImage) { retTile.TextureReady = true; InitializeTile(retTile); return(retTile); } string directory = retTile.Directory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.FileName; Client = new WebClient(); FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 8 && fi.Length < 100 || retTile.Volitile) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { if (retTile.Dataset.IsMandelbrot) { retTile.ComputeMandel(); fi = new FileInfo(filename); exists = fi.Exists; } else { Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string url = retTile.URL; if (string.IsNullOrEmpty(url)) { retTile.errored = true; } else { string dlFile = string.Format("{0}.tmp{1}", filename, NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(url), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } fi = new FileInfo(filename); exists = fi.Exists; } // Code for drawing tile it onto tile for debuggin //if (retTile.Dataset.Projection == ProjectionType.Toast) //{ // //Bitmap bmpText = new Bitmap(filename); // Bitmap bmpText = UiTools.LoadBitmap(filename); // Graphics g = Graphics.FromImage(bmpText); // g.DrawString(retTile.Key, UiTools.StandardRegular, UiTools.StadardTextBrush, new RectangleF(0, 0, 255, 255), UiTools.StringFormatCenterCenter); // g.Flush(); // g.Dispose(); // bmpText.Save(filename); // bmpText.Dispose(); //} } } catch { //todo retry login on non - HTTP failuers. if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Download: Exception"); } retTile.errored = true; } } try { if (exists) { if (fi.Length < 100 || (fi.Length == 1033)) { retTile.errored = true; return(retTile); } } // todo 3d Cities remove support for 3d Cities for now if (retTile.Dataset.Projection == ProjectionType.Mercator && Properties.Settings.Default.Show3dCities) { string tileID = retTile.GetTileID(); //check coverage cache before downloading int gen = CoverageMap.GetCoverage(tileID); if (gen > 0) { //try downloading mesh try { string meshFilename = retTile.FileName + ".mesh"; if (!File.Exists(meshFilename)) { Client.Headers.Add("User-Agent", "Win8Microsoft.BingMaps.3DControl/2.214.2315.0 (;;;;x64 Windows RT)"); string dlFile = string.Format("{0}.tmp{1}", meshFilename, NodeID); Client.DownloadFile(string.Format("http://ak.t{1}.tiles.virtualearth.net/tiles/mtx{0}?g={2}", tileID, Tile.GetServerID(retTile.X, retTile.Y), gen.ToString()), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(meshFilename)) { File.Delete(meshFilename); } File.Move(dlFile, meshFilename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } } } catch { } } } retTile.FileExists = true; retTile.TextureReady = true; if (Initialize) { InitializeTile(retTile); } } catch (System.Exception) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Initialize: Exception"); } retTile.errored = true; } return(retTile); }