Example #1
0
        public XElement[] GetOpenSearchEntries(OpenSearchRequest request)
        {
            Func <string, IEnumerable <XElement> > parseEntriesAlias = (string input) => {
                var doc  = XDocument.Parse(input);
                var root = Utils.RemoveAllNamespaces(doc.Root);
                var el1  = root.Elements("entry");
                return(el1);
            };

            IEnumerable <XElement> result = new List <XElement>();

            try {
                var response     = GetAsString(new Uri("https://scihub.copernicus.eu/" + request.ToString()));
                var root         = Utils.RemoveAllNamespaces(XDocument.Parse(response).Root);
                var totalResults = Convert.ToInt32(root.Element("totalResults").Value);
                var itemsPerPage = Convert.ToInt32(root.Element("itemsPerPage").Value);

                result = result.Concat(parseEntriesAlias(response));

                for (int current = itemsPerPage; current < totalResults; current += itemsPerPage)
                {
                    request.start = current;
                    response      = GetAsString(new Uri("https://scihub.copernicus.eu/" + request.ToString()));
                    result        = result.Concat(parseEntriesAlias(response));
                }
            } catch (Exception ex) {
                _log.LogError(ex, "Loading entries failed with error!");
            }
            return(result.ToArray());
        }
 public static IEnumerable <XElement> LoadAllEntries(WebClient client, OpenSearchRequest request) => LoadAllEntries(client, request.ToString());