public void Issue1()
        {
            OwsContextAtomFeed feed = new OwsContextAtomFeed();

            /// entries
            List <OwsContextAtomEntry> items = new List <OwsContextAtomEntry>();
            OwsContextAtomEntry        item  = new OwsContextAtomEntry();

            feed.Publisher = "manu";
            item.Publisher = "manu";
            items.Add(item);

            feed.Items = items;

            MemoryStream stream = new MemoryStream();

            SerializationTest.SerializeToStream(feed, stream);

            stream.Seek(0, SeekOrigin.Begin);

            XDocument doc = XDocument.Load(stream);

            Assert.AreEqual("manu", doc.Element(XName.Get("feed", OwcNamespaces.Atom))
                            .Element(XName.Get("publisher", OwcNamespaces.Dc)).Value);

            Assert.AreEqual("manu", doc.Element(XName.Get("feed", OwcNamespaces.Atom))
                            .Elements(XName.Get("entry", OwcNamespaces.Atom)).First()
                            .Element(XName.Get("publisher", OwcNamespaces.Dc)).Value);
        }
示例#2
0
        public void GetAtomItemWithoutProxy()
        {
            WpsProcessOffering process = CreateProcess(false);
            var entry = process.ToAtomItem(new NameValueCollection());
            OwsContextAtomEntry result = new OwsContextAtomEntry(entry);

            Assert.That(result != null);
        }
示例#3
0
        public static string GetExtensionFromFeed(OwsContextAtomEntry entry, string extension, string ns)
        {
            string val  = "";
            var    vals = entry.ElementExtensions.ReadElementExtensions <string>(extension, ns);

            if (vals.Count > 0)
            {
                val = vals[0];
            }
            return(val);
        }
示例#4
0
        /// <summary>
        /// Gets the identifier from feed.
        /// </summary>
        /// <returns>The identifier from feed.</returns>
        /// <param name="entry">Entry.</param>
        public static string GetIdentifierFromFeed(OwsContextAtomEntry entry)
        {
            string uid         = "";
            var    identifiers = entry.ElementExtensions.ReadElementExtensions <string>("identifier", "http://purl.org/dc/elements/1.1/");

            if (identifiers.Count > 0)
            {
                uid = identifiers[0];
            }
            return(uid);
        }
示例#5
0
        /// <summary>
        /// Creates or update the cached app
        /// </summary>
        /// <returns>The or update.</returns>
        /// <param name="entry">Entry.</param>
        /// <param name="domainid">Domainid.</param>
        public ThematicApplicationCached CreateOrUpdateCachedApp(OwsContextAtomEntry entry, int domainid, string index = null)
        {
            var appCategory = entry.Categories.FirstOrDefault(l => l.Label == "App");

            if (appCategory == null)
            {
                return(null);
            }

            var identifier = GetIdentifierFromFeed(entry);
            var appcached  = new ThematicApplicationCached(context);

            appcached.UId = identifier;

            if (index != null)
            {
                appcached.Index = index;
            }
            else
            {
                appcached.DomainId = domainid;
            }

            try
            {
                appcached.Load();
            }
            catch (Exception) { }

            var feed = new OwsContextAtomFeed();

            feed.Items = new List <OwsContextAtomEntry> {
                entry
            };

            appcached.Index      = index;
            appcached.Feed       = feed;
            appcached.TextFeed   = System.Text.RegularExpressions.Regex.Replace(GetOwsContextAtomFeedAsString(feed), @"\p{Cs}", "");
            appcached.Searchable = System.Text.RegularExpressions.Regex.Replace(GetSearchableTextFromAtomEntry(entry), @"\p{Cs}", "");
            appcached.LastUpdate = entry.LastUpdatedTime.DateTime;
            if (appcached.DomainId == 0 && domainid > 0)
            {
                appcached.DomainId = domainid;
            }
            appcached.Store();

            return(appcached);
        }
