// Get Add to map information 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() { try { _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; // generate getRecords query string requestUrl = _catalog.Capabilities.GetRecords_PostURL; //Set Breakpoint to see transformed request (use xml viewer on tooltip variable) string requestQuery = profile.GenerateCSWGetRecordsRequest(_criteria); sb.AppendLine("Untransformed Request Query : " + profile.LastUntransformedGetRecordsRequest.InnerXml); // 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()); } catch (Exception e) { writeLogMessage(DateTime.Now + " " + e.ToString()); } }
/// <summary> /// Parse a CSW response. /// </summary> /// <remarks> /// The CSW response is parsed and the records collection is populated /// with the result.The reponse is parsed based on the response xslt. /// </remarks> /// <param name="param1">The string response</param> /// <param name="param2">The recordlist which needs to be populated</param> public void ReadCSWGetRecordsResponse(string responsestring, CswRecords recordslist) { try { TextReader textreader = new StringReader(responsestring); XmlTextReader xmltextreader = new XmlTextReader(textreader); //load the Xml doc XPathDocument xPathDoc = new XPathDocument(xmltextreader); if (responsexsltobj == null) { responsexsltobj = new XslCompiledTransform(); XsltSettings settings = new XsltSettings(true, true); responsexsltobj.Load(responsexslt,settings, new XmlUrlResolver() ); } //create the output stream StringWriter writer = new StringWriter(); //do the actual transform of Xml responsexsltobj.Transform(xPathDoc, null, writer); writer.Close(); //populate CswRecords XmlDocument doc = new XmlDocument(); doc.LoadXml(writer.ToString()); recordslist.SetNumberOfRecordsMatched(doc); XmlNodeList xmlnodes = doc.GetElementsByTagName("Record"); foreach (XmlNode xmlnode in xmlnodes) { CswRecord record = new CswRecord(); record.ID = xmlnode.SelectSingleNode ("ID").InnerText; record.Title = xmlnode.SelectSingleNode("Title").InnerText; record.ResponsibleOrganisation = xmlnode.SelectSingleNode("ReponsibleOrganisation").InnerText; record.MetadataVersion = xmlnode.SelectSingleNode("MetadataVersion").InnerText; record.Abstract = xmlnode.SelectSingleNode("Abstract").InnerText; String lowercorner = ""; if(this.SupportSpatialBoundary){ lowercorner = xmlnode.SelectSingleNode("LowerCorner").InnerText; } String uppercorner = ""; if (this.SupportSpatialBoundary){ uppercorner = xmlnode.SelectSingleNode("UpperCorner").InnerText; } if ((lowercorner.Length>0 && uppercorner.Length>0 )) { /* record.BoundingBox.Maxx = Double.Parse(lowercorner.Substring(0, lowercorner.IndexOf(' '))); record.BoundingBox.Miny = Double.Parse(lowercorner.Substring(lowercorner.IndexOf(' ') + 1)); record.BoundingBox.Minx = Double.Parse(uppercorner.Substring(0, uppercorner.IndexOf(' '))); record.BoundingBox.Maxy = Double.Parse(uppercorner.Substring(uppercorner.IndexOf(' ') + 1));*/ Boolean parseFlag = false; CultureInfo cultureInfo = new CultureInfo("en-us"); double pareseResult = 0.0; parseFlag = Double.TryParse(lowercorner.Substring(0, lowercorner.IndexOf(' ')), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Minx = pareseResult; parseFlag = Double.TryParse(lowercorner.Substring(lowercorner.IndexOf(' ') + 1), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Miny = pareseResult; parseFlag = Double.TryParse(uppercorner.Substring(0, uppercorner.IndexOf(' ')), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Maxx = pareseResult; parseFlag = Double.TryParse(uppercorner.Substring(uppercorner.IndexOf(' ') + 1), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Maxy = pareseResult; if (parseFlag == false) { throw new Exception("Number format error"); } } else { record.BoundingBox.Maxx = 500.00; record.BoundingBox.Miny = 500.00; record.BoundingBox.Minx = 500.00; record.BoundingBox.Maxy = 500.00; } XmlNode node = xmlnode.SelectSingleNode("Type"); if (node != null) { record.IsLiveDataOrMap = node.InnerText.Equals("liveData", StringComparison.OrdinalIgnoreCase); } else { record.IsLiveDataOrMap = false; } XmlNode referencesNode = xmlnode.SelectSingleNode("References"); if (referencesNode != null) { String references = referencesNode.InnerText; DcList list = new DcList(); list.add(references); record.SetServiceProps(list); } else { record.MapServerURL = String.Empty; } recordslist.AddRecord(record.ID, record); } } catch (Exception e) { throw e; } //return recordslist; }
/// <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; // 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> /// Constructor /// </summary> public CswSearchResponse() { _responseXML = ""; _records = new CswRecords(); }
/// <summary> /// Search CSW catalog using the provided criteria. Search result can be accessed by calling GetResponse(). /// </summary> public void Search() { try { _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; // generate getRecords query string requestUrl = _catalog.Capabilities.GetRecords_PostURL; //Set Breakpoint to see transformed request (use xml viewer on tooltip variable) string requestQuery = profile.GenerateCSWGetRecordsRequest(_criteria); sb.AppendLine("Untransformed Request Query : " + profile.LastUntransformedGetRecordsRequest.InnerXml); // 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()); } catch (Exception e) { writeLogMessage(DateTime.Now + " " + e.ToString()); } }
// Get Add to map information 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; // 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); }