private void DownloadComplete(WebDownload downloadInfo) { Log.Write(Log.Levels.Debug+1, "GSDR", "Download completed for " + downloadInfo.Url); try { downloadInfo.Verify(); m_quadTile.QuadTileSet.NumberRetries = 0; // Rename temp file to real name File.Delete(m_localFilePath); File.Move(downloadInfo.SavedFilePath, m_localFilePath); // Make the quad tile reload the new image m_quadTile.DownloadRequest = null; m_quadTile.Initialize(); } catch(System.Net.WebException caught) { System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse; if(response!=null && response.StatusCode==System.Net.HttpStatusCode.NotFound) { using(File.Create(m_localFilePath + ".txt")) {} return; } m_quadTile.QuadTileSet.NumberRetries++; } catch { using(File.Create(m_localFilePath + ".txt")) {} if (File.Exists(downloadInfo.SavedFilePath)) { try { File.Delete(downloadInfo.SavedFilePath); } catch (Exception e) { Log.Write(Log.Levels.Error, "GSDR", "could not delete file " + downloadInfo.SavedFilePath + ":"); Log.Write(e); } } } finally { if(download != null) download.IsComplete = true; m_quadTile.QuadTileSet.RemoveFromDownloadQueue(this); // potential deadlock! -step // Immediately queue next download m_quadTile.QuadTileSet.ServiceDownloadQueue(); } }
protected override void DownloadComplete(WebDownload downloadInfo) { try { downloadInfo.Verify(); if (downloadInfo.Exception != null) { Log.Write(downloadInfo.Exception); return; } XmlDocument hResponseDocument = new XmlDocument(); XmlReaderSettings oSettings = new XmlReaderSettings(); oSettings.IgnoreWhitespace = true; XmlReader oResponseXmlStream = XmlReader.Create(downloadInfo.ContentStream, oSettings); hResponseDocument.Load(oResponseXmlStream); downloadInfo.ContentStream.Close(); // Get the URL, save the image XmlElement nOutputElement = hResponseDocument.SelectSingleNode("/ARCXML/RESPONSE/IMAGE/OUTPUT") as XmlElement; if (nOutputElement != null) { String imageURL = nOutputElement.GetAttribute("url"); Log.Write(Log.Levels.Debug, "ADGR", "Downloading file " + imageURL); // --------------------------- downloadImage(imageURL, downloadInfo.SavedFilePath); } else { XmlElement nErrorElement = hResponseDocument.SelectSingleNode("/ARCXML/RESPONSE/ERROR") as XmlElement; if (nErrorElement != null) Log.Write(Log.Levels.Debug, "ADGR", nErrorElement.InnerText); } m_tile.TileSet.NumberRetries = 0; if (nOutputElement != null) { // Rename temp file to real name File.Delete(m_localFilePath); // Convert the image to a PNG from a GIF so DirectX doesn't throw a hissy fit trying to load gifs if (downloadInfo.SavedFilePath.EndsWith(".gif")) { Image oConverter = Image.FromFile(downloadInfo.SavedFilePath); oConverter.Save(m_localFilePath, System.Drawing.Imaging.ImageFormat.Png); oConverter.Dispose(); File.Delete(downloadInfo.SavedFilePath); } else { File.Move(downloadInfo.SavedFilePath, m_localFilePath); } // Make the tile reload the new image m_tile.DownloadRequests.Remove(this); m_tile.Initialize(); } else { using (File.Create(m_localFilePath + ".txt")) { } if (File.Exists(downloadInfo.SavedFilePath)) { try { File.Delete(downloadInfo.SavedFilePath); } catch (Exception e) { Log.Write(e); } } } } catch (System.Net.WebException caught) { System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse; if (response != null && response.StatusCode == System.Net.HttpStatusCode.NotFound) { using (File.Create(m_localFilePath + ".txt")) { } return; } m_tile.TileSet.NumberRetries++; } catch { using (File.Create(m_localFilePath + ".txt")) { } if (File.Exists(downloadInfo.SavedFilePath)) { try { File.Delete(downloadInfo.SavedFilePath); } catch (Exception e) { Log.Write(e); } } } finally { if (download != null) download.IsComplete = true; // Immediately queue next download m_tile.TileSet.RemoveFromDownloadQueue(this, true); } }
private void DownloadComplete(WebDownload downloadInfo) { try { downloadInfo.Verify(); m_quadTile.QuadTileSet.NumberRetries = 0; // Rename temp file to real name File.Delete(m_localFilePath); File.Move(downloadInfo.SavedFilePath, m_localFilePath); // Make the quad tile reload the new image m_quadTile.DownloadRequest = null; m_quadTile.Initialize(); } catch (WebException caught) { HttpWebResponse response = caught.Response as HttpWebResponse; if (response != null && response.StatusCode == HttpStatusCode.NotFound) { using (File.Create(m_localFilePath + ".txt")) {} return; } m_quadTile.QuadTileSet.NumberRetries++; } catch { using (File.Create(m_localFilePath + ".txt")) {} if (File.Exists(downloadInfo.SavedFilePath)) { File.Delete(downloadInfo.SavedFilePath); } } finally { #region by zzm if (download != null) { download.IsComplete = true; } #endregion m_quadTile.QuadTileSet.RemoveFromDownloadQueue(this); //Immediately queue next download m_quadTile.QuadTileSet.ServiceDownloadQueue(); } }
private void UpdateDownloadComplete(WebDownload downloadInfo) { // First compare the file to the one we have bool bUpdate = false; string strVersion; string strTemp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { string[] tokens; int iHaveVer1, iHaveVer2, iHaveVer3; int iCurVer1, iCurVer2, iCurVer3; downloadInfo.Verify(); downloadInfo.SaveMemoryDownloadToFile(strTemp); using (StreamReader sr = new StreamReader(Path.Combine(DirectoryPath, VersionFile))) { strVersion = sr.ReadLine(); tokens = strVersion.Split('.'); iHaveVer1 = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture); iHaveVer2 = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture); iHaveVer3 = Convert.ToInt32(tokens[2], CultureInfo.InvariantCulture); } using (StreamReader sr = new StreamReader(strTemp)) { strVersion = sr.ReadLine(); tokens = strVersion.Split('.'); iCurVer1 = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture); iCurVer2 = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture); iCurVer3 = Convert.ToInt32(tokens[2], CultureInfo.InvariantCulture); } if (iCurVer1 > iHaveVer1 || (iCurVer1 == iHaveVer1 && iCurVer2 > iHaveVer2) || (iCurVer1 == iHaveVer1 && iCurVer2 == iHaveVer2 && iCurVer3 > iHaveVer3)) { this.BeginInvoke(new NotifyUpdateDelegate(NotifyUpdate), new object[] { strVersion }); bUpdate = true; } File.Delete(strTemp); } catch (System.Net.WebException) { } catch { } finally { if (!bUpdate && m_bUpdateFromMenu) this.BeginInvoke(new MethodInvoker(NotifyUpdateNotAvailable)); } }
private void DownloadComplete(WebDownload downloadInfo) { try { downloadInfo.Verify(); // Rename temp file to real name File.Delete(textureName); File.Move(downloadInfo.SavedFilePath, textureName); if (!IsBadTile()) { // Make the quad tile reload the new image //m_quadTile.DownloadRequest = null; //m_quadTile.isInitialized = false; this.texture = TextureLoader.FromFile(drawArgs.device, textureName); } } catch (System.Net.WebException caught) { System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse; if (response != null && response.StatusCode == System.Net.HttpStatusCode.NotFound) { using (File.Create(textureName + ".txt")) { } return; } //m_quadTile.QuadTileArgs.NumberRetries++; } catch { using (File.Create(textureName + ".txt")) { } if (File.Exists(downloadInfo.SavedFilePath)) File.Delete(downloadInfo.SavedFilePath); } finally { if (download != null) download.IsComplete = true; m_blDownloading = false; } }
protected override void DownloadComplete(WebDownload downloadInfo) { try { downloadInfo.Verify(); // --- Load Response into XML Document and convert to real image --- System.Xml.XmlDocument hResponseDocument = new System.Xml.XmlDocument(); System.Xml.XmlReaderSettings oSettings = new System.Xml.XmlReaderSettings(); oSettings.IgnoreWhitespace = true; System.Xml.XmlReader oResponseXmlStream = System.Xml.XmlReader.Create(downloadInfo.ContentStream, oSettings); hResponseDocument.Load(oResponseXmlStream); SaveDAPImage(hResponseDocument, downloadInfo.SavedFilePath); // --- search for an error --- System.Xml.XmlNodeList hNodeList = hResponseDocument.SelectNodes("//" + Geosoft.Dap.Xml.Common.Constant.Tag.ERROR_TAG); if (hNodeList.Count >= 1) { System.Xml.XmlNode hNode = hNodeList[0]; throw new Geosoft.Dap.DapException(hNode.InnerText); } m_tile.TileSet.NumberRetries = 0; // Rename temp file to real name File.Delete(m_localFilePath); File.Move(downloadInfo.SavedFilePath, m_localFilePath); // Make the tile reload the new image m_tile.DownloadRequests.Remove(this); m_tile.Initialize(); } catch (System.Net.WebException caught) { System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse; if (response != null && response.StatusCode == System.Net.HttpStatusCode.NotFound) { using (File.Create(m_localFilePath + ".txt")) { } return; } Log.Write(Log.Levels.Error, "DGDR", "web exception occurred"); Log.Write(Log.Levels.Error, "DGDR", "Dataset Name: " + (m_DapImageStore.DataSet == null ? "Browser Map" : m_DapImageStore.DataSet.Name)); Log.Write(Log.Levels.Error, "DGDR", "West: " + Tile.West + " South: " + Tile.South + " East: " + Tile.East + " North: " + Tile.North); m_tile.TileSet.NumberRetries++; } catch { using (File.Create(m_localFilePath + ".txt")) { } if (File.Exists(downloadInfo.SavedFilePath)) { try { File.Delete(downloadInfo.SavedFilePath); } catch (Exception e) { Log.Write(Log.Levels.Error, "GSDR", "could not delete file " + downloadInfo.SavedFilePath + ":"); Log.Write(e); } } } finally { if (download != null) download.IsComplete = true; // Immediately queue next download m_tile.TileSet.RemoveFromDownloadQueue(this, true); } }
private void Downloader() { WMSDownload wmsDownload = null; while(true) { try { lock(this.downloadQueue) { if(this.downloadQueue.Count <= 0) // Queue empty return; wmsDownload = (WMSDownload)this.downloadQueue.Dequeue(); } if(this.checkBoxAnimationCache.Checked && File.Exists(wmsDownload.SavedFilePath + ".wwi") && File.Exists(wmsDownload.SavedFilePath + ".dds")) { try { ImageLayerInfo imageLayerInfo = ImageLayerInfo.FromFile(wmsDownload.SavedFilePath + ".wwi"); const float epsilon = Single.Epsilon*100; if(Math.Abs(imageLayerInfo.North - (float)wmsDownload.North)<epsilon && Math.Abs(imageLayerInfo.South - (float)wmsDownload.South)<epsilon && Math.Abs(imageLayerInfo.West - (float)wmsDownload.West)<epsilon && Math.Abs(imageLayerInfo.East - (float)wmsDownload.East)<epsilon) { lock(this.animationFrames.SyncRoot) { animationFrames.Add(imageLayerInfo); // Process next queue item continue; } } } // Cached file not readable for some reason - reload catch(IOException) {} catch(FormatException) {} } UpdateStatusBar( "Downloading: " + Path.GetFileName(wmsDownload.SavedFilePath) ); using( WebDownload dl = new WebDownload(wmsDownload.Url) ) { dl.ProgressCallback += new DownloadProgressHandler(this.updateCurrentProgressBar); dl.DownloadMemory(DownloadType.Wms); if(this.animationState == AnimationState.Cancel || this.animationState == AnimationState.Stop) return; dl.Verify(); ProcessDownloadedImage(wmsDownload, dl.ContentStream); } } catch(WebException caught) { this.worldWindow.Caption = caught.Message; } finally { updateCurrentProgressBar(0,1); } } }
private void SetSearchParametersComplete(WebDownload oWebDownload) { try { DappleSearchWebDownload oDSWebDownload = oWebDownload as DappleSearchWebDownload; oWebDownload.Verify(); // --- If the search indices don't match, it's because a new search was done before this one completed, so discard these results --- if (oDSWebDownload.SearchIndex == m_lSearchIndex) { XmlDocument oDoc = new XmlDocument(); oDoc.Load(oWebDownload.ContentStream); SearchResultSet oPage1 = new SearchResultSet(oDoc); InitSearch(oPage1); } } catch (WebException) { this.Invoke(new MethodInvoker(SetSearchFailed)); } catch (XmlException) { this.Invoke(new MethodInvoker(SetSearchFailed)); } }
private void DownloadComplete(WebDownload downloadInfo) { try { downloadInfo.Verify(); //m_quadTile.QuadTileArgs.NumberRetries = 0; //TODO add back in logic to check for the no data tile? //the logic was to not display that tile to at least show some data for the layers beneath VE //or show the no data tile so they know that VE has not covered that area yet //then just let those tiles get periodically deleted from cache for when VE updates // Rename temp file to real name File.Delete(textureName); File.Move(downloadInfo.SavedFilePath, textureName); // Make the quad tile reload the new image //m_quadTile.DownloadRequest = null; //m_quadTile.isInitialized = false; this.texture = TextureLoader.FromFile(drawArgs.device, textureName); } catch (System.Net.WebException caught) { System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse; if (response != null && response.StatusCode == System.Net.HttpStatusCode.NotFound) { using (File.Create(textureName + ".txt")) { } return; } //m_quadTile.QuadTileArgs.NumberRetries++; } catch { using (File.Create(textureName + ".txt")) { } if (File.Exists(downloadInfo.SavedFilePath)) File.Delete(downloadInfo.SavedFilePath); } finally { download.IsComplete = true; //m_quadTile.QuadTileArgs.RemoveFromDownloadQueue(this); //Immediately queue next download //m_quadTile.QuadTileArgs.ServiceDownloadQueue(); } }
void DownloadComplete( WebDownload downloadInfo ) { if(this.InvokeRequired) { Invoke(new DownloadCompleteHandler(DownloadComplete), new object[]{downloadInfo}); return; } try { downloadInfo.Verify(); Image = System.Drawing.Image.FromStream(downloadInfo.ContentStream); } catch(Exception caught) { this.Visible = false; MessageBox.Show(caught.Message, "Legend image download failed.", MessageBoxButtons.OK,MessageBoxIcon.Warning); } finally { if(downloadInfo!=null) downloadInfo.Dispose(); Text = oldText; } }