示例#6
0
        public static string GetSearchableTextFromAtomEntry(OwsContextAtomEntry entry)
        {
            string result = GetIdentifierFromFeed(entry);

            result += entry.Title != null && !string.IsNullOrEmpty(entry.Title.Text) ? " | " + entry.Title.Text : "";
            result += entry.Summary != null && !string.IsNullOrEmpty(entry.Summary.Text) ? " | " + entry.Summary.Text : "";
            result += entry.Authors != null && entry.Authors.Count > 0 && !string.IsNullOrEmpty(entry.Authors[0].Name) ? " | " + entry.Authors[0].Name : "";
            if (entry.Categories != null && entry.Categories.Count > 0)
            {
                foreach (var category in entry.Categories)
                {
                    if (category.Name == "keyword" && !string.IsNullOrEmpty(category.Label))
                    {
                        result += " | " + category.Label;
                    }
                }
            }
            return(result);
        }
示例#7
0
        public static List <WpsServiceOverview> GetWpsServiceOverviews(IfyContext context, OwsContextAtomEntry entry)
        {
            var appUid   = GetExtensionFromFeed(entry, "identifier", "http://purl.org/dc/elements/1.1/");
            var appTitle = entry.Title != null?entry.Title.Text.Trim() : appUid;

            var    appIconLink = entry.Links.FirstOrDefault(l => l.RelationshipType == "icon");
            string appIcon     = "";

            if (appIconLink != null)
            {
                appIcon = appIconLink.Uri.AbsoluteUri;
            }
            var offerings = entry.ElementExtensions.ReadElementExtensions <OwcOffering>("offering", OwcNamespaces.Owc, new System.Xml.Serialization.XmlSerializer(typeof(OwcOffering)));
            var offering  = offerings.First(p => p.Code == "http://www.opengis.net/spec/owc/1.0/req/atom/wps");

            return(GetWpsServiceOverview(context, offering, appUid, appTitle, appIcon));
        }
        public void Serialize()
        {
            OwsContextAtomFeed feed = new OwsContextAtomFeed();

            // display
            OwcDisplay display = new OwcDisplay()
            {
                PixelWidth = 800, PixelHeight = 600, MmPerPixel = 100
            };
            var displayAny = new System.Collections.Generic.List <XmlElement>();

            display.Any  = displayAny.ToArray();
            feed.Display = display;

            // date
            DateTimeInterval interval = new DateTimeInterval();

            interval.StartDate = DateTime.Parse("2010-05-30T05:54:34+02");
            interval.EndDate   = DateTime.Parse("2010-05-31T20:20:20.000Z");
            feed.Date          = interval;

            // georss
            GeoRssWhere georss = (GeoRssWhere)GeoRssHelper.Deserialize(XmlReader.Create(new StringReader("<georss:where xmlns:georss=\"http://www.georss.org/georss\">\n<gml:Polygon xmlns:gml=\"http://www.opengis.net/gml\">\n<gml:exterior>\n<gml:LinearRing>\n<gml:posList>45 -2 45 8 55 8 55 -2 45 -2</gml:posList>\n</gml:LinearRing>\n</gml:exterior>\n</gml:Polygon>\n</georss:where>")));

            feed.Where = georss;

            /// entries
            List <OwsContextAtomEntry> items     = new List <OwsContextAtomEntry>();
            OwsContextAtomEntry        item      = new OwsContextAtomEntry();
            List <OwcOffering>         offerings = new List <OwcOffering>();
            OwcOffering       offering           = new OwcOffering();
            List <XmlElement> offeringAny        = new List <XmlElement>();

            offering.Any = offeringAny.ToArray();
            List <OwcOperation> ops = new List <OwcOperation>();

            ops.Add(new OwcOperation("GetCapabilities", new Uri("http://ows.genesi-dec.eu/geoserver/385d7d71-650a-414b-b8c7-739e2c0b5e76/wms?SERVICE=WMS&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilitiesVERSION=1.3.0&REQUEST=GetCapabilities")));
            ops.Add(new OwcOperation("GetCapabilities2", new Uri("http://ows.genesi-dec.eu/geoserver/385d7d71-650a-414b-b8c7-739e2c0b5e76/wms?SERVICE=WMS&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilitiesVERSION=1.3.0&REQUEST=GetCapabilities")));
            offering.Operations = ops.ToArray();
            offerings.Add(offering);
            item.Offerings = offerings;
            items.Add(item);

            feed.Items = items;

            MemoryStream stream = new MemoryStream();

            SerializeToStream(feed, stream);

            stream.Seek(0, SeekOrigin.Begin);

            SerializeToStream(feed, Console.Out);

            XDocument doc = XDocument.Load(stream);

            Assert.NotNull(doc.Element(XName.Get("feed", OwcNamespaces.Atom)));

            Assert.NotNull(doc.Element(XName.Get("feed", OwcNamespaces.Atom)).Element(XName.Get("display", OwcNamespaces.Owc)));

            Assert.AreEqual("2010-05-30T03:54:34.0000000Z/2010-05-31T20:20:20.0000000Z", doc.Element(XName.Get("feed", OwcNamespaces.Atom)).Element(XName.Get("date", OwcNamespaces.Dc)).Value);
        }
        public void SerializeWithAny()
        {
            OwsContextAtomFeed  feed  = new OwsContextAtomFeed();
            OwsContextAtomEntry entry = new OwsContextAtomEntry();
            var items = new List <OwsContextAtomEntry>();

            items.Add(entry);

            var offering = new OwcOffering();

            List <OwcOperation> operations = new List <OwcOperation>();

            Uri executeUri = new Uri("http://localhost/wps?");

            Terradue.ServiceModel.Ogc.Owc.AtomEncoding.OwcOperation operation = new OwcOperation {
                Method = "POST", Code = "Execute", RequestUrl = executeUri
            };

            List <KeyValuePair <string, string> > Parameters = new List <KeyValuePair <string, string> >();

            Parameters.Add(new KeyValuePair <string, string>("manu", "test"));

            Execute execute = new Execute();

            execute.Identifier = new CodeType {
                Value = "id"
            };
            execute.DataInputs = new List <InputType>();
            foreach (var param in Parameters)
            {
                InputType input = new InputType();
                input.Identifier = new CodeType {
                    Value = param.Key
                };
                input.Data = new DataType {
                    Item = new LiteralDataType {
                        Value = param.Value
                    }
                };
                execute.DataInputs.Add(input);
            }


            MemoryStream ms     = new MemoryStream();
            XmlWriter    writer = XmlWriter.Create(ms);

            new System.Xml.Serialization.XmlSerializer(typeof(Execute)).Serialize(writer, execute);
            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            XmlDocument doc = new XmlDocument();

            doc.Load(ms);

            XmlElement any = (XmlElement)doc.DocumentElement.CloneNode(true);

            operation.Request = new OwcContent();
            ((OwcContent)operation.Request).Any = any;
            operations.Add(operation);
            offering.Operations = operations.ToArray();
            entry.Offerings     = new List <OwcOffering> {
                offering
            };
            entry.Categories.Add(new SyndicationCategory("WpsOffering"));

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

            feed.Items = items;

            SerializeToStream(feed, Console.Out);
        }
        //---------------------------------------------------------------------------------------------------------------------

        public override AtomItem ToAtomItem(NameValueCollection parameters)
        {
            string providerUrl = null;
            string identifier  = null;

            log.Debug("WpsProcessOffering - ToAtomItem");

            if (this.ProviderId == 0 || this.Provider.Proxy)
            {
                providerUrl = context.BaseUrl + "/wps/WebProcessingService";
                identifier  = this.Identifier;
            }
            else
            {
                identifier = this.RemoteIdentifier;
                if (this.Provider.BaseUrl.Contains("request="))
                {
                    providerUrl = this.Provider.BaseUrl.Substring(0, this.Provider.BaseUrl.IndexOf("?"));
                }
                else
                {
                    providerUrl = this.Provider.BaseUrl;
                }
            }

            var status = this.DoesGrantPermissionsToAll() ? "public" : (IsRestricted() ? "restricted" : "private");

            if (identifier == null)
            {
                identifier = "";
            }
            string name        = (this.Name != null ? this.Name : identifier);
            string description = this.Description;
            string text        = (this.TextContent != null ? this.TextContent : "");

            if (!IsSearchable(parameters))
            {
                return(null);
            }

            var capurl = providerUrl + "?service=WPS&request=GetCapabilities";

            log.Debug("capabilities = " + capurl);

            Uri capabilitiesUri = new Uri(capurl);

            AtomItem atomEntry  = null;
            var      entityType = EntityType.GetEntityType(typeof(WpsProcessOffering));
            Uri      id         = null;
            var      idurl      = context.BaseUrl;

            if (this.ProviderId == 0)
            {
                idurl = context.BaseUrl + "/" + entityType.Keyword + "/search?wpsUrl=" + HttpUtility.UrlEncode(this.Provider.BaseUrl) + "&pId=" + this.RemoteIdentifier;
            }
            else
            {
                idurl = context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier;
            }
            log.Debug("id url = " + idurl);
            id = new Uri(idurl);

            try{
                atomEntry = new AtomItem(name, description, capabilitiesUri, id.ToString(), DateTime.UtcNow);
            } catch (Exception) {
                atomEntry = new AtomItem();
            }

            log.Debug("Adding owscontext");
            OwsContextAtomEntry entry = new OwsContextAtomEntry(atomEntry);
            var offering = new OwcOffering();
            List <OwcOperation> operations = new List <OwcOperation>();

            var describeurl = providerUrl + "?service=WPS" +
                              "&request=DescribeProcess" +
                              "&version=" + this.Provider.WPSVersion +
                              "&identifier=" + identifier;

            log.Debug("describeprocess url = " + describeurl);
            Uri describeUri = new Uri(describeurl);

            var executeurl = providerUrl + "?service=WPS" +
                             "&request=Execute" +
                             "&version=" + this.Provider.WPSVersion +
                             "&identifier=" + identifier;

            log.Debug("execute url = " + executeurl);
            Uri executeUri = new Uri(executeurl);

            operations.Add(new OwcOperation {
                Method = "GET", Code = "GetCapabilities", Href = capabilitiesUri.AbsoluteUri
            });
            operations.Add(new OwcOperation {
                Method = "GET", Code = "DescribeProcess", Href = describeUri.AbsoluteUri
            });
            operations.Add(new OwcOperation {
                Method = "POST", Code = "Execute", Href = executeUri.AbsoluteUri
            });

            offering.Operations = operations.ToArray();
            entry.Offerings     = new List <OwcOffering> {
                offering
            };
            if (string.IsNullOrEmpty(this.provider.Description))
            {
                entry.Publisher = (this.Provider != null ? this.Provider.Name : "Unknown");
            }
            else
            {
                entry.Publisher = this.Provider.Name + " (" + this.Provider.Description + ")";
            }
            if (this.Provider != null)
            {
                entry.ElementExtensions.Add("providerId", "https://www.terradue.com/", this.Provider.Identifier);
            }

            //categories
            if (this.Available)
            {
                entry.Categories.Add(new SyndicationCategory("available"));
            }
            if (this.Commercial)
            {
                entry.Categories.Add(new SyndicationCategory("commercial"));
            }
            if (this.Provider.Id == 0)
            {
                entry.Categories.Add(new SyndicationCategory("Discovered"));
            }
            if (this.Provider.IsSandbox)
            {
                entry.Categories.Add(new SyndicationCategory("sandbox"));
            }
            entry.Categories.Add(new SyndicationCategory("visibility", null, status));
            entry.Categories.Add(new SyndicationCategory("WpsOffering"));
            foreach (var tag in GetTagsAsList())
            {
                entry.Categories.Add(new SyndicationCategory("tag", "", tag));
            }
            if (this.Commercial)
            {
                var contact = ExtractProviderContact(this.Provider.Contact);
                if (!string.IsNullOrEmpty(contact))
                {
                    entry.Categories.Add(new SyndicationCategory("contact", null, contact));
                }
            }

            if (this.Quotable)
            {
                entry.Categories.Add(new SyndicationCategory("quotable"));
            }

            entry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier);
            if (!string.IsNullOrEmpty(this.RemoteIdentifier))
            {
                entry.ElementExtensions.Add("remote_identifier", "http://purl.org/dc/elements/1.1/", this.RemoteIdentifier);
            }
            if (!string.IsNullOrEmpty(this.Version))
            {
                entry.ElementExtensions.Add("version", "https://www.terradue.com/", this.Version);
            }
            if (this.Domain != null)
            {
                entry.ElementExtensions.Add("domain", "https://www.terradue.com/", this.Domain.Identifier);
            }
            if (!string.IsNullOrEmpty(this.Geometry))
            {
                entry.ElementExtensions.Add("spatial", "http://purl.org/dc/terms/", this.Geometry);
            }

            entry.Links.Add(new SyndicationLink(id, "self", name, "application/atom+xml", 0));

            if (!string.IsNullOrEmpty(this.IconUrl))
            {
                log.Debug("icon link = " + IconUrl);
                entry.Links.Add(new SyndicationLink(new Uri(this.IconUrl), "icon", null, null, 0));
            }

            if (!string.IsNullOrEmpty(this.Geometry))
            {
                entry.ElementExtensions.Add("box", "http://www.georss.org/georss", this.Geometry);
            }

            return(new AtomItem(entry));
        }
