示例#1
0
        /// <summary>
        /// Send an xml request on the wire, get the response and parse it into an XML document
        /// </summary>
        /// <param name="hRequestDocument"></param>
        /// <param name="szUrl"></param>
        /// <param name="progressCallBack"></param>
        /// <returns></returns>
        protected System.Xml.XmlDocument SendHttp(string szUrl, System.Xml.XmlDocument hRequestDocument, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument = null;
            System.Xml.XmlReader oResponse = null;

            try
            {

                // --- send the http request ---

                oResponse = SendHttpInternal(szUrl, hRequestDocument, progressCallBack);

                // --- Load Response into XML Document ---

                hResponseDocument = new System.Xml.XmlDocument();
                hResponseDocument.Load(oResponse);
            }
            catch (System.Xml.XmlException)
            {
                hResponseDocument = null;
                throw new DapException("Error reading server response");
            }
            catch (Exception e)
            {
                hResponseDocument = null;
                throw e;
            }
            finally
            {
                if (oResponse != null) oResponse.Close();
            }
            return hResponseDocument;
        }
示例#2
0
        public byte[] Download(string url, UpdateProgessCallback progressCB)
        {
            // Get the URI from the command line.
            Uri httpSite = new Uri(url);

            // Create the request object.
            WebRequest req = WebRequest.Create(httpSite);

            #if DAPPLE
            req.Proxy = ProxyHelper.DetermineProxyForUrl(
                              url,
                              WorldWind.Net.WebDownload.useWindowsDefaultProxy,
                              WorldWind.Net.WebDownload.useDynamicProxy,
                              WorldWind.Net.WebDownload.proxyUrl,
                              WorldWind.Net.WebDownload.proxyUserName,
                              WorldWind.Net.WebDownload.proxyPassword);
            req.Timeout = WorldWind.Net.WebDownload.DownloadTimeout;
            #endif

            return Download(req, progressCB);
        }
        private void Download()
        {
            try
            {
                StringBuilder    webPageString = new StringBuilder();
                StringCollection fileNames     = new StringCollection();

                rtb_statusAtualiza.Text = ("Iniciando o download...");
                // Get the HTTP content.
                GetHTTPContent(webPageString);
                string webPageContent = webPageString.ToString();

                // Parse out all the file names.
                ParseFileNamesFromWebPage(fileNames, webPageContent);

                foreach (String fileName in fileNames)
                {
                    if (this.textExclude.Text.Length > 0 ||
                        this.textOnlyInclude.Text.Length > 0)
                    {
                        if (fileName.Contains(this.textExclude.Text) ||
                            !fileName.Contains(this.textOnlyInclude.Text))
                        {
                            UpdateProgessCallback delegateCB =
                                new UpdateProgessCallback(UpdateProgress);
                            this.Invoke(delegateCB,
                                        new object[] { filesRead++, totalFiles });


                            continue;
                        }
                    }


                    DownloadFile(
                        textBoxRemoteUrl.Text + "/" + fileName,
                        textLocalPath.Text + fileName);
                }

                UpdateStatusBox("Download Completed...");
            }
            catch (NotSupportedException exception)
            {
                UpdateStatusBox("Exception! " + exception.Message);
            }
            catch (WebException exception)
            {
                UpdateStatusBox("Exception! " + exception.Message);
            }
            catch (InvalidOperationException exception)
            {
                UpdateStatusBox("Exception! " + exception.Message);
            }
            finally
            {
                // Check if this method is running on a different thread
                // than the thread that created the control.
                if (this.textStatus.InvokeRequired)
                {
                    // It's on a different thread, so use Invoke.
                    EnableBtnDownloadCallback delegateCB =
                        new EnableBtnDownloadCallback(EnableBtnDownload);
                    this.Invoke(delegateCB);
                }
                else
                {
                    btnStartDownload.Enabled = true;
                }
            }
        }
示例#4
0
 /// <summary>
 /// Send an xml request on the wire, get the response and parse it into an XML reader
 /// </summary>
 /// <param name="hRequestDocument"></param>
 /// <param name="szUrl"></param>
 /// <param name="strResponseFile"></param>
 /// <param name="progressCallBack">Progress handler (may be null)</param>
 /// <returns></returns>
 public System.Xml.XmlReader SendEx(string szUrl, System.Xml.XmlDocument hRequestDocument, string strResponseFile, UpdateProgessCallback progressCallBack)
 {
     #if !DAPPLE
     if (m_bTask)
     {
         return SendTaskEx(szUrl, hRequestDocument, strResponseFile);
     }
     #endif
     return SendHttpEx(szUrl, hRequestDocument, progressCallBack);
 }
