Esempio n. 1
0
        /// <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;

        }
Esempio n. 2
0
        // 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());
    }
Esempio n. 3
0
        /// <summary>
        /// Read a CSW metadata response. 
        /// </summary>
        /// <remarks>
        /// The CSW metadata response is read.
        /// The CSw record is updated with the metadata
        /// </remarks>
        /// <param name="param1">The metadata response string</param>
        /// <param name="param2">The CSW record for the record</param>
        public void ReadCSWGetMetadataByIDResponse(string response,CswRecord record) {
            if (metadataxslt == null || metadataxslt.Equals("")) {
                record.FullMetadata = response;
                record.MetadataResourceURL = "";
            }
            else {
                //create the output stream
                StringWriter writer = new StringWriter();

                    TextReader textreader = new StringReader(response);
                    XmlTextReader xmltextreader = new XmlTextReader(textreader);
                    //load the Xml doc
                    XPathDocument xpathDoc = new XPathDocument(xmltextreader);
                    if (metadataxsltobj == null)
                    {
                        metadataxsltobj = new XslCompiledTransform();
                        //enable document() support
                        XsltSettings settings = new XsltSettings(true, true);
                        metadataxsltobj.Load(metadataxslt, settings, new XmlUrlResolver());

                    }

                                
                   //do the actual transform of Xml
                   metadataxsltobj.Transform(xpathDoc, null, writer);

                writer.Close();

                // full metadata or resource url
                String outputStr = writer.ToString();

                if (IsUrl(outputStr))
                {

                    if (outputStr.Contains("\u2715"))
                    {
                        DcList list = new DcList();
                        list.add(outputStr);

                        LinkedList<String> serverList = list.get(DcList.getScheme(DcList.Scheme.SERVER));
                        LinkedList<String> documentList = list.get(DcList.getScheme(DcList.Scheme.METADATA_DOCUMENT));

                        
                        if (serverList.Count > 0){
                            String serviceType = DeduceProtocolFromURL(serverList.First.Value);
                            if (serviceType.Equals("aims") || serviceType.Equals("ags") || serviceType.Equals("wms") || serviceType.Equals("wcs"))
                            {
                                record.MapServerURL = serverList.First.Value;
                            }
                        }
                        else
                            record.MapServerURL = "";

                        if(documentList.Count > 0)
                            record.MetadataResourceURL = documentList.First.Value;

                    }
                    else
                    {
                        if (DeduceProtocolFromURL(response).Equals("ags"))
                        {

                            outputStr = outputStr.Replace("http", "|http");
                            string[] s = outputStr.Split('|');
                            for (int i = 0; i < s.Length; i++)
                            {
                                if (s[i].ToString().Contains("MapServer"))
                                    record.MapServerURL = s[i];
                                else
                                    record.MetadataResourceURL = s[i];
                            }
                        }
                        else
                        {
                            record.MapServerURL = "";
                            record.MetadataResourceURL = outputStr;
                        }
                    }



                    record.FullMetadata = "";

                }
                else
                {
                    record.MapServerURL = "";
                    record.MetadataResourceURL = "";
                    record.FullMetadata = outputStr;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Transform a CSW metadata response. 
        /// </summary>
        /// <remarks>
        /// The CSW metadata response is read.
        /// The CSw record is updated with the metadata
        /// </remarks>
        /// <param name="param1">The metadata response string</param>
        /// <param name="param2">The CSW record for the record</param>
        public bool TransformCSWGetMetadataByIDResponse(string response, CswRecord record)
        {
            if (xsltStyledResponse == null || xsltStyledResponse.Equals(""))
            {
                record.FullMetadata = response;
                record.MetadataResourceURL = "";
                return false;
            }
            else
            {
                //create the output stream
                StringWriter writer = new StringWriter();

                TextReader textreader = new StringReader(response);
                XmlTextReader xmltextreader = new XmlTextReader(textreader);
                //load the Xml doc
                XPathDocument xpathDoc = new XPathDocument(xmltextreader);
                if (displayResponseXsltObj == null)
                {
                    displayResponseXsltObj = new XslCompiledTransform();
                    //enable document() support
                    XsltSettings settings = new XsltSettings(true, true);
                    displayResponseXsltObj.Load(xsltStyledResponse, settings, new XmlUrlResolver());

                }


                //do the actual transform of Xml
                displayResponseXsltObj.Transform(xpathDoc, null, writer);

                writer.Close();

                // full metadata or resource url
                String outputStr = writer.ToString();
                record.MapServerURL = "";
                record.MetadataResourceURL = "";
                record.FullMetadata = outputStr;

                return true;
            }
        }
Esempio n. 5
0
        private void AddLayerWFS(CswRecord cswrecord)
        {
            string urlEndpoint = cswrecord.MapServerURL;
            
            string getFeatureUrl = BuildGetFeatureRequest(urlEndpoint);

            string wfsDownloadFolder = MakeValidFileName(urlEndpoint);
            //string downloadFileName = System.IO.Path.Combine(Utils.GetSpecialFolderPath(SpecialFolder.Temp), "PDOK");
            //downloadFileName = System.IO.Path.Combine(downloadFileName, wfsDownloadFolder);
            //System.IO.Directory.CreateDirectory(downloadFileName);
            //downloadFileName = System.IO.Path.Combine(downloadFileName, "shapes.zip");

            //Replaced the above by explicit user interaction to specify filename (requested by RWS because they expect most users dont have the right to create a file in the temp folder (?)
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "Zip file|*.zip";
            saveFileDialog1.DefaultExt = "zip";
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.Title = "WFS zipped shape opslaan als";
            saveFileDialog1.FileName = wfsDownloadFolder + ".zip";
            DialogResult dlgResult = saveFileDialog1.ShowDialog();
            if (String.IsNullOrEmpty(saveFileDialog1.FileName)||dlgResult == System.Windows.Forms.DialogResult.Cancel) return;
            string downloadFileName = saveFileDialog1.FileName;

            try
            {
                if (System.IO.File.Exists(downloadFileName))
                    System.IO.File.Delete(downloadFileName);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "File delete failed");
            }

            if (!DownloadShapeZip(getFeatureUrl, downloadFileName)) return;
            string extractedFilesFolder = downloadFileName.Replace(".zip", "");
            Unzip(downloadFileName,extractedFilesFolder);
            AddShapesFromDirToFocusMap(extractedFilesFolder, cswrecord.Title);
        }
Esempio n. 6
0
        /// <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;

        }
Esempio n. 7
0
 private void AddLayerTMS(CswRecord cswrecord)
 {
 }
Esempio n. 8
0
        private void AddLayerWMTS(CswRecord cswrecord)
        {
            //string url = @"http://gisdemo.agro.nl/wmts/PDOK_wmts_met_bbox_groot.xml";
            //string url = "http://acceptatie." + cswrecord.MapServerURL.Substring(7, cswrecord.MapServerURL.Length - 7);
            string url = cswrecord.MapServerURL;
            int lastIndex = cswrecord.MapServerURL.LastIndexOf('/') + 1;
            int length = cswrecord.MapServerURL.IndexOf('?') - lastIndex;
            string layerTitle = cswrecord.MapServerURL.Substring(lastIndex, length);

            try
            {
                IPropertySet propertySet = new PropertySetClass();
                propertySet.SetProperty("URL", url);

                IMxDocument mxDoc = (IMxDocument)m_application.Document;
                IMap map = (IMap)mxDoc.FocusMap;
                IActiveView activeView = (IActiveView)map;

                IWMTSConnectionFactory wmtsconnFact = new WMTSConnectionFactoryClass();
                IWMTSConnection wmtsconn = wmtsconnFact.Open(propertySet, 0, null);
                IWMTSServiceDescription wmtsServiceDesc = (IWMTSServiceDescription)wmtsconn;
                
                //Get WMTSConnectionName
                IWMTSConnectionName wmtsConnectionName = (IWMTSConnectionName)wmtsconn.FullName;

                for (int i = 0; i < wmtsServiceDesc.LayerDescriptionCount; i++)
                {
                    IWMTSLayerDescription ld = wmtsServiceDesc.get_LayerDescription(i);

                    IPropertySet layerPropertiesSet = wmtsConnectionName.ConnectionProperties;
                    //Set the layer name and assign this to the WMTSConnectionName
                    layerPropertiesSet.SetProperty("LAYERNAME", ld.Identifier);
                    wmtsConnectionName.ConnectionProperties = layerPropertiesSet;

                    if (ld.Title == layerTitle)//cswrecord.Title)
                    {
                        bool connected = false;
                        try
                        {
                            IWMTSLayer wmtslayer = new WMTSLayerClass();
                            
                            //Pass in the Name with layerIdentifier.
                            connected = wmtslayer.Connect((IName)wmtsConnectionName);

                            map.AddLayer((ILayer)wmtslayer);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + "url:" + url + "\r\n" + ex.Message);
                            connected = false;
                        }
                    }
                }

                return;
            }
            catch (Exception ex)
            {
                //TODO: wmts string resource aanmaken?
                ShowErrorMessageBox(StringResources.AddWmsLayerFailed + "\r\n" + ex.Message);
            }
        }