示例#11
0
        /// <summary>
        /// Synchronize WPS services
        /// </summary>
        /// <param name="context"></param>
        /// <param name="entry"></param>
        /// <param name="domain"></param>
        public static void SyncWpsServices(IfyContext context, OwsContextAtomEntry entry, Domain domain = null)
        {
            if (entry.Offerings == null)
            {
                return;
            }

            var offering = entry.Offerings.First(p => p.Code == "http://www.opengis.net/spec/owc/1.0/req/atom/wps");

            if (offering == null)
            {
                return;
            }

            string wpsDomainIdentifier = null;
            string wpsTags             = null;

            //get domain and tag for app
            var op = offering.Operations.FirstOrDefault(o => o.Code == "ListProcess");

            if (op != null && op.Href != null)
            {
                var nvc = HttpUtility.ParseQueryString((new Uri(op.Href)).Query);
                foreach (var key in nvc.AllKeys)
                {
                    switch (key)
                    {
                    case "domain":
                        wpsDomainIdentifier = nvc[key];
                        break;

                    case "tag":
                        wpsTags = nvc[key];
                        break;

                    default:
                        break;
                    }
                }
            }

            //check domain
            if (domain == null)
            {
                domain = Domain.FromIdentifier(context, wpsDomainIdentifier);
            }

            op = offering.Operations.FirstOrDefault(o => o.Code == "RemoteSyncProcess");
            if (op != null && op.Href != null)
            {
                //get current services from DB
                string[] tags        = !string.IsNullOrEmpty(wpsTags) ? wpsTags.Split(",".ToArray()) : new string[0];
                var      dbProcesses = WpsProcessOfferingTep.GetWpsProcessingOfferingsForApp(context, domain, tags);

                //get new services from remote
                var remoteProcesses = WpsProcessOfferingTep.GetRemoteWpsProcessingOfferingsFromUrl(context, op.Href, true);
                foreach (var p in remoteProcesses)
                {
                    p.Domain    = domain;
                    p.Tags      = wpsTags;
                    p.Available = true;
                }

                //store only new services (not already in DB)
                foreach (WpsProcessOffering pR in remoteProcesses)
                {
                    bool inDB = false;
                    foreach (WpsProcessOffering pDB in dbProcesses)
                    {
                        if (pR.ProviderId == pDB.ProviderId &&
                            pR.RemoteIdentifier == pDB.RemoteIdentifier &&
                            pR.Version == pDB.Version)
                        {
                            inDB = true;
                            //we update title/description/icon
                            pDB.Name        = pR.Name;
                            pDB.Description = pR.Description;
                            pDB.IconUrl     = pR.IconUrl;
                            pDB.Store();
                        }
                    }
                    if (!inDB)
                    {
                        pR.Store();
                    }
                }

                //remove services from DB not anymore in the list
                foreach (WpsProcessOffering pDB in dbProcesses)
                {
                    bool inRemote = false;
                    foreach (WpsProcessOffering pR in remoteProcesses)
                    {
                        if (pR.ProviderId == pDB.ProviderId &&
                            pR.RemoteIdentifier == pDB.RemoteIdentifier &&
                            pR.Version == pDB.Version)
                        {
                            inRemote = true;
                            break;
                        }
                    }
                    if (!inRemote)
                    {
                        pDB.Delete();
                    }
                }
            }
        }
