예제 #1
0
        /// <summary>
        /// Generates the catalogue syndication feed.
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="parameters">Parameters.</param>
        public AtomFeed GenerateCatalogueAtomFeed(NameValueCollection parameters)
        {
            UriBuilder myUrl = new UriBuilder(context.BaseUrl + "/" + Name);

            string[] queryString = Array.ConvertAll(parameters.AllKeys, key => String.Format("{0}={1}", key, parameters[key]));
            myUrl.Query = string.Join("&", queryString);

            AtomFeed feed = new AtomFeed("Discovery feed for Tep QuickWin",
                                         "This OpenSearch Service allows the discovery of the Tep Quickwin Digital Repository" +
                                         "This search service is in accordance with the OGC 10-032r3 specification.",
                                         myUrl.Uri, myUrl.ToString(), DateTimeOffset.UtcNow);

            feed.Generator = "Terradue Web Server";

            List <AtomItem> items = new List <AtomItem>();

            // Load all avaialable Datasets according to the context
            EntityList <Series> series = new EntityList <Series>(context);

            series.Load();
            var pds = new Terradue.OpenSearch.Request.PaginatedList <Series>();

            int startIndex = 0;

            if (parameters["startIndex"] != null)
            {
                startIndex = int.Parse(parameters["startIndex"]);
            }

            pds.AddRange(series);

            pds.PageNo = 1;
            if (parameters["startPage"] != null)
            {
                pds.PageNo = int.Parse(parameters["startPage"]);
            }

            pds.PageSize = 20;
            if (parameters["count"] != null)
            {
                pds.PageSize = int.Parse(parameters["count"]);
            }

            pds.StartIndex = startIndex;

            feed.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", "data/collection");

            foreach (Series s in pds.GetCurrentPage())
            {
                Uri alternate = new Uri(context.BaseUrl + "/" + Name + "/" + s.Identifier + "/search?count=0");
                Uri id        = new Uri(context.BaseUrl + "/" + Name + "/" + s.Identifier);

                AtomItem entry = new AtomItem(s.Name, s.Description, alternate, id.ToString(), DateTime.UtcNow);

                entry.Summary = new TextSyndicationContent(s.Name);
                entry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", s.Identifier);

                UriBuilder search = new UriBuilder(context.BaseUrl + "/" + Name + "/" + s.Identifier + "/description");
                entry.Links.Add(new SyndicationLink(search.Uri, "search", s.Name, "application/atom+xml", 0));

                items.Add(entry);
            }

            feed.Items = items;

            return(feed);
        }
        private AtomFeed GenerateSyndicationFeed(NameValueCollection parameters)
        {
            AtomFeed feed = new AtomFeed("Discovery feed for WPS output",
                                         "This OpenSearch Service allows the discovery of the different items which are part of the local CIOP results. " +
                                         "This search service is in accordance with the OGC 10-032r3 specification.",
                                         new Uri(context.BaseUrl), context.BaseUrl.ToString(), DateTimeOffset.UtcNow);



            feed.Generator = "Terradue OpenSearch WPS Output generator";

            List <AtomItem> items = new List <AtomItem>();

            var pds = new Terradue.OpenSearch.Request.PaginatedList <ExecuteResponseOutput>();



            if (execResponse.ProcessOutputs != null || execResponse.ProcessOutputs.Count() > 0)
            {
                List <OutputDataType> outputs = new List <OutputDataType>();

                if (!string.IsNullOrEmpty(parameters["q"]))
                {
                    string q = parameters["q"];
                    outputs = execResponse.ProcessOutputs.Where(p => p.Abstract.Value.ToLower().Contains(q.ToLower()) || (p.Identifier.Value.ToLower().Contains(q.ToLower()))).ToList();
                }

                if (!string.IsNullOrEmpty(parameters["uid"]))
                {
                    outputs = outputs.Where(p => p.Identifier.Value == parameters["uid"]).ToList();
                }


                pds.AddRange(outputs.Select(o => new ExecuteResponseOutput(o, context)));
            }

            pds.StartIndex = 1;
            if (!string.IsNullOrEmpty(parameters["startIndex"]))
            {
                pds.StartIndex = int.Parse(parameters["startIndex"]);
            }

            pds.PageNo = 1;
            if (!string.IsNullOrEmpty(parameters["startPage"]))
            {
                pds.PageNo = int.Parse(parameters["startPage"]);
            }

            pds.PageSize = 20;
            if (!string.IsNullOrEmpty(parameters["count"]))
            {
                pds.PageSize = int.Parse(parameters["count"]);
            }

            if (this.Identifier != null)
            {
                feed.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier);
            }

            foreach (var o in pds.GetCurrentPage())
            {
                AtomItem item = (o as IAtomizable).ToAtomItem(parameters);
                if (item != null)
                {
                    items.Add(item);
                }
            }

            feed.Items = items;

            return(feed);
        }