상속: SyndicationFeed, IOpenSearchResultCollection
예제 #1
0
        public void WPSAtomToJsonTest()
        {
            FileStream wps = new FileStream("../Samples/wps.xml", FileMode.Open);

            AtomFeed feed = new AtomFeed(DeserializeFromStream(wps));

            FeatureCollectionResult fc = FeatureCollectionResult.FromOpenSearchResultCollection(feed);

            Assert.That(((Dictionary<string, object>)fc.FeatureResults.First().Properties["offering"])["operation"] is List<object>);
        }
예제 #2
0
 public AtomFeed(AtomFeed feed, bool cloneItems = false)
     : base(feed, false)
 {
     if (cloneItems == true) {
         items = feed.items.Select(i => new AtomItem(i)).ToList();
     } else
         items = feed.items;
     QueryTimeSpan = feed.QueryTimeSpan;
     OpenSearchable = feed.OpenSearchable;
     Parameters = feed.Parameters;
     TotalResults = feed.TotalResults;
 }
        public void FromLandsat8_2AtomTest()
        {
            XmlReader reader = XmlReader.Create("../Samples/landsat8-2.atom");
            SyndicationFeed feed = SyndicationFeed.Load(reader);
            AtomFeed atom = new AtomFeed(feed);

            FeatureCollectionResult col = FeatureCollectionResult.FromOpenSearchResultCollection(atom);

            Assert.That(col.Features[0].Geometry != null);

            var jsont = col.SerializeToString();

            JToken json = JToken.Parse(jsont);

            Assert.That(json.SelectToken("features").First().SelectToken("properties").SelectToken("authors").First().SelectToken("name").ToString().Contains("EROS"));

            Assert.AreEqual(json.SelectToken("features").First().SelectToken("properties").SelectToken("polygon").ToString().Split(' ').First(),
                            (col.Features[0].Geometry as Polygon).Coordinates.First().First()[1].ToString());
        }
        public void FromLandsat8AtomTest()
        {
            XmlReader reader = XmlReader.Create("../Samples/landsat8.atom");
            SyndicationFeed feed = SyndicationFeed.Load(reader);
            AtomFeed atom = new AtomFeed(feed);

            FeatureCollectionResult col = FeatureCollectionResult.FromOpenSearchResultCollection(atom);

            Assert.That(col.Features[0].Geometry != null);

            var jsont = col.SerializeToString();

            JToken json = JToken.Parse(jsont);

            Assert.AreEqual("ceos", json.SelectToken("properties").SelectToken("authors").First().SelectToken("identifier").ToString());
            Assert.AreEqual("eros", json.SelectToken("features").First().SelectToken("properties").SelectToken("authors").First().SelectToken("identifier").ToString());

            Assert.AreEqual("private", json.SelectToken("features").First().SelectToken("properties").SelectToken("categories").First().SelectToken("@label").ToString());
        }
 public AtomFeedOpenSearchable(AtomFeed feed)
 {
     this.feed = feed;
 }
        AtomFeed SearchInAtom(NameValueCollection parameters)
        {
            var alternate = (feed != null && feed.Links != null) ? feed.Links.FirstOrDefault(l => l.RelationshipType == "alternate") : null;
            if(alternate == null) alternate = feed.Links.FirstOrDefault(l => l.RelationshipType == "self");

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

            AtomFeed resultfeed = new AtomFeed("Discovery feed for " + this.Identifier,
                                         "This OpenSearch Service allows the discovery of the different items which are part of the " + this.Identifier + " collection" +
                                         "This search service is in accordance with the OGC 10-032r3 specification.",
                                               alternate != null ? alternate.Uri : new Uri(feed.Id) , feed.Id, DateTimeOffset.UtcNow);

            resultfeed.Generator = "Terradue Web Server";

            // Load all avaialable Datasets according to the context

            PaginatedList<AtomItem> pds = new PaginatedList<AtomItem>();

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

            pds.AddRange(SearchInItem((IEnumerable < AtomItem > )feed.Items, parameters));

            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"]);

            pds.StartIndex = startIndex - 1;

            if (this.Identifier != null)
                resultfeed.Identifier = this.Identifier;

            resultfeed.Items = pds.GetCurrentPage();
            resultfeed.TotalResults = pds.Count(); ;

            return resultfeed;
        }
        public override IOpenSearchResponse GetResponse()
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            AtomFeed feed = new AtomFeed();

            int count = string.IsNullOrEmpty(parameters["count"]) ? 20 : int.Parse(parameters["count"]);
            int page = string.IsNullOrEmpty(parameters["startPage"]) ? 1 : int.Parse(parameters["startPage"]);
            int index = string.IsNullOrEmpty(parameters["startIndex"]) ? 1 : int.Parse(parameters["startIndex"]);
            string type = string.IsNullOrEmpty(parameters["auxtype"]) ? "aux_resorb" : parameters["auxtype"];
            bool withOrbits = parameters["orbits"] == "true";

            int absindex = index + ((page - 1) * count);
            int queryindex = absindex % 20;
            int querypage = (absindex / 20) + 1;

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

            while (items.Count() < count)
            {

                Uri url = BuildUrl(qcBaseUrl, count, index, page, type, parameters["start"], parameters["stop"]);

                var request = HttpWebRequest.Create(url);

                log.DebugFormat("Query: {0}", url);

                HtmlDocument doc = new HtmlDocument();

                using (var response = request.GetResponse())
                {
                    doc.Load(response.GetResponseStream());
                }

                Dictionary<string, Uri> list = new Dictionary<string, Uri>();

                var pagesli = doc.DocumentNode.SelectNodes("/html/body/div/div/div/div[1]/div/ul/li");
                int lastpage = 1;

                if (pagesli != null)
                {
                    lastpage = pagesli.Max(li =>
                    {
                        int pageo = 0;
                        if (int.TryParse(li.FirstChild.InnerText, out pageo))
                            return pageo;
                        return 0;
                    });
                }

                if (lastpage < querypage)
                    break;

                var trs = doc.DocumentNode.SelectNodes("/html/body/div/div/div/div[1]/table/tbody/tr");

                if (trs == null)
                    break;

                foreach (HtmlNode tr in trs)
                {
                    var a = tr.SelectSingleNode("td/a");
                    log.Debug(a.InnerText);
                    HtmlAttribute href = a.Attributes["href"];
                    var producturl = new Uri(string.Format("{0}/{1}/{2}", qcBaseUrl, type, href.Value));
                    log.Debug(producturl);
                    list.Add(a.InnerText, producturl);
                }

                if (list.Count() == 0)
                    break;

                if (items.FirstOrDefault(i => i.Identifier == list.Last().Key.Replace(".EOF", "")) != null)
                    break;

                items.AddRange(BuildAtomItem(list.Skip(queryindex - 1).Take(count - items.Count()), withOrbits));

                queryindex = 1;
                page++;

            }

            feed.Items = items;

            sw.Stop();

            return new Terradue.OpenSearch.Response.AtomOpenSearchResponse(feed, sw.Elapsed);
        }
        private AtomFeed GenerateSyndicationFeed(NameValueCollection parameters)
        {
            UriBuilder myUrl = new UriBuilder("file:///test");
            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 " + this.Identifier,
                                         "This OpenSearch Service allows the discovery of the different items which are part of the " + this.Identifier + " collection" +
                                         "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

            PaginatedList<TestItem> pds = new PaginatedList<TestItem>();

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

            pds.StartIndex = startIndex;
            pds.AddRange(Items);

            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"]);

            if (this.Identifier != null)
                feed.Identifier = this.Identifier;

            foreach (TestItem s in pds.GetCurrentPage()) {

                if (s is IAtomizable) {
                    AtomItem item = (s as IAtomizable).ToAtomItem(parameters);
                    if (item != null)
                        items.Add(item);
                } else {

                    string fIdentifier = s.Identifier;
                    string fName = s.Name;
                    string fText = (s.TextContent != null ? s.TextContent : "");

                    if (!string.IsNullOrEmpty(parameters["q"])) {
                        string q = parameters["q"];
                        if (!(fName.Contains(q) || fIdentifier.Contains(q) || fText.Contains(q)))
                            continue;
                    }

                    Uri alternate = new Uri("file:///test/search?count=0&id=" + fIdentifier);
                    Uri id = new Uri(s.Id);

                    AtomItem entry = new AtomItem(fIdentifier, fName, alternate, id.ToString(), s.Date);
                    entry.PublishDate = s.Date.DateTime;
                    entry.LastUpdatedTime = s.Date.DateTime;
                    entry.Categories.Add(new SyndicationCategory(this.Identifier));

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

                    items.Add(entry);
                }
            }

            feed.Items = items;
            var tr = pds.Count();
            feed.TotalResults = tr;

            return feed;
        }
