private AtomFeed CreateFeedForRDF(XmlNode any, string identifier, string baseurl) { OwsContextAtomFeed feed = new OwsContextAtomFeed(); List <OwsContextAtomEntry> entries = new List <OwsContextAtomEntry> (); XmlDocument doc = new XmlDocument(); doc.LoadXml(any.OuterXml); XmlNamespaceManager xmlns = new XmlNamespaceManager(doc.NameTable); xmlns.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); xmlns.AddNamespace("dclite4g", "http://xmlns.com/2008/dclite4g#"); xmlns.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); xmlns.AddNamespace("dct", "http://purl.org/dc/terms/"); var onlineResource = doc.SelectNodes("rdf:RDF/dclite4g:DataSet/dclite4g:onlineResource", xmlns); var createddate = doc.SelectSingleNode("rdf:RDF/dclite4g:DataSet/dct:created", xmlns).InnerText; var modifieddate = doc.SelectSingleNode("rdf:RDF/dclite4g:DataSet/dct:modified", xmlns).InnerText; feed.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent(doc.SelectSingleNode("rdf:RDF/dclite4g:DataSet/dc:title", xmlns).InnerText); feed.Description = new Terradue.ServiceModel.Syndication.TextSyndicationContent(doc.SelectSingleNode("rdf:RDF/dclite4g:DataSet/dc:subject", xmlns).InnerText); feed.Date = new DateTimeInterval { StartDate = Convert.ToDateTime(modifieddate), EndDate = Convert.ToDateTime(modifieddate) }; for (int i = 0; i < onlineResource.Count; i++) { string id = onlineResource [i].ChildNodes [0].Attributes.GetNamedItem("rdf:about").InnerText; Uri remoteUri = new Uri(id); OwsContextAtomEntry entry = new OwsContextAtomEntry(); entry.Id = remoteUri.AbsoluteUri; entry.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent(remoteUri.AbsoluteUri); entry.PublishDate = new DateTimeOffset(Convert.ToDateTime(modifieddate)); entry.LastUpdatedTime = new DateTimeOffset(Convert.ToDateTime(modifieddate)); entry.Date = new DateTimeInterval { StartDate = Convert.ToDateTime(modifieddate), EndDate = Convert.ToDateTime(modifieddate) }; entry.ElementExtensions.Add("identifier", OwcNamespaces.Dc, identifier); entry.Links.Add(Terradue.ServiceModel.Syndication.SyndicationLink.CreateMediaEnclosureLink(remoteUri, "application/octet-stream", 0)); List <OwcOffering> offerings = new List <OwcOffering> (); OwcOffering offering = new OwcOffering(); OwcContent content = new OwcContent(); content.Url = remoteUri;; string extension = remoteUri.AbsoluteUri.Substring(remoteUri.AbsoluteUri.LastIndexOf(".") + 1); switch (extension.ToLower()) { case "gif": content.Type = "image/gif"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/gif"; break; case "gtiff": content.Type = "image/tiff"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/geotiff"; break; case "jpeg": content.Type = "image/jpg"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/jpg"; break; case "png": content.Type = "image/png"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/png"; break; default: content.Type = "application/octet-stream"; offering.Code = null; break; } List <OwcContent> contents = new List <OwcContent> (); contents.Add(content); offering.Contents = contents.ToArray(); offerings.Add(offering); entry.Offerings = offerings; entries.Add(entry); } feed.Items = entries; AtomFeed atomfeed = new AtomFeed(feed); atomfeed.Title = feed.Title; atomfeed.Description = feed.Description; var urib = new UriBuilder(baseurl); urib.Path += "/proxy/wps/" + identifier + "/description"; atomfeed.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(urib.Uri, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0)); return(atomfeed); }
private AtomFeed CreateFeedForMetalink(XmlNode any, string identifier, string baseurl, IfyContext context) { OwsContextAtomFeed feed = new OwsContextAtomFeed(); List <OwsContextAtomEntry> entries = new List <OwsContextAtomEntry> (); XmlDocument doc = new XmlDocument(); doc.LoadXml(any.OuterXml); XmlNamespaceManager xmlns = new XmlNamespaceManager(doc.NameTable); xmlns.AddNamespace("ml", "http://www.metalinker.org"); var onlineResource = doc.SelectNodes("ml:metalink/ml:files/ml:file/ml:resources/ml:url", xmlns); var createddate = doc.SelectSingleNode("ml:metalink/ml:files/ml:file/ml:releasedate", xmlns).InnerText; var self = baseurl + "/proxy/wps/" + identifier + "/search"; var search = baseurl + "/proxy/wps/" + identifier + "/description"; feed.Id = self; feed.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent("Wps job results"); feed.Date = new DateTimeInterval { StartDate = Convert.ToDateTime(createddate), EndDate = Convert.ToDateTime(createddate) }; foreach (XmlNode node in onlineResource) { string url = node.InnerText; context.LogDebug(this, "Url = " + url); Uri remoteUri = new Uri(url); OwsContextAtomEntry entry = new OwsContextAtomEntry(); //link is an OWS context, we add it as is Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(); if (url.Contains(".atom")) { NetworkCredential credentials = null; var uri = new UriBuilder(url); if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password)) { credentials = new NetworkCredential(uri.UserName, uri.Password); } HttpWebRequest atomRequest = WpsProvider.CreateWebRequest(url, credentials, context.Username); atomRequest.Accept = "*/*"; atomRequest.UserAgent = "Terradue TEP"; try { using (var atomResponse = (HttpWebResponse)atomRequest.GetResponse()) { using (var atomResponseStream = new MemoryStream()) { using (var stream = atomResponse.GetResponseStream()) stream.CopyTo(atomResponseStream); atomResponseStream.Seek(0, SeekOrigin.Begin); var sr = XmlReader.Create(atomResponseStream); atomFormatter.ReadFrom(sr); sr.Close(); } } } catch (Exception e) { context.LogError(this, e.Message, e); throw e; } return(new AtomFeed(atomFormatter.Feed)); } //we build the OWS context entry.Id = node.InnerText.Contains("/") ? node.InnerText.Substring(node.InnerText.LastIndexOf("/") + 1) : node.InnerText; entry.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent(remoteUri.AbsoluteUri); entry.PublishDate = new DateTimeOffset(Convert.ToDateTime(createddate)); entry.LastUpdatedTime = new DateTimeOffset(Convert.ToDateTime(createddate)); entry.Date = new DateTimeInterval { StartDate = Convert.ToDateTime(createddate), EndDate = Convert.ToDateTime(createddate) }; entry.ElementExtensions.Add("identifier", OwcNamespaces.Dc, entry.Id); entry.Links.Add(Terradue.ServiceModel.Syndication.SyndicationLink.CreateMediaEnclosureLink(remoteUri, "application/octet-stream", 0)); List <OwcOffering> offerings = new List <OwcOffering> (); OwcOffering offering = new OwcOffering(); OwcContent content = new OwcContent(); content.Url = remoteUri; string extension = remoteUri.AbsoluteUri.Substring(remoteUri.AbsoluteUri.LastIndexOf(".") + 1); switch (extension.ToLower()) { case "gif": content.Type = "image/gif"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/gif"; break; case "gtiff": content.Type = "image/tiff"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/geotiff"; break; case "jpeg": content.Type = "image/jpg"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/jpg"; break; case "png": content.Type = "image/png"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/png"; break; case "tgz": content.Type = "application/tar+gzip"; offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/tgz"; break; default: content.Type = "application/octet-stream"; offering.Code = ""; break; } List <OwcContent> contents = new List <OwcContent> (); contents.Add(content); offering.Contents = contents.ToArray(); offerings.Add(offering); entry.Offerings = offerings; entries.Add(entry); } feed.Items = entries; AtomFeed atomfeed = new AtomFeed(feed); atomfeed.Title = feed.Title; atomfeed.Description = feed.Description; var urib = new UriBuilder(baseurl); urib.Path += "/proxy/wps/" + identifier + "/description"; atomfeed.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(urib.Uri, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0)); return(atomfeed); }