示例#5
0
        /// <summary>
        /// Get the extract progress from the dap server
        /// </summary>
        /// <param name="szKey">The extraction key</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The extract progress response in GeosoftXML</returns>
        public System.Xml.XmlDocument ExtractProgress(string szKey, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.EXTRACT);

                hRequestDocument = m_hEncodeRequest.ExtractProgress(null, szKey);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#6
0
        /// <summary>
        /// Get the capabilities in GeosoftXML format from the dap server
        /// </summary>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The capabilities response in GeosoftXML</returns>
        public System.Xml.XmlDocument GetCapabilities(UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.CAPABILITIES);

                hRequestDocument = m_hEncodeRequest.Capabilities(null);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#7
0
        /// <summary>
        /// Translate a bounding box into a new projection
        /// </summary>
        /// <param name="hBoundingBox">The bounding box to translate</param>
        /// <param name="hOCS">The output coordinate system</param>
        /// <param name="hOutBoundingBox">The translated bounding box</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The translated bounding box response in GeosoftXML</returns>
        public void TranslateBoundingBox(BoundingBox hBoundingBox, CoordinateSystem hOCS, out BoundingBox hOutBoundingBox, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument;
            Double dResolution;

            hResponseDocument = TranslateBoundingBox(hBoundingBox, 0, hOCS, progressCallBack);
            m_hParse.TranslateBoundingBox(hResponseDocument, out hOutBoundingBox, out dResolution);
        }
示例#8
0
        /// <summary>
        /// Begin the extraction process for a particular dataset
        /// </summary>
        /// <param name="hDataSetList">The list of datasets to extract</param>
        /// <param name="hBox">The projection to extract the datasets to</param>
        /// <param name="bNative">Save datasets in native coordinate system or that of the bounding box</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The extract response in GeosoftXML</returns>
        public System.Xml.XmlDocument Extract(ArrayList hDataSetList, BoundingBox hBox, bool bNative, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.EXTRACT);

                hRequestDocument = m_hEncodeRequest.Extract(null, hDataSetList, hBox, bNative);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#9
0
        /// <summary>
        /// list the stylesheets
        /// </summary>
        /// <param name="oStylesheets"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The configuration response in GeosoftXML</returns>
        public void ListStylesheets(out System.Collections.Generic.SortedList<string, string> oStylesheets, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument oDoc;

            oDoc = ListStylesheets(progressCallBack);
            m_hParse.ListStylesheets(oDoc, out oStylesheets);
        }
