/// <summary> /// https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#instrument /// </summary> /// <param name="item"></param> /// <param name="properties"></param> private static void FillInstrument(AtomItem item, Dictionary <string, object> properties) { // platform & constellation var platformname = item.FindPlatformShortName(); if (!string.IsNullOrEmpty(platformname)) { platformname = platformname.Replace("S1", "sentinel-1").Replace("S2", "sentinel-2").Replace("S3", "sentinel-3").ToLower(); properties.Remove("platform"); properties.Add("platform", platformname); var constellationName = platformname.TrimEnd('a').TrimEnd('b'); properties.Remove("constellation"); properties.Add("constellation", constellationName); properties.Remove("mission"); properties.Add("mission", constellationName); } // instruments var instrumentName = item.FindInstrumentShortName(); if (!string.IsNullOrEmpty(instrumentName)) { if (instrumentName == "SAR") { instrumentName = "c-sar"; } instrumentName = instrumentName.ToLower(); properties.Remove("instruments"); properties.Add("instruments", new string[] { instrumentName }); } // TODO gsd }
public override Terradue.OpenSearch.Result.AtomItem ToAtomItem(System.Collections.Specialized.NameValueCollection parameters) { string name = (this.Title != null ? this.Title : this.Identifier); var entityType = EntityType.GetEntityType(typeof(Article)); Uri id = new Uri(context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier); if (!IsSearchable(parameters)) { return(null); } AtomItem result = new AtomItem(); result.Id = id.ToString(); result.Title = new TextSyndicationContent(name); result.Summary = new TextSyndicationContent(Abstract); result.Content = new TextSyndicationContent(Content); result.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); result.ReferenceData = this; result.PublishDate = this.Time; SyndicationPerson author = new SyndicationPerson(null, this.Author, null); result.Authors.Add(author); result.Links.Add(new SyndicationLink(id, "self", name, "application/atom+xml", 0)); foreach (var tag in this.Tags.Split(",".ToCharArray())) { result.Categories.Add(new SyndicationCategory("tag", null, tag)); } return(result); }
public static AtomFeed ToAtomFeed(this AtomItem atomItem) { AtomFeed feed = new AtomFeed(); List <AtomItem> items = new List <AtomItem>(); items.Add(atomItem); feed.Items = items.ToArray(); return(feed); }
public AtomItem ToAtomItem(NameValueCollection parameters) { AtomItem item = new AtomItem(string.Format("{0}", o.Title != null ? o.Title.Value : o.Identifier.Value), "", null, o.Identifier.Value, DateTime.UtcNow); item.PublishDate = DateTime.UtcNow; item.Identifier = o.Identifier.Value; item.Categories.Add(new SyndicationCategory(o.Identifier.Value, null, "wpsoutput")); string enclosure = null; if (o.Item is DataType && ((DataType)(o.Item)).Item != null) { if (((DataType)(o.Item)).Item is ComplexDataType) { var content = ((DataType)(o.Item)).Item as ComplexDataType; if (content.Reference != null) { var reference = content.Reference as OutputReferenceType; enclosure = reference.href; } item.Summary = new TextSyndicationContent(content.Serialize()); } if (((DataType)(o.Item)).Item is LiteralDataType) { var content = ((DataType)(o.Item)).Item as LiteralDataType; item.Summary = new TextSyndicationContent(string.Format("{0} {1} {2}", content.Value, content.uom, content.dataType)); } if (((DataType)(o.Item)).Item is LiteralDataType) { var bbox = ((DataType)(o.Item)).Item as BoundingBoxType; item.Summary = new TextSyndicationContent(bbox.Serialize()); item.ElementExtensions.Add("box", "http://www.georss.org/georss", string.Format("{0} {1} {2} {3}", bbox.LowerCorner.Trim(' ').Split(' ')[0], bbox.LowerCorner.Trim(' ').Split(' ')[1], bbox.UpperCorner.Trim(' ').Split(' ')[0], bbox.UpperCorner.Trim(' ').Split(' ')[1])); } } else if (o.Item is OutputReferenceType) { var reference = o.Item as OutputReferenceType; enclosure = reference.href; item.Summary = new TextSyndicationContent(o.Title != null ? o.Title.Value : o.Identifier.Value); } if (!string.IsNullOrEmpty(enclosure)) { item.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(new Uri(enclosure), "search", "Download output " + o.Identifier.Value, "application/octet-stream", 0)); } return(item); }
/// <summary> /// https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md /// </summary> /// <param name="item"></param> /// <returns></returns> public static Dictionary <string, object> GetCommonMetadata(this SyndicationItem item) { AtomItem atomItem = new AtomItem(item); Dictionary <string, object> properties = new Dictionary <string, object>(); FillBasicsProperties(atomItem, properties); FillDateTimeProperties(atomItem, properties); // TODO Licensing // TODO Provider FillInstrument(atomItem, properties); return(properties); }
public override AtomItem ToAtomItem(NameValueCollection parameters) { var atomFormatter = new Atom10FeedFormatter(); XmlReader xmlreader = XmlReader.Create(new StringReader(TextFeed = this.TextFeed)); atomFormatter.ReadFrom(xmlreader); var feed = new OwsContextAtomFeed(atomFormatter.Feed, true); var item = feed.Items.First(); var result = new AtomItem(item); if (parameters["admin"] != null && parameters["admin"] == "true") { try{ var wpsOverviews = ThematicAppFactory.GetWpsServiceOverviews(context, item); if (wpsOverviews.Count > 0) { result.ElementExtensions.Add("wps", "https://standards.terradue.com", wpsOverviews); } }catch (Exception) {} try{ var collOverviews = ThematicAppFactory.GetDataCollectionOverview(context, item); if (collOverviews.Count > 0) { result.ElementExtensions.Add("collection", "https://standards.terradue.com", collOverviews); } }catch (Exception) {} try{ if (this.Domain != null) { var community = ThematicCommunity.FromId(context, this.DomainId); var comOverview = new CommunityOverview { Identifier = community.Identifier, Title = community.Name, Icon = community.IconUrl }; result.ElementExtensions.Add("community", "https://standards.terradue.com", comOverview); } }catch (Exception) {} try{ var editorUrl = string.Format("{0}/{1}/{2}", context.GetConfigValue("ellip.editor-url"), this.Index, this.UId); result.Links.Add(new SyndicationLink(new Uri(editorUrl), "related", "geobrowser editor", "application/html", 0)); }catch (Exception) {} } return(result); }
AtomItem CreateItemFromLink(string key, Uri url, bool withOrbits) { string identifier = key.Replace(".EOF", ""); Match match = Regex.Match(identifier, @"^(?'mission'\w{3})_OPER_AUX_(?'type'\w{6})_(?'system'\w{4})_(?'proddate'\w{15})_V(?'startdate'\w{15})_(?'stopdate'\w{15})$"); if (!match.Success) { return(null); } AtomItem item = new AtomItem(identifier, string.Format("{0} {1} {2} {3}", match.Groups["mission"].Value, match.Groups["type"].Value, match.Groups["startdate"].Value, match.Groups["stopdate"].Value), url, identifier, DateTimeOffset.ParseExact(match.Groups["proddate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime()); DateTime start = DateTime.ParseExact(match.Groups["startdate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); DateTime stop = DateTime.ParseExact(match.Groups["stopdate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); item.Identifier = identifier; item.PublishDate = DateTimeOffset.ParseExact(match.Groups["proddate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); item.Links.Add(SyndicationLink.CreateMediaEnclosureLink(url, "application/xml", 0)); item.ElementExtensions.Add("polygon", "http://www.georss.org/georss", "-90 -180 -90 180 90 180 90 -180 -90 -180"); item.ElementExtensions.Add("date", "http://purl.org/dc/elements/1.1/", string.Format("{0}/{1}", start.ToString("O"), stop.ToString("O"))); Terradue.ServiceModel.Ogc.Eop21.EarthObservationType eo = OrbToEo(identifier, match.Groups["mission"].Value, match.Groups["type"].Value, start, stop, item.PublishDate); if (eo != null) { log.DebugFormat("EOP extension created from {0}", url); item.ElementExtensions.Add(eo.CreateReader()); } if (withOrbits) { var request = HttpWebRequest.Create(url); using (var response = request.GetResponse()) { Terradue.OpenSearch.Sentinel.Data.Earth_Explorer_File eefile = (Terradue.OpenSearch.Sentinel.Data.Earth_Explorer_File)eeser.Deserialize(response.GetResponseStream()); item.ElementExtensions.Add(GenerateOrbitsExtension(eefile)); } } return(item); }
public override AtomItem ToAtomItem(NameValueCollection parameters) { string identifier = this.Identifier; string name = (this.Name != null ? this.Name : this.Identifier); string text = (this.TextContent != null ? this.TextContent : name); AtomItem atomEntry = null; var entityType = EntityType.GetEntityType(typeof(Collection)); Uri id = new Uri(context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier); try { atomEntry = new AtomItem(name, text, null, id.ToString(), DateTime.UtcNow); } catch (Exception) { atomEntry = new AtomItem(); } atomEntry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); atomEntry.Links.Add(new SyndicationLink(id, "self", name, "application/atom+xml", 0)); //add description link UriBuilder search = new UriBuilder(context.BaseUrl + "/" + entityType.Keyword + "/" + this.Identifier + "/description"); atomEntry.Links.Add(new SyndicationLink(search.Uri, "search", name, "application/atom+xml", 0)); //add search link search = new UriBuilder(context.BaseUrl + "/" + entityType.Keyword + "/" + identifier + "/search"); atomEntry.Links.Add(new SyndicationLink(search.Uri, "public", name, "application/atom+xml", 0)); //add alternate link search = new UriBuilder(this.CatalogueDescriptionUrl); atomEntry.Links.Add(new SyndicationLink(search.Uri, "alternate", name, "application/atom+xml", 0)); //add via link Uri share = new Uri(context.BaseUrl + "/share?url=" + id.AbsoluteUri); atomEntry.Links.Add(new SyndicationLink(share, "via", name, "application/atom+xml", 0)); atomEntry.ReferenceData = this; var basepath = new UriBuilder(context.BaseUrl); basepath.Path = "user"; return(atomEntry); }
private AtomFeed OneWpsGenerateSyndicationFeed(NameValueCollection parameters) { UriBuilder myUrl = new UriBuilder(context.BaseUrl + "/" + this.Identifier); 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>(); var processes = GetWPSprocessesFromVMs(parameters); foreach (WpsProcessOffering process in processes) { try{ AtomItem item = process.ToAtomItem(parameters); if (item != null) { Items.Add(process); items.Add(item); } } catch (Exception) { //we do nothing, we just dont add the process } } // Load all avaialable Datasets according to the context if (this.Identifier != null) { feed.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); } feed.Items = items; feed.TotalResults = items.Count; return(feed); }
public static IGeometryObject FindGeometry(this AtomItem item) { IGeometryObject savegeom = null; savegeom = Terradue.Stars.Geometry.Atom.AtomExtensions.FindGeometry(item); if (savegeom == null) { var eop = item.GetEarthObservationProfile(); if (eop != null) { savegeom = EoProfileExtensions.FindGeometry(eop); } } return(savegeom); }
/// <summary> /// https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#date-and-time /// </summary> /// <param name="item"></param> /// <param name="properties"></param> private static void FillDateTimeProperties(AtomItem item, Dictionary <string, object> properties) { DateTime startDate = item.FindStartDate(); DateTime endDate = item.FindEndDate(); Itenso.TimePeriod.TimeInterval dateInterval = new Itenso.TimePeriod.TimeInterval(startDate, endDate); // remove previous values properties.Remove("datetime"); properties.Remove("start_datetime"); properties.Remove("end_datetime"); // datetime, start_datetime, end_datetime if (dateInterval.IsAnytime) { properties.Add("datetime", null); } else { if (dateInterval.IsMoment) { properties.Add("datetime", dateInterval.Start); } else { properties.Add("datetime", dateInterval.Start); properties.Add("start_datetime", dateInterval.Start); properties.Add("end_datetime", dateInterval.Start); } } if (item.PublishDate.Ticks != 0) { properties.Remove("created"); properties.Add("created", item.PublishDate.DateTime); } if (item.LastUpdatedTime.Ticks != 0) { properties.Remove("updated"); properties.Add("updated", item.LastUpdatedTime.DateTime); } }
public override AtomItem ToAtomItem(NameValueCollection parameters) { string identifier = (this.Identifier != null ? this.Identifier : "service" + this.Id); string name = (this.Name != null ? this.Name : identifier); if (!IsSearchable(parameters)) { return(null); } Uri alternate = new Uri(this.Url); AtomItem entry = new AtomItem(identifier, name, alternate, this.Id.ToString(), DateTime.UtcNow); entry.Categories.Add(new SyndicationCategory("service")); entry.Summary = new TextSyndicationContent(name); entry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", identifier); return(entry); }
public override AtomItem ToAtomItem(NameValueCollection parameters) { AtomItem result = new AtomItem(); if (Identifier != null) { var entityType = EntityType.GetEntityType(typeof(Transaction)); Uri id = new Uri(context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier); result.Id = id.ToString(); result.Title = new TextSyndicationContent(GetHumanReadableReference()); result.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); } else { result.Title = new TextSyndicationContent("n/a"); } result.ElementExtensions.Add("balance", "http://purl.org/dc/elements/1.1/", this.Balance); result.PublishDate = new DateTimeOffset(this.LogTime); result.Categories.Add(new SyndicationCategory("kind", null, (int)Kind + "")); return(result); }
/// <summary> /// https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#basics /// </summary> /// <param name="item"></param> /// <param name="properties"></param> private static void FillBasicsProperties(AtomItem item, Dictionary <string, object> properties) { // title if (item.Title != null) { properties.Remove("title"); properties.Add("title", item.Title.Text); } // description if (item.Summary != null) { properties.Remove("description"); var summary = item.Summary.Text; if (item.Summary.Type.Contains("html", StringComparison.InvariantCultureIgnoreCase)) { var converter = new Html2Markdown.Converter(); summary = converter.Convert(item.Summary.Text); } properties.Add("description", summary); } }
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); }
public override AtomItem ToAtomItem(NameValueCollection parameters) { string identifier = this.Identifier; string name = (this.Name != null ? this.Name : this.Identifier); string text = (this.TextContent != null ? this.TextContent : ""); AtomItem atomEntry = null; var entityType = EntityType.GetEntityType(typeof(DataPackage)); Uri id = new Uri(context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier); try { atomEntry = new AtomItem(identifier, name, null, id.ToString(), DateTime.UtcNow); } catch (Exception) { atomEntry = new AtomItem(); } atomEntry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); atomEntry.Links.Add(new SyndicationLink(id, "self", name, "application/atom+xml", 0)); UriBuilder search = new UriBuilder(context.BaseUrl + "/" + entityType.Keyword + "/" + (Kind == KINDRESOURCESETUSER ? "default" : identifier) + "/description"); atomEntry.Links.Add(new SyndicationLink(search.Uri, "search", name, "application/atom+xml", 0)); search = new UriBuilder(context.BaseUrl + "/" + entityType.Keyword + "/" + identifier + "/search"); search.Query = "key=" + this.AccessKey; atomEntry.Links.Add(new SyndicationLink(search.Uri, "public", name, "application/atom+xml", 0)); atomEntry.Links.Add(new SyndicationLink(search.Uri, "alternate", name, "application/atom+xml", 0)); Uri share = new Uri(context.BaseUrl + "/share?url=" + id.AbsoluteUri); atomEntry.Links.Add(new SyndicationLink(share, "via", name, "application/atom+xml", 0)); atomEntry.ReferenceData = this; atomEntry.PublishDate = new DateTimeOffset(this.CreationTime); if (Owner != null) { var basepath = new UriBuilder(context.BaseUrl); basepath.Path = "user"; string usrUri = basepath.Uri.AbsoluteUri + "/" + Owner.Username; string usrName = (!String.IsNullOrEmpty(owner.FirstName) && !String.IsNullOrEmpty(Owner.LastName) ? Owner.FirstName + " " + Owner.LastName : Owner.Username); SyndicationPerson author = new SyndicationPerson(null, usrName, usrUri); author.ElementExtensions.Add(new SyndicationElementExtension("identifier", "http://purl.org/dc/elements/1.1/", Owner.Username)); atomEntry.Authors.Add(author); atomEntry.Categories.Add(new SyndicationCategory("visibility", null, IsPublic() ? "public" : (IsRestricted() ? "restricted" : "private"))); if (Kind == KINDRESOURCESETUSER) { atomEntry.Categories.Add(new SyndicationCategory("default", null, "true")); } if (Owner.Id == context.UserId) { //for owner only, we give the link to know with who the data package is shared Uri sharedUrl = null; //if shared with users if (IsSharedToUser()) { sharedUrl = new Uri(string.Format("{0}/user/search?correlatedTo={1}", context.BaseUrl, HttpUtility.UrlEncode(id.AbsoluteUri))); } else if (IsSharedToCommunity()) { sharedUrl = new Uri(string.Format("{0}/community/search?correlatedTo={1}", context.BaseUrl, HttpUtility.UrlEncode(id.AbsoluteUri))); } if (sharedUrl != null) { atomEntry.Links.Add(new SyndicationLink(sharedUrl, "results", name, "application/atom+xml", 0)); } } } if (Items == null) { LoadItems(); } var nbitems = Items == null ? 0 : Items.Count; atomEntry.Categories.Add(new SyndicationCategory("nbItems", null, "" + nbitems)); if (Kind != KINDRESOURCESETNORMAL) { atomEntry.Categories.Add(new SyndicationCategory("kind", null, Kind == KINDRESOURCESETUSER ? "basket" : "app")); } return(atomEntry); }
//--------------------------------------------------------------------------------------------------------------------- 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)); }
AtomItem CreateItemFromLink(string key, Uri url, bool withOrbits) { string identifier = key.Replace(".EOF", ""); Match match = Regex.Match(identifier, @"^(?'mission'\w{3})_OPER_AUX_(?'type'\w{6})_(?'system'\w{4})_(?'proddate'\w{15})_V(?'startdate'\w{15})_(?'stopdate'\w{15})$"); if (!match.Success) return null; AtomItem item = new AtomItem(identifier, string.Format("{0} {1} {2} {3}", match.Groups["mission"].Value, match.Groups["type"].Value, match.Groups["startdate"].Value, match.Groups["stopdate"].Value), url, identifier, DateTimeOffset.ParseExact(match.Groups["proddate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture).ToUniversalTime()); DateTime start = DateTime.ParseExact(match.Groups["startdate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture).ToUniversalTime(); DateTime stop = DateTime.ParseExact(match.Groups["stopdate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture).ToUniversalTime(); item.Identifier = identifier; item.PublishDate = DateTimeOffset.ParseExact(match.Groups["proddate"].Value, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture).ToUniversalTime(); item.Links.Add(SyndicationLink.CreateMediaEnclosureLink(url, "application/xml", 0)); item.ElementExtensions.Add("polygon", "http://www.georss.org/georss", "-90 -180 -90 180 90 180 90 -180 -90 -180"); item.ElementExtensions.Add("date", "http://purl.org/dc/elements/1.1/", string.Format("{0}/{1}", start.ToString("O"), stop.ToString("O"))); Terradue.ServiceModel.Ogc.Eop21.EarthObservationType eo = OrbToEo(identifier, match.Groups["mission"].Value, match.Groups["type"].Value, start, stop, item.PublishDate); if (eo != null) { log.DebugFormat("EOP extension created from {0}", url); using (MemoryStream stream = new MemoryStream()) { XmlWriter writer = XmlWriter.Create(stream); var ser = OgcHelpers.GetXmlSerializerFromType(eo.GetType()); ser.Serialize(stream, eo); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); item.ElementExtensions.Add(XmlReader.Create(stream)); } } if (withOrbits) { var request = HttpWebRequest.Create(url); using (var response = request.GetResponse()) { Terradue.OpenSearch.SciHub.Data.Earth_Explorer_File eefile = (Terradue.OpenSearch.SciHub.Data.Earth_Explorer_File)eeser.Deserialize(response.GetResponseStream()); item.ElementExtensions.Add(GenerateOrbitsExtension(eefile)); } } return item; }
public override AtomItem ToAtomItem(NameValueCollection parameters) { if (!IsSearchable(parameters)) { return(null); } UserTep owner = (UserTep)UserTep.ForceFromId(context, this.OwnerId); //string identifier = null; string name = (Entity.Name != null ? Entity.Name : Entity.Identifier); string description = null; Uri id = new Uri(context.BaseUrl + "/" + this.ActivityEntityType.Keyword + "/search?id=" + Entity.Identifier); switch (this.Privilege.Operation) { case EntityOperationType.Create: description = string.Format("created {0} '{1}'", this.ActivityEntityType.SingularCaption, name); break; case EntityOperationType.Change: description = string.Format("updated {0} '{1}'", this.ActivityEntityType.SingularCaption, name); break; case EntityOperationType.Delete: description = string.Format("deleted {0} '{1}'", this.ActivityEntityType.SingularCaption, name); break; case EntityOperationType.Share: description = string.Format("shared {0} '{1}'", this.ActivityEntityType.SingularCaption, name); break; default: break; } //AtomItem atomEntry = null; AtomItem result = new AtomItem(); result.Id = id.ToString(); result.Title = new TextSyndicationContent(base.Entity.Identifier); result.Content = new TextSyndicationContent(name); result.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", Guid.NewGuid()); result.Summary = new TextSyndicationContent(description); result.ReferenceData = this; result.PublishDate = this.CreationTime; result.LastUpdatedTime = this.CreationTime; var basepath = new UriBuilder(context.BaseUrl); basepath.Path = "user"; string usrUri = basepath.Uri.AbsoluteUri + "/" + owner.Username; string usrName = (!String.IsNullOrEmpty(owner.FirstName) && !String.IsNullOrEmpty(owner.LastName) ? owner.FirstName + " " + owner.LastName : owner.Username); SyndicationPerson author = new SyndicationPerson(null, usrName, usrUri); var ownername = string.IsNullOrEmpty(owner.FirstName) || string.IsNullOrEmpty(owner.LastName) ? owner.Username : owner.FirstName + " " + owner.LastName; author.ElementExtensions.Add(new SyndicationElementExtension("identifier", "http://purl.org/dc/elements/1.1/", ownername)); author.ElementExtensions.Add(new SyndicationElementExtension("avatar", "http://purl.org/dc/elements/1.1/", owner.GetAvatar())); result.Authors.Add(author); result.Links.Add(new SyndicationLink(id, "self", name, "application/atom+xml", 0)); Uri share = new Uri(context.BaseUrl + "/share?url=" + System.Web.HttpUtility.UrlEncode(id.AbsoluteUri) + (!string.IsNullOrEmpty(AppId) ? "&id=" + AppId : "")); result.Links.Add(new SyndicationLink(share, "related", "share", "application/atom+xml", 0)); return(result); }
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; }
/// <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); }
internal string GetAtomItemText(Package package) { var item = new AtomItem(package); using(var sw = new StringWriter() ) { using(var xw = XmlWriter.Create(sw) ) { item.SaveAsAtom10(xw); } return sw.ToString(); } }
private void InsertIntoFeed(CanonicalName pkgCanonicalName, FourPartVersion pkgVersion, Uri location , AtomItem item = null) { lock (typeof(UploadedFileHandler)) { // update the feed var feed = new AtomFeed(); //load the feed from the _canonicalFeedUrl if we can try { var originalFeed = LoadFeed(); foreach (AtomItem i in originalFeed.Items.Where(each => each is AtomItem)) { if (_feedName == "current") { // if an older version of this package is in the current feed, if (i.Model.CanonicalName.DiffersOnlyByVersion(pkgCanonicalName) && i.Model.CanonicalName.Version < pkgVersion) { // push it to the archive feed. FeedHandlers["archive"].InsertIntoFeed(i.Model.CanonicalName, i.Model.Version, i.Model.Locations[0]); // and skip it continue; } } feed.Add(i); } } catch { } item = item ?? _packageManager.GetAtomItem(pkgCanonicalName).Result; if (item != null) { // first, make sure that the feeds contains the intended feed location. item.Model.Feeds = item.Model.Feeds ??new XList<Uri>(); if (!item.Model.Feeds.Contains(_canonicalFeedUrl)) { item.Model.Feeds.Insert(0, _canonicalFeedUrl); } item.Model.Locations = item.Model.Locations ?? new XList<Uri>(); if (!item.Model.Locations.Contains(location)) { item.Model.Locations.Insert(0, location); } // drop dead urls item.Model.Feeds = item.Model.Feeds.Distinct().Where(Peek).ToXList(); item.Model.Locations = item.Model.Locations.Distinct().Where(Peek).ToXList(); foreach( var l in item.Links.ToArray().Where( each => !Peek(each.Uri) ) ) { item.Links.Remove(l); } if (item.Model.Locations.Any()) { // if we've got at least one valid location, add the item to the feed. feed.Add(item); } } SaveFeed( feed); } }
public override AtomItem ToAtomItem(NameValueCollection parameters) { bool ispublic = this.Kind == DomainKind.Public; bool isprivate = this.Kind == DomainKind.Private; bool ishidden = this.Kind == DomainKind.Hidden; bool searchAll = false; if (!string.IsNullOrEmpty(parameters["visibility"])) { switch (parameters["visibility"]) { case "public": if (this.Kind != DomainKind.Public) { return(null); } break; case "private": if (this.Kind != DomainKind.Private) { return(null); } break; case "hidden": if (this.Kind != DomainKind.Hidden) { return(null); } break; case "owned": if (!(context.UserId == this.OwnerId)) { return(null); } break; case "all": searchAll = true; break; } } //if private or hidden, lets check the current user can access it (have a role in the domain) //if private but visibility=all, user can access if (ishidden || (isprivate && !searchAll)) { var proles = Role.GetUserRolesForDomain(context, context.UserId, this.Id); if (proles == null || proles.Length == 0) { return(null); } } var entityType = EntityType.GetEntityType(typeof(Domain)); Uri id = new Uri(context.BaseUrl + "/" + entityType.Keyword + "/search?id=" + this.Identifier); if (!string.IsNullOrEmpty(parameters["q"])) { string q = parameters["q"].ToLower(); if (!this.Identifier.ToLower().Contains(q) && !(Description != null && Description.ToLower().Contains(q))) { return(null); } } AtomItem result = new AtomItem(); result.Id = id.ToString(); result.Title = new TextSyndicationContent(Identifier); result.Content = new TextSyndicationContent(Identifier); result.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", this.Identifier); result.Summary = new TextSyndicationContent(Description); result.ReferenceData = this; result.PublishDate = new DateTimeOffset(DateTime.UtcNow); //members var roles = new EntityList <Role>(context); roles.Load(); foreach (var role in roles) { var usrs = role.GetUsers(this.Id); foreach (var usrId in usrs) { User usr = User.FromId(context, usrId); SyndicationPerson author = new SyndicationPerson(usr.Email, usr.FirstName + " " + usr.LastName, ""); author.ElementExtensions.Add(new SyndicationElementExtension("identifier", "http://purl.org/dc/elements/1.1/", usr.Username)); author.ElementExtensions.Add(new SyndicationElementExtension("role", "http://purl.org/dc/elements/1.1/", role.Identifier)); result.Authors.Add(author); } } result.Links.Add(new SyndicationLink(id, "self", Identifier, "application/atom+xml", 0)); if (!string.IsNullOrEmpty(IconUrl)) { Uri uri; if (IconUrl.StartsWith("http")) { uri = new Uri(IconUrl); } else { var urib = new UriBuilder(System.Web.HttpContext.Current.Request.Url); urib.Path = IconUrl; uri = urib.Uri; } result.Links.Add(new SyndicationLink(uri, "icon", "", GetImageMimeType(IconUrl), 0)); } result.Categories.Add(new SyndicationCategory("visibility", null, ispublic ? "public" : isprivate ? "private" : "hidden")); return(result); }
public AtomItemNode(AtomItem item, Uri sourceUri, System.Net.ICredentials credentials = null) { this.item = item; this.sourceUri = sourceUri; this.credentials = credentials; }
/// <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; }