示例#12
0
        public static WpsProcessOffering GetWpsProcessOfferingFromProcessDescriptionAtomFeed(IfyContext context, OwsContextAtomEntry entry)
        {
            var wpsOffering = entry.Offerings.FirstOrDefault(of => of.Code == "http://www.opengis.net/spec/owc/1.0/req/atom/wps");

            if (wpsOffering == null)
            {
                return(null);
            }

            var wps = new WpsProcessOffering(context);

            wps.Identifier = Guid.NewGuid().ToString();
            var identifiers = entry.ElementExtensions.ReadElementExtensions <string>("identifier", "http://purl.org/dc/elements/1.1/");

            if (identifiers.Count > 0)
            {
                wps.RemoteIdentifier = identifiers[0];
            }
            wps.Name        = entry.Title != null ? entry.Title.Text : "";
            wps.Description = entry.Summary != null ? entry.Summary.Text : "";

            var appIconLink = entry.Links.FirstOrDefault(l => l.RelationshipType == "icon");

            if (appIconLink != null)
            {
                wps.IconUrl = appIconLink.Uri.AbsoluteUri;
            }

            var operation          = wpsOffering.Operations.FirstOrDefault(o => o.Code == "ProcessDescription");
            var href               = operation.Href;
            var dpUri              = new Uri(href);
            var describeProcessUrl = dpUri.GetLeftPart(UriPartial.Path);

            wps.Url = describeProcessUrl;

            operation = wpsOffering.Operations.FirstOrDefault(o => o.Code == "ValidateProcess");
            if (operation != null)
            {
                wps.ValidationUrl = operation.Href;
            }

            return(wps);
        }