示例#10
0
        /// <summary>
        /// Inform the dap server that it must refresh its catalog
        /// </summary>
        /// <param name="strPassword"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>True/False</returns>
        public bool RefreshCatalog(string strPassword, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;
            bool bRet = false;

            try
            {
                m_oLock.AcquireReaderLock(-1);

                szUrl = CreateUrl(Constant.Request.CATALOG);
                hRequestDocument = m_hEncodeRequest.RefreshCatalog(null, strPassword);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
                bRet = m_hParse.RefreshCatalog(hResponseDocument);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return bRet;
        }
示例#11
0
        /// <summary>
        /// Get the list of stylesheets
        /// </summary>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The configuration response in GeosoftXML</returns>
        public System.Xml.XmlDocument ListStylesheets(UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);

                szUrl = CreateUrl(Constant.Request.LIST_STYLESHEETS);
                hRequestDocument = m_hEncodeRequest.ListStylesheets(null);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#12
0
        /// <summary>
        /// list the logs in GeosoftXML format from the dap server
        /// </summary>
        /// <param name="strPassword"></param>
        /// <param name="oLogs"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The configuration response in GeosoftXML</returns>
        public void ListLogs(string strPassword, out ArrayList oLogs, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument oDoc;

            oDoc = ListLogs(strPassword, progressCallBack);
            m_hParse.ListLogs(oDoc, out oLogs);
        }
示例#13
0
        /// <summary>
        /// Get the xml meta information for a paricular dataset
        /// </summary>
        /// <param name="szDataSet">The unique name of the dataset</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The meta response in GeosoftXML</returns>
        public System.Xml.XmlDocument GetXMLMetaData(string szDataSet, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.META);

                hRequestDocument = m_hEncodeRequest.XMLMetadata(null, szDataSet);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#14
0
        /// <summary>
        /// Get xml meta information for a particular dataset
        /// </summary>
        /// <param name="hItem">The item element within a catalog response</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The meta response in GeosoftXML</returns>
        public System.Xml.XmlDocument GetXMLMetaData(System.Xml.XmlNode hItem, UpdateProgessCallback progressCallBack)
        {
            if (hItem == null || hItem.Name != Constant.Tag.ITEM_TAG) throw new DapException("Invalid item element");

            // --- get the dataset name ---

            System.Xml.XmlNode hAttr = hItem.Attributes.GetNamedItem("name");
            if (hAttr == null) throw new DapException("Missing name attribute in item element");

            return GetXMLMetaData(hAttr.Value, progressCallBack);
        }
示例#15
0
        /// <summary>
        /// Translate a bounding box into a new projection
        /// </summary>
        /// <param name="hBoundingBox">The bounding box to translate</param>
        /// <param name="hOCS">The output coordinate system</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The translated bounding box response in GeosoftXML</returns>
        public System.Xml.XmlDocument TranslateBoundingBox(BoundingBox hBoundingBox, CoordinateSystem hOCS, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument;

            hResponseDocument = TranslateBoundingBox(hBoundingBox, 0, hOCS, progressCallBack);
            return hResponseDocument;
        }
示例#16
0
        /// <summary>
        /// Begin the extraction process for a collection of datasets
        /// </summary>
        /// <param name="hDataSetList">The list of datasets to extract</param>
        /// <param name="hBox">The projection to extract the datasets to</param>
        /// <param name="bNative">Save datasets in native coordinate system or that of the bounding box</param>
        /// <param name="szKey">The extraction key</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        public void Extract(ArrayList hDataSetList, BoundingBox hBox, bool bNative, out string szKey, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument;

            hResponseDocument = Extract(hDataSetList, hBox, bNative, progressCallBack);
            m_hParse.ExtractKey(hResponseDocument, out szKey);
        }
示例#17
0
        /// <summary>
        /// Translate a bounding box into a new projection
        /// </summary>
        /// <param name="hBoundingBox">The bounding box to translate</param>      
        /// <param name="dResolution">The extraction resolution</param>
        /// <param name="hOCS">The output coordinate system</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The translated bounding box in GeosoftXML</returns>
        public System.Xml.XmlDocument TranslateBoundingBox(BoundingBox hBoundingBox, Double dResolution, CoordinateSystem hOCS, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.TRANSLATE);

                hRequestDocument = m_hEncodeRequest.TranslateBoundingBox(null, hBoundingBox, hOCS, dResolution);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#18
0
        /// <summary>
        /// Get the extract progress from the dap server
        /// </summary>
        /// <param name="szKey">The extraction key</param>
        /// <param name="eStatus">The status of the extraction</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns></returns>
        public void ExtractProgress(string szKey, out Constant.ExtractStatus eStatus, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument;
            Int32 iProgress;
            string szStatus;

            hResponseDocument = ExtractProgress(szKey, progressCallBack);
            m_hParse.ExtractProgress(hResponseDocument, out eStatus, out iProgress, out szStatus);
        }
示例#19
0
        /// <summary>
        /// Translate a series of coordinates into a new projection
        /// </summary>
        /// <param name="hICS">The input coordinate system</param>
        /// <param name="hOCS">The output coordinate system</param>
        /// <param name="hItems">The list of points to translate</param>
        /// <param name="hOutItems">The translate points</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        public void TranslateCoordinates(CoordinateSystem hICS,
            CoordinateSystem hOCS,
            System.Collections.ArrayList hItems,
            out System.Collections.ArrayList hOutItems,
            UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponseDocument;

            hResponseDocument = TranslateCoordinates(hICS, hOCS, hItems, progressCallBack);
            m_hParse.TranslateCoordinates(hResponseDocument, out hOutItems);
        }
示例#20
0
        /// <summary>
        /// Get the capabilities structure from the dap server
        /// </summary>
        /// <param name="hCapabilities">The capabilities of the dap server</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        public void GetCapabilities(out Capabilities hCapabilities, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument hResponse = null;

            hCapabilities = null;

            hResponse = GetCapabilities(progressCallBack);
            hCapabilities = new Capabilities(hResponse);
        }
