Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Feb 7, 2023
1 parent 1203c35 commit 2846bdf
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ dotnet_diagnostic.IDE0073.severity = warning # Enforce file header
file_header_template = Copyright (c) by Terradue Srl. All Rights Reserved.\nLicense under the AGPL, Version 3.0.\nFile Name: {fileName}

dotnet_diagnostic.SA1101.severity = warning # Prefix local calls with this
dotnet_diagnostic.SA1116.severity = warning # Split parameters should start on line after declaration
dotnet_diagnostic.SA1119.severity = warning # Statement must not use unnecessary parenthesis
dotnet_diagnostic.SA1124.severity = warning # Do not use regions
dotnet_diagnostic.SA1127.severity = warning # Generic type constraints must be on their own line or share line with previous
Expand Down
3 changes: 3 additions & 0 deletions src/DotNetStac/Collection/IStacSummaryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public interface IStacSummaryItem : IEnumerable<JToken>
/// <summary>
/// Gets the summary item as a JToken
/// </summary>
/// <value>
/// The summary item as a JToken
/// </value>
IEnumerable<object> Enumerate();

}
Expand Down
9 changes: 6 additions & 3 deletions src/DotNetStac/Collection/StacExtent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static StacExtent Create(IEnumerable<StacItem> items)
minDate = minDate == DateTime.MinValue ? null : minDate;
maxDate = maxDate == DateTime.MaxValue ? null : maxDate;
return new StacExtent(
new StacSpatialExtent(items.Min(i => i.GetBoundingBoxFromGeometryExtent()[0]),
new StacSpatialExtent(
items.Min(i => i.GetBoundingBoxFromGeometryExtent()[0]),
items.Min(i => i.GetBoundingBoxFromGeometryExtent()[1]),
items.Max(i => i.GetBoundingBoxFromGeometryExtent()[2]),
items.Max(i => i.GetBoundingBoxFromGeometryExtent()[3])),
Expand All @@ -82,7 +83,8 @@ public object Clone()

internal void Update(ICollection<StacItem> items)
{
this.Spatial = new StacSpatialExtent(items.Select(i => i.GetBoundingBoxFromGeometryExtent()[0])
this.Spatial = new StacSpatialExtent(
items.Select(i => i.GetBoundingBoxFromGeometryExtent()[0])
.Concat(new double[] { this.Spatial.BoundingBoxes[0][0] })
.Min(),
items.Select(i => i.GetBoundingBoxFromGeometryExtent()[1])
Expand All @@ -94,7 +96,8 @@ internal void Update(ICollection<StacItem> items)
items.Select(i => i.GetBoundingBoxFromGeometryExtent()[3])
.Concat(new double[] { this.Spatial.BoundingBoxes[0][3] })
.Max());
this.Temporal = new StacTemporalExtent(items.Select(i => i.DateTime.Start)
this.Temporal = new StacTemporalExtent(
items.Select(i => i.DateTime.Start)
.Concat(new DateTime[] { this.Temporal.Interval[0][0].GetValueOrDefault() })
.Min(),
items.Select(i => i.DateTime.End)
Expand Down
9 changes: 6 additions & 3 deletions src/DotNetStac/Extensions/File/FileStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public static FileStacExtension FileExtension(this StacAsset stacAsset)
/// - size
/// - checksum
/// </summary>
public static async Task SetFileExtensionProperties(this FileStacExtension fileStacExtension,
public static async Task SetFileExtensionProperties(
this FileStacExtension fileStacExtension,
FileInfo file,
HashType hashType = HashType.SHA1,
MultibaseEncoding encoding = MultibaseEncoding.Base16Lower)
Expand All @@ -139,7 +140,8 @@ public static async Task SetFileExtensionProperties(this FileStacExtension fileS
/// - size
/// - checksum
/// </summary>
public static async Task SetFileExtensionProperties(this FileStacExtension fileStacExtension,
public static async Task SetFileExtensionProperties(
this FileStacExtension fileStacExtension,
Stream stream,
HashType hashType = HashType.SHA1,
MultibaseEncoding encoding = MultibaseEncoding.Base16Lower)
Expand All @@ -150,7 +152,8 @@ public static async Task SetFileExtensionProperties(this FileStacExtension fileS
/// <summary>
/// Add the checksum property of the file extension
/// </summary>
public static async Task SetFileCheckSum(this FileStacExtension fileStacExtension,
public static async Task SetFileCheckSum(
this FileStacExtension fileStacExtension,
HashType hashType,
MultibaseEncoding encoding,
Func<Uri, Stream> uriStreamer)
Expand Down
6 changes: 4 additions & 2 deletions src/DotNetStac/Extensions/ItemCollection/ItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public class ItemCollection : StacCollection, IStacExtension

public const string JsonSchemaUrl = "https://stac-extensions.github.io/processing/v1.0.0/schema.json";

public ItemCollection(string id,
public ItemCollection(
string id,
string description,
List<StacItem> stacItems)
: base(id,
: base(
id,
description,
null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public static ProcessingStacExtension ProcessingExtension(this StacItem stacItem
/// <summary>
/// Initialize the major fields of processing extensions
/// </summary>
public static void Init(this ProcessingStacExtension processingStacExtension,
public static void Init(
this ProcessingStacExtension processingStacExtension,
string lineage,
string level,
string facility = null)
Expand Down
3 changes: 2 additions & 1 deletion src/DotNetStac/Extensions/Sar/SarStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static StacAsset GetAsset(this StacItem stacItem, string polarization)
return stacItem.Assets.Values.FirstOrDefault(a => a.SarExtension().Polarizations.Contains(polarization));
}

public static void Required(this SarStacExtension sarStacExtension,
public static void Required(
this SarStacExtension sarStacExtension,
string instrumentMode,
SarCommonFrequencyBandName frequencyBandName,
string[] polarizations,
Expand Down
15 changes: 10 additions & 5 deletions src/DotNetStac/Extensions/SchemaBasedStacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ public class SchemaBasedStacExtension : StacPropertiesContainerExtension, IStacE
{
private readonly IStacObject stacObject;

public SchemaBasedStacExtension(Uri jsonSchema,
public SchemaBasedStacExtension(
Uri jsonSchema,
IStacObject stacObject)
: base(jsonSchema.ToString(),
: base(
jsonSchema.ToString(),
stacObject)
{
Preconditions.CheckNotNull(jsonSchema, "jsonSchema");
this.JsonSchema = jsonSchema;
this.stacObject = stacObject;
}

public SchemaBasedStacExtension(Uri schemaUri,
public SchemaBasedStacExtension(
Uri schemaUri,
StacSchemaResolver stacSchemaResolver,
IStacObject stacObject)
: base(schemaUri.ToString(),
: base(
schemaUri.ToString(),
stacObject)
{
Preconditions.CheckNotNull(schemaUri, "schemaUri");
Expand All @@ -43,7 +47,8 @@ public SchemaBasedStacExtension(Uri schemaUri,
/// <inheritdoc/>
public override IDictionary<string, Type> ItemFields => new Dictionary<string, Type>();

public static SchemaBasedStacExtension Create(string shortcut,
public static SchemaBasedStacExtension Create(
string shortcut,
StacSchemaResolver stacSchemaResolver,
IStacObject stacObject)
{
Expand Down
28 changes: 18 additions & 10 deletions src/DotNetStac/Model/ObservableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Stac.Model
{
#pragma warning disable SA1649 // File name should match first type name

/// <summary>
/// Provides a thread-safe dictionary for use with data binding.
/// </summary>
Expand Down Expand Up @@ -69,6 +71,13 @@ public ICollection<TValue> Values
get => this._dictionary.Values;
}

/// <inheritdoc/>
public TValue this[TKey key]
{
get => this._dictionary[key];
set => this.UpdateWithNotification(key, value);
}

/// <summary>
/// Notifies observers of CollectionChanged or PropertyChanged of an update to the dictionary.
/// </summary>
Expand All @@ -78,7 +87,8 @@ private void NotifyObserversOfChange()
var propertyHandler = this.PropertyChanged;
if (collectionHandler != null || propertyHandler != null)
{
this._context.Send(s =>
this._context.Send(
s =>
{
collectionHandler?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
propertyHandler?.Invoke(this, new PropertyChangedEventArgs("Count"));
Expand All @@ -99,7 +109,8 @@ private void NotifyObserversOfChange(NotifyCollectionChangedAction actionType, o
var propertyHandler = this.PropertyChanged;
if (collectionHandler != null || propertyHandler != null)
{
this._context.Send(s =>
this._context.Send(
s =>
{
collectionHandler?.Invoke(this, new NotifyCollectionChangedEventArgs(actionType, changedItem));
propertyHandler?.Invoke(this, new PropertyChangedEventArgs("Count"));
Expand All @@ -121,7 +132,8 @@ private void NotifyObserversOfChange(NotifyCollectionChangedAction actionType, o
var propertyHandler = this.PropertyChanged;
if (collectionHandler != null || propertyHandler != null)
{
this._context.Send(s =>
this._context.Send(
s =>
{
collectionHandler?.Invoke(this, new NotifyCollectionChangedEventArgs(actionType, item, index));
propertyHandler?.Invoke(this, new PropertyChangedEventArgs("Count"));
Expand Down Expand Up @@ -216,13 +228,6 @@ bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue>
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
=> ((ICollection<KeyValuePair<TKey, TValue>>)this._dictionary).CopyTo(array, arrayIndex);

/// <inheritdoc/>
public TValue this[TKey key]
{
get => this._dictionary[key];
set => this.UpdateWithNotification(key, value);
}

bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
=> this.TryRemoveWithNotification(item.Key, out TValue temp);

Expand Down Expand Up @@ -252,4 +257,7 @@ public bool Remove(TKey key)
public bool TryGetValue(TKey key, out TValue value)
=> this._dictionary.TryGetValue(key, out value);
}

#pragma warning restore SA1649 // File name should match first type name

}
28 changes: 14 additions & 14 deletions src/DotNetStac/StacAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ internal StacAsset()
this.Roles = new SortedSet<string>();
}

/// <summary>
/// Gets or sets media type of the asset
/// </summary>
/// <value>
/// Media type of the asset
/// </value>
[JsonProperty("type")]
[JsonConverter(typeof(ContentTypeConverter))]
public ContentType MediaType
{
get { return this._type; }
set { this._type = value; }
}

/// <summary>
/// Create a thumbnail asset
/// </summary>
Expand Down Expand Up @@ -158,20 +172,6 @@ public static StacAsset CreateMetadataAsset(IStacObject stacObject, Uri uri, Con
return new StacAsset(stacObject, uri, new string[] { "metadata" }, title, mediaType);
}

/// <summary>
/// Gets or sets media type of the asset
/// </summary>
/// <value>
/// Media type of the asset
/// </value>
[JsonProperty("type")]
[JsonConverter(typeof(ContentTypeConverter))]
public ContentType MediaType
{
get { return this._type; }
set { this._type = value; }
}

/// <summary>
/// Gets the semantic roles of the asset
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/DotNetStac/StacCatalog.CommonMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public Itenso.TimePeriod.ITimePeriod DateTime
if (this.Properties.ContainsKey("start_datetime") && this.Properties.ContainsKey("end_datetime"))
{
if (this.Properties["start_datetime"] is DateTime? && this.Properties["end_datetime"] is DateTime?)
return new Itenso.TimePeriod.TimeInterval((DateTime)this.Properties["start_datetime"],
return new Itenso.TimePeriod.TimeInterval(
(DateTime)this.Properties["start_datetime"],
(DateTime)this.Properties["end_datetime"]);
throw new FormatException(string.Format("start_datetime and/or end_datetime are not a valid: {0}", e.Message), e);
}
Expand Down
6 changes: 4 additions & 2 deletions src/DotNetStac/StacCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public partial class StacCollection : IStacObject, IStacParent, IStacCatalog, IC
public static readonly ContentType COLLECTION_MEDIATYPE = new ContentType(MEDIATYPE);

[JsonConstructor]
public StacCollection(string id,
public StacCollection(
string id,
string description,
StacExtent extent,
IDictionary<string, StacAsset> assets = null,
Expand Down Expand Up @@ -222,7 +223,8 @@ public bool ShouldSerializeAssets()
/// <param name="license">License of the collection</param>
/// <param name="collectionUri">Uri of the collection. If provided, the items Uri and made relative to this one.</param>
/// <param name="assets">Assets of the collection</param>
public static StacCollection Create(string id,
public static StacCollection Create(
string id,
string description,
IDictionary<Uri, StacItem> items,
string license = null,
Expand Down
3 changes: 2 additions & 1 deletion src/DotNetStac/StacItem.CommonMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public Itenso.TimePeriod.ITimePeriod DateTime
if (this.Properties.ContainsKey("start_datetime") && this.Properties.ContainsKey("end_datetime"))
{
if (this.Properties["start_datetime"] is DateTime? && this.Properties["end_datetime"] is DateTime?)
return new Itenso.TimePeriod.TimeInterval((DateTime)this.Properties["start_datetime"],
return new Itenso.TimePeriod.TimeInterval(
(DateTime)this.Properties["start_datetime"],
(DateTime)this.Properties["end_datetime"]);
throw new FormatException(string.Format("start_datetime and/or end_datetime are not a valid"));
}
Expand Down
12 changes: 7 additions & 5 deletions src/DotNetStac/StacItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public partial class StacItem : GeoJSON.Net.Feature.Feature, IStacObject, IClone
private readonly StacItemRootPropertyContainer Root;

[JsonConstructor]
public StacItem(string id,
public StacItem(
string id,
IGeometryObject geometry,
IDictionary<string, object> properties = null)
: base(geometry, properties, id)
Expand All @@ -45,7 +46,8 @@ public StacItem(string id,
}

public StacItem(StacItem stacItem)
: base(Preconditions.CheckNotNull(stacItem, "stacItem").Geometry,
: base(
Preconditions.CheckNotNull(stacItem, "stacItem").Geometry,
new Dictionary<string, object>(Preconditions.CheckNotNull(stacItem).Properties),
Preconditions.CheckNotNull(stacItem, "id").Id)
{
Expand Down Expand Up @@ -97,6 +99,9 @@ public ICollection<StacLink> Links
[JsonIgnore]
public ContentType MediaType => ITEM_MEDIATYPE;

[JsonProperty("assets", Order = 4)]
public IDictionary<string, StacAsset> Assets { get; private set; }

private void LinksCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
Expand All @@ -122,9 +127,6 @@ private void LinksCollectionChanged(object sender, NotifyCollectionChangedEventA
}
}

[JsonProperty("assets", Order = 4)]
public IDictionary<string, StacAsset> Assets { get; private set; }

/// <summary>
/// Gets or sets the id of the STAC Collection this Item references to
/// </summary>
Expand Down
16 changes: 8 additions & 8 deletions src/DotNetStac/StacLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public StacLink(StacLink source)
this.Parent = source.Parent;
this.Length = source.Length;
}

[JsonProperty("type")]
[DataMember(Name = "type")]
public string Type
{
get => this.ContentType?.ToString();
set => this.ContentType = value == null ? null : new ContentType(value);
}

public static StacLink CreateSelfLink(Uri uri, string mediaType = null, string title = null)
{
Expand Down Expand Up @@ -92,14 +100,6 @@ public static StacLink CreateObjectLink(IStacObject stacObject, Uri uri)
return new StacObjectLink(stacObject, uri);
}

[JsonProperty("type")]
[DataMember(Name = "type")]
public string Type
{
get => this.ContentType?.ToString();
set => this.ContentType = value == null ? null : new ContentType(value);
}

[JsonIgnore]
[IgnoreDataMember]
public virtual ContentType ContentType { get; set; }
Expand Down

0 comments on commit 2846bdf

Please sign in to comment.