/// <summary> /// Function to add to map /// </summary> private void AddToMap_Clicked() { try { /* if (addedLayer[lstSearchResults.SelectedItem.GetHashCode()] != null) { AGXM.ServiceLayer resultLayer = (AGXM.ServiceLayer)addedLayer[lstSearchResults.SelectedItem.GetHashCode()]; try { if (resultLayer.Extent.GetEnvelope() != null) { MessageBox.Show(resourceManager.GetString("layerAdded"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception e) { addedLayer.Remove(lstSearchResults.SelectedItem.GetHashCode()); } }*/ // if (addedLayer[lstSearchResults.SelectedItem.GetHashCode()] == null) { Cursor.Current = Cursors.WaitCursor; // retrieve metadata CswRecord record = (CswRecord)lstSearchResults.SelectedItem; if (record == null) throw new NullReferenceException("CswRecord is null."); if (record.MapServerURL == null || record.MapServerURL.Trim().Length == 0) { // retrieve metadata RetrieveAddToMapInfoFromCatalog(); } else { _mapServerUrl = record.MapServerURL; } // if (xmlDoc == null) return; // prepare metadata for service info // xmlDoc = PrepareMetadata(xmlDoc); // if (xmlDoc == null) return; if (_mapServerUrl != null && _mapServerUrl.Trim().Length > 0) { String serviceType = record.ServiceType; if (serviceType == null || serviceType.Length == 0) { serviceType = CswProfile.getServiceType(_mapServerUrl); } if (serviceType.Equals("ags")) { if (_mapServerUrl.ToLower().Contains("arcgis/rest")) { _mapServerUrl = _mapServerUrl + "?f=nmf"; CswClient client = new CswClient(); AddAGSService(client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, "")); } else { AddAGSService(_mapServerUrl); } } else if (serviceType.Equals("wms") || serviceType.Equals("aims")) { try { MapServiceInfo msinfo = new MapServiceInfo(); msinfo.Server = record.MapServerURL; msinfo.Service = record.ServiceName; msinfo.ServiceType = record.ServiceType; CswProfile.ParseServiceInfoFromUrl(msinfo, _mapServerUrl, serviceType); addMapServiceLayer(msinfo); } catch (Exception e) { AddAGSService(_mapServerUrl); } } } else { MapServiceInfo msi = new MapServiceInfo(); // parse out service information // ParseServiceInfoFromMetadata(xmlDoc, ref msi); if (msi.IsMapService()) { addMapServiceLayer(msi); } else { MessageBox.Show(resourceManager.GetString("invalidService"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // } } catch (Exception ex) { MessageBox.Show(resourceManager.GetString("addMapFailed"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }
/// <summary> /// Adds WMS layer to map /// </summary> /// <param name="msi">map service information</param> /// <param name="fromServerUrl">service url</param> /// <returns></returns> private bool addLayerWMS2(MapServiceInfo msi, Boolean fromServerUrl) { bool flag = false; if (msi == null) { throw new ArgumentNullException("msi"); } string service = msi.Service; string url = AppendQuestionOrAmpersandToUrlString(msi.Server); // append serviceParam to server url? if (msi.ServiceParam.Length > 0 && !fromServerUrl) { url = url + msi.ServiceParam; url = AppendQuestionOrAmpersandToUrlString(url); } CswClient client = new CswClient(); string response = client.SubmitHttpRequest("GET", url + "request=GetCapabilities&service=WMS", ""); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(response); XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable); xmlnsManager.AddNamespace("wms", "http://www.opengis.net/wms"); XmlNodeList nl = null; if (xmlDoc.SelectSingleNode("//wms:Layer", xmlnsManager) != null) { nl = xmlDoc.SelectNodes("/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer/wms:Title", xmlnsManager); } if (nl != null) { flag = true; for (int i = nl.Count - 1; i >= 0; i--) { AGXD.ServiceConnectionProperties conn = new AGXD.ServiceConnectionProperties (AGXD.ServiceType.Wms, new Uri(url), "", nl.Item(i).InnerText); AGXM.ServiceLayer sl = new AGXM.ServiceLayer(conn); bool connected = sl.Connect(); if (connected) { addLayer(sl); addedLayer.Add(DateTime.Now.Millisecond, sl); } } } return flag; }
/// <summary> /// Add WCS map service layer to map /// </summary> /// <param name="msi">Map service information</param> private void AddLayerWCS(esri.gpt.csw.MapServiceInfo msi, Boolean fromServerUrl) { if (msi == null) { throw new ArgumentNullException(); } try { string _mapServerUrl = AppendQuestionOrAmpersandToUrlString(msi.Server); // append serviceParam to server url // todo: does msi.ServiceParam have a leading "?" or "&"? if (msi.ServiceParam.Length > 0 && !fromServerUrl) { _mapServerUrl = _mapServerUrl + msi.ServiceParam; _mapServerUrl = AppendQuestionOrAmpersandToUrlString(_mapServerUrl); } // MapServiceInfo msi = new MapServiceInfo(); String[] s = _mapServerUrl.Trim().Split('?'); _mapServerUrl = s[0] + "?request=GetCapabilities&service=WCS"; CswClient client = new CswClient(); String response = client.SubmitHttpRequest("GET", _mapServerUrl, ""); XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(response); } catch (XmlException xmlEx) { } XmlNodeList contentMetadata = xmlDocument.GetElementsByTagName("ContentMetadata"); if (contentMetadata != null && contentMetadata.Count > 0) { XmlNodeList coverageList = contentMetadata.Item(0).ChildNodes; foreach (XmlNode coverage in coverageList) { XmlNodeList nodes = coverage.ChildNodes; foreach(XmlNode node in nodes) { if (node.Name.ToLower().Equals("name")) { _mapServerUrl = s[0] + "?request=GetCoverage&service=WCS&format=GeoTIFF&coverage=" + node.InnerText; try{ String filePath = client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, ""); AddAGSService(filePath); } catch(Exception e){ ShowErrorMessageBox("WCS service with no GeoTiff interface"); return; } } } } } } catch (Exception ex) { // ShowErrorMessageBox(StringResources.AddWcsLayerFailed + "\r\n" + ex.Message); } }
/// <summary> /// Retrieve metadta for the selected record from server. /// Then add the live data or maps that the metadta describes to ArcMap as a layer. /// </summary> private void AddToMap_Clicked() { try { Cursor.Current = Cursors.WaitCursor; CswRecord record = (CswRecord)resultsListBox.SelectedItem; if (record == null) throw new NullReferenceException(StringResources.CswRecordIsNull); if (record.MapServerURL == null || record.MapServerURL.Trim().Length == 0) { // retrieve metadata RetrieveAddToMapInfoFromCatalog(); } else { _mapServerUrl = record.MapServerURL; } if (_mapServerUrl != null && _mapServerUrl.Trim().Length > 0) { String serviceType = record.ServiceType; if (serviceType == null || serviceType.Length == 0) { serviceType = CswProfile.getServiceType(_mapServerUrl); } if (serviceType.Equals("unknown")) { System.Diagnostics.Process.Start("IExplore", _mapServerUrl); Cursor.Current = Cursors.Default; return; } else if (serviceType.Equals("ags")) { if (_mapServerUrl.ToLower().Contains("arcgis/rest")) { var urlparts = _mapServerUrl.Split('/'); if (urlparts != null && urlparts.Length > 0) { var lastPartOfUrl = urlparts[urlparts.Length - 1]; if (lastPartOfUrl.Length > 0 && IsNumeric(lastPartOfUrl)) { // CswClient client = new CswClient(); AddAGSService( _mapServerUrl); } else { _mapServerUrl = _mapServerUrl + "?f=lyr"; CswClient client = new CswClient(); AddAGSService(client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, "")); } } } else { AddAGSService(_mapServerUrl); } } else if (serviceType.Equals("wms")) { MapServiceInfo msinfo = new MapServiceInfo(); msinfo.Server = record.MapServerURL; msinfo.Service = record.ServiceName; msinfo.ServiceType = record.ServiceType; CswProfile.ParseServiceInfoFromUrl(msinfo,_mapServerUrl, serviceType); AddLayerWMS(msinfo, true); } else if (serviceType.Equals("aims")) { MapServiceInfo msinfo = new MapServiceInfo(); msinfo.Server = record.MapServerURL; msinfo.Service = record.ServiceName; msinfo.ServiceType = record.ServiceType; CswProfile.ParseServiceInfoFromUrl(msinfo,_mapServerUrl, serviceType); AddLayerArcIMS(msinfo); } else if (serviceType.Equals("wcs")) { // MapServiceInfo msi = new MapServiceInfo(); String[] s = _mapServerUrl.Trim().Split('?'); _mapServerUrl = s[0] + "?request=GetCapabilities&service=WCS"; CswClient client = new CswClient(); String response = client.SubmitHttpRequest("GET", _mapServerUrl, ""); XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(response); } catch (XmlException xmlEx) { } XmlNodeList contentMetadata = xmlDocument.GetElementsByTagName("ContentMetadata"); if (contentMetadata != null && contentMetadata.Count > 0) { XmlNodeList coverageList = contentMetadata.Item(0).ChildNodes; foreach (XmlNode coverage in coverageList) { XmlNodeList nodes = coverage.ChildNodes; foreach (XmlNode node in nodes) { if (node.Name.ToLower().Equals("name")) { _mapServerUrl = s[0] + "?request=GetCoverage&service=WCS&format=GeoTIFF&coverage=" + node.InnerText; try { String filePath = client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, ""); AddAGSService(filePath); } catch (Exception e) { ShowErrorMessageBox(StringResources.wcsWithNoGeoTiffInterface); return; } } } } } else { ShowErrorMessageBox(StringResources.serviceTypeUnknown); return; /* contentMetadata = xmlDocument.GetElementsByTagName("CoverageSummary"); if (contentMetadata != null && contentMetadata.Count > 0) { XmlNodeList coverageList = contentMetadata.Item(0).ChildNodes; foreach (XmlNode coverage in coverageList) { if (coverage.Name.ToLower().Equals("identifier")) { _mapServerUrl = s[0] + "?request=GetCoverage&service=WCS&format=GeoTIFF&coverage=" + coverage.InnerText; try { String filePath = client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, ""); AddAGSService(filePath); } catch (Exception e) { ShowErrorMessageBox("WCS service with no GeoTiff interface"); return; } } } }*/ } } } } catch (Exception ex) { ShowErrorMessageBox(ex.Message); } finally { Cursor.Current = Cursors.Default; } }
/// <summary> /// Get Add to map information /// </summary> /// <param name="DocID">document identifier</param> public void GetAddToMapInfoByID(string DocID) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { sb.AppendLine(DateTime.Now + " GetRecordByID URL not specified for the catalog capabilities."); throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); profile.ReadCSWGetMetadataByIDResponse(responseText, record); if (record.MetadataResourceURL != null && record.MetadataResourceURL.Equals("") && profile.Name.Equals("terra catalog CSW 2.0.2 AP ISO")) { record.FullMetadata = responseText; } if (record == null) { throw new NullReferenceException("Record not populated."); } // check if full metadata or resourceURL has been returned bool hasFullMetadata = !(record.FullMetadata == null || record.FullMetadata == ""); bool hasResourceUrl = !(record.MetadataResourceURL == null || record.MetadataResourceURL == ""); if (!hasFullMetadata && !hasResourceUrl) { // throw new InvalidOperationException("Neither full metadata nor metadata resource URL was found for the CSW record."); } else if (!hasFullMetadata && record.MetadataResourceURL != null) { // need to load metadata from resource URL responseText = _cswClient.SubmitHttpRequest("GET", record.MetadataResourceURL, "", "", ""); record.FullMetadata = responseText; } // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) { sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); } writeLogMessage(sb.ToString()); }
/// <summary> /// Search CSW catalog using the provided criteria. Search result can be accessed by calling GetResponse(). /// </summary> public void Search() { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (_criteria == null) { sb.AppendLine(DateTime.Now + " Criteria not specified."); throw new NullReferenceException("Criteria not specified."); } if (_catalog == null) { sb.AppendLine(DateTime.Now + " Catalog not specified."); throw new NullReferenceException("Catalog not specified."); } if (_catalog.URL == null || _catalog.URL.Length == 0) { sb.AppendLine(DateTime.Now + " Catalog URL not specified."); throw new NullReferenceException("Catalog URL not specified."); } if (_catalog.Profile == null) { sb.AppendLine(DateTime.Now + " Catalog profile not specified."); throw new NullReferenceException("Catalog profile not specified."); } CswProfile profile = _catalog.Profile; writeLogMessage("Csw profile used : " + profile.Name); // generate getRecords query string requestUrl = ""; string requestQuery = ""; if (_catalog.Profile.isOGCRecords) { requestUrl = _catalog.URL; requestQuery = "f=json&q=" + _criteria.SearchText; } else { requestUrl = _catalog.Capabilities.GetRecords_PostURL; requestQuery = profile.GenerateCSWGetRecordsRequest(_criteria); } // requestQuery = "<csw:GetCapabilities xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" request=\"GetCapabilities\" service=\"CSW\" version=\"2.0.2\"/>"; requestQuery = requestQuery.Replace("utf-16", "utf-8"); requestQuery = requestQuery.Replace("UTF-16", "UTF-8"); // submit search query if (_cswClient == null) { _cswClient = new CswClient(); } string responseText; sb.AppendLine(DateTime.Now + " Sending CSW GetRecords request to endpoint : " + requestUrl); sb.AppendLine("Request Query : " + requestQuery); if (_catalog.Profile.isOGCRecords) { responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, requestQuery); } else { if (!_catalog.Capabilities.GetRecords_IsSoapEndPoint) { responseText = _cswClient.SubmitHttpRequest("POST", requestUrl, requestQuery); } else { responseText = _cswClient.SubmitHttpRequest("SOAP", requestUrl, requestQuery); } } // parse out csw search records CswRecords records = new CswRecords(); sb.AppendLine(DateTime.Now + " Response received : " + responseText); if (_catalog.Profile.isOGCRecords) { profile.ReadOGCAPIRecordsResponse(responseText, records); } else { profile.ReadCSWGetRecordsResponse(responseText, records); } sb.AppendLine(DateTime.Now + " Parsed GetRecords response."); // populate CSW response _response.ResponseXML = responseText; _response.Records = records; writeLogMessage(sb.ToString()); }
/// <summary> /// Retrieve metadata from CSW service by its ID /// </summary> /// <param name="DocID">Metadata document ID</param> public bool GetMetadataByID(string DocID, bool bApplyTransform) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; writeLogMessage(" Csw profile used : " + profile.Name); // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); bool isTransformed = false; if (bApplyTransform) { isTransformed = profile.TransformCSWGetMetadataByIDResponse(responseText, record); if (isTransformed) { sb.AppendLine(DateTime.Now + " Transformed xml : " + record.FullMetadata); } } else { record.FullMetadata = responseText; } /*if (!isTransformed) * { * XmlDocument responseXml = new XmlDocument(); * try { responseXml.LoadXml(responseText); } * catch (XmlException xmlEx) * { * throw new XmlException("Error occurred \r\n" + xmlEx.Message); * } * record.FullMetadata = responseXml.FirstChild.InnerText ; * }*/ // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) { sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); } writeLogMessage(sb.ToString()); return(isTransformed); }
/// <summary> /// To retrieve informations about the CSW service. /// </summary> /// <remarks> /// </remarks> /// <param name="param1">capabilities baseurl</param> /// <returns>Response the get capabilities url</returns> private string GetCapabilities(string capabilitiesurl) { try { CswClient client = new CswClient(); Utils.logger.writeLog("GetCapabilities url : " + capabilitiesurl); string response = client.SubmitHttpRequest("GET", capabilitiesurl, ""); Utils.logger.writeLog("GetCapabilities response : " + response); //Console.WriteLine() XmlDocument xmlDoc = new XmlDocument(); if (response == null) return null ; xmlDoc.LoadXml(response); XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable); if (this.Profile.CswNamespace.Length <= 0) { this.Profile.CswNamespace = CswProfiles.DEFAULT_CSW_NAMESPACE; } xmlnsManager.AddNamespace("ows", "http://www.opengis.net/ows"); xmlnsManager.AddNamespace("csw", this.Profile.CswNamespace); xmlnsManager.AddNamespace("wrs10", "http://www.opengis.net/cat/wrs/1.0"); xmlnsManager.AddNamespace("wrs", "http://www.opengis.net/cat/wrs"); xmlnsManager.AddNamespace("xlink", "http://www.w3.org/1999/xlink"); xmlnsManager.AddNamespace("wcs", "http://www.opengis.net/wcs"); if (xmlDoc.SelectSingleNode("/csw:Capabilities|/wrs:Capabilities| /wrs10:Capabilities | /wcs:WCS_Capabilities", xmlnsManager) != null) return response; else return null; } catch (Exception ex) { Utils.logger.writeLog(ex.StackTrace); throw ex; } }
/// <summary> /// Search CSW catalog using the provided criteria. Search result can be accessed by calling GetResponse(). /// </summary> public void Search() { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (_criteria == null) { sb.AppendLine(DateTime.Now + " Criteria not specified."); throw new NullReferenceException("Criteria not specified."); } if (_catalog == null) { sb.AppendLine(DateTime.Now + " Catalog not specified."); throw new NullReferenceException("Catalog not specified."); } if (_catalog.URL == null || _catalog.URL.Length == 0) { sb.AppendLine(DateTime.Now + " Catalog URL not specified."); throw new NullReferenceException("Catalog URL not specified."); } if (_catalog.Profile == null) { sb.AppendLine(DateTime.Now + " Catalog profile not specified."); throw new NullReferenceException("Catalog profile not specified."); } CswProfile profile = _catalog.Profile; writeLogMessage("Csw profile used : " + profile.Name); // generate getRecords query string requestUrl = _catalog.Capabilities.GetRecords_PostURL; string requestQuery = profile.GenerateCSWGetRecordsRequest(_criteria); // requestQuery = "<csw:GetCapabilities xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" request=\"GetCapabilities\" service=\"CSW\" version=\"2.0.2\"/>"; requestQuery = requestQuery.Replace("utf-16", "utf-8"); requestQuery = requestQuery.Replace("UTF-16", "UTF-8"); // submit search query if (_cswClient == null) { _cswClient = new CswClient(); } string responseText; sb.AppendLine(DateTime.Now + " Sending CSW GetRecords request to endpoint : " + requestUrl); sb.AppendLine("Request Query : " + requestQuery); if(!_catalog.Capabilities.GetRecords_IsSoapEndPoint) responseText = _cswClient.SubmitHttpRequest("POST", requestUrl, requestQuery); else responseText = _cswClient.SubmitHttpRequest("SOAP", requestUrl, requestQuery); // parse out csw search records CswRecords records = new CswRecords(); sb.AppendLine(DateTime.Now + " Response received : " + responseText); profile.ReadCSWGetRecordsResponse(responseText, records); sb.AppendLine(DateTime.Now + " Parsed GetRecords response."); // populate CSW response _response.ResponseXML = responseText; _response.Records = records; writeLogMessage(sb.ToString()); }
/// <summary> /// Get Add to map information /// </summary> /// <param name="DocID">document identifier</param> public void GetAddToMapInfoByID(string DocID) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { sb.AppendLine(DateTime.Now + " GetRecordByID URL not specified for the catalog capabilities."); throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); profile.ReadCSWGetMetadataByIDResponse(responseText, record); if (record.MetadataResourceURL != null && record.MetadataResourceURL.Equals("") && profile.Name.Equals("terra catalog CSW 2.0.2 AP ISO")) { record.FullMetadata = responseText; } if (record == null) { throw new NullReferenceException("Record not populated."); } // check if full metadata or resourceURL has been returned bool hasFullMetadata = !(record.FullMetadata == null || record.FullMetadata == ""); bool hasResourceUrl = !(record.MetadataResourceURL == null || record.MetadataResourceURL == ""); if (!hasFullMetadata && !hasResourceUrl) { // throw new InvalidOperationException("Neither full metadata nor metadata resource URL was found for the CSW record."); } else if (!hasFullMetadata && record.MetadataResourceURL != null) { // need to load metadata from resource URL responseText = _cswClient.SubmitHttpRequest("GET", record.MetadataResourceURL, "", "", ""); record.FullMetadata = responseText; } // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); writeLogMessage(sb.ToString()); }
/// <summary> /// Retrieve metadata from CSW service by its ID /// </summary> /// <param name="DocID">Metadata document ID</param> public bool GetMetadataByID(string DocID, bool bApplyTransform) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; writeLogMessage(" Csw profile used : " + profile.Name); // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); bool isTransformed = false; if (bApplyTransform) { isTransformed = profile.TransformCSWGetMetadataByIDResponse(responseText, record); if(isTransformed) sb.AppendLine(DateTime.Now + " Transformed xml : " + record.FullMetadata); } else { record.FullMetadata = responseText; } /*if (!isTransformed) { XmlDocument responseXml = new XmlDocument(); try { responseXml.LoadXml(responseText); } catch (XmlException xmlEx) { throw new XmlException("Error occurred \r\n" + xmlEx.Message); } record.FullMetadata = responseXml.FirstChild.InnerText ; }*/ // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); writeLogMessage(sb.ToString()); return isTransformed; }