示例#21
0
        /// <summary>
        /// Translate a series of coordinates to the new projection
        /// </summary>      
        /// <param name="hInputCoordinateSystem">The input coordinate system</param>
        /// <param name="hOutputCoordinateSystem">The output coordinate system</param>
        /// <param name="hItems">The list of points to translate</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The translated coordinates response in GeosoftXML</returns>
        public System.Xml.XmlDocument TranslateCoordinates(CoordinateSystem hInputCoordinateSystem,
            CoordinateSystem hOutputCoordinateSystem,
            System.Collections.ArrayList hItems,
            UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.TRANSLATE);

                hRequestDocument = m_hEncodeRequest.TranslateCoordinates(null, hInputCoordinateSystem, hOutputCoordinateSystem, hItems);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#22
0
        /// <summary>
        /// Get a list of the datasets stored by the dap server
        /// Note: No hierarchy information is retained
        /// </summary>
        /// <param name="szPath">A path to filter the result set by. Eg. /folder1/folder2/@datasetname</param>
        /// <param name="iDepth">Number of levels to recurse down. Only valid if szPath is used</param>
        /// <param name="hDataSets">The list of datasets</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        public void GetCatalog(string szPath, int iDepth, out System.Collections.ArrayList hDataSets, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);
                szUrl = CreateUrl(Constant.Request.CATALOG);

                hRequestDocument = m_hEncodeRequest.Catalog(null, false, szPath, iDepth, 0, 0, null, null);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);

                m_hParse.Catalog(hResponseDocument, out hDataSets);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
        }
示例#23
0
 /// <summary>
 /// clear the log in GeosoftXML format from the dap server
 /// </summary>
 /// <param name="strPassword"></param>
 /// <param name="progressCallBack">Progress handler (may be null)</param>
 /// <returns>The configuration response in GeosoftXML</returns>
 public System.Xml.XmlDocument ClearLog(string strPassword, UpdateProgessCallback progressCallBack)
 {
     return ClearLog(strPassword, DateTime.Today, progressCallBack);
 }
示例#24
0
        /// <summary>
        /// Send an xml request on the wire, get the response and parse it into an XML document
        /// </summary>
        /// <param name="hRequestDocument"></param>
        /// <param name="szUrl"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns></returns>
        public System.Xml.XmlDocument Send(string szUrl, System.Xml.XmlDocument hRequestDocument, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlDocument result = null;
            #if !DAPPLE
            if (m_bTask)
            {
                result = SendTask(szUrl, hRequestDocument);
            }
            else
            #endif
            {
                result = SendHttp(szUrl, hRequestDocument, progressCallBack);
            }

            CheckForError(result);

            return result;
        }
示例#25
0
        /// <summary>
        /// clear the log in GeosoftXML format from the dap server
        /// </summary>
        /// <param name="strPassword"></param>
        /// <param name="oDate"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The configuration response in GeosoftXML</returns>
        public System.Xml.XmlDocument ClearLog(string strPassword, DateTime oDate, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);

                szUrl = CreateUrl(Constant.Request.CONFIGURATION);
                hRequestDocument = m_hEncodeRequest.ClearLog(null, strPassword, oDate);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return hResponseDocument;
        }
示例#26
0
        /// <summary>
        /// Send an xml request onto the wire and return a pointer to the actual response stream. Used when you have a long response
        /// that you do not want to load into an XML document and store all in memory. 
        /// Note: The response stream is not closed. That is left up to the caller to dispose of
        /// </summary>
        /// <param name="hRequestDocument"></param>
        /// <param name="szUrl"></param>
        /// <param name="progressCallBack"></param>
        /// <returns></returns>
        public System.Xml.XmlReader SendHttpEx(string szUrl, System.Xml.XmlDocument hRequestDocument, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlReader oResponse = null;

            try
            {

                // --- send the http request ---

                oResponse = SendHttpInternal(szUrl, hRequestDocument, progressCallBack);
            }
            catch (Exception e)
            {
                oResponse = null;
                throw e;
            }
            return oResponse;
        }
示例#27
0
        /// <summary>
        /// Destroy a client state object on the server
        /// </summary>
        /// <param name="strKey"></param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>True/False</returns>
        public bool DestroyClientState(string strKey, UpdateProgessCallback progressCallBack)
        {
            string szUrl;
            System.Xml.XmlDocument hRequestDocument;
            System.Xml.XmlDocument hResponseDocument;

            try
            {
                m_oLock.AcquireReaderLock(-1);

                szUrl = CreateUrl(Constant.Request.CATALOG);
                hRequestDocument = m_hEncodeRequest.DestroyClientState(null, strKey);
                hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack);
            }
            finally
            {
                m_oLock.ReleaseReaderLock();
            }
            return true;
        }