Esempio n. 9
0
 private void AddMapServiceLayer(CswRecord cswrecord, string sldForWMS)
 {
     MapServiceInfo msinfo = new MapServiceInfo();
     msinfo.Server = cswrecord.MapServerURL;
     msinfo.Service = cswrecord.ServiceName;
     msinfo.ServiceType = cswrecord.Protocol;
     CswProfile.ParseServiceInfoFromUrl(msinfo, cswrecord.MapServerURL, cswrecord.Protocol);
     switch (cswrecord.Protocol.ToUpper())
     {
         case "WMS":
         case "OGC:WMS":
             AddLayerWMS(msinfo, true,sldForWMS);
             break;
         case "WCS":
         case "OGC:WCS":
             AddLayerWCS(cswrecord.MapServerURL);
             break;
         case "OGC:WMTS"://"TMS":
         case "UKST":
             AddLayerWMTS(cswrecord);//AddLayerTMS(cswrecord);
             break;
         case "WFS":
         case "OGC:WFS":
             AddLayerWFS(cswrecord);
             break;
         case "AGS":
             string url = String.Empty;
             url = cswrecord.MapServerURL;
             if (url.ToLower().Contains("arcgis/rest"))
             {
                 url = url + "?f=lyr";
                 CswClient client = new CswClient();
                 AddAGSService(client.SubmitHttpRequest("DOWNLOAD", url, ""));
             }
             else
             {
                 AddAGSService(url);
             }
             break;
         case "AIMS":
             AddLayerArcIMS(msinfo);
             break;
         default: 
             MessageBox.Show(String.Format("Adding data of type {0} is not implemented yet.",cswrecord.Protocol.ToUpper()));
             break;
     }
 }
Esempio n. 10
0
        // 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());
        }
Esempio n. 11
0
        /// <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);
        }
Esempio n. 12
0
 public void AddRecord(object key, CswRecord record) {
     base.Add(key, record);
 }
Esempio n. 13
0
 public void AddRecord(object key, CswRecord record)
 {
     base.Add(key, record);
 }