Exemplo n.º 1
0
        /// <summary>
        /// Download all the datasets
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bDownload_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                this.DialogResult = DialogResult.None;
                return;
            }

            if (!DoFilenamePrompt())
            {
                this.DialogResult = DialogResult.None;
                return;
            }

             try
             {
            DownloadCoordinateSystem eCS = DownloadCoordinateSystem.Native;

            if (rbReproject.Checked)
               eCS = DownloadCoordinateSystem.OriginalMap;

            System.Xml.XmlDocument oExtractDoc = new System.Xml.XmlDocument();
            System.Xml.XmlElement oRootElement = oExtractDoc.CreateElement("geosoft_xml");
            System.Xml.XmlElement oExtractElement = oExtractDoc.CreateElement("extract");

            oExtractDoc.AppendChild(oRootElement);
            oRootElement.AppendChild(oExtractElement);

                // --- create xml document for each dataset ---

                int iCount = 0;
                for (int count = 0; count < m_oDownloadSettings.Count; count++)
                {
                    System.Xml.XmlElement oDatasetElement;
                    if (m_oDownloadSettings[count] is PersonalDataset)
                    {
                        oDatasetElement = oExtractDoc.CreateElement("personal_dataset");
                    }
                    else
                    {
                        oDatasetElement = oExtractDoc.CreateElement("dataset");
                    }

                    DownloadCoordinateSystem eCSForLayer = eCS;

                    // --- Don't 'reproject to original map' if their projections have different orientations ---
                    if (eCS == DownloadSettings.DownloadCoordinateSystem.OriginalMap && !String.IsNullOrEmpty(m_oDownloadSettings[count].Projection) && !MainForm.MontajInterface.ProjectionsHaveSameOrientation(MainForm.MapAoiCoordinateSystem, m_oDownloadSettings[count].Projection))
                        eCSForLayer = DownloadSettings.DownloadCoordinateSystem.Native;

                    switch (m_oDownloadSettings[count].Save(oDatasetElement, cFolderControl.Value, eCSForLayer))
                    {
                        case DownloadOptions.ExtractSaveResult.Cancel:
                            SetActivePage(count);
                            DialogResult = DialogResult.None;
                            return;
                        case DownloadOptions.ExtractSaveResult.Extract:
                            iCount++;
                            oExtractElement.AppendChild(oDatasetElement);
                            break;
                        case DownloadOptions.ExtractSaveResult.Ignore:
                            continue;

                    }
                }

                if (iCount == 0)
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }

            #if DEBUG
            System.Xml.XmlElement oDebugElement = oExtractDoc.CreateElement("debug");
            WorldWind.GeographicBoundingBox oViewAOI = WorldWind.GeographicBoundingBox.FromQuad(MainForm.WorldWindowSingleton.CurrentAreaOfInterest);
                oDebugElement.SetAttribute("wgs84_west", oViewAOI.West.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_south", oViewAOI.South.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_east", oViewAOI.East.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_north", oViewAOI.North.ToString("f2", CultureInfo.InvariantCulture));
            oExtractElement.AppendChild(oDebugElement);
            #endif
                DatasetDisclaimer oDisclaimers = null;
                try
                {
                    oDisclaimers = new DatasetDisclaimer(m_oLayersToDownload, oExtractDoc);
                }
                catch (System.Net.WebException ex)
                {
                    String strErrorMessage = "Could not access disclaimer information for ";
                    if (ex.Data["dataset"] != null)
                    {
                        strErrorMessage += "data layer " + ex.Data["dataset"];
                    }
                    else
                    {
                        strErrorMessage += "one or more data layers";
                    }

                    if (ex.Message != null)
                    {
                        strErrorMessage += ":" + Environment.NewLine + ex.Message;
                    }
                    else
                    {
                        strErrorMessage += ".";
                    }

                    Program.ShowMessageBox(
                        strErrorMessage,
                        "Extract Layers",
                        MessageBoxButtons.OK,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }
                oDisclaimers.ShowInTaskbar = false;

            #if DEBUG
                ExtractDebug oDebug = new ExtractDebug(oExtractDoc);
                oDebug.ShowDialog(this);
            #endif

                if (oDisclaimers.HasDisclaimer)
                {
                    if (oDisclaimers.ShowDialog(this) == DialogResult.OK)
                    {
                        m_blLayersDownloaded = DoDownload(oExtractDoc);
                    }
                    else
                    {
                        this.DialogResult = DialogResult.Cancel;
                    }
                }
                else
                {
                    m_blLayersDownloaded = DoDownload(oExtractDoc);
                }
             }
             catch (System.Runtime.Remoting.RemotingException)
             {
                this.DialogResult = DialogResult.Abort;
                return;
             }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Download all the datasets
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bDownload_Click(object sender, EventArgs e)
        {
            if (!this.ValidateChildren())
            {
                this.DialogResult = DialogResult.None;
                return;
            }

            if (!DoFilenamePrompt())
            {
                this.DialogResult = DialogResult.None;
                return;
            }

            try
            {
                DownloadCoordinateSystem eCS = DownloadCoordinateSystem.Native;

                if (rbReproject.Checked)
                {
                    eCS = DownloadCoordinateSystem.OriginalMap;
                }


                System.Xml.XmlDocument oExtractDoc     = new System.Xml.XmlDocument();
                System.Xml.XmlElement  oRootElement    = oExtractDoc.CreateElement("geosoft_xml");
                System.Xml.XmlElement  oExtractElement = oExtractDoc.CreateElement("extract");

                oExtractDoc.AppendChild(oRootElement);
                oRootElement.AppendChild(oExtractElement);

                // --- create xml document for each dataset ---

                int iCount = 0;
                for (int count = 0; count < m_oDownloadSettings.Count; count++)
                {
                    System.Xml.XmlElement oDatasetElement;
                    if (m_oDownloadSettings[count] is PersonalDataset)
                    {
                        oDatasetElement = oExtractDoc.CreateElement("personal_dataset");
                    }
                    else
                    {
                        oDatasetElement = oExtractDoc.CreateElement("dataset");
                    }

                    DownloadCoordinateSystem eCSForLayer = eCS;

                    // --- Don't 'reproject to original map' if their projections have different orientations ---
                    if (eCS == DownloadSettings.DownloadCoordinateSystem.OriginalMap && !String.IsNullOrEmpty(m_oDownloadSettings[count].Projection) && !MainForm.MontajInterface.ProjectionsHaveSameOrientation(MainForm.MapAoiCoordinateSystem, m_oDownloadSettings[count].Projection))
                    {
                        eCSForLayer = DownloadSettings.DownloadCoordinateSystem.Native;
                    }

                    switch (m_oDownloadSettings[count].Save(oDatasetElement, cFolderControl.Value, eCSForLayer))
                    {
                    case DownloadOptions.ExtractSaveResult.Cancel:
                        SetActivePage(count);
                        DialogResult = DialogResult.None;
                        return;

                    case DownloadOptions.ExtractSaveResult.Extract:
                        iCount++;
                        oExtractElement.AppendChild(oDatasetElement);
                        break;

                    case DownloadOptions.ExtractSaveResult.Ignore:
                        continue;
                    }
                }

                if (iCount == 0)
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }

#if DEBUG
                System.Xml.XmlElement           oDebugElement = oExtractDoc.CreateElement("debug");
                WorldWind.GeographicBoundingBox oViewAOI      = WorldWind.GeographicBoundingBox.FromQuad(MainForm.WorldWindowSingleton.CurrentAreaOfInterest);
                oDebugElement.SetAttribute("wgs84_west", oViewAOI.West.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_south", oViewAOI.South.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_east", oViewAOI.East.ToString("f2", CultureInfo.InvariantCulture));
                oDebugElement.SetAttribute("wgs84_north", oViewAOI.North.ToString("f2", CultureInfo.InvariantCulture));
                oExtractElement.AppendChild(oDebugElement);
#endif
                DatasetDisclaimer oDisclaimers = null;
                try
                {
                    oDisclaimers = new DatasetDisclaimer(m_oLayersToDownload, oExtractDoc);
                }
                catch (System.Net.WebException ex)
                {
                    String strErrorMessage = "Could not access disclaimer information for ";
                    if (ex.Data["dataset"] != null)
                    {
                        strErrorMessage += "data layer " + ex.Data["dataset"];
                    }
                    else
                    {
                        strErrorMessage += "one or more data layers";
                    }

                    if (ex.Message != null)
                    {
                        strErrorMessage += ":" + Environment.NewLine + ex.Message;
                    }
                    else
                    {
                        strErrorMessage += ".";
                    }

                    Program.ShowMessageBox(
                        strErrorMessage,
                        "Extract Layers",
                        MessageBoxButtons.OK,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }
                oDisclaimers.ShowInTaskbar = false;

#if DEBUG
                ExtractDebug oDebug = new ExtractDebug(oExtractDoc);
                oDebug.ShowDialog(this);
#endif

                if (oDisclaimers.HasDisclaimer)
                {
                    if (oDisclaimers.ShowDialog(this) == DialogResult.OK)
                    {
                        m_blLayersDownloaded = DoDownload(oExtractDoc);
                    }
                    else
                    {
                        this.DialogResult = DialogResult.Cancel;
                    }
                }
                else
                {
                    m_blLayersDownloaded = DoDownload(oExtractDoc);
                }
            }
            catch (System.Runtime.Remoting.RemotingException)
            {
                this.DialogResult = DialogResult.Abort;
                return;
            }
        }