示例#28
0
        /// <summary>
        /// Send an xml request on the wire, get the response and parse it into an XML document
        /// </summary>
        /// <param name="oRequestDocument"></param>
        /// <param name="szUrl"></param>
        /// <param name="progressCallBack"></param>
        /// <returns></returns>
        protected System.Xml.XmlReader SendHttpInternal(string szUrl, System.Xml.XmlDocument oRequestDocument, UpdateProgessCallback progressCallBack)
        {
            System.Xml.XmlReaderSettings oSettings = new System.Xml.XmlReaderSettings();
            oSettings.IgnoreWhitespace = true;
            int iCanKey = 0;
            if (m_bReadFromCan || m_bWriteToCan)
                iCanKey = szUrl.GetHashCode() ^ oRequestDocument.OuterXml.GetHashCode();

            // Get responses from the can if available
            if (m_bReadFromCan)
            {
            #if DEBUG
                System.Diagnostics.Debug.WriteLine("Loading can entry " + iCanKey.ToString("x"));
            #endif
                if (m_oResponseCan.ContainsKey(iCanKey))
                {
                    MemoryStream oBackingStore = new MemoryStream();
                    lock (((System.Collections.ICollection)m_oResponseCan).SyncRoot)
                    {
                        MemoryStream oCannedStore = m_oResponseCan[iCanKey];
                        oCannedStore.WriteTo(oBackingStore);
                        oCannedStore.Position = 0;
                        oBackingStore.Position = 0;
                    }

                    return System.Xml.XmlReader.Create(oBackingStore, oSettings);
                }
                else
                {
                    throw new WebException("Response can does not contain this datum", WebExceptionStatus.ConnectFailure);
                }
            }

            byte[] byte1;

            System.IO.StringWriter hRequest = null;
            System.IO.Stream hRequestStream = null;
            System.Xml.XmlReader oResponseXmlStream = null;

            System.Net.HttpWebRequest cHttpWReq = null;
            System.Net.HttpWebResponse cHttpWResp = null;

            try
            {
                // --- Initialize all the required streams to write out the xml request ---

                hRequest = new System.IO.StringWriter();

                // --- Create a HTTP Request to the Dap Server and HTTP Response Objects---

                cHttpWReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(szUrl);
                cHttpWReq.Pipelined = false;

            #if DAPPLE
                cHttpWReq.Proxy = ProxyHelper.DetermineProxyForUrl(
                                  szUrl,
                                  WorldWind.Net.WebDownload.useWindowsDefaultProxy,
                                  WorldWind.Net.WebDownload.useDynamicProxy,
                                  WorldWind.Net.WebDownload.proxyUrl,
                                  WorldWind.Net.WebDownload.proxyUserName,
                                  WorldWind.Net.WebDownload.proxyPassword);
            #endif

                // --- Encode the document into ascii ---

                System.Text.UTF8Encoding hRequestEncoding = new System.Text.UTF8Encoding();

                oRequestDocument.Save(hRequest);
                byte1 = hRequestEncoding.GetBytes(hRequest.GetStringBuilder().ToString());

                // --- Setup the HTTP Request ---

                cHttpWReq.Method = "POST";
            #if DAPPLE
                if (WorldWind.Net.WebDownload.useProto == WorldWind.Net.WebDownload.HttpProtoVersion.HTTP1_1)
                    cHttpWReq.ProtocolVersion = HttpVersion.Version11;
                else
                    cHttpWReq.ProtocolVersion = HttpVersion.Version10;
            #else
                cHttpWReq.ProtocolVersion = HttpVersion.Version11;
            #endif
                cHttpWReq.KeepAlive = false;
                cHttpWReq.ContentType = "application/x-www-form-urlencoded";
                cHttpWReq.ContentLength = byte1.Length;
                cHttpWReq.Timeout = m_iTimeout;

                // --- Serialize the XML document onto the wire ---

                hRequestStream = cHttpWReq.GetRequestStream();
                hRequestStream.Write(byte1, 0, byte1.Length);
                hRequestStream.Close();

                // --- Turn off connection keep-alives. ---

                cHttpWReq.KeepAlive = false;

                if (progressCallBack == null)
                {
                    // --- Get the response ---

                    cHttpWResp = (System.Net.HttpWebResponse)cHttpWReq.GetResponse();

                    if (m_bWriteToCan)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine("Saving can entry " + iCanKey.ToString("x"));
            #endif
                        MemoryStream oCannedData = bufferResponseStream(cHttpWResp.GetResponseStream());
                        MemoryStream oResponseBackingStore = new MemoryStream();
                        oCannedData.WriteTo(oResponseBackingStore);
                        oCannedData.Position = 0;
                        oResponseBackingStore.Position = 0;
                        oResponseXmlStream = System.Xml.XmlReader.Create(oResponseBackingStore, oSettings);

                        m_oResponseCan[iCanKey] = oCannedData;
                    }
                    else
                    {
                        oResponseXmlStream = System.Xml.XmlReader.Create(cHttpWResp.GetResponseStream(), oSettings);
                    }
                }
                else
                {
                    // Create the download thread (class) and populate with filename and callbacks
                    DownloadThread dl = new DownloadThread();
                    dl.ProgressCallback += progressCallBack;
                    dl.webReq = cHttpWReq;
                    // Start the download thread....
                    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(dl.Download));
                    t.Start();
                    t.Join();

                    if (dl.excepted != null)
                        throw dl.excepted;

                    MemoryStream memStrm = new MemoryStream(dl.downloadedData);

                    if (m_bWriteToCan)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine("Saving can entry " + iCanKey.ToString("x"));
            #endif
                        MemoryStream oCannedData = new MemoryStream();
                        memStrm.WriteTo(oCannedData);
                        oCannedData.Position = 0;
                        memStrm.Position = 0;
                        oResponseXmlStream = System.Xml.XmlReader.Create(memStrm, oSettings);

                        lock (((System.Collections.ICollection)m_oResponseCan).SyncRoot)
                        {
            #if DEBUG
                            if (m_oResponseCan.ContainsKey(iCanKey))
                                System.Diagnostics.Debug.WriteLine("Duplicate can key detected");
            #endif
                            m_oResponseCan[iCanKey] = oCannedData;
                        }
                    }
                    else
                    {
                        oResponseXmlStream = System.Xml.XmlReader.Create(memStrm, oSettings);
                    }
                }
            }
            catch (Exception e)
            {
                oResponseXmlStream = null;
                throw e;
            }
            return oResponseXmlStream;
        }
