/// <summary> /// Retrieves the selected metadata (in search result listbox) from CSW catalog. Exception shall be thrown. /// </summary> /// <remarks> /// Called in View Metadata, Download Metadata, and Add to Map /// </remarks> /// <returns>A XMLDocument object if metadata was retrieved successfully. Null if otherwise.</returns> private void RetrieveAddToMapInfoFromCatalog() { try { // validate if (catalogComboBox.SelectedIndex == -1) { throw new Exception(StringResources.NoCatalogSelected); } if (dgvCswRecords.SelectedRows.Count == 0) { throw new Exception(StringResources.NoSearchResultSelected); } CswCatalog catalog = (CswCatalog)catalogComboBox.SelectedItem; if (catalog == null) { throw new NullReferenceException(StringResources.CswCatalogIsNull); } CswRecord record = (CswRecord)dgvCswRecords.CurrentRow.DataBoundItem; if (record == null) throw new NullReferenceException(StringResources.CswRecordIsNull); // connect to catalog if needed if (!catalog.IsConnected()) { string errMsg = ""; try { catalog.Connect(_isWriteLogs); } catch (Exception ex) { errMsg = ex.Message; } // exit if still not connected if (!catalog.IsConnected()) { ShowErrorMessageBox(StringResources.ConnectToCatalogFailed + "\r\n" + errMsg); } } // retrieve metadata doc by its ID if (_searchRequest == null) { _searchRequest = new CswSearchRequest(_isWriteLogs); } _searchRequest.Catalog = catalog; try { _searchRequest.GetAddToMapInfoByID(record.ID); } catch (Exception ex) { ShowDetailedErrorMessageBox(StringResources.RetrieveMetadataFromCatalogFailed, _searchRequest.Response().ResponseXML); System.Diagnostics.Trace.WriteLine(StringResources.RetrieveMetadataFromCatalogFailed); System.Diagnostics.Trace.WriteLine(ex.Message); System.Diagnostics.Trace.WriteLine(_searchRequest.Response().ResponseXML); } } catch (Exception ex) { ShowErrorMessageBox(StringResources.RetrieveMetadataFromCatalogFailed + "\r\n" + ex.Message); } }
/// <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(_isWriteLogs); } 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.SearchTextLogicalOperator = (CswSearchCriteria.LogicalOperator)cbSearchTextLO.SelectedIndex; searchCriteria.FilterLogicalOperator = CswSearchCriteria.LogicalOperator.And; searchCriteria.Organisation = tbOrganisation.Text; if (cbDownload.Checked) searchCriteria.TypesOfUse.Add(cbDownload.Text); if (cbRaadplegen.Checked) searchCriteria.TypesOfUse.Add(cbRaadplegen.Text); if (cbAchtergrond.Checked) searchCriteria.TypesOfUse.Add(cbAchtergrond.Text); searchCriteria.StartPosition = 1; searchCriteria.MaxRecords = (int)maxResultsNumericUpDown.Value; //searchCriteria.LiveDataAndMapOnly = (liveDataAndMapsOnlyCheckBox.Checked); searchCriteria.RefinePreviousFilter = ((cbRefine.Checked) && (cbRefine.Enabled)); //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(_isWriteLogs); } _searchRequest.Catalog = catalog; _searchRequest.Criteria = searchCriteria; _searchRequest.Search(); ShowSearchResults(sb); } catch (Exception ex) { sb.AppendLine(ex.Message); ShowErrorMessageBox (ex.Message); } finally { if (_isWriteLogs) Utils.writeFile(sb.ToString()); System.Windows.Forms.Cursor.Current = Cursors.Default; } }
/// <summary> /// Retrieves the selected metadata (in search result listbox) from CSW catalog. Exception shall be thrown. /// </summary> /// <remarks> /// Called in View Metadata, Download Metadata, and Add to Map /// </remarks> /// <returns>A XMLDocument object if metadata was retrieved successfully. Null if otherwise.</returns> private XmlDocument RetrieveSelectedMetadataFromCatalog(bool bApplyTransform) { try { // validate if (catalogComboBox.SelectedIndex == -1) { throw new Exception(StringResources.NoCatalogSelected); } if (dgvCswRecords.SelectedRows.Count == 0) { throw new Exception(StringResources.NoSearchResultSelected); } CswCatalog catalog = (CswCatalog)catalogComboBox.SelectedItem; if (catalog == null) { throw new NullReferenceException(StringResources.CswCatalogIsNull); } CswRecord record = (CswRecord)dgvCswRecords.CurrentRow.DataBoundItem; if (record == null) throw new NullReferenceException(StringResources.CswRecordIsNull); // connect to catalog if needed if (!catalog.IsConnected()) { string errMsg = ""; try { catalog.Connect(_isWriteLogs); } catch (Exception ex) { errMsg = ex.Message; } // exit if still not connected if (!catalog.IsConnected()) { ShowErrorMessageBox(StringResources.ConnectToCatalogFailed + "\r\n" + errMsg); return null; } } bool isTransformed = false; // retrieve metadata doc by its ID if (_searchRequest == null) { _searchRequest = new CswSearchRequest(_isWriteLogs); } _searchRequest.Catalog = catalog; try { isTransformed = _searchRequest.GetMetadataByID(record.ID, bApplyTransform); } catch (Exception ex) { ShowDetailedErrorMessageBox(StringResources.RetrieveMetadataFromCatalogFailed, _searchRequest.Response().ResponseXML); System.Diagnostics.Trace.WriteLine(StringResources.RetrieveMetadataFromCatalogFailed); System.Diagnostics.Trace.WriteLine(ex.Message); System.Diagnostics.Trace.WriteLine(_searchRequest.Response().ResponseXML); return null; } CswSearchResponse response = _searchRequest.Response(); CswRecord recordMetadata = response.Records[0]; if (recordMetadata.FullMetadata.Length == 0) { throw new Exception(StringResources.EmptyMetadata); } if (!isTransformed) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(recordMetadata.FullMetadata); } catch (XmlException xmlEx) { ShowDetailedErrorMessageBox(StringResources.LoadMetadataFailed + "\r\n" + xmlEx.Message, recordMetadata.FullMetadata); return null; } return xmlDoc; } else { styledRecordResponse = recordMetadata.FullMetadata; return null; } } catch (Exception ex) { ShowErrorMessageBox(StringResources.RetrieveMetadataFromCatalogFailed + "\r\n" + ex.Message); return null; } }