コード例 #1
0
ファイル: CswProfile.cs プロジェクト: k4th/geoportal-server
        /// <summary>
        /// Generate a CSW request string. 
        /// </summary>
        /// <remarks>
        /// The CSW request string is built.
        /// The request is string is build based on the request xslt.
        /// </remarks>
        /// <param name="param1">The search criteria</param>
        /// <returns>The request string</returns>
        public string GenerateCSWGetRecordsRequest(CswSearchCriteria search)
        {
            //build xml
            StringWriter writer = new StringWriter();
            StringBuilder request = new StringBuilder();
            request.Append("<?xml version='1.0' encoding='UTF-8'?>");
            request.Append("<GetRecords>");
            request.Append("<StartPosition>" + search.StartPosition + "</StartPosition>");
            request.Append("<MaxRecords>" + search.MaxRecords + "</MaxRecords>");
            request.Append("<KeyWord>" + this.XmlEscape(search.SearchText) + "</KeyWord>");
            request.Append("<LiveDataMap>" + search.LiveDataAndMapOnly.ToString() + "</LiveDataMap>");
            if (search.Envelope != null)
            {
                request.Append("<Envelope>");
                request.Append("<MinX>" + search.Envelope.MinX + "</MinX>");
                request.Append("<MinY>" + search.Envelope.MinY + "</MinY>");
                request.Append("<MaxX>" + search.Envelope.MaxX + "</MaxX>");
                request.Append("<MaxY>" + search.Envelope.MaxY + "</MaxY>");
                request.Append("</Envelope>");
            }
            request.Append("</GetRecords>");
            try
            {
                TextReader textreader = new StringReader(request.ToString());
                XmlTextReader xmltextreader = new XmlTextReader(textreader);
                //load the Xml doc
                XPathDocument myXPathDoc = new XPathDocument(xmltextreader);
                if (requestxsltobj == null)
                {
                    requestxsltobj = new XslCompiledTransform();
                    XsltSettings settings = new XsltSettings(true, true);
                    requestxsltobj.Load(requestxslt, settings, new XmlUrlResolver());
                }
                //do the actual transform of Xml
                requestxsltobj.Transform(myXPathDoc, null, writer);
                //requestxsltobj.Transform(myXPathDoc, null, writer);
                writer.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            return writer.ToString();
        }
コード例 #2
0
        /// <summary>
        /// Function on click of find button
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The event arguments</param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbCswCatalog.SelectedIndex == -1)
                {
                    MessageBox.Show(resourceManager.GetString("catalogNotSelected"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;

                }
                CswCatalog catalog = (CswCatalog)cmbCswCatalog.SelectedItem;
                if (catalog == null) { throw new NullReferenceException(resourceManager.GetString("catalogNotSpecified")); }
                if (!catalog.IsConnected())
                {
                    string errMsg = "";
                    try { catalog.Connect(); }
                    catch (Exception ex) { errMsg = ex.ToString(); }
                    if (!catalog.IsConnected())
                    {
                        MessageBox.Show(resourceManager.GetString("catalogConnectFailed"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                // clear up result list
                lstSearchResults.DataSource = null;
                Cursor.Current = Cursors.WaitCursor;
                // genrate search criteria
                CswSearchCriteria searchCriteria = new CswSearchCriteria();
                searchCriteria.SearchText = txtSearchPhrase.Text;
                searchCriteria.StartPosition = 1;
                searchCriteria.MaxRecords = (int)nudNumOfResults.Value; ;
                searchCriteria.LiveDataAndMapOnly = (chkLiveDataAndMapOnly.CheckState == CheckState.Checked);
                searchCriteria.Envelope = null;   // place holder

                CswSearchRequest searchRequest = new CswSearchRequest();
                searchRequest.Catalog = catalog;
                searchRequest.Criteria = searchCriteria;

                searchRequest.Search();
                CswSearchResponse response = searchRequest.GetResponse();
                ArrayList alRecords = CswObjectsToArrayList(response.Records);
                if (alRecords.Count == 0)
                {
                    MessageBox.Show(resourceManager.GetString("noRecordFound"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (alRecords.Count > 0)
                {
                    lstSearchResults.DataSource = alRecords;
                    lstSearchResults.DisplayMember = "Title";
                    lstSearchResults.ValueMember = "ID";
                    showAllFootPrintTSBtn.Enabled = catalog.Profile.SupportSpatialBoundary;
                    clearAllFootPrintTSBtn.Enabled = catalog.Profile.SupportSpatialBoundary;
                    displayFootPrintTSBtn.Enabled = catalog.Profile.SupportSpatialBoundary;
                    zoomToFootPrintTSBtn.Enabled = catalog.Profile.SupportSpatialBoundary;
                    showAll = true;
                }
                lblResult.Text = resourceManager.GetString("resultTxt") + " (" + alRecords.Count + ")";

            }
            catch (Exception ex)
            {
                MessageBox.Show(resourceManager.GetString("searchFailed"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
コード例 #3
0
        /// <summary>
        /// Search CSW catalog with the criteria defined by user
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void FindButton_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            try
            {

                // Todo: add more validation. only minimum validation at this point.
                if (catalogComboBox.SelectedIndex == -1)
                {
                    ShowErrorMessageBox(StringResources.PleaseSelectACswCatalog);
                    return;
                }

                CswCatalog catalog = (CswCatalog)catalogComboBox.SelectedItem;
                if (catalog == null) { throw new NullReferenceException(StringResources.CswCatalogIsNull); }

                // reset GUI for search results
                ResetSearchResultsGUI();

                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                if (!catalog.IsConnected())
                {
                    string errMsg = "";
                    try { catalog.Connect();
                    }
                    catch (Exception ex) { errMsg = ex.Message; }
                    if (!catalog.IsConnected())
                    {
                         sb.AppendLine("Failed to connect to Catalog");
                        ShowErrorMessageBox (StringResources.ConnectToCatalogFailed + "\r\n" + errMsg);
                        return;
                    }
                }

                // todo: need paging maganism. update SearchCriteria.StartPoistion

                // generate search criteria
                CswSearchCriteria searchCriteria = new CswSearchCriteria();
                searchCriteria.SearchText = searchPhraseTextBox.Text;
                searchCriteria.StartPosition = 1;
                searchCriteria.MaxRecords = (int)maxResultsNumericUpDown.Value;
                searchCriteria.LiveDataAndMapOnly = (liveDataAndMapsOnlyCheckBox.Checked);
                if (useCurrentExtentCheckBox.Checked)
                {
                    try { searchCriteria.Envelope = CurrentMapViewExtent(); }
                    catch (Exception ex)
                    {
                        String errMsg = StringResources.GetCurrentExtentFailed + "\r\n" +
                                            ex.Message + "\r\n" + "\r\n" +
                                            StringResources.UncheckCurrentExtentAndTryAgain;

                        sb.AppendLine(errMsg);
                        ShowErrorMessageBox(errMsg);
                        return;
                    }
                }
                else { searchCriteria.Envelope = null; }

                // search
                if (_searchRequest == null) { _searchRequest = new CswSearchRequest(); }
                _searchRequest.Catalog = catalog;
                _searchRequest.Criteria = searchCriteria;
                _searchRequest.Search();
                CswSearchResponse response = _searchRequest.GetResponse();
                // show search results
                ArrayList alRecords = CswObjectsToArrayList(response.Records);
                if (alRecords.Count > 0)
                {
                    resultsListBox.BeginUpdate();
                    resultsListBox.DataSource = alRecords;
                    resultsListBox.DisplayMember = "Title";
                    resultsListBox.ValueMember = "ID";
                    resultsListBox.SelectedIndex = 0;
                    resultsListBox.EndUpdate();
                    showAllFootprintToolStripButton.Enabled = catalog.Profile.SupportSpatialBoundary;
                    clearAllFootprinttoolStripButton.Enabled = catalog.Profile.SupportSpatialBoundary;
                    showAll = true;
                }
                else
                {
                    sb.AppendLine(StringResources.NoRecordsFound);
                    ShowErrorMessageBox(StringResources.NoRecordsFound);
                }

                resultsLabel.Text = StringResources.SearchResultsLabelText + " (" + alRecords.Count.ToString() + ")";
            }
            catch (Exception ex)
            {
                sb.AppendLine(ex.Message);
                ShowErrorMessageBox (ex.Message);
            }
            finally
            {
                Utils.logger.writeLog(sb.ToString());
                Cursor.Current = Cursors.Default;
            }
        }