示例#29
0
        /// <summary>
        /// Begin the extraction process for a particular dataset
        /// </summary>
        /// <param name="hDataSet">The dataset to extract</param>
        /// <param name="hBox">The region to extract</param>
        /// <param name="bNative">Download in native coordinate system or that of bounding box</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The extract response in GeosoftXML</returns>
        public System.Xml.XmlDocument Extract(ExtractDataSet hDataSet, BoundingBox hBox, bool bNative, UpdateProgessCallback progressCallBack)
        {
            ArrayList hList = new ArrayList();

            hList.Add(hDataSet);
            return Extract(hList, hBox, bNative, progressCallBack);
        }
示例#30
0
        public byte[] Download(WebRequest req, UpdateProgessCallback progressCB)
        {
            // Ensure flag set correctly.
            allDone.Reset();

            // Create the state object.
            DownloadInfo info = new DownloadInfo();

            // Put the request into the state object so it can be passed around.
            info.Request = req;

            // Assign the callbacks
            info.ProgressCallback += progressCB;

            // Issue the async request.
            IAsyncResult r = (IAsyncResult)req.BeginGetResponse(new AsyncCallback(ResponseCallback), info);

            // Wait until the ManualResetEvent is set so that the application
            // does not exit until after the callback is called.
            allDone.WaitOne();

            // Pass back the downloaded information.

            if (info.useFastBuffers)
                return info.dataBufferFast;
            else
            {
                byte[] data = new byte[info.dataBufferSlow.Count];
                for (int b = 0; b < info.dataBufferSlow.Count; b++)
                    data[b] = (byte)info.dataBufferSlow[b];
                return data;
            }
        }
示例#31
0
        /// <summary>
        /// Get xml meta information for a particular dataset
        /// </summary>
        /// <param name="hDataSet">The dataset to retrieve meta information for</param>
        /// <param name="progressCallBack">Progress handler (may be null)</param>
        /// <returns>The meta response in GeosoftXML</returns>
        public System.Xml.XmlDocument GetXMLMetaData(DataSet hDataSet, UpdateProgessCallback progressCallBack)
        {
            // --- check to make sure that the dataset is located on the server this command is connected to ---

            if (hDataSet.Url != Url)
                throw new DapException("The dataset is not located on this server.");

            return GetXMLMetaData(hDataSet.Name, progressCallBack);
        }