예제 #9
0
        public static IOpenSearchResultCollection CreateFromOpenSearchResultCollection(IOpenSearchResultCollection results)
        {
            if (results == null)
                throw new ArgumentNullException("results");

            AtomFeed feed = new AtomFeed(new SyndicationFeed());

            feed.Id = results.Id;
            feed.Identifier = results.Identifier;
            feed.Title = results.Title;

            foreach ( var author in results.Authors ){
                feed.Authors.Add(author);
            }

            if ( results.ElementExtensions != null )
                feed.ElementExtensions = new SyndicationElementExtensionCollection(results.ElementExtensions);

            if ( results.LastUpdatedTime.Ticks > 0 )
                feed.LastUpdatedTime = results.LastUpdatedTime;
            feed.Links = new Collection<SyndicationLink>(results.Links);

            if (results.Items != null) {
                List<AtomItem> items = new List<AtomItem>();
                foreach (var item in results.Items) {
                    items.Add(AtomItem.FromOpenSearchResultItem(item));
                }
                feed.Items = items;
            }

            feed.QueryTimeSpan = results.QueryTimeSpan;
            feed.OpenSearchable = results.OpenSearchable;
            feed.TotalResults = results.TotalResults;

            return feed;
        }
        public void FromWPSAtomTest3()
        {
            XmlReader reader = XmlReader.Create("../Samples/test2.xml");
            SyndicationFeed feed = SyndicationFeed.Load(reader);
            AtomFeed atom = new AtomFeed(feed);

            FeatureCollectionResult col = FeatureCollectionResult.FromOpenSearchResultCollection(atom);

            Console.Out.Write(col.SerializeToString());
        }
        public void FromWPSAtomTest()
        {
            XmlReader reader = XmlReader.Create("../Samples/wps.atom");
            SyndicationFeed feed = SyndicationFeed.Load(reader);
            AtomFeed atom = new AtomFeed(feed);

            FeatureCollectionResult col = FeatureCollectionResult.FromOpenSearchResultCollection(atom);

            Console.Out.Write(col.SerializeToString());
            Assert.That(col.Features[0].Geometry != null);
        }
        /// <summary>
        /// Merges the results.
        /// </summary>
        void MergeResults()
        {
            feed = new AtomFeed();
            List<AtomItem> items = new List<AtomItem>();

            foreach (var key in results.Keys) {

                IOpenSearchResultCollection result = results[key];
                AtomItem item = null;

                if (result.Count == 1) {
                    item = AtomItem.FromOpenSearchResultItem(result.Items.First());
                } else {
                    item = new AtomItem(result.Title.Text,
                                        result.Description,
                                        result.Links.FirstOrDefault(l => l.RelationshipType == "self").Uri,
                                        result.Id,
                                        result.LastUpdatedTime);
                    item.Identifier = result.Identifier;
                    item.ElementExtensions = result.ElementExtensions;
                    result.Authors.FirstOrDefault( a => {
                        item.Authors.Add(a);
                        return false;
                    });
                    result.Categories.FirstOrDefault( a => {
                        item.Categories.Add(a);
                        return false;
                    });
                    item.Categories.Add(new SyndicationCategory("group", null, result.Id));
                    result.Contributors.FirstOrDefault( a => {
                        item.Contributors.Add(a);
                        return false;
                    });
                    item.Copyright = result.Copyright;
                    item.Links = result.Links;
                    item.PublishDate = result.LastUpdatedTime;
                    item.SourceFeed = (SyndicationFeed)AtomFeed.CreateFromOpenSearchResultCollection(result);
                }
                items.Add(item);
            }
            feed.Items = items;
        }