Exemple #1
0
        void ListChildrensItemsAndAssets(IStacParent catalog, Uri baseUri, string prefix = "", int limit = 2)
        {
            // Get children first (sub catalogs and collections)
            foreach (var childLink in catalog.GetChildrenLinks().Concat(catalog.GetItemLinks()))
            {
                Uri childUri = childLink.Uri;
                if (!childUri.IsAbsoluteUri)
                {
                    childUri = new Uri(baseUri, childUri.ToString());
                }
                IStacObject child = StacConvert.Deserialize <IStacObject>(httpClient.GetStringAsync(childUri).GetAwaiter().GetResult());

                Console.Out.WriteLine(prefix + child.Id + ": " + child.Title);
                if (child is StacCatalog || child is StacCollection)
                {
                    ListChildrensItemsAndAssets(child as IStacParent, childUri, prefix + " ");
                }

                if (child is StacItem)
                {
                    foreach (var asset in (child as StacItem).Assets)
                    {
                        Console.Out.WriteLine(prefix + asset.Key + ": *[" + asset.Value.MediaType + "] " + asset.Value.Uri);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initialize a new asset from an existing one
 /// </summary>
 /// <param name="source">asset source to be copied</param>
 /// <param name="stacObject">new parent stac object</param>
 public StacAsset(StacAsset source, IStacObject stacObject)
 {
     if (!(stacObject == null || stacObject is StacItem || stacObject is StacCollection))
     {
         throw new InvalidOperationException("An asset cannot be defined in " + stacObject.GetType().Name);
     }
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     base_uri = source.base_uri;
     href     = source.href;
     if (source.Roles != null)
     {
         Roles = new SortedSet <string>(source.Roles);
     }
     else
     {
         Roles = new SortedSet <string>();
     }
     title       = source.title;
     type        = source.type;
     description = source.description;
     if (source.properties != null)
     {
         properties = new Dictionary <string, object>(source.properties);
     }
     parentStacObject = stacObject;
 }
Exemple #3
0
 public SchemaBasedStacExtension(Uri jsonSchema,
                                 IStacObject stacObject) : base(jsonSchema.ToString(),
                                                                stacObject)
 {
     Preconditions.CheckNotNull <Uri>(jsonSchema, "jsonSchema");
     JsonSchema      = jsonSchema;
     this.stacObject = stacObject;
 }
Exemple #4
0
 public ViewStacExtension(IStacObject stacObject) : base(JsonSchemaUrl, stacObject)
 {
     itemFields = new Dictionary <string, Type>();
     itemFields.Add(OffNadirField, typeof(double));
     itemFields.Add(IncidenceAngleField, typeof(double));
     itemFields.Add(AzimuthField, typeof(double));
     itemFields.Add(SunAzimuthField, typeof(double));
     itemFields.Add(SunElevationField, typeof(double));
 }
Exemple #5
0
 public SchemaBasedStacExtension(Uri schemaUri,
                                 StacSchemaResolver stacSchemaResolver,
                                 IStacObject stacObject) : base(schemaUri.ToString(),
                                                                stacObject)
 {
     Preconditions.CheckNotNull <Uri>(schemaUri, "schemaUri");
     this.stacObject = stacObject;
     JsonSchema      = schemaUri;
 }
Exemple #6
0
 public static string Serialize(IStacObject stacObject, JsonSerializerSettings serializerSettings = null)
 {
     if (serializerSettings == null)
     {
         serializerSettings = defaultJsonSerializerSettings;
     }
     serializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
     return(JsonConvert.SerializeObject(stacObject, serializerSettings));
 }
Exemple #7
0
 /// <summary>
 /// Initialize a new asset with a Uri
 /// </summary>
 /// <param name="stacObject">parent stac object</param>
 /// <param name="uri">uri to the asset</param>
 public StacAsset(IStacObject stacObject, Uri uri) : this()
 {
     if (!(stacObject == null || stacObject is StacItem || stacObject is StacCollection))
     {
         throw new InvalidOperationException("An asset cannot be defined in " + stacObject.GetType().Name);
     }
     parentStacObject = stacObject;
     Uri = uri;
 }
Exemple #8
0
 protected StacNode(IStacObject stacObject, Uri uri = null, ICredentials credentials = null)
 {
     if (stacObject == null)
     {
         throw new ArgumentNullException("stacObject");
     }
     this.stacObject  = stacObject;
     this.credentials = credentials;
     this.uri         = uri == null ? new Uri(Id + ".json", UriKind.Relative) : uri;
 }
Exemple #9
0
        public static SchemaBasedStacExtension Create(string shortcut,
                                                      StacSchemaResolver stacSchemaResolver,
                                                      IStacObject stacObject)
        {
            if (StacSchemaResolver.CoreTypes.Contains(shortcut))
            {
                throw new Exceptions.InvalidStacSchemaException(shortcut + "is not an extension");
            }
            Uri schema = new Uri($"https://stac-extensions.github.io/{shortcut}/v1.0.0/schema.json");

            return(new SchemaBasedStacExtension(schema, stacObject));
        }
Exemple #10
0
 internal StacObjectLink(IStacObject stacObject, Uri uri)
 {
     this.stacObject = stacObject;
     if (stacObject is StacItem)
     {
         this.RelationshipType = "item";
     }
     if (stacObject is StacCatalog || stacObject is StacCollection)
     {
         this.RelationshipType = "child";
     }
     Uri = uri;
 }
        public static async Task <IDictionary <Uri, StacItem> > GetItemsAsync(this IStacObject stacObject, Uri baseUri, StacRouter stacRouter)
        {
            Dictionary <Uri, StacItem> items = new Dictionary <Uri, StacItem>();

            foreach (var itemLink in stacObject.Links.Where(l => !string.IsNullOrEmpty(l.RelationshipType) && l.RelationshipType == "item"))
            {
                Uri linkUri = itemLink.Uri;
                if (!linkUri.IsAbsoluteUri && baseUri.IsAbsoluteUri)
                {
                    linkUri = new Uri(baseUri, itemLink.Uri);
                }
                items.Add(linkUri, await itemLink.CreateStacObject(baseUri, stacRouter.Credentials) as StacItem);
            }
            return(items);
        }
        public static async Task <IDictionary <Uri, IStacCatalog> > GetChildrenAsync(this IStacObject stacObject, Uri baseUri, StacRouter stacRouter)
        {
            Dictionary <Uri, IStacCatalog> children = new Dictionary <Uri, IStacCatalog>();

            foreach (var childLink in stacObject.Links.Where(l => !string.IsNullOrEmpty(l.RelationshipType) && l.RelationshipType == "child"))
            {
                Uri linkUri = childLink.Uri;
                if (!linkUri.IsAbsoluteUri && baseUri.IsAbsoluteUri)
                {
                    linkUri = new Uri(baseUri, childLink.Uri);
                }
                children.Add(linkUri, await childLink.CreateStacObject(baseUri, stacRouter.Credentials) as IStacCatalog);
            }
            return(children);
        }
 public static IDictionary <Uri, IStacCatalog> GetChildren(this IStacObject stacObject, Uri baseUri, StacRouter stacRouter)
 {
     return(GetChildrenAsync(stacObject, baseUri, stacRouter).GetAwaiter().GetResult());
 }
Exemple #14
0
 public static void SetProperty(this IStacObject stacObject, string key, object value)
 {
     stacObject.Properties.SetProperty(key, value);
 }
Exemple #15
0
 /// <summary>
 /// Create a metadata asset
 /// </summary>
 /// <param name="stacObject">parent stac object</param>
 /// <param name="uri">Uri to the metadata</param>
 /// <param name="mediaType">media type of the metadata</param>
 /// <param name="title">title of the metadata (if any)</param>
 /// <returns>A new Asset describing the metadata</returns>
 public static StacAsset CreateMetadataAsset(IStacObject stacObject, Uri uri, ContentType mediaType, string title = null)
 {
     return(new StacAsset(stacObject, uri, new string[] { "metadata" }, title, mediaType));
 }
Exemple #16
0
 internal VersionStacExtension(IStacObject stacObject) : base(JsonSchemaUrl, stacObject)
 {
     itemFields = new Dictionary<string, Type>();
     itemFields.Add(VersionField, typeof(string));
     itemFields.Add(DeprecatedField, typeof(bool));
 }
Exemple #17
0
        /// <summary>
        /// Create a new Virtual Asset from assets defined in an existing stac item
        /// </summary>
        /// <param name="stacItem">Stac Item to reference the assets from</param>
        /// <param name="assetsKey">keys of the assets to be referenced</param>
        /// <param name="newStacObject">new stac object container of the virtuals assets. If not specified, the stacItem is used</param>
        /// <returns></returns>
        public static VirtualAsset Create(StacItem stacItem, IList <string> assetsKey, IStacObject newStacObject = null)
        {
            IStacObject parentObject = newStacObject == null ? stacItem : newStacObject;

            return(new VirtualAsset(parentObject, stacItem.Assets.Select(asset => new Uri(asset.Value.Uri, "#" + asset.Key)).ToList()));
        }
Exemple #18
0
 /// <summary>
 /// Initialize a new asset
 /// </summary>
 /// <param name="stacObject">parent stac object</param>
 /// <param name="uri">uri to the asset</param>
 /// <param name="roles">roles of the asset</param>
 /// <param name="title">title of the asset</param>
 /// <param name="mediaType">media-type of the asset</param>
 public StacAsset(IStacObject stacObject, Uri uri, IEnumerable <string> roles, string title, ContentType mediaType) : this(stacObject, uri)
 {
     Roles     = roles == null ? new SortedSet <string>() : new SortedSet <string>(roles.ToList());
     Title     = title;
     MediaType = mediaType;
 }
Exemple #19
0
 /// <summary>
 /// Initialize a new Virtual Asset for a STAC object with an array of items
 /// </summary>
 /// <returns></returns>
 public VirtualAsset(IStacObject stacObject, IList <Uri> uris) : base(stacObject, null)
 {
     Uris = uris;
 }
Exemple #20
0
 /// <summary>
 /// Create a thumbnail asset
 /// </summary>
 /// <param name="stacObject">parent stac object</param>
 /// <param name="uri">Uri to the thumbnail</param>
 /// <param name="mediaType">media type of the thumbnail</param>
 /// <param name="title">title of the thumbnail (if any)</param>
 /// <returns>A new Asset describing the thumbnail</returns>
 public static StacAsset CreateThumbnailAsset(IStacObject stacObject, Uri uri, ContentType mediaType, string title = null)
 {
     return(new StacAsset(stacObject, uri, new string[] { "thumbnail" }, title, mediaType));
 }
 public static IDictionary <Uri, StacItem> GetItems(this IStacObject stacObject, Uri baseUri, StacRouter stacRouter)
 {
     return(GetItemsAsync(stacObject, baseUri, stacRouter).GetAwaiter().GetResult());
 }
Exemple #22
0
 /// <summary>
 /// Create an overview asset
 /// </summary>
 /// <param name="stacObject">parent stac object</param>
 /// <param name="uri">Uri to the overview</param>
 /// <param name="mediaType">media type of the overview</param>
 /// <param name="title">title of the overview (if any)</param>
 /// <returns>A new Asset describing the overview</returns>
 public static StacAsset CreateOverviewAsset(IStacObject stacObject, Uri uri, ContentType mediaType, string title = null)
 {
     return(new StacAsset(stacObject, uri, new string[] { "overview" }, title, mediaType));
 }
Exemple #23
0
 public static StacLink CreateObjectLink(IStacObject stacObject, Uri uri)
 {
     return(new StacObjectLink(stacObject, uri));
 }
Exemple #24
0
 internal VirtualAssetsStacExtension(IStacObject stacObject) : base(JsonSchemaUrl, stacObject)
 {
     itemFields = new Dictionary <string, Type>();
     itemFields.Add(VirtualAssetsField, typeof(VirtualAsset));
 }