示例#13
0
        /// <summary>
        /// Transform the current object to OwsContextAtomEntry.
        /// </summary>
        /// <returns>The context atom entry.</returns>
        public OwsContextAtomEntry ToContextAtomEntry()
        {
            OwsContextAtomEntry item = new OwsContextAtomEntry();

            item.Title           = new TextSyndicationContent(this.Title);
            item.Summary         = new TextSyndicationContent(this.Abstract);
            item.Id              = this.Id;
            item.LastUpdatedTime = this.UpdateDate;
            item.Publisher       = this.Publisher;
            item.Copyright       = new TextSyndicationContent(this.Rights);
            if (this.GeospatialExtent != null)
            {
                item.Where = this.GeospatialExtent;
            }
            if (this.TemporalExtent != null)
            {
                item.Date = this.TemporalExtent;
            }
            item.MinScaleDenominator = this.MinScaleDenominator;
            item.MaxScaleDenominator = this.MaxScaleDenominator;

            if (this.Authors != null)
            {
                foreach (string author in this.Authors)
                {
                    item.Authors.Add(new SyndicationPerson(null, author, null));
                }
            }

            if (this.Preview != null)
            {
                foreach (Uri uri in this.Preview)
                {
                    item.Links.Add(new SyndicationLink(uri, "icon", "Preview image", null, uri.AbsoluteUri.Length));
                }
            }

            if (this.ContentByRef != null)
            {
                foreach (Uri uri in this.ContentByRef)
                {
                    item.Links.Add(new SyndicationLink(uri, "enclosure", "Data resource location", null, uri.AbsoluteUri.Length));
                }
            }

            if (this.ResourceMetadata != null)
            {
                Uri u = new Uri((string)this.ResourceMetadata);//TODO: validate type of ResourceMetadata
                item.Links.Add(new SyndicationLink(u, "via", "Reference to the resource from which the Context resource is derived", null, u.AbsoluteUri.Length));
            }

            if (this.Offerings != null)
            {
                List <Terradue.ServiceModel.Ogc.Owc.AtomEncoding.OwcOffering> offerings = new List <Terradue.ServiceModel.Ogc.Owc.AtomEncoding.OwcOffering>();
                foreach (Offering off in this.Offerings)
                {
                    offerings.Add(new Terradue.ServiceModel.Ogc.Owc.AtomEncoding.OwcOffering(off));
                }
                item.Offerings = offerings;
            }

            item.Categories.Add(new SyndicationCategory(this.Active.ToString(), "http://www.opengis.net/spec/owc/active", null));

            if (this.Keywords != null)
            {
                foreach (string kw in this.Keywords)
                {
                    item.Categories.Add(new SyndicationCategory(kw));
                }
            }
            if (this.Folder != null)
            {
                item.Categories.Add(new SyndicationCategory(this.Folder, "http://www.opengis.net/spec/owc/folder", null));
            }

//            feed.ElementExtensions = Extension.ToAtom(); //TODO: implement

            return(item);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }