Пример #1
0
        public datacontract.metadataResponse searchAll(string q,
                                                       string themekey     = "", string orgName      = "", string dataType = "", string siteId = "",
                                                       string inspiretheme = "", string inspireannex = "", string inspireServiceType = "")
        {
            datacontract.metadataResponse metaResp = search(
                q, 1, 20, themekey, orgName, dataType, siteId, inspireannex, inspireServiceType);

            for (int i = 21; i < metaResp.maxCount; i += 20)
            {
                datacontract.metadataResponse metaResp2 = search(
                    q, i, i + 19, themekey, orgName, dataType, siteId, inspireannex, inspireServiceType);

                metaResp.metadataRecords.AddRange(metaResp2.metadataRecords);
            }
            metaResp.to = metaResp.maxCount;
            return(metaResp);
        }
Пример #2
0
        public datacontract.metadataResponse search(string q, int start = 1, int to               = 20,
                                                    string themekey     = "", string orgName      = "", string dataType = "", string siteId = "",
                                                    string inspiretheme = "", string inspireannex = "", string inspireServiceType = "")
        {
            qryValues.Add("fast", "index");
            qryValues.Add("sortBy", "changeDate");
            if (q != "" && q != null)
            {
                qryValues.Add("any", "*" + q + "*");
            }
            qryValues.Add("from", start.ToString());
            qryValues.Add("to", to.ToString());
            if (themekey != "")
            {
                qryValues.Add("themekey", ("\"" + themekey + "\"").Replace("&", "%26"));
            }
            if (orgName != "")
            {
                qryValues.Add("orgName", "\"" + orgName + "\"");
            }
            if (dataType != "")
            {
                qryValues.Add("type", dataType);
            }
            if (siteId != "")
            {
                qryValues.Add("siteId", siteId);
            }
            if (inspiretheme != "")
            {
                qryValues.Add("inspiretheme", inspiretheme);
            }
            if (inspireannex != "")
            {
                qryValues.Add("inspireannex", inspireannex);
            }
            if (inspireServiceType != "")
            {
                qryValues.Add("inspireServiceType", inspireServiceType);
            }

            client.QueryString = qryValues;

            Uri url = new Uri(geoNetworkUrl + "/q");

            string   xmlDoc  = client.DownloadString(url);
            XElement element = XElement.Parse(xmlDoc);

            int maxCount; int from; int xto;

            int.TryParse(element.Element("summary").Attribute("count").Value, out maxCount);
            int.TryParse(element.Attribute("from").Value, out from);
            int.TryParse(element.Attribute("to").Value, out xto);

            datacontract.metadataResponse metaResp = new datacontract.metadataResponse()
            {
                from = from, to = xto, maxCount = maxCount
            };
            List <datacontract.metadata> metaList = new List <datacontract.metadata>();
            IEnumerable <XElement>       sources  = element.Elements("metadata");

            foreach (var item in sources)
            {
                datacontract.metadata meta = new datacontract.metadata();
                XNamespace            ns   = "http://www.fao.org/geonetwork";

                var xsource   = item.Element(ns + "info");
                var xtitle    = item.Element("title");
                var xabstract = item.Element("abstract");

                if (xsource == null || xtitle == null)
                {
                    continue;
                }

                meta.sourceID = xsource.Element("uuid").Value;
                meta.title    = xtitle.Value;
                if (xabstract != null)
                {
                    meta.description = xabstract.Value;
                }
                else
                {
                    meta.description = "";
                }
                meta.links = new List <string>();
                foreach (var elem in item.Elements("link"))
                {
                    meta.links.Add(elem.Value);
                }
                metaList.Add(meta);
            }
            metaResp.metadataRecords = metaList;

            qryValues.Clear();
            client.QueryString.Clear();

            return(metaResp);
        }
Пример #3
0
        public datacontract.metadataResponse search(string q, int start = 1, int to = 20, 
            string themekey="", string orgName="", string dataType="", string siteId="", 
            string inspiretheme="", string inspireannex="", string inspireServiceType="")
        {
            qryValues.Add("fast", "index");
            qryValues.Add("sortBy", "changeDate");
            if (q != "" && q != null) qryValues.Add("any", "*" + q + "*");
            qryValues.Add("from", start.ToString());
            qryValues.Add("to", to.ToString());
            if (themekey != "") qryValues.Add("themekey", ("\"" + themekey + "\"").Replace("&", "%26"));
            if (orgName != "") qryValues.Add("orgName", "\"" + orgName + "\"" );
            if (dataType != "") qryValues.Add("type", dataType);
            if (siteId != "") qryValues.Add("siteId", siteId);
            if (inspiretheme != "") qryValues.Add("inspiretheme", inspiretheme);
            if (inspireannex != "") qryValues.Add("inspireannex", inspireannex);
            if (inspireServiceType != "") qryValues.Add("inspireServiceType", inspireServiceType);

            client.QueryString = qryValues;

            Uri url = new Uri(geoNetworkUrl + "/q");

            string xmlDoc = client.DownloadString(url);
            XElement element = XElement.Parse(xmlDoc);

            int maxCount; int from; int xto ;
            int.TryParse( element.Element("summary").Attribute("count").Value , out maxCount);
            int.TryParse(element.Attribute("from").Value, out from);
            int.TryParse(element.Attribute("to").Value, out xto);

            datacontract.metadataResponse metaResp = new datacontract.metadataResponse()
                                {from = from, to=xto, maxCount=maxCount };
            List<datacontract.metadata> metaList = new List<datacontract.metadata>();
            IEnumerable<XElement> sources = element.Elements("metadata");
            foreach (var item in sources)
            {
                datacontract.metadata meta = new datacontract.metadata();
                XNamespace ns = "http://www.fao.org/geonetwork";

                var xsource = item.Element(ns + "info");
                var xtitle = item.Element("title");
                var xabstract = item.Element("abstract");

                if (xsource == null || xtitle == null) continue;

                meta.sourceID = xsource.Element("uuid").Value;
                meta.title = xtitle.Value;
                if (xabstract != null) meta.description = xabstract.Value;
                else meta.description = "";
                meta.links = new List<string>();
                foreach (var elem in item.Elements("link"))
                {
                    meta.links.Add(elem.Value);
                }
                metaList.Add(meta);
            }
            metaResp.metadataRecords = metaList ;

            qryValues.Clear();
            client.QueryString.Clear();

            return metaResp;
        }