Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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));
            }
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
 private void positionupdateComplete(WebDownload wd)
 {
     //TODO: Update Object Position
     try
     {
         wd.Verify();
         StreamReader reader   = File.OpenText(wd.SavedFilePath);
         string[]     location = reader.ReadLine().Split(new char[] { ',' });
         this.Latitude  = Convert.ToSingle(location[0]);
         this.Longitude = Convert.ToSingle(location[1]);
         this.Altitude  = Convert.ToSingle(location[2]);
     }
     finally
     {
         isUpdating = false;
     }
 }
        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();
            }
        }
Exemple #6
0
        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.DownloadRequests.Remove(this);
// ### ??!??				m_quadTile.Initialize();
            }
            catch (System.Net.WebException caught)
            {
                System.Net.HttpWebResponse response = caught.Response as System.Net.HttpWebResponse;

                /*
                 * null response
                 */
                if (response == null)
                {
                    m_quadTile.QuadTileSet.RecordFailedRequest(this);
                }

                /* 4xx - Client error
                 * 400 Bad Request
                 * 401 Unauthorized
                 * 403 Forbidden
                 * 404 Not Found
                 * 206 Partial Content
                 * 200 OK && Content length == 0
                 */
                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound ||
                         response.StatusCode == System.Net.HttpStatusCode.Unauthorized ||
                         response.StatusCode == System.Net.HttpStatusCode.Forbidden ||
                         response.StatusCode == System.Net.HttpStatusCode.BadRequest ||
                         response.StatusCode == System.Net.HttpStatusCode.PartialContent ||
                         (response.StatusCode == System.Net.HttpStatusCode.OK &&
                          response.ContentLength == 0))
                {
                    m_quadTile.QuadTileSet.RecordFailedRequest(this);
                }

                /*
                 * 5xx - Server Error
                 * 500 Internal Server Error
                 * 501 Not Implemented
                 * 502 Bad Gateway
                 * 503 Service Unavailable
                 */
                else if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError ||
                         response.StatusCode == System.Net.HttpStatusCode.NotImplemented ||
                         response.StatusCode == System.Net.HttpStatusCode.BadGateway ||
                         response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable
                         )
                {
                    //server problem, directly start timeout for the layer, rather than counter per tile


                    TimeSpan waitTime = TimeSpan.FromSeconds(120);
                    //if retry-after is specified then wait for that length of time before retrying
                    String retryAfter = response.GetResponseHeader("Retry-After");
                    if (retryAfter != null && !retryAfter.Equals(String.Empty))
                    {
                        Log.Write(Log.Levels.Verbose, "GSDR", "Retry-After response header " + retryAfter);
                        try
                        {
                            //try to convert
                            double retryAfterNumber = Convert.ToDouble(retryAfter);
                            waitTime = TimeSpan.FromSeconds(retryAfterNumber);
                        }
                        catch (System.FormatException fe)
                        {
                            //ignore retry-after, just wait for 60 seconds
                        }
                    }
                    //wait before retrying
                    m_quadTile.QuadTileSet.setTimeoutAndWait(waitTime);
                }
            }
            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();
            }
        }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
        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);
            }
        }