From 7a98692a829c993d685f0e0277310900b9e438b9 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 4 Jun 2024 12:13:40 +0200 Subject: [PATCH 1/3] Add Collection Node Copy --- .editorconfig | 2 +- .vscode/launch.json | 28 ++ .../Utilities/XunitTextWriter.cs | 2 +- .../ConsoleCredentialsManager.cs | 32 +-- src/Stars.Console/ConsoleUserSettings.cs | 2 +- src/Stars.Console/Operations/BaseOperation.cs | 2 +- src/Stars.Console/Operations/CopyOperation.cs | 254 ++++++++++-------- src/Stars.Console/Operations/ListOperation.cs | 2 +- src/Stars.Console/PluginLoadContext.cs | 2 +- .../StarsConsoleLoggerProvider.cs | 2 +- .../Harvesters/MetadataExtractorsTests.cs | 8 +- .../SearchExpressionSupplierTests.cs | 4 +- src/Stars.Data.Tests/TestBase.cs | 2 +- src/Stars.Data.Tests/TestFileAsset.cs | 6 +- src/Stars.Data.Tests/TestNode.cs | 8 +- .../Translators/StacItemToAtomItemTests.cs | 6 +- src/Stars.Data/Log4Net2LoggerAppender.cs | 2 +- src/Stars.Data/Model/Atom/StarsAtomItem.cs | 4 +- .../Airbus/AirbusMetadataExtractor.cs | 2 +- .../Metadata/Alos2/Alos2MetadataExtractor.cs | 16 +- .../Metadata/Bka/BkaMetadataExtractor.cs | 2 +- .../BlackSkyGlobalMetadataExtractor.cs | 20 +- .../CosmoSkymedMetadataExtractor.cs | 8 +- .../Metadata/Dimap/DimapMetadataExtractor.cs | 2 +- .../Gaofen1-2-4/GaofenMetadataExtractor.cs | 2 +- .../Gaofen3/Gaofen3MetadataExtractor.cs | 2 +- .../Metadata/Gdal/GdalMetadataExtractor.cs | 2 +- .../Geoeye/GeoeyeMetadataExtractor.cs | 2 +- .../Metadata/Iceye/IceyeMetadataExtractor.cs | 2 +- .../Metadata/Inpe/InpeMetadataExtractor.cs | 18 +- .../Metadata/Isro/IsroMetadataExtractor.cs | 4 +- .../Kajabity/Tools/Java/JavaPropertyReader.cs | 10 +- .../Kajabity/Tools/Java/JavaPropertyWriter.cs | 6 +- .../Kanopus/KanopusVMetadataExtractor.cs | 4 +- .../Model/Metadata/Kompsat3/Auxiliary.cs | 2 +- .../Kompsat3/Kompsat3MetadataExtractor.cs | 2 +- .../Kompsat3/XmlKeyTextValueListWrapper.cs | 4 +- .../Kompsat5/Kompsat5MetadataExtractor.cs | 10 +- .../Landsat8/Landsat8MetadataExtractor.cs | 2 +- .../Landsat9/Landsat9MetadataExtractor.cs | 2 +- .../NewSat/NewSatMetadataExtractor.cs | 2 +- .../PlanetScopeMetadataExtractor.cs | 4 +- .../Metadata/RCM/RcmMetadataExtractor.cs | 2 +- .../Resursp/ResurspMetadataExtractor.cs | 2 +- .../Saocom1/Saocom1MetadataExtractor.cs | 2 +- .../Sentinel1/S1L1AssetCalibration.cs | 2 +- .../Sentinels/Sentinel1/S1L1AssetNoise.cs | 2 +- .../Sentinels/Sentinel1/S1L1AssetProduct.cs | 2 +- .../Sentinels/Sentinel1/S1L2AssetProduct.cs | 2 +- .../Sentinel1/Sentinel1MetadataExtractor.cs | 2 +- .../Sentinel2Level1MetadataExtractor.cs | 4 +- .../Sentinel2Level2MetadataExtractor.cs | 4 +- .../Sentinels/SentinelMetadataExtractor.cs | 2 +- .../Sentinels/SentinelSafeStacFactory.cs | 4 +- .../TerrasarX/TerrasarXMetadataExtractor.cs | 2 +- .../Metadata/Vrss/VrssMetadataExtractor.cs | 6 +- .../Worldview/WorldviewMetadataExtractor.cs | 2 +- .../Routers/DataHubResultItemRoutable.cs | 2 +- .../Routers/OpenSearchResultFeedRoutable.cs | 6 +- .../Routers/OpenSearchResultItemRoutable.cs | 6 +- src/Stars.Data/Routers/OrderableAsset.cs | 2 +- .../Routers/TransferRequestAsset.cs | 4 +- .../Suppliers/Astrium/GeodeliverySupplier.cs | 6 +- .../Suppliers/DataHubSourceSupplier.cs | 4 +- .../PlanetScope/PlanetScopeSupplier.cs | 4 +- .../Publication/GeosquarePublicationModel.cs | 2 +- .../Publication/GeosquareService.cs | 4 +- .../StacCollectionToAtomItemTranslator.cs | 2 +- .../StacItemToAtomItemTranslator.cs | 2 +- src/Stars.Geometry/Atom/AtomExtensions.cs | 2 +- src/Stars.Geometry/Gml/Gml311Extensions.cs | 2 +- src/Stars.Geometry/Gml/Gml321Extensions.cs | 12 +- src/Stars.Geometry/Wkt/WktExtensions.cs | 17 +- src/Stars.Services/AssetImportException.cs | 2 +- src/Stars.Services/BlockingStream.cs | 10 +- src/Stars.Services/FilteredAssetContainer.cs | 4 +- .../Model/Atom/AtomExtensions.cs | 2 +- .../Model/Atom/AtomFeedCatalog.cs | 2 +- src/Stars.Services/Model/Atom/AtomItemNode.cs | 4 +- .../Model/Atom/AtomLinkAsset.cs | 4 +- .../Model/Atom/AtomResourceLink.cs | 2 +- src/Stars.Services/Model/Atom/AtomRouter.cs | 4 +- src/Stars.Services/Model/Stac/StacNode.cs | 2 +- .../Model/Stac/StacResourceLink.cs | 2 +- .../Plugins/PluginPriorityAttribute.cs | 2 +- src/Stars.Services/Processing/Archive.cs | 2 +- src/Stars.Services/Processing/GzipArchive.cs | 4 +- .../Processing/GzipEntryAsset.cs | 6 +- .../Processing/TarArchiveAsset.cs | 2 +- .../Processing/TarEntryAsset.cs | 6 +- .../Processing/ZipArchiveAsset.cs | 4 +- .../Processing/ZipEntryAsset.cs | 2 +- .../Resources/AmazonCustomS3Config.cs | 2 +- .../Resources/HttpCachedHeaders.cs | 12 +- .../Resources/LocalDirectoryResource.cs | 2 +- .../Resources/LocalFileResource.cs | 4 +- .../Resources/S3ClientFactory.cs | 2 +- src/Stars.Services/Resources/S3Resource.cs | 2 +- src/Stars.Services/Resources/S3Url.cs | 6 +- .../Router/CachedWebResponse.cs | 3 +- src/Stars.Services/Router/RouterService.cs | 21 +- src/Stars.Services/StacResourceExtensions.cs | 21 +- src/Stars.Services/StarsBuilder.cs | 2 +- src/Stars.Services/StarsExtensions.cs | 2 +- src/Stars.Services/Store/StacStoreService.cs | 6 + .../Supplier/Carrier/S3UploadStream.cs | 12 +- .../Supplier/DeliveryQuotation.cs | 2 +- src/Stars.Services/Supplier/GenericAsset.cs | 4 +- src/Stars.Services/Supplier/NoDelivery.cs | 2 +- src/Stars.Services/Supplier/OrderVoucher.cs | 4 +- .../Egms/EgmsTimeSeriesOperationStatus.cs | 4 +- .../ThirdParty/Titiler/TitilerService.cs | 4 +- .../Translator/DefaultStacTranslator.cs | 2 +- .../Translator/StacLinkTranslator.cs | 9 +- src/Stars.Tests/Atom2StacTests.cs | 4 +- src/Stars.Tests/S3Tests.cs | 6 +- src/Stars.Tests/Startup.cs | 2 +- src/Stars.Tests/TestStreamable.cs | 8 +- src/Stars.Tests/TilerTests.cs | 6 +- 119 files changed, 471 insertions(+), 364 deletions(-) diff --git a/.editorconfig b/.editorconfig index 20b14592..43978418 100644 --- a/.editorconfig +++ b/.editorconfig @@ -384,7 +384,7 @@ dotnet_diagnostic.IDE0083.severity = warning # Use pattern matching dotnet_diagnostic.IDE0084.severity = warning # Use IsNot dotnet_diagnostic.IDE0090.severity = warning # Use new(...) dotnet_diagnostic.IDE1006.severity = warning # Naming styles Task Open() Task OpenAsync() -dotnet_diagnostic.IDE1006WithoutSuggestion.severity = suggestion +# dotnet_diagnostic.IDE1006WithoutSuggestion.severity = suggestion # Microsoft.VisualStudio.Threading.Analyzers diff --git a/.vscode/launch.json b/.vscode/launch.json index d803781d..c44129ea 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -944,6 +944,34 @@ // }, "enableStepFiltering": false }, + { + "name": "Copy User Product Collection", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/src/Stars.Console/bin/Debug/net6.0/Stars.dll", + "args": [ + "copy", + "-v", + "-r", + "4", + "--output", + "/tmp/stars", + "s3://dc-acceptance-catalog/users/evopm1/products/evopm1-product-test_upload-product1/evopm1-product-test_upload-product1.json" + ], + "cwd": "${workspaceFolder}/src", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false, + "logging": { + "moduleLoad": false + }, + "justMyCode": false, + "requireExactSource": false, + "enableStepFiltering": false + }, + { "name": ".NET Core Attach", "type": "coreclr", diff --git a/src/Stars.Console.Tests/Utilities/XunitTextWriter.cs b/src/Stars.Console.Tests/Utilities/XunitTextWriter.cs index b41cb3d6..038ce133 100644 --- a/src/Stars.Console.Tests/Utilities/XunitTextWriter.cs +++ b/src/Stars.Console.Tests/Utilities/XunitTextWriter.cs @@ -11,7 +11,7 @@ namespace Stars.Console.Tests public class XunitTextWriter : TextWriter { private readonly ITestOutputHelper _output; - private readonly StringBuilder _sb = new StringBuilder(); + private readonly StringBuilder _sb = new(); public XunitTextWriter(ITestOutputHelper output) { diff --git a/src/Stars.Console/ConsoleCredentialsManager.cs b/src/Stars.Console/ConsoleCredentialsManager.cs index 35db6e59..31e137df 100644 --- a/src/Stars.Console/ConsoleCredentialsManager.cs +++ b/src/Stars.Console/ConsoleCredentialsManager.cs @@ -14,13 +14,13 @@ namespace Terradue.Stars.Console.Operations { internal class ConsoleCredentialsManager : ConfigurationCredentialsManager { - private readonly IConsole console; - private readonly ConsoleUserSettings consoleUserSettings; + private readonly IConsole _console; + private readonly ConsoleUserSettings _consoleUserSettings; public ConsoleCredentialsManager(IOptions options, IConsole console, ConsoleUserSettings consoleUserSettings, ILogger logger) : base(options, logger) { - this.console = console; - this.consoleUserSettings = consoleUserSettings; + _console = console; + _consoleUserSettings = consoleUserSettings; } public override NetworkCredential GetCredential(Uri uri, string authType) @@ -39,14 +39,14 @@ public override NetworkCredential GetCredential(Uri uri, string authType) catch { } if (cred == null && authority.Length > 2 && uri.UserInfo != "preauth") { - if (!console.IsInputRedirected) + if (!_console.IsInputRedirected) { - console.WriteLine("No credentials found for {0}. Please provide one.", uriCut); + _console.WriteLine("No credentials found for {0}. Please provide one.", uriCut); cred = PromptCredentials(uriCut, authType); } if (cred != null) { - base.CacheCredential(uriCut, authType, cred); + CacheCredential(uriCut, authType, cred); PromptSaveCredentials(cred, uriCut, authType); } } @@ -59,8 +59,8 @@ private void PromptSaveCredentials(ICredentials cred, Uri uri, string authType) int i = 3; while ((string.IsNullOrEmpty(answer) || !"yn".Contains(answer[0])) && i > 0) { - console.Write("Save credentials in user settings? [y/N]:"); - answer = console.In.ReadLine().ToLower(); + _console.Write("Save credentials in user settings? [y/N]:"); + answer = _console.In.ReadLine().ToLower(); i--; } if (answer == "y") @@ -70,12 +70,12 @@ private void PromptSaveCredentials(ICredentials cred, Uri uri, string authType) private void SaveCredentials(ICredentials cred, Uri uri, string authType) { CredentialsConfigurationSection credConfigSection = cred.ToCredentialsConfigurationSection(uri, authType); - consoleUserSettings.AddOrUpdateSetting("Credentials:" + Guid.NewGuid().ToString(), credConfigSection); + _consoleUserSettings.AddOrUpdateSetting("Credentials:" + Guid.NewGuid().ToString(), credConfigSection); } private NetworkCredential PromptCredentials(Uri uri, string authType) { - if (console.IsInputRedirected) return null; + if (_console.IsInputRedirected) return null; string usernameLabel = "username"; string passwordLabel = "password"; @@ -90,16 +90,16 @@ private NetworkCredential PromptCredentials(Uri uri, string authType) int rtry = 3; while (string.IsNullOrEmpty(username) && rtry > 0) { - console.Write(usernameLabel + ": "); - username = console.In.ReadLine(); + _console.Write(usernameLabel + ": "); + username = _console.In.ReadLine(); rtry--; } if (string.IsNullOrEmpty(username)) { - console.WriteLine("No input. Skipping"); + _console.WriteLine("No input. Skipping"); return null; } - console.Write(passwordLabel + ": "); + _console.Write(passwordLabel + ": "); var pass = string.Empty; ConsoleKey key; do @@ -118,7 +118,7 @@ private NetworkCredential PromptCredentials(Uri uri, string authType) pass += keyInfo.KeyChar; } } while (key != ConsoleKey.Enter); - console.WriteLine(); + _console.WriteLine(); return new NetworkCredential(username, pass); } diff --git a/src/Stars.Console/ConsoleUserSettings.cs b/src/Stars.Console/ConsoleUserSettings.cs index 4ea702aa..fee4851f 100644 --- a/src/Stars.Console/ConsoleUserSettings.cs +++ b/src/Stars.Console/ConsoleUserSettings.cs @@ -12,7 +12,7 @@ namespace Terradue.Stars.Console { internal class ConsoleUserSettings { - private readonly string userSettingsFilePath = Path.Join(System.Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"); + private readonly string userSettingsFilePath = Path.Join(Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"); private readonly ILogger logger; private readonly IConfigurationRoot configuration; diff --git a/src/Stars.Console/Operations/BaseOperation.cs b/src/Stars.Console/Operations/BaseOperation.cs index 0d5d4f87..3959d1f4 100644 --- a/src/Stars.Console/Operations/BaseOperation.cs +++ b/src/Stars.Console/Operations/BaseOperation.cs @@ -117,7 +117,7 @@ private ServiceCollection RegisterServices() foreach (var yamlFilename in Directory.EnumerateFiles("/etc/Stars/conf.d", "*.json", SearchOption.TopDirectoryOnly)) builder.AddNewtonsoftJsonFile(yamlFilename); } - builder.AddNewtonsoftJsonFile(Path.Join(System.Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"), optional: true) + builder.AddNewtonsoftJsonFile(Path.Join(Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"), optional: true) .AddNewtonsoftJsonFile("appsettings.json", optional: true); //only add secrets in development diff --git a/src/Stars.Console/Operations/CopyOperation.cs b/src/Stars.Console/Operations/CopyOperation.cs index 463744ea..1a319a22 100644 --- a/src/Stars.Console/Operations/CopyOperation.cs +++ b/src/Stars.Console/Operations/CopyOperation.cs @@ -103,7 +103,7 @@ internal class CopyOperation : BaseOperation private StacStoreService storeService; private StacLinkTranslator stacLinkTranslator; private IResourceServiceProvider resourceServiceProvider; - private string[] inputs = new string[0]; + private string[] inputs = Array.Empty(); private int recursivity = 1; private string output = "file://" + Directory.GetCurrentDirectory(); @@ -120,7 +120,8 @@ private void InitRoutingTask() }; // routingTask.OnRoutingToNodeException((route, router, exception, state) => PrintRouteInfo(route, router, exception, state)); routingService.OnBeforeBranching((node, router, state, subroutes, ct) => CreateCatalog(node, router, state, ct)); - routingService.OnItem((node, router, state, ct) => CopyNodeAsync(node, router, state, ct)); + routingService.OnItem((node, router, state, ct) => CopyItemAsync(node, router, state, ct)); + routingService.OnCollection((node, router, state, ct) => CopyCollectionAsync(node, router, state, ct)); routingService.OnBranching(async (parentRoute, route, siblings, state, ct) => await PrepareNewRouteAsync(parentRoute, route, siblings, state, ct)); routingService.OnAfterBranching(async (parentRoute, router, parentState, subStates, ct) => await UpdateCatalog(parentRoute, router, parentState, subStates, ct)); } @@ -178,151 +179,183 @@ private async Task PrepareNewRouteAsync(IResource parentRout return new CopyOperationState(operationState.Depth + 1, operationState.StoreService, newDestination); } - private async Task CopyNodeAsync(IResource node, IRouter router, object state, CancellationToken ct) + private async Task CopyItemAsync(IItem item, IRouter router, object state, CancellationToken ct) { CopyOperationState operationState = state as CopyOperationState; - StacNode stacNode = node as StacNode; - if (stacNode == null) + StacItemNode stacItemNode = item as StacItemNode; + if (stacItemNode == null) { // No? Let's try to translate it to Stac - stacNode = await translatorManager.TranslateAsync(node, ct); - if (stacNode == null) - throw new InvalidDataException(string.Format("Impossible to translate node {0} into STAC.", node.Uri)); + stacItemNode = await translatorManager.TranslateAsync(item, ct); + if (stacItemNode == null) + throw new InvalidDataException(string.Format("Impossible to translate item {0} into STAC.", item.Uri)); } - logger.Output(string.Format("Copy node {0} from {1}", stacNode.Id, node.Uri)); + logger.Output(string.Format("Copy item {0} from {1}", stacItemNode.Id, item.Uri)); // We update the destination in case a new router updated the route - IDestination destination = operationState.CurrentDestination.To(stacNode); + IDestination destination = operationState.CurrentDestination.To(stacItemNode); + + // Copy Assets + AssetService assetService = ServiceProvider.GetService(); - // In case of a Item - if (node is IItem) + // For items, Stars copy allows to copy assets from configured suppliers + // 1. Select Suppliers + SupplierFilters supplierFilters = new SupplierFilters(); + + if (SuppliersIncluded != null && SuppliersIncluded.Count() > 0) { - StacItemNode stacItemNode = stacNode as StacItemNode; + supplierFilters = new SupplierFilters(); + supplierFilters.IncludeIds = SuppliersIncluded; + } - // 1. Select Suppliers - AssetService assetService = ServiceProvider.GetService(); + if (SuppliersExcluded != null && SuppliersExcluded.Count() > 0) + { + supplierFilters = new SupplierFilters(); + supplierFilters.ExcludeIds = SuppliersExcluded; + } - SupplierFilters supplierFilters = new SupplierFilters(); + PluginList suppliers = InitSuppliersEnumerator(stacItemNode, supplierFilters); - if (SuppliersIncluded != null && SuppliersIncluded.Count() > 0) + // 2. Try each of them until one provide the resource + foreach (var supplier in suppliers) + { + IResource supplierNode = null; + try { - supplierFilters = new SupplierFilters(); - supplierFilters.IncludeIds = SuppliersIncluded; + logger.Output(string.Format("[{0}] Searching for {1}", supplier.Value.Id, stacItemNode.Uri.ToString())); + supplierNode = await supplier.Value.SearchForAsync(stacItemNode, ct); + if (supplierNode == null && supplierNode is not IAssetsContainer) + { + logger.Output(string.Format("[{0}] --> no supply possible", supplier.Value.Id)); + continue; + } + logger.Output(string.Format("[{0}] resource found at {1} [{2}]", supplier.Value.Id, supplierNode.Uri, supplierNode.ContentType)); } - - if (SuppliersExcluded != null && SuppliersExcluded.Count() > 0) + catch (Exception e) { - supplierFilters = new SupplierFilters(); - supplierFilters.ExcludeIds = SuppliersExcluded; + logger.Warn(string.Format("[{0}] Exception searching for {1}: {2}", supplier.Value.Id, stacItemNode.Uri.ToString(), e.Message)); + logger.Verbose(e.StackTrace); + continue; } - IItem sourceItemNode = await stacLinkTranslator.TranslateAsync(node, ct); - if (sourceItemNode == null) + if (!SkipAssets) { - sourceItemNode = node as IItem; + // Copy assets from supplier + AssetImportReport deliveryReport = await CopyAssetsFromContainer(destination, assetService, supplierNode as IAssetsContainer, ct); + + if (deliveryReport.ImportedAssets.Count() > 0) + stacItemNode.StacItem.MergeAssets(deliveryReport, !KeepOriginalAssets); + else continue; } else { - logger.Output(string.Format("alternate STAC source found at {0}", sourceItemNode.Uri)); - stacItemNode = sourceItemNode as StacItemNode; + // Merge assets from supplier + stacItemNode.StacItem.MergeAssets(supplierNode as IAssetsContainer, false); } + break; + } - PluginList suppliers = InitSuppliersEnumerator(sourceItemNode, supplierFilters); + // Store the item + stacItemNode = await storeService.StoreItemNodeAtDestinationAsync(stacItemNode, destination, ct); - // 2. Try each of them until one provide the resource - foreach (var supplier in suppliers) - { - IResource supplierNode = null; - try - { - logger.Output(string.Format("[{0}] Searching for {1}", supplier.Value.Id, sourceItemNode.Uri.ToString())); - supplierNode = await supplier.Value.SearchForAsync(sourceItemNode, ct); - if (supplierNode == null && !(supplierNode is IAssetsContainer)) - { - logger.Output(string.Format("[{0}] --> no supply possible", supplier.Value.Id)); - continue; - } - logger.Output(string.Format("[{0}] resource found at {1} [{2}]", supplier.Value.Id, supplierNode.Uri, supplierNode.ContentType)); - } - catch (Exception e) - { - logger.Warn(string.Format("[{0}] Exception searching for {1}: {2}", supplier.Value.Id, sourceItemNode.Uri.ToString(), e.Message)); - logger.Verbose(e.StackTrace); - continue; - } + operationState.CurrentStacObject = stacItemNode; - if (!SkipAssets) - { - AssetFilters assetFilters = AssetFilters.CreateAssetFilters(AssetsFilters); - if (NoCopyCog) - { - Dictionary cogParameters = new Dictionary(); - cogParameters.Add("cloud-optimized", "true"); - cogParameters.Add("profile", "cloud-optimized"); - assetFilters.Add(new NotAssetFilter(new ContentTypeAssetFilter(null, cogParameters))); - KeepOriginalAssets = true; - } - AssetChecks assetChecks = GetAssetChecks(); - AssetImportReport deliveryReport = await assetService.ImportAssetsAsync(supplierNode as IAssetsContainer, destination, assetFilters, assetChecks, ct); - - // Process cases that must raise an exception - if (StopOnError) - { - // exception in delivery report - if (deliveryReport.AssetsExceptions.Count > 0) - throw new AggregateException(deliveryReport.AssetsExceptions.Values); - // no delivery but exception in quotation - if (deliveryReport.AssetsExceptions.Count == 0 && deliveryReport.Quotation.AssetsExceptions != null) - throw new AggregateException(deliveryReport.Quotation.AssetsExceptions.Values); - } - - if (deliveryReport.ImportedAssets.Count() > 0) - stacItemNode.StacItem.MergeAssets(deliveryReport, !KeepOriginalAssets); - else continue; - } - else - { - stacItemNode.StacItem.MergeAssets(supplierNode as IAssetsContainer, false); - } - break; - } + // Apply processing services if node was not stac originally + await ApplyProcessing(stacItemNode, destination, ct); - stacNode = await storeService.StoreItemNodeAtDestinationAsync(stacItemNode, destination, ct); - } - else + return operationState; + } + + private async Task CopyCollectionAsync(ICollection collection, IRouter router, object state, CancellationToken ct) + { + CopyOperationState operationState = state as CopyOperationState; + + StacCollectionNode stacCollectionNode = collection as StacCollectionNode; + if (stacCollectionNode == null) { - stacNode = await storeService.StoreCatalogNodeAtDestinationAsync(stacNode as StacCatalogNode, destination, ct); + // No? Let's try to translate it to Stac + stacCollectionNode = await translatorManager.TranslateAsync(collection, ct); + if (stacCollectionNode == null) + throw new InvalidDataException(string.Format("Impossible to translate item {0} into STAC.", collection.Uri)); } - operationState.CurrentStacObject = stacNode; + logger.Output(string.Format("Copy collection {0} from {1}", stacCollectionNode.Id, collection.Uri)); + + // We update the destination in case a new router updated the route + IDestination destination = operationState.CurrentDestination.To(stacCollectionNode); - // 2. Apply processing services if node was not stac originally - if (node is IItem) + // Copy Assets + AssetService assetService = ServiceProvider.GetService(); + + if (!SkipAssets) { - ProcessingService processingService = ServiceProvider.GetService(); - processingService.Parameters.KeepOriginalAssets = KeepAll; - if (ExtractArchives) - stacNode = await processingService.ExtractArchiveAsync(stacNode as StacItemNode, destination, storeService, ct); - if (Harvest) - stacNode = await processingService.ExtractMetadataAsync(stacNode as StacItemNode, destination, storeService, ct); - - if (AssetsFiltersOut != null && AssetsFiltersOut.Count() > 0) - { - AssetFilters assetFilters = AssetFilters.CreateAssetFilters(AssetsFiltersOut); - FilteredAssetContainer filteredAssetContainer = new FilteredAssetContainer(stacNode as IItem, assetFilters); - var assets = filteredAssetContainer.Assets.ToDictionary(a => a.Key, a => (a.Value as StacAssetAsset).StacAsset); - (stacNode as StacItemNode).StacItem.Assets.Clear(); - (stacNode as StacItemNode).StacItem.Assets.AddRange(assets); - logger.Verbose(string.Format("{0} assets kept: {1}", assets.Count, string.Join(", ", assets.Keys))); - stacNode = await storeService.StoreItemNodeAtDestinationAsync(stacNode as StacItemNode, destination, ct); - } + // Copy assets from supplier + AssetImportReport deliveryReport = await CopyAssetsFromContainer(destination, assetService, stacCollectionNode as IAssetsContainer, ct); + + if (deliveryReport.ImportedAssets.Count() > 0) + stacCollectionNode.StacCollection.MergeAssets(deliveryReport, !KeepOriginalAssets); } + // Store the item + stacCollectionNode = await storeService.StoreCollectionNodeAtDestinationAsync(stacCollectionNode, destination, ct); + + operationState.CurrentStacObject = stacCollectionNode; + return operationState; } + private async Task ApplyProcessing(StacItemNode stacItemNode, IDestination destination, CancellationToken ct) + { + ProcessingService processingService = ServiceProvider.GetService(); + processingService.Parameters.KeepOriginalAssets = KeepAll; + StacNode stacNode = stacItemNode; + if (ExtractArchives) + stacNode = await processingService.ExtractArchiveAsync(stacItemNode, destination, storeService, ct); + if (Harvest) + stacNode = await processingService.ExtractMetadataAsync(stacItemNode as StacItemNode, destination, storeService, ct); + + if (AssetsFiltersOut != null && AssetsFiltersOut.Count() > 0) + { + AssetFilters assetFilters = AssetFilters.CreateAssetFilters(AssetsFiltersOut); + FilteredAssetContainer filteredAssetContainer = new FilteredAssetContainer(stacNode as IItem, assetFilters); + var assets = filteredAssetContainer.Assets.ToDictionary(a => a.Key, a => (a.Value as StacAssetAsset).StacAsset); + (stacNode as StacItemNode).StacItem.Assets.Clear(); + (stacNode as StacItemNode).StacItem.Assets.AddRange(assets); + logger.Verbose(string.Format("{0} assets kept: {1}", assets.Count, string.Join(", ", assets.Keys))); + stacNode = await storeService.StoreItemNodeAtDestinationAsync(stacNode as StacItemNode, destination, ct); + } + } + + private async Task CopyAssetsFromContainer(IDestination destination, AssetService assetService, IAssetsContainer assetsContainer, CancellationToken ct) + { + AssetFilters assetFilters = AssetFilters.CreateAssetFilters(AssetsFilters); + if (NoCopyCog) + { + Dictionary cogParameters = new Dictionary(); + cogParameters.Add("cloud-optimized", "true"); + cogParameters.Add("profile", "cloud-optimized"); + assetFilters.Add(new NotAssetFilter(new ContentTypeAssetFilter(null, cogParameters))); + KeepOriginalAssets = true; + } + AssetChecks assetChecks = GetAssetChecks(); + AssetImportReport deliveryReport = await assetService.ImportAssetsAsync(assetsContainer, destination, assetFilters, assetChecks, ct); + + // Process cases that must raise an exception + if (StopOnError) + { + // exception in delivery report + if (deliveryReport.AssetsExceptions.Count > 0) + throw new AggregateException(deliveryReport.AssetsExceptions.Values); + // no delivery but exception in quotation + if (deliveryReport.AssetsExceptions.Count == 0 && deliveryReport.Quotation.AssetsExceptions != null) + throw new AggregateException(deliveryReport.Quotation.AssetsExceptions.Values); + } + + return deliveryReport; + } + private AssetChecks GetAssetChecks() { if (NoHtmlAsset) @@ -376,8 +409,9 @@ protected override async Task ExecuteAsync(CancellationToken ct) storeService.RootCatalogNode.StacCatalog.UpdateLinks(stacNodes.SelectMany(sn => { if (sn is StacItemNode) return new IResource[] { sn }; + if (sn is StacCollectionNode) return new IResource[] { sn }; if (sn is StacCatalogNode) return sn.GetRoutes(stacRouter); - return new IResource[0]; + return Array.Empty(); })); var rootCat = await storeService.StoreCatalogNodeAtDestinationAsync(storeService.RootCatalogNode, storeService.RootCatalogDestination, ct); if (!string.IsNullOrEmpty(ResultFile)) diff --git a/src/Stars.Console/Operations/ListOperation.cs b/src/Stars.Console/Operations/ListOperation.cs index 0c4bdf69..97f13e8c 100644 --- a/src/Stars.Console/Operations/ListOperation.cs +++ b/src/Stars.Console/Operations/ListOperation.cs @@ -32,7 +32,7 @@ internal class ListOperation : BaseOperation private RouterService routingService; private IResourceServiceProvider resourceServiceProvider; private int recursivity = 1; - private string[] inputs = new string[0]; + private string[] inputs = Array.Empty(); public ListOperation(IConsole console) : base(console) { diff --git a/src/Stars.Console/PluginLoadContext.cs b/src/Stars.Console/PluginLoadContext.cs index dd88f27e..1e99cdfd 100644 --- a/src/Stars.Console/PluginLoadContext.cs +++ b/src/Stars.Console/PluginLoadContext.cs @@ -11,7 +11,7 @@ namespace Terradue.Stars.Console internal class PluginLoadContext : AssemblyLoadContext { private readonly AssemblyLoadContext mainAppAssemblyLoadContext; - private AssemblyDependencyResolver _resolver; + private readonly AssemblyDependencyResolver _resolver; public PluginLoadContext(string pluginPath, AssemblyLoadContext mainAppAssemblyLoadContext) { diff --git a/src/Stars.Console/StarsConsoleLoggerProvider.cs b/src/Stars.Console/StarsConsoleLoggerProvider.cs index 2c785b16..7ffd07eb 100644 --- a/src/Stars.Console/StarsConsoleLoggerProvider.cs +++ b/src/Stars.Console/StarsConsoleLoggerProvider.cs @@ -10,7 +10,7 @@ namespace Terradue.Stars.Console { public class StarsConsoleLoggerProvider : ILoggerProvider { - private readonly ConcurrentDictionary _loggers = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _loggers = new(); private readonly IConsole console; private readonly int verbose; diff --git a/src/Stars.Data.Tests/Harvesters/MetadataExtractorsTests.cs b/src/Stars.Data.Tests/Harvesters/MetadataExtractorsTests.cs index 5ffd6a87..ec9c35b3 100644 --- a/src/Stars.Data.Tests/Harvesters/MetadataExtractorsTests.cs +++ b/src/Stars.Data.Tests/Harvesters/MetadataExtractorsTests.cs @@ -41,7 +41,7 @@ public static IEnumerable TestData } } - [Theory, MemberData("TestData", DisableDiscoveryEnumeration = true)] + [Theory, MemberData(nameof(TestData), DisableDiscoveryEnumeration = true)] public async void TestExtractors(string key, string datadir, MetadataExtraction extractor) { StacRouter stacRouter = ServiceProvider.GetService(); @@ -82,7 +82,7 @@ public async void TestExtractors(string key, string datadir, MetadataExtraction } catch (Exception) { - System.Console.WriteLine(actualJson); + Console.WriteLine(actualJson); throw; } // Dot NOT uncomment unless you are changing the expected JSON @@ -94,7 +94,7 @@ public async void TestExtractors(string key, string datadir, MetadataExtraction } catch (Exception) { - System.Console.WriteLine(actualJson); + Console.WriteLine(actualJson); throw; } // stacValidator.ValidateJson(expectedJson); @@ -105,7 +105,7 @@ public async void TestExtractors(string key, string datadir, MetadataExtraction } catch (Exception) { - System.Console.WriteLine(actualJson); + Console.WriteLine(actualJson); throw; } } diff --git a/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs b/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs index e1f51aff..20552e73 100644 --- a/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs +++ b/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs @@ -37,8 +37,8 @@ public static IEnumerable AllSuppliersTestsData } } - [Theory, MemberData("AllSuppliersTestsData", DisableDiscoveryEnumeration = true)] - public async Task AllSuppliersSearchExpression(string key, ISupplier supplier, string file) + [Theory, MemberData(nameof(AllSuppliersTestsData), DisableDiscoveryEnumeration = true)] + public async Task AllSuppliersSearchExpression(ISupplier supplier, string file) { string json = File.ReadAllText(file); JObject jObject = JObject.Parse(json); diff --git a/src/Stars.Data.Tests/TestBase.cs b/src/Stars.Data.Tests/TestBase.cs index 1c128bd8..ed08bc6c 100644 --- a/src/Stars.Data.Tests/TestBase.cs +++ b/src/Stars.Data.Tests/TestBase.cs @@ -37,7 +37,7 @@ public abstract class TestBase protected IConfigurationRoot configuration; - protected static StacValidator stacValidator = new StacValidator(new JSchemaUrlResolver()); + protected static StacValidator stacValidator = new(new JSchemaUrlResolver()); private static readonly Assembly ThisAssembly = typeof(TestBase) #if NETCOREAPP1_1 diff --git a/src/Stars.Data.Tests/TestFileAsset.cs b/src/Stars.Data.Tests/TestFileAsset.cs index 1886c41e..332f8fc9 100644 --- a/src/Stars.Data.Tests/TestFileAsset.cs +++ b/src/Stars.Data.Tests/TestFileAsset.cs @@ -30,15 +30,15 @@ public TestFileAsset(FileInfo fileInfo, Uri folderUri, Uri itemUri) public IReadOnlyList Roles => new string[1] { "data" }; - public Uri Uri => new Uri(fileInfo.FullName); + public Uri Uri => new(fileInfo.FullName); - public ContentType ContentType => new ContentType("application/octet-stream"); + public ContentType ContentType => new("application/octet-stream"); public ResourceType ResourceType => ResourceType.Asset; public ulong ContentLength => Convert.ToUInt64(fileInfo.Length); - public ContentDisposition ContentDisposition => new ContentDisposition() + public ContentDisposition ContentDisposition => new() { FileName = fileInfo.Name, Size = fileInfo.Length, diff --git a/src/Stars.Data.Tests/TestNode.cs b/src/Stars.Data.Tests/TestNode.cs index 54c29649..dd91b33b 100644 --- a/src/Stars.Data.Tests/TestNode.cs +++ b/src/Stars.Data.Tests/TestNode.cs @@ -16,7 +16,7 @@ namespace Terradue.Data.Tests { internal class TestItem : IItem { - private DirectoryInfo directory; + private readonly DirectoryInfo directory; public TestItem(string folderPath) { @@ -29,9 +29,9 @@ public TestItem(string folderPath) public bool IsCatalog => false; - public Uri Uri => new Uri(Path.Combine(directory.FullName, "../..")); + public Uri Uri => new(Path.Combine(directory.FullName, "../..")); - public ContentType ContentType => new ContentType("application/x-directory"); + public ContentType ContentType => new("application/x-directory"); public ResourceType ResourceType => ResourceType.Item; @@ -41,7 +41,7 @@ public TestItem(string folderPath) public IGeometryObject Geometry => null; - public ContentDisposition ContentDisposition => new ContentDisposition() { FileName = Path.GetFileNameWithoutExtension(directory.FullName) }; + public ContentDisposition ContentDisposition => new() { FileName = Path.GetFileNameWithoutExtension(directory.FullName) }; public IDictionary Properties => new Dictionary(); diff --git a/src/Stars.Data.Tests/Translators/StacItemToAtomItemTests.cs b/src/Stars.Data.Tests/Translators/StacItemToAtomItemTests.cs index 1c078619..153ad092 100644 --- a/src/Stars.Data.Tests/Translators/StacItemToAtomItemTests.cs +++ b/src/Stars.Data.Tests/Translators/StacItemToAtomItemTests.cs @@ -65,7 +65,7 @@ public async System.Threading.Tasks.Task S1A_OPER_SAR_EOSSP__CORE_L1A_OLF_202111 var twmOfferings = offerings.Where(r => r.Code == "http://www.terradue.com/twm"); Assert.NotNull(twmOfferings); - Assert.Equal(1, twmOfferings.Count()); + Assert.Single(twmOfferings); Assert.Equal("GetMap", twmOfferings.ElementAt(0).Operations.First().Code); Assert.Equal("image/png", twmOfferings.ElementAt(0).Operations.First().Type); @@ -139,7 +139,7 @@ public async System.Threading.Tasks.Task TWMTest() var twmOfferings = offerings.Where(r => r.Code == "http://www.terradue.com/twm"); Assert.NotNull(twmOfferings); - Assert.Equal(1, twmOfferings.Count()); + Assert.Single(twmOfferings); Assert.Equal("GetMap", twmOfferings.ElementAt(0).Operations.First().Code); Assert.Equal("image/png", twmOfferings.ElementAt(0).Operations.First().Type); } @@ -162,7 +162,7 @@ public async System.Threading.Tasks.Task HANDTest() var twmOfferings = offerings.Where(r => r.Code == "http://www.terradue.com/twm"); Assert.NotNull(twmOfferings); - Assert.Equal(1, twmOfferings.Count()); + Assert.Single(twmOfferings); Assert.Equal("GetMap", twmOfferings.ElementAt(0).Operations.First().Code); Assert.Equal("image/png", twmOfferings.ElementAt(0).Operations.First().Type); } diff --git a/src/Stars.Data/Log4Net2LoggerAppender.cs b/src/Stars.Data/Log4Net2LoggerAppender.cs index 8d24b97d..0c4c910f 100644 --- a/src/Stars.Data/Log4Net2LoggerAppender.cs +++ b/src/Stars.Data/Log4Net2LoggerAppender.cs @@ -10,7 +10,7 @@ namespace Terradue.Stars.Data { internal class Log4Net2LoggerAppender : AppenderSkeleton { - private Microsoft.Extensions.Logging.ILogger logger; + private readonly Microsoft.Extensions.Logging.ILogger logger; public Log4Net2LoggerAppender(Microsoft.Extensions.Logging.ILogger logger) { diff --git a/src/Stars.Data/Model/Atom/StarsAtomItem.cs b/src/Stars.Data/Model/Atom/StarsAtomItem.cs index 9fbb301d..054b6cbe 100644 --- a/src/Stars.Data/Model/Atom/StarsAtomItem.cs +++ b/src/Stars.Data/Model/Atom/StarsAtomItem.cs @@ -280,7 +280,7 @@ public bool TryAddEarthObservationProfile(StacItem stacItem) EarthObservationType eop = CreateEOProfileFromStacItem(stacItem); if (eop != null) { - EarthObservationExtension = new SyndicationElementExtension(Terradue.ServiceModel.Ogc.OgcHelpers.CreateReader(eop)); + EarthObservationExtension = new SyndicationElementExtension(ServiceModel.Ogc.OgcHelpers.CreateReader(eop)); return true; } return false; @@ -559,7 +559,7 @@ private static Dictionary SelectOverlayOverviewAssets(StacCol return new Dictionary(); } - SyndicationElementExtension earthObservationExtension = null; + private SyndicationElementExtension earthObservationExtension = null; public SyndicationElementExtension EarthObservationExtension { diff --git a/src/Stars.Data/Model/Metadata/Airbus/AirbusMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Airbus/AirbusMetadataExtractor.cs index 2f489c63..7854c0d1 100644 --- a/src/Stars.Data/Model/Metadata/Airbus/AirbusMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Airbus/AirbusMetadataExtractor.cs @@ -198,7 +198,7 @@ internal StacItemNode ExtractMetadata(IItem item, AirbusProfiler dimapProfiler, // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri) as StacItemNode; + return StacNode.Create(stacItem, item.Uri) as StacItemNode; } private void AddEoBandPropertyInItem(StacItem stacItem) diff --git a/src/Stars.Data/Model/Metadata/Alos2/Alos2MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Alos2/Alos2MetadataExtractor.cs index 32421619..fef7bcdb 100644 --- a/src/Stars.Data/Model/Metadata/Alos2/Alos2MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Alos2/Alos2MetadataExtractor.cs @@ -57,7 +57,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, item, metadata); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } internal virtual StacItem CreateStacItem(Alos2Metadata metadata) @@ -324,13 +324,13 @@ public class Alos2Metadata { // Regular expressions should normally be static but creates problem with async methods - private Regex lineRegex = new Regex("^ *([^= ]+) *= *(.*)$"); - private Regex quotedValueRegex = new Regex("^\"(.*)\"$"); - private Regex fileNameKeyRegex = new Regex("Pdi_L\\d{2}ProductFileName\\d{2}"); // e.g. Pdi_L15ProductFileName01 - private Regex fileNameValueRegex = new Regex("(?'type'IMG|LUT)-(?'pol'HH|HV|VH|VV)-(?'id'.{32})\\.(tif|txt)"); // e.g. IMG-HH-ALOS2146686640-170209-FBDR1.5GUA.tif - private Regex identifierRegex = new Regex("ALOS2(?'orbit'\\d{5})(?'frame'\\d{4})-(?'date'\\d{6})-(?'mode'(SBS|UBS|UBD|HBS|HBD|HBQ|FBS|FBD|FBQ|WBS|WBD|WWS|WWD|VBS|VBD))(?'obsdir'[LR])(?'level'.{3})(?'proc'[GR_])(?'proj'[UPML_])(?'orbitdir'[AD])"); // e.g. ALOS2146686640-170209-FBDR1.5GUA - private Regex siteRegex = new Regex(".* (?'dt'\\d{8} \\d{6})$"); - private IAsset summaryAsset; + private readonly Regex lineRegex = new Regex("^ *([^= ]+) *= *(.*)$"); + private readonly Regex quotedValueRegex = new Regex("^\"(.*)\"$"); + private readonly Regex fileNameKeyRegex = new Regex("Pdi_L\\d{2}ProductFileName\\d{2}"); // e.g. Pdi_L15ProductFileName01 + private readonly Regex fileNameValueRegex = new Regex("(?'type'IMG|LUT)-(?'pol'HH|HV|VH|VV)-(?'id'.{32})\\.(tif|txt)"); // e.g. IMG-HH-ALOS2146686640-170209-FBDR1.5GUA.tif + private readonly Regex identifierRegex = new Regex("ALOS2(?'orbit'\\d{5})(?'frame'\\d{4})-(?'date'\\d{6})-(?'mode'(SBS|UBS|UBD|HBS|HBD|HBQ|FBS|FBD|FBQ|WBS|WBD|WWS|WWD|VBS|VBD))(?'obsdir'[LR])(?'level'.{3})(?'proc'[GR_])(?'proj'[UPML_])(?'orbitdir'[AD])"); // e.g. ALOS2146686640-170209-FBDR1.5GUA + private readonly Regex siteRegex = new Regex(".* (?'dt'\\d{8} \\d{6})$"); + private readonly IAsset summaryAsset; private Dictionary properties { get; set; } diff --git a/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs index e0688e3f..0d7c9f6c 100644 --- a/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs @@ -114,7 +114,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, item, innerZipAssetContainers?.ToArray()); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/BlackSkyGlobal/BlackSkyGlobalMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/BlackSkyGlobal/BlackSkyGlobalMetadataExtractor.cs index 5de5ad9e..fa661443 100644 --- a/src/Stars.Data/Model/Metadata/BlackSkyGlobal/BlackSkyGlobalMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/BlackSkyGlobal/BlackSkyGlobalMetadataExtractor.cs @@ -28,7 +28,7 @@ namespace Terradue.Stars.Data.Model.Metadata.BlackSkyGlobal { public class BlackSkyGlobalMetadataExtractor : MetadataExtraction { - public static Dictionary platformDesignators = new Dictionary { + public static Dictionary PlatformDesignators = new Dictionary { { 1, "2018-096M" }, { 2, "2018-099BG" }, { 3, "2019-037C" }, @@ -45,12 +45,12 @@ public class BlackSkyGlobalMetadataExtractor : MetadataExtraction // Possible identifiers: // CSKS4_SCS_B_HI_16_HH_RA_FF_20211016045150_20211016045156 - private Regex identifierRegex = new Regex(@"(?'id'CSKS(?'i'\d)_(?'pt'RAW_B|SCS_B|SCS_U|DGM_B|GEC_B|GTC_B)_(?'mode'HI|PP|WR|HR|S2)_(?'swath'..)_(?'pol'HH|VV|HV|VH|CO|CH|CV)_(?'look'L|R)(?'dir'A|D)_.._\d{14}_\d{14})"); - private Regex coordinateRegex = new Regex(@"(?'lat'[^ ]+) (?'lon'[^ ]+)"); - private static Regex h5dumpValueRegex = new Regex(@".*\(0\): *(?'value'.*)"); - private static Regex satNumberRegex = new Regex(@".+?(?'n'\d+)$"); + private readonly Regex _identifierRegex = new Regex(@"(?'id'CSKS(?'i'\d)_(?'pt'RAW_B|SCS_B|SCS_U|DGM_B|GEC_B|GTC_B)_(?'mode'HI|PP|WR|HR|S2)_(?'swath'..)_(?'pol'HH|VV|HV|VH|CO|CH|CV)_(?'look'L|R)(?'dir'A|D)_.._\d{14}_\d{14})"); + private readonly Regex _coordinateRegex = new Regex(@"(?'lat'[^ ]+) (?'lon'[^ ]+)"); + private static readonly Regex H5dumpValueRegex = new Regex(@".*\(0\): *(?'value'.*)"); + private static readonly Regex SatNumberRegex = new Regex(@".+?(?'n'\d+)$"); - public static XmlSerializer metadataSerializer = new XmlSerializer(typeof(Schemas.Metadata)); + public static XmlSerializer MetadataSerializer = new XmlSerializer(typeof(Schemas.Metadata)); public override string Label => "COSMO SkyMed (ASI) mission product metadata extractor"; @@ -90,7 +90,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddEoStacExtension(stacItem, metadata); AddOtherProperties(stacItem, metadata); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } @@ -363,10 +363,10 @@ private void AddSatStacExtension(StacItem stacItem, Schemas.Metadata metadata) var sat = new SatStacExtension(stacItem); if (!string.IsNullOrEmpty("")) { - Match match = satNumberRegex.Match(""); - if (match != null && int.TryParse(match.Groups["n"].Value, out int n) && platformDesignators.ContainsKey(n)) + Match match = SatNumberRegex.Match(""); + if (match != null && int.TryParse(match.Groups["n"].Value, out int n) && PlatformDesignators.ContainsKey(n)) { - sat.PlatformInternationalDesignator = platformDesignators[n]; + sat.PlatformInternationalDesignator = PlatformDesignators[n]; } } diff --git a/src/Stars.Data/Model/Metadata/CosmoSkymed/CosmoSkymedMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/CosmoSkymed/CosmoSkymedMetadataExtractor.cs index 99d1d92c..565d30d3 100644 --- a/src/Stars.Data/Model/Metadata/CosmoSkymed/CosmoSkymedMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/CosmoSkymed/CosmoSkymedMetadataExtractor.cs @@ -30,9 +30,9 @@ public class CosmoSkymedMetadataExtractor : MetadataExtraction { // Possible identifiers: // CSKS4_SCS_B_HI_16_HH_RA_FF_20211016045150_20211016045156 - private Regex identifierRegex = new Regex(@"(?'id'CSKS(?'i'\d)_(?'pt'RAW_B|SCS_B|SCS_U|DGM_B|GEC_B|GTC_B)_(?'mode'HI|PP|WR|HR|S2)_(?'swath'..)_(?'pol'HH|VV|HV|VH|CO|CH|CV)_(?'look'L|R)(?'dir'A|D)_.._\d{14}_\d{14})"); - private Regex coordinateRegex = new Regex(@"(?'lat'[^ ,]+),? (?'lon'[^ ,]+)"); - private static Regex h5dumpValueRegex = new Regex(@".*\(0\): *(?'value'.*)"); + private readonly Regex identifierRegex = new Regex(@"(?'id'CSKS(?'i'\d)_(?'pt'RAW_B|SCS_B|SCS_U|DGM_B|GEC_B|GTC_B)_(?'mode'HI|PP|WR|HR|S2)_(?'swath'..)_(?'pol'HH|VV|HV|VH|CO|CH|CV)_(?'look'L|R)(?'dir'A|D)_.._\d{14}_\d{14})"); + private readonly Regex coordinateRegex = new Regex(@"(?'lat'[^ ,]+),? (?'lon'[^ ,]+)"); + private static readonly Regex h5dumpValueRegex = new Regex(@".*\(0\): *(?'value'.*)"); public static XmlSerializer metadataSerializer = new XmlSerializer(typeof(Schemas.Metadata)); @@ -82,7 +82,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // FillAdditionalSarProperties(stacItem.Properties, metadata, identifierMatch); //FillBasicsProperties(stacItem.Properties, metadata); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } internal virtual StacItem CreateStacItem(Dictionary hdfAttributes, Schemas.Metadata metadata, Match identifierMatch) diff --git a/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs index 662ce375..21706ac6 100644 --- a/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs @@ -108,7 +108,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } private void AddEoBandPropertyInItem(StacItem stacItem) diff --git a/src/Stars.Data/Model/Metadata/Gaofen1-2-4/GaofenMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Gaofen1-2-4/GaofenMetadataExtractor.cs index 54bce3d6..99643892 100644 --- a/src/Stars.Data/Model/Metadata/Gaofen1-2-4/GaofenMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Gaofen1-2-4/GaofenMetadataExtractor.cs @@ -104,7 +104,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(productMetadataList[0], stacItem.Properties); AddOtherProperties(productMetadataList[0], stacItem); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } diff --git a/src/Stars.Data/Model/Metadata/Gaofen3/Gaofen3MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Gaofen3/Gaofen3MetadataExtractor.cs index 34be96c4..6381a6e4 100644 --- a/src/Stars.Data/Model/Metadata/Gaofen3/Gaofen3MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Gaofen3/Gaofen3MetadataExtractor.cs @@ -93,7 +93,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(metadata, stacItem.Properties); AddOtherProperties(metadata, stacItem); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } private void AddProjStacExtension(ProductMetadata metadata, StacItem stacItem) diff --git a/src/Stars.Data/Model/Metadata/Gdal/GdalMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Gdal/GdalMetadataExtractor.cs index 200b1347..84ef597d 100644 --- a/src/Stars.Data/Model/Metadata/Gdal/GdalMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Gdal/GdalMetadataExtractor.cs @@ -56,7 +56,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, gdalAsset, dataset); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } internal virtual StacItem CreateStacItem(KeyValuePair gdalAsset, Dataset dataset, IItem item) diff --git a/src/Stars.Data/Model/Metadata/Geoeye/GeoeyeMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Geoeye/GeoeyeMetadataExtractor.cs index 63626c2d..db61372f 100644 --- a/src/Stars.Data/Model/Metadata/Geoeye/GeoeyeMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Geoeye/GeoeyeMetadataExtractor.cs @@ -96,7 +96,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, metadata, isdMetadata, item); // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } private void AddProcessingStacExtension(JavaProperties metadata, StacItem stacItem) diff --git a/src/Stars.Data/Model/Metadata/Iceye/IceyeMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Iceye/IceyeMetadataExtractor.cs index d5deb29a..ecdf8273 100644 --- a/src/Stars.Data/Model/Metadata/Iceye/IceyeMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Iceye/IceyeMetadataExtractor.cs @@ -58,7 +58,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, item, metadata); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } internal virtual StacItem CreateStacItem(Schemas.Metadata metadata) diff --git a/src/Stars.Data/Model/Metadata/Inpe/InpeMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Inpe/InpeMetadataExtractor.cs index 7208c505..e5d34673 100644 --- a/src/Stars.Data/Model/Metadata/Inpe/InpeMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Inpe/InpeMetadataExtractor.cs @@ -31,26 +31,26 @@ namespace Terradue.Stars.Data.Model.Metadata.Inpe { public class InpeMetadataExtractor : MetadataExtraction { - private static Regex identifierRegex = new Regex(@"(?'id1'(CBERS_4A?|AMAZONIA-1)_(?'type'[^_]+)_\d{8}_\d{3}_\d{3}_L(?'level'[^_]+))(_LEFT|RIGHT)?(?'id2'_BAND(?'band'\d+))"); + private static readonly Regex identifierRegex = new Regex(@"(?'id1'(CBERS_4A?|AMAZONIA-1)_(?'type'[^_]+)_\d{8}_\d{3}_\d{3}_L(?'level'[^_]+))(_LEFT|RIGHT)?(?'id2'_BAND(?'band'\d+))"); // alternative identifier regex for for filename of // this type 956-INPE-CBERS-4-urn_ogc_def_EOP_INPE_CBERS_4_AWFI_20220731_111_063_L4_B_compose - private static Regex identifierRegex2 = new Regex(@".*_inpe_(call[0-9]*|cbers_4a?|amazonia_1)_(?'type'[^_]+)_\d{8}_\d{3}_\d{3}_l(?'level'[^_]+)_(band|b)?(\d+)?(.+)?\.csv$"); + private static readonly Regex identifierRegex2 = new Regex(@".*_inpe_(call[0-9]*|cbers_4a?|amazonia_1)_(?'type'[^_]+)_\d{8}_\d{3}_\d{3}_l(?'level'[^_]+)_(band|b)?(\d+)?(.+)?\.csv$"); protected static string metadataAssetRegexPattern => @".*(CBERS_4|Call|CBERS_4A?|cbers_4|call|cbers_4A?|AMAZONIA_1|amazonia_1).*\.(xml|csv)$"; protected static string compositeAssetRegexPattern => @".*(CBERS_4|Call|CBERS_4A?|cbers_4|call|cbers_4A?|AMAZONIA_1|amazonia_1).*\.(tif|tiff)$"; - private Regex identifierInfoRegex = new Regex(@".*(?'mode'awfi|mux|pan|pan5m|pan10m|wfi|wpm)_\d{8}_\d{3}_\d{3}_l(?'level'[^_]+)_(?'rest'.*)$"); + private readonly Regex identifierInfoRegex = new Regex(@".*(?'mode'awfi|mux|pan|pan5m|pan10m|wfi|wpm)_\d{8}_\d{3}_\d{3}_l(?'level'[^_]+)_(?'rest'.*)$"); // Dictionary containing platform international designators - private Dictionary platformInternationalDesignators = new Dictionary { + private readonly Dictionary platformInternationalDesignators = new Dictionary { {"CBERS-4", "2014-079A"}, {"CBERS-4A", "2019-093E"}, {"AMAZONIA-1", "2021-015A"}, }; // Dictionary containing the bands offered by each spectral mode - private Dictionary spectralModeBandsCbers = new Dictionary { + private readonly Dictionary spectralModeBandsCbers = new Dictionary { {"AWFI", new int[] {13, 14, 15, 16}}, {"MUX", new int[] {5, 6, 7, 8}}, {"PAN5M", new int[] {1}}, @@ -60,12 +60,12 @@ public class InpeMetadataExtractor : MetadataExtraction {"WPM-pansharpening", new int[] {1, 2, 3, 4}}, }; - private Dictionary spectralModeBandsAmazonia = new Dictionary { + private readonly Dictionary spectralModeBandsAmazonia = new Dictionary { {"WFI", new int[] {1, 2, 3, 4}}, }; - private Regex bandKeyRegex = new Regex(@"band-\d+"); - private Regex utmZoneRegex = new Regex(@"(?'num'\d+)(?'hem'[NS])"); + private readonly Regex bandKeyRegex = new Regex(@"band-\d+"); + private readonly Regex utmZoneRegex = new Regex(@"(?'num'\d+)(?'hem'[NS])"); public static XmlSerializer metadataSerializer = new XmlSerializer(typeof(Schemas.Metadata)); @@ -122,7 +122,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(metadata, stacItem.Properties); AddOtherProperties(metadata, stacItem.Properties); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/Isro/IsroMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Isro/IsroMetadataExtractor.cs index a277b9fa..5b4dfc98 100644 --- a/src/Stars.Data/Model/Metadata/Isro/IsroMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Isro/IsroMetadataExtractor.cs @@ -35,7 +35,7 @@ public class IsroMetadataExtractor : MetadataExtraction private const string ASCENDING = "Ascending Orbit"; private const string DESCENDING = "Descending Orbit"; - private static string[] satelliteIds = new string[] { "CARTOSAT-2", "IRS-R2", "IRS-R2A" }; + private static readonly string[] satelliteIds = new string[] { "CARTOSAT-2", "IRS-R2", "IRS-R2A" }; public override string Label => "ResourceSat/CartoSat (ISRO) constellation product metadata extractor"; @@ -86,7 +86,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(metadata, stacItem.Properties); AddOtherProperties(metadata, stacItem.Properties); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyReader.cs b/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyReader.cs index 1fdf1e6b..9e0cf6df 100644 --- a/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyReader.cs +++ b/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyReader.cs @@ -53,12 +53,12 @@ public class JavaPropertyReader private const int STATE_value_ws = 9; private const int STATE_finish = 10; - private static string[] stateNames = new string[] + private static readonly string[] stateNames = new string[] { "STATE_start", "STATE_comment", "STATE_key", "STATE_key_escape", "STATE_key_ws", "STATE_before_separator", "STATE_after_separator", "STATE_value", "STATE_value_escape", "STATE_value_ws", "STATE_finish" }; - private static int[][] states = new int[][] { + private static readonly int[][] states = new int[][] { new int[]{//STATE_start MATCH_end_of_input, STATE_finish, ACTION_ignore, MATCH_terminator, STATE_start, ACTION_ignore, @@ -132,13 +132,13 @@ public class JavaPropertyReader } }; - private System.Collections.Specialized.NameValueCollection hashtable; + private readonly System.Collections.Specialized.NameValueCollection hashtable; private const int bufferSize = 1000; private bool escaped = false; - private StringBuilder keyBuilder = new StringBuilder(); - private StringBuilder valueBuilder = new StringBuilder(); + private readonly StringBuilder keyBuilder = new StringBuilder(); + private readonly StringBuilder valueBuilder = new StringBuilder(); /// /// Construct a reader passing a reference to a Hashtable (or JavaProperties) instance diff --git a/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyWriter.cs b/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyWriter.cs index 7e6f0866..5cb82b84 100644 --- a/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyWriter.cs +++ b/src/Stars.Data/Model/Metadata/Kajabity/Tools/Java/JavaPropertyWriter.cs @@ -34,9 +34,9 @@ namespace Kajabity.Tools.Java /// public class JavaPropertyWriter { - private static char[] HEX = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + private static readonly char[] HEX = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - private NameValueCollection hashtable; + private readonly NameValueCollection hashtable; /// /// Construct an instance of this class. @@ -56,7 +56,7 @@ public JavaPropertyWriter(NameValueCollection hashtable) public void Write(Stream stream, string comments) { // Create a writer to output to an ISO-8859-1 encoding (code page 28592). - StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.GetEncoding(28592)); + StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding(28592)); //TODO: Confirm correct codepage: // 28592 iso-8859-2 Central European (ISO) diff --git a/src/Stars.Data/Model/Metadata/Kanopus/KanopusVMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Kanopus/KanopusVMetadataExtractor.cs index 045aa01f..c70d3d1f 100644 --- a/src/Stars.Data/Model/Metadata/Kanopus/KanopusVMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Kanopus/KanopusVMetadataExtractor.cs @@ -53,7 +53,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, item, metadata); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } @@ -310,7 +310,7 @@ public virtual async Task ReadMetadata(IAsset manifestAsset) public class KanopusVMetadata { - private IAsset summaryAsset; + private readonly IAsset summaryAsset; public Dictionary> properties { get; set; } public List Assets { get; set; } diff --git a/src/Stars.Data/Model/Metadata/Kompsat3/Auxiliary.cs b/src/Stars.Data/Model/Metadata/Kompsat3/Auxiliary.cs index 44cdb8e9..b84b14e2 100644 --- a/src/Stars.Data/Model/Metadata/Kompsat3/Auxiliary.cs +++ b/src/Stars.Data/Model/Metadata/Kompsat3/Auxiliary.cs @@ -702,7 +702,7 @@ public class Auxiliary [XmlElement(ElementName = "Metadata")] public Metadata Metadata { get; set; } - Dictionary images; + private Dictionary images; [XmlIgnore] public Dictionary Images diff --git a/src/Stars.Data/Model/Metadata/Kompsat3/Kompsat3MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Kompsat3/Kompsat3MetadataExtractor.cs index 7233dad8..94c23c2b 100644 --- a/src/Stars.Data/Model/Metadata/Kompsat3/Kompsat3MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Kompsat3/Kompsat3MetadataExtractor.cs @@ -78,7 +78,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(auxiliary, stacItem.Properties); AddOtherProperties(auxiliary, stacItem); - return StacItemNode.Create(stacItem, item.Uri); ; ; + return StacNode.Create(stacItem, item.Uri); ; ; } diff --git a/src/Stars.Data/Model/Metadata/Kompsat3/XmlKeyTextValueListWrapper.cs b/src/Stars.Data/Model/Metadata/Kompsat3/XmlKeyTextValueListWrapper.cs index 3d1bace4..b3cd72dd 100644 --- a/src/Stars.Data/Model/Metadata/Kompsat3/XmlKeyTextValueListWrapper.cs +++ b/src/Stars.Data/Model/Metadata/Kompsat3/XmlKeyTextValueListWrapper.cs @@ -113,7 +113,7 @@ public static void CopyTo(this XmlKeyTextValueListWrapper collec public class CollectionWrapper : ICollection { - readonly Func> getCollection; + private readonly Func> getCollection; public CollectionWrapper(ICollection baseCollection) { @@ -136,7 +136,7 @@ public bool IsWrapperFor(ICollection other) return other is CollectionWrapper otherWrapper && otherWrapper.IsWrapperFor(Collection); } - ICollection Collection { get { return getCollection(); } } + private ICollection Collection { get { return getCollection(); } } #region ICollection Members diff --git a/src/Stars.Data/Model/Metadata/Kompsat5/Kompsat5MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Kompsat5/Kompsat5MetadataExtractor.cs index 205dcd14..736a09b4 100644 --- a/src/Stars.Data/Model/Metadata/Kompsat5/Kompsat5MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Kompsat5/Kompsat5MetadataExtractor.cs @@ -94,7 +94,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, auxiliary, item); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } @@ -378,19 +378,19 @@ private IDictionary GetCommonMetadata(Auxiliary auxiliary) private void FillInstrument(Auxiliary auxiliary, Dictionary properties) { // platform - if (!string.IsNullOrEmpty(Kompsat5MetadataExtraction.PLATFORM)) + if (!string.IsNullOrEmpty(PLATFORM)) { properties.Remove("platform"); properties.Remove("constellation"); properties.Remove("mission"); - properties.Add("platform", Kompsat5MetadataExtraction.PLATFORM); - properties.Add("mission", Kompsat5MetadataExtraction.PLATFORM); + properties.Add("platform", PLATFORM); + properties.Add("mission", PLATFORM); } // instruments properties.Remove("instruments"); - properties.Add("instruments", new string[] { Kompsat5MetadataExtraction.INSTRUMENT }); + properties.Add("instruments", new string[] { INSTRUMENT }); properties.Remove("sensor_type"); properties.Add("sensor_type", "radar"); diff --git a/src/Stars.Data/Model/Metadata/Landsat8/Landsat8MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Landsat8/Landsat8MetadataExtractor.cs index 17238ace..66531a52 100644 --- a/src/Stars.Data/Model/Metadata/Landsat8/Landsat8MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Landsat8/Landsat8MetadataExtractor.cs @@ -93,7 +93,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/Landsat9/Landsat9MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Landsat9/Landsat9MetadataExtractor.cs index f441bc32..45403930 100644 --- a/src/Stars.Data/Model/Metadata/Landsat9/Landsat9MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Landsat9/Landsat9MetadataExtractor.cs @@ -110,7 +110,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/NewSat/NewSatMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/NewSat/NewSatMetadataExtractor.cs index 812d5863..1b92acdd 100644 --- a/src/Stars.Data/Model/Metadata/NewSat/NewSatMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/NewSat/NewSatMetadataExtractor.cs @@ -84,7 +84,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // add L3 visual tif asset AddL3Assets(item, stacItem); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } private void FixAssetPaths(StacItem stacItem, IItem item) diff --git a/src/Stars.Data/Model/Metadata/PlanetScope/PlanetScopeMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/PlanetScope/PlanetScopeMetadataExtractor.cs index f778d2b8..4915525a 100644 --- a/src/Stars.Data/Model/Metadata/PlanetScope/PlanetScopeMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/PlanetScope/PlanetScopeMetadataExtractor.cs @@ -60,7 +60,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi StacItem stacItem = CreateStacItem(metadata, item); AddAssets(stacItem, item, metadata); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); ; } @@ -428,7 +428,7 @@ public virtual async Task ReadMetadata(IAsset manifestAsset public class PlanetScopeMetadata { - private IAsset summaryAsset; + private readonly IAsset summaryAsset; public XmlNamespaceManager nsmgr { get; set; } public XPathNavigator nav { get; set; } diff --git a/src/Stars.Data/Model/Metadata/RCM/RcmMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/RCM/RcmMetadataExtractor.cs index a98ca6a7..94e3b28a 100644 --- a/src/Stars.Data/Model/Metadata/RCM/RcmMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/RCM/RcmMetadataExtractor.cs @@ -96,7 +96,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, auxiliary, item); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } diff --git a/src/Stars.Data/Model/Metadata/Resursp/ResurspMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Resursp/ResurspMetadataExtractor.cs index 2dd15ce5..d65e53f0 100644 --- a/src/Stars.Data/Model/Metadata/Resursp/ResurspMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Resursp/ResurspMetadataExtractor.cs @@ -98,7 +98,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(stacItem.Properties); AddOtherProperties(stacItem.Properties); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } private GeoJSON.Net.Geometry.IGeometryObject GetGeometryFromShpFileAsset(IAsset shapeFileAsset) diff --git a/src/Stars.Data/Model/Metadata/Saocom1/Saocom1MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Saocom1/Saocom1MetadataExtractor.cs index e3680d78..c0a1bf00 100644 --- a/src/Stars.Data/Model/Metadata/Saocom1/Saocom1MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Saocom1/Saocom1MetadataExtractor.cs @@ -123,7 +123,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi StacItem stacItem = CreateStacItem(metadata, manifest, innerStacItem, kml); await AddAssets(stacItem, innerStacItem, manifestAsset); - var stacNode = StacItemNode.Create(stacItem, innerStacItem.Uri); + var stacNode = StacNode.Create(stacItem, innerStacItem.Uri); return stacNode; } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetCalibration.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetCalibration.cs index 87d6751e..616050af 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetCalibration.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetCalibration.cs @@ -24,7 +24,7 @@ public S1L1AssetCalibration(l1CalibrationType l1Calibration, IAsset calibrationA this.calibrationAsset = calibrationAsset; } - public async static Task Create(IAsset calibrationAsset, IResourceServiceProvider resourceServiceProvider) + public static async Task Create(IAsset calibrationAsset, IResourceServiceProvider resourceServiceProvider) { return new S1L1AssetCalibration((l1CalibrationType)s1L1CalibrationSerializer.Deserialize(await resourceServiceProvider.GetAssetStreamAsync(calibrationAsset, System.Threading.CancellationToken.None)), calibrationAsset, resourceServiceProvider); } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetNoise.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetNoise.cs index d5972832..086d93c5 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetNoise.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetNoise.cs @@ -24,7 +24,7 @@ public S1L1AssetNoise(l1NoiseVectorType l1Calibration, IAsset calibrationAsset, noiseAsset = calibrationAsset; } - public async static Task Create(IAsset calibrationAsset, IResourceServiceProvider resourceServiceProvider) + public static async Task Create(IAsset calibrationAsset, IResourceServiceProvider resourceServiceProvider) { return new S1L1AssetNoise((l1NoiseVectorType)s1L1NoiseSerializer.Deserialize(await resourceServiceProvider.GetAssetStreamAsync(calibrationAsset, System.Threading.CancellationToken.None)), calibrationAsset, resourceServiceProvider); } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetProduct.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetProduct.cs index 0a0a1578..48fd7e1d 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetProduct.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L1AssetProduct.cs @@ -27,7 +27,7 @@ public S1L1AssetProduct(l1ProductType l1ProductType, IAsset annotationAsset, IAs this.dataAsset = dataAsset; } - public async static Task Create(IAsset annotationAsset, IAsset dataAsset, IResourceServiceProvider resourceServiceProvider) + public static async Task Create(IAsset annotationAsset, IAsset dataAsset, IResourceServiceProvider resourceServiceProvider) { return new S1L1AssetProduct((l1ProductType)s1L1ProductSerializer.Deserialize(await resourceServiceProvider.GetAssetStreamAsync(annotationAsset, System.Threading.CancellationToken.None)), annotationAsset, dataAsset, resourceServiceProvider); } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L2AssetProduct.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L2AssetProduct.cs index c4bd07d7..ec13aaef 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L2AssetProduct.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/S1L2AssetProduct.cs @@ -24,7 +24,7 @@ public S1L2AssetProduct(level2ProductType l2ProductType, string type, IResourceS this.type = type; } - public async static Task CreateData(IAsset annotationAsset, IResourceServiceProvider resourceServiceProvider) + public static async Task CreateData(IAsset annotationAsset, IResourceServiceProvider resourceServiceProvider) { return new S1L2AssetProduct((level2ProductType)s1L2ProductSerializer.Deserialize(await resourceServiceProvider.GetAssetStreamAsync(annotationAsset, System.Threading.CancellationToken.None)), "data", resourceServiceProvider); } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/Sentinel1MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/Sentinel1MetadataExtractor.cs index 8de9fdc2..25e92f75 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/Sentinel1MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel1/Sentinel1MetadataExtractor.cs @@ -33,7 +33,7 @@ public override async Task ReadManifest(IAsset manifestAsset) return xfdu; } - protected async override Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) + protected override async Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) { foreach (var bandAsset in FindAllAssetsFromFileNameRegex(item, "\\.tiff$")) { diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level1MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level1MetadataExtractor.cs index 2cad8346..55406ae9 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level1MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level1MetadataExtractor.cs @@ -44,7 +44,7 @@ public override async Task ReadManifest(IAsset manifestAsset) throw new FormatException(string.Format("Not a Sentinel-2 Level 1C manifest SAFE file asset")); } - protected async override Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) + protected override async Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) { var mtdAsset = FindFirstAssetFromFileNameRegex(item, "MTD_MSIL1C.xml$") ?? throw new FileNotFoundException("Product metadata file 'MTD_MSIL1C.xml' not found"); var mtdtlAsset = FindFirstAssetFromFileNameRegex(item, "MTD_TL.xml$"); @@ -67,7 +67,7 @@ protected async override Task AddAssets(StacItem stacItem, IItem item, SentinelS } - protected async override Task AddAdditionalProperties(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) + protected override async Task AddAdditionalProperties(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) { await GetUserProduct(item); stacItem.Properties.Add("processing_baseline", level1C_User_Product.General_Info.Product_Info.PROCESSING_BASELINE); diff --git a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level2MetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level2MetadataExtractor.cs index dc489c50..d4ae1dea 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level2MetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/Sentinel2/Sentinel2Level2MetadataExtractor.cs @@ -44,7 +44,7 @@ public override async Task ReadManifest(IAsset manifestAsset) } - protected async override Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) + protected override async Task AddAssets(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) { var mtdtlAsset = FindFirstAssetFromFileNameRegex(item, "MTD_TL.xml$"); Level2A_Tile mtdTile = null; @@ -75,7 +75,7 @@ protected async override Task AddAssets(StacItem stacItem, IItem item, SentinelS } - protected async override Task AddAdditionalProperties(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) + protected override async Task AddAdditionalProperties(StacItem stacItem, IItem item, SentinelSafeStacFactory stacFactory) { await GetUserProduct(item); stacItem.Properties.Add("processing_baseline", level2A_User_Product.General_Info.L2A_Product_Info.PROCESSING_BASELINE); diff --git a/src/Stars.Data/Model/Metadata/Sentinels/SentinelMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Sentinels/SentinelMetadataExtractor.cs index afdfff5b..7254d1cd 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/SentinelMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/SentinelMetadataExtractor.cs @@ -75,7 +75,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // AddEoBandPropertyInItem(stacItem); - var stacNode = StacItemNode.Create(stacItem, item.Uri); + var stacNode = StacNode.Create(stacItem, item.Uri); return stacNode; } diff --git a/src/Stars.Data/Model/Metadata/Sentinels/SentinelSafeStacFactory.cs b/src/Stars.Data/Model/Metadata/Sentinels/SentinelSafeStacFactory.cs index 5fba6534..d5d5fc22 100644 --- a/src/Stars.Data/Model/Metadata/Sentinels/SentinelSafeStacFactory.cs +++ b/src/Stars.Data/Model/Metadata/Sentinels/SentinelSafeStacFactory.cs @@ -367,7 +367,7 @@ public virtual IGeometryObject GetGeometry() posList[0].Text += " " + posList[0].Text.Split(' ')[0] + " " + posList[0].Text.Split(' ')[1]; } linearRing.Items = posList.ToArray(); - linearRing.ItemsElementName = new ServiceModel.Ogc.Gml321.ItemsChoiceType6[1] { Terradue.ServiceModel.Ogc.Gml321.ItemsChoiceType6.posList }; + linearRing.ItemsElementName = new ServiceModel.Ogc.Gml321.ItemsChoiceType6[1] { ServiceModel.Ogc.Gml321.ItemsChoiceType6.posList }; polygon.exterior.Item = linearRing; return polygon.ToGeometry().NormalizePolygon(); @@ -389,7 +389,7 @@ public virtual IGeometryObject GetGeometry() posList[0].Text += " " + posList[0].Text.Split(' ')[0] + " " + posList[0].Text.Split(' ')[1]; } linearRing.Items = posList.ToArray(); - linearRing.ItemsElementName = new ServiceModel.Ogc.Gml321.ItemsChoiceType6[1] { Terradue.ServiceModel.Ogc.Gml321.ItemsChoiceType6.posList }; + linearRing.ItemsElementName = new ServiceModel.Ogc.Gml321.ItemsChoiceType6[1] { ServiceModel.Ogc.Gml321.ItemsChoiceType6.posList }; polygon.exterior.Item = linearRing; return polygon.ToGeometry().NormalizePolygon(); diff --git a/src/Stars.Data/Model/Metadata/TerrasarX/TerrasarXMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/TerrasarX/TerrasarXMetadataExtractor.cs index e53043c2..7e093462 100644 --- a/src/Stars.Data/Model/Metadata/TerrasarX/TerrasarXMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/TerrasarX/TerrasarXMetadataExtractor.cs @@ -60,7 +60,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi // Add assets AddAssets(stacItem, item, metadata); - var stacNode = StacItemNode.Create(stacItem, item.Uri); + var stacNode = StacNode.Create(stacItem, item.Uri); return stacNode; } diff --git a/src/Stars.Data/Model/Metadata/Vrss/VrssMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Vrss/VrssMetadataExtractor.cs index 5199d956..93f2346f 100644 --- a/src/Stars.Data/Model/Metadata/Vrss/VrssMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Vrss/VrssMetadataExtractor.cs @@ -34,9 +34,9 @@ public class VrssMetadataExtractor : MetadataExtraction // VRSS-1_MSS-2_0698_0239_20200814_L2B_81713505511_1 // VRSS-2_PAN_0996_0379_20210127_L2B_128183941985 // VRSS-2_MSS_0996_0379_20210127_L2B_12818393908 - private Regex identifierRegex = new Regex(@"(?'id'VRSS-[12]_(?'type'[A-Z]{3})(-\d)?_\d{4}_\d{4}_\d{8}_.{3}_\d+)(_(?'n'\d+))?"); + private readonly Regex identifierRegex = new Regex(@"(?'id'VRSS-[12]_(?'type'[A-Z]{3})(-\d)?_\d{4}_\d{4}_\d{8}_.{3}_\d+)(_(?'n'\d+))?"); - private Regex utmZoneRegex = new Regex(@"(?'num'\d+)(?'hem'[NS])"); + private readonly Regex utmZoneRegex = new Regex(@"(?'num'\d+)(?'hem'[NS])"); public static XmlSerializer metadataSerializer = new XmlSerializer(typeof(Schemas.Metadata)); @@ -79,7 +79,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi FillBasicsProperties(metadata, stacItem.Properties); AddOtherProperties(metadata, stacItem.Properties); - return StacItemNode.Create(stacItem, item.Uri); ; + return StacNode.Create(stacItem, item.Uri); ; } internal virtual StacItem CreateStacItem(Schemas.Metadata metadata) diff --git a/src/Stars.Data/Model/Metadata/Worldview/WorldviewMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Worldview/WorldviewMetadataExtractor.cs index 7e954e50..02425697 100644 --- a/src/Stars.Data/Model/Metadata/Worldview/WorldviewMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Worldview/WorldviewMetadataExtractor.cs @@ -96,7 +96,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi AddAssets(stacItem, metadata, isdMetadata, item); // AddEoBandPropertyInItem(stacItem); - return StacItemNode.Create(stacItem, item.Uri); + return StacNode.Create(stacItem, item.Uri); } private void AddProcessingStacExtension(JavaProperties metadata, StacItem stacItem) diff --git a/src/Stars.Data/Routers/DataHubResultItemRoutable.cs b/src/Stars.Data/Routers/DataHubResultItemRoutable.cs index d4b89744..897855eb 100644 --- a/src/Stars.Data/Routers/DataHubResultItemRoutable.cs +++ b/src/Stars.Data/Routers/DataHubResultItemRoutable.cs @@ -24,7 +24,7 @@ public DataHubResultItemRoutable(IOpenSearchResultItem item, DataHubSourceSuppli this.supplier = supplier; } - Dictionary assets = null; + private Dictionary assets = null; public override IReadOnlyDictionary Assets { diff --git a/src/Stars.Data/Routers/OpenSearchResultFeedRoutable.cs b/src/Stars.Data/Routers/OpenSearchResultFeedRoutable.cs index 6cde312e..00681fd9 100644 --- a/src/Stars.Data/Routers/OpenSearchResultFeedRoutable.cs +++ b/src/Stars.Data/Routers/OpenSearchResultFeedRoutable.cs @@ -24,7 +24,7 @@ public class OpenSearchResultFeedRoutable : IItemCollection, IStreamResource { protected IOpenSearchResultCollection osCollection; - private Uri sourceUri; + private readonly Uri sourceUri; protected readonly ILogger logger; public OpenSearchResultFeedRoutable(IOpenSearchResultCollection collection, Uri sourceUri, ILogger logger) @@ -54,7 +54,7 @@ public OpenSearchResultFeedRoutable() public string Filename => Id + ".atom.xml"; - public ulong ContentLength => Convert.ToUInt64(Encoding.Default.GetBytes(ReadAsStringAsync(System.Threading.CancellationToken.None)).Length); + public ulong ContentLength => Convert.ToUInt64(Encoding.Default.GetBytes(ReadAsStringAsync(CancellationToken.None)).Length); public bool IsCatalog => false; @@ -74,7 +74,7 @@ public string ReadAsStringAsync(CancellationToken ct) public async Task GetStreamAsync(CancellationToken ct) { - return await Task.Run(() => + return await Task.Run(() => { AtomFeed atomFeed = AtomFeed.CreateFromOpenSearchResultCollection(osCollection) as AtomFeed; MemoryStream ms = new MemoryStream(); diff --git a/src/Stars.Data/Routers/OpenSearchResultItemRoutable.cs b/src/Stars.Data/Routers/OpenSearchResultItemRoutable.cs index eb7e49e6..0b01ac00 100644 --- a/src/Stars.Data/Routers/OpenSearchResultItemRoutable.cs +++ b/src/Stars.Data/Routers/OpenSearchResultItemRoutable.cs @@ -23,7 +23,7 @@ public class OpenSearchResultItemRoutable : IResource, IAssetsContainer, IStream { protected IOpenSearchResultItem osItem; - private Uri sourceUri; + private readonly Uri sourceUri; protected readonly ILogger logger; public OpenSearchResultItemRoutable(IOpenSearchResultItem item, Uri sourceUri, ILogger logger) @@ -53,7 +53,7 @@ public OpenSearchResultItemRoutable() public string Filename => Id + ".atom.xml"; - public ulong ContentLength => Convert.ToUInt64(Encoding.Default.GetBytes(ReadAsStringAsync(System.Threading.CancellationToken.None)).Length); + public ulong ContentLength => Convert.ToUInt64(Encoding.Default.GetBytes(ReadAsStringAsync(CancellationToken.None)).Length); public bool IsCatalog => false; @@ -69,7 +69,7 @@ public string ReadAsStringAsync(CancellationToken ct) public async Task GetStreamAsync(CancellationToken ct) { - return await Task.Run(() => + return await Task.Run(() => { var atomItem = AtomItem.FromOpenSearchResultItem(osItem); MemoryStream ms = new MemoryStream(); diff --git a/src/Stars.Data/Routers/OrderableAsset.cs b/src/Stars.Data/Routers/OrderableAsset.cs index f512261c..afa57d00 100644 --- a/src/Stars.Data/Routers/OrderableAsset.cs +++ b/src/Stars.Data/Routers/OrderableAsset.cs @@ -18,7 +18,7 @@ internal class OrderableAsset : IAsset, IOrderable { private readonly IOpenSearchResultItem osItem; private readonly ISupplier supplier; - private Dictionary properties; + private readonly Dictionary properties; public OrderableAsset(IOpenSearchResultItem osItem, ISupplier supplier) { diff --git a/src/Stars.Data/Routers/TransferRequestAsset.cs b/src/Stars.Data/Routers/TransferRequestAsset.cs index c2308c46..74ef8bcc 100644 --- a/src/Stars.Data/Routers/TransferRequestAsset.cs +++ b/src/Stars.Data/Routers/TransferRequestAsset.cs @@ -16,9 +16,9 @@ namespace Terradue.Stars.Data.Routers { internal class TransferRequestAsset : IAsset, IStreamResource { - private ITransferRequest tr; + private readonly ITransferRequest tr; private readonly string label; - private Dictionary properties; + private readonly Dictionary properties; public TransferRequestAsset(ITransferRequest tr, string label = null) { diff --git a/src/Stars.Data/Suppliers/Astrium/GeodeliverySupplier.cs b/src/Stars.Data/Suppliers/Astrium/GeodeliverySupplier.cs index cf80c627..42f0998a 100644 --- a/src/Stars.Data/Suppliers/Astrium/GeodeliverySupplier.cs +++ b/src/Stars.Data/Suppliers/Astrium/GeodeliverySupplier.cs @@ -26,7 +26,7 @@ public class GeodeliverySupplier : ISupplier { protected ILogger logger; private readonly TranslatorManager translatorManager; - private ICredentials credentials; + private readonly ICredentials credentials; public GeodeliverySupplier(ILogger logger, TranslatorManager translatorManager, ICredentials credentials) { @@ -96,11 +96,11 @@ private async Task AddAssets(string pattern, int callid, StacItemNode itemNode) try { FtpWebRequest reqFTP; - reqFTP = (FtpWebRequest)FtpWebRequest.Create(ftpUri); + reqFTP = (FtpWebRequest)WebRequest.Create(ftpUri); reqFTP.UseBinary = true; reqFTP.Credentials = credentials; reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails; - reqFTP.Timeout = System.Threading.Timeout.Infinite; + reqFTP.Timeout = Timeout.Infinite; reqFTP.Proxy = null; reqFTP.KeepAlive = true; reqFTP.UsePassive = true; diff --git a/src/Stars.Data/Suppliers/DataHubSourceSupplier.cs b/src/Stars.Data/Suppliers/DataHubSourceSupplier.cs index 6ec7afb6..8e5b188c 100644 --- a/src/Stars.Data/Suppliers/DataHubSourceSupplier.cs +++ b/src/Stars.Data/Suppliers/DataHubSourceSupplier.cs @@ -29,7 +29,7 @@ namespace Terradue.Stars.Data.Suppliers public class DataHubSourceSupplier : OpenSearchableSupplier, ISupplier { private IDataHubSourceWrapper wrapper; - private ICredentials credentialsManager; + private readonly ICredentials credentialsManager; private readonly IS3ClientFactory _s3ClientFactory; public DataHubSourceSupplier(ILogger logger, @@ -175,7 +175,7 @@ private IResource CreateDataHubResultItem(OpenSearch.Result.IOpenSearchResultCol public override async Task Order(IOrderable orderableRoute) { OrderableAsset orderableAsset = orderableRoute as OrderableAsset; - IAssetAccess assetAccess = await Task.Run(() => wrapper.OrderProduct(orderableAsset.OpenSearchResultItem)); + IAssetAccess assetAccess = await Task.Run(() => wrapper.OrderProduct(orderableAsset.OpenSearchResultItem)); OrderVoucher orderVoucher = new OrderVoucher(orderableRoute, assetAccess.Id); return orderVoucher; } diff --git a/src/Stars.Data/Suppliers/PlanetScope/PlanetScopeSupplier.cs b/src/Stars.Data/Suppliers/PlanetScope/PlanetScopeSupplier.cs index 0909f357..4b3a766a 100644 --- a/src/Stars.Data/Suppliers/PlanetScope/PlanetScopeSupplier.cs +++ b/src/Stars.Data/Suppliers/PlanetScope/PlanetScopeSupplier.cs @@ -25,8 +25,8 @@ public class PlanetScopeSupplier : ISupplier { protected ILogger logger; private readonly TranslatorManager translatorManager; - private ICredentials credentials; - private string baseUrl; + private readonly ICredentials credentials; + private readonly string baseUrl; // These are the asset types to be supported initially public static Dictionary assetTypes = new Dictionary() diff --git a/src/Stars.Data/ThirdParty/Publication/GeosquarePublicationModel.cs b/src/Stars.Data/ThirdParty/Publication/GeosquarePublicationModel.cs index 93f5d135..f78f45da 100644 --- a/src/Stars.Data/ThirdParty/Publication/GeosquarePublicationModel.cs +++ b/src/Stars.Data/ThirdParty/Publication/GeosquarePublicationModel.cs @@ -22,7 +22,7 @@ namespace Terradue.Stars.Data.ThirdParty.Geosquare [DataContract] public class GeosquarePublicationModel : IPublicationModel { - private AuthenticationHeaderValue authorizationHeaderValue; + private readonly AuthenticationHeaderValue authorizationHeaderValue; public GeosquarePublicationModel() { diff --git a/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs b/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs index 156d59f0..5563a8c2 100644 --- a/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs +++ b/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs @@ -337,8 +337,8 @@ public async Task CreateOpenSearchLinkAsync(SyndicationLink lin { var template = geosquareConfiguration.GetOpenSearchForUri(link.Uri); if (string.IsNullOrEmpty(template)) return null; - var webRoute = await resourceServiceProvider.GetStreamResourceAsync(new AtomResourceLink(link), System.Threading.CancellationToken.None); - IStacObject linkedStacObject = StacConvert.Deserialize(await webRoute.GetStreamAsync(System.Threading.CancellationToken.None)); + var webRoute = await resourceServiceProvider.GetStreamResourceAsync(new AtomResourceLink(link), CancellationToken.None); + IStacObject linkedStacObject = StacConvert.Deserialize(await webRoute.GetStreamAsync(CancellationToken.None)); var osUrl = template.ReplaceMacro("stacObject", linkedStacObject); osUrl = osUrl.ReplaceMacro("index", catalogPublicationState.GeosquarePublicationModel.Index); var osUri = new Uri(osUrl); diff --git a/src/Stars.Data/Translators/StacCollectionToAtomItemTranslator.cs b/src/Stars.Data/Translators/StacCollectionToAtomItemTranslator.cs index c5378c76..19a0eb0d 100644 --- a/src/Stars.Data/Translators/StacCollectionToAtomItemTranslator.cs +++ b/src/Stars.Data/Translators/StacCollectionToAtomItemTranslator.cs @@ -20,7 +20,7 @@ namespace Terradue.Stars.Data.Translators public class StacCollectionToAtomItemTranslator : ITranslator { private readonly IServiceProvider serviceProvider; - private AtomRouter atomRouter; + private readonly AtomRouter atomRouter; public StacCollectionToAtomItemTranslator(IServiceProvider serviceProvider) { diff --git a/src/Stars.Data/Translators/StacItemToAtomItemTranslator.cs b/src/Stars.Data/Translators/StacItemToAtomItemTranslator.cs index 22237051..a5ea0b6d 100644 --- a/src/Stars.Data/Translators/StacItemToAtomItemTranslator.cs +++ b/src/Stars.Data/Translators/StacItemToAtomItemTranslator.cs @@ -19,7 +19,7 @@ namespace Terradue.Stars.Data.Translators public class StacItemToAtomItemTranslator : ITranslator { private readonly IServiceProvider serviceProvider; - private AtomRouter atomRouter; + private readonly AtomRouter atomRouter; public StacItemToAtomItemTranslator(IServiceProvider serviceProvider) { diff --git a/src/Stars.Geometry/Atom/AtomExtensions.cs b/src/Stars.Geometry/Atom/AtomExtensions.cs index fa32c169..8ac71380 100644 --- a/src/Stars.Geometry/Atom/AtomExtensions.cs +++ b/src/Stars.Geometry/Atom/AtomExtensions.cs @@ -31,7 +31,7 @@ public static IGeometryObject FindGeometry(this SyndicationItem item) { // 1) search for georss case "http://www.georss.org/georss": - var georss = ServiceModel.Ogc.GeoRss.GeoRss.GeoRssHelper.Deserialize(xr); + var georss = GeoRssHelper.Deserialize(xr); savegeom = georss.ToGeometry(); if (!(georss is GeoRssBox || georss is GeoRssPoint)) { diff --git a/src/Stars.Geometry/Gml/Gml311Extensions.cs b/src/Stars.Geometry/Gml/Gml311Extensions.cs index 7853e7c3..6860577c 100644 --- a/src/Stars.Geometry/Gml/Gml311Extensions.cs +++ b/src/Stars.Geometry/Gml/Gml311Extensions.cs @@ -670,7 +670,7 @@ public static IPosition ToGeometry(this CoordType coord) if (coord.X == default(decimal) || coord.Y == default(decimal)) throw new FormatException("invalid GML representation: gml:coord missing X or Y"); - Position geopos = new Position(System.Convert.ToDouble(coord.X), System.Convert.ToDouble(coord.Y), System.Convert.ToDouble(coord.Z)); + Position geopos = new Position(Convert.ToDouble(coord.X), Convert.ToDouble(coord.Y), Convert.ToDouble(coord.Z)); return geopos; } diff --git a/src/Stars.Geometry/Gml/Gml321Extensions.cs b/src/Stars.Geometry/Gml/Gml321Extensions.cs index fa5c96b9..d0089820 100644 --- a/src/Stars.Geometry/Gml/Gml321Extensions.cs +++ b/src/Stars.Geometry/Gml/Gml321Extensions.cs @@ -15,8 +15,8 @@ namespace Terradue.Stars.Geometry.Gml321 public static class Gml321Extensions { - private static string conversionSpecifier = "G"; - private static CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); + private static readonly string conversionSpecifier = "G"; + private static readonly CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); public static MultiSurfaceType ToGmlMultiSurface(this IGeometryObject geometry) @@ -143,7 +143,7 @@ public static DirectPositionListType ToGmlPosList(this IPosition[] positions) DirectPositionListType gmlPosList = new DirectPositionListType(); gmlPosList.count = positions.Length.ToString(); gmlPosList.Text = string.Join(" ", positions.Cast() - .SelectMany(p => p.Altitude == null ? new string[2] { + .SelectMany(p => p.Altitude == null ? new string[2] { p.Latitude.ToString(), p.Longitude.ToString() } : new string[3] { @@ -237,7 +237,7 @@ public static MultiSurfaceType ToGmlMultiSurface(this MultiPolygon multiPolygon) { MultiSurfaceType gmlMultiSurface = new MultiSurfaceType(); gmlMultiSurface.surfaceMembers = new SurfaceArrayPropertyType(); - gmlMultiSurface.surfaceMembers.Items = multiPolygon.Coordinates.Select(p => p.ToGmlPolygon()).ToArray(); + gmlMultiSurface.surfaceMembers.Items = multiPolygon.Coordinates.Select(p => p.ToGmlPolygon()).ToArray(); return gmlMultiSurface; } @@ -420,7 +420,7 @@ public static LineString ToGeometry(this LinearRingType linearRing) Type posType = linearRing.ItemsElementName.First().GetType(); - positions = FromGMLData(linearRing.Items, Array.ConvertAll(linearRing.ItemsElementName, i => i.ToString())); + positions = FromGMLData(linearRing.Items, Array.ConvertAll(linearRing.ItemsElementName, i => i.ToString())); LineString linestring = new LineString(positions); @@ -435,7 +435,7 @@ public static LineString ToGeometry(this LineStringType lineString) if (lineString.Items == null) return null; - List points = FromGMLData(lineString.Items, Array.ConvertAll(lineString.ItemsElementName, i => i.ToString())); + List points = FromGMLData(lineString.Items, Array.ConvertAll(lineString.ItemsElementName, i => i.ToString())); if (points.Count < 2) throw new FormatException("invalid GML representation: LineString type must have at least 2 positions"); diff --git a/src/Stars.Geometry/Wkt/WktExtensions.cs b/src/Stars.Geometry/Wkt/WktExtensions.cs index f8fdafa5..2bbe0dd3 100644 --- a/src/Stars.Geometry/Wkt/WktExtensions.cs +++ b/src/Stars.Geometry/Wkt/WktExtensions.cs @@ -15,8 +15,7 @@ namespace Terradue.Stars.Geometry.Wkt { public static class WktExtensions { - - static readonly IFormatProvider ci = CultureInfo.InvariantCulture; + private static readonly IFormatProvider ci = CultureInfo.InvariantCulture; public static string ToWkt(this Feature feature) { @@ -87,17 +86,17 @@ public static string ToWkt(this IGeometryObject geometry) return null; } - static string GeometryToWktString(Point point) + private static string GeometryToWktString(Point point) { return GeometryToWktString(point.Coordinates); } - static string GeometryToWktString(MultiPoint multiPoint) + private static string GeometryToWktString(MultiPoint multiPoint) { return string.Format("({0})", string.Join(",", multiPoint.Coordinates.Select(GeometryToWktString))); } - static string GeometryToWktString(IPosition position) + private static string GeometryToWktString(IPosition position) { if (position is Position) @@ -106,22 +105,22 @@ static string GeometryToWktString(IPosition position) return ""; } - static string GeometryToWktString(LineString lineString) + private static string GeometryToWktString(LineString lineString) { return string.Format("({0})", string.Join(",", lineString.Coordinates.Select(GeometryToWktString))); } - static string GeometryToWktString(Polygon polygon) + private static string GeometryToWktString(Polygon polygon) { return string.Format("({0})", string.Join(",", polygon.Coordinates.Select(GeometryToWktString))); } - static string GeometryToWktString(MultiPolygon multiPolygon) + private static string GeometryToWktString(MultiPolygon multiPolygon) { return string.Format("({0})", string.Join(",", multiPolygon.Coordinates.Select(GeometryToWktString))); } - static string GeometryToWktString(MultiLineString multiLineString) + private static string GeometryToWktString(MultiLineString multiLineString) { return string.Format("({0})", string.Join(",", multiLineString.Coordinates.Select(GeometryToWktString))); } diff --git a/src/Stars.Services/AssetImportException.cs b/src/Stars.Services/AssetImportException.cs index 5a7aad7a..d028103d 100644 --- a/src/Stars.Services/AssetImportException.cs +++ b/src/Stars.Services/AssetImportException.cs @@ -12,7 +12,7 @@ namespace Terradue.Stars.Services [Serializable] internal class AssetImportException : AggregateException { - private IReadOnlyDictionary assets; + private readonly IReadOnlyDictionary assets; public AssetImportException() { diff --git a/src/Stars.Services/BlockingStream.cs b/src/Stars.Services/BlockingStream.cs index ffb44740..77ab68df 100644 --- a/src/Stars.Services/BlockingStream.cs +++ b/src/Stars.Services/BlockingStream.cs @@ -12,15 +12,15 @@ namespace Terradue.Stars.Services { public class BlockingStream : Stream { - private object _lockForRead; - private object _lockForAll; - private Queue _chunks; + private readonly object _lockForRead; + private readonly object _lockForAll; + private readonly Queue _chunks; private byte[] _currentChunk; private int _currentChunkPosition; private ManualResetEvent _doneWriting; private ManualResetEvent _dataAvailable; - private WaitHandle[] _events; - private int _doneWritingHandleIndex; + private readonly WaitHandle[] _events; + private readonly int _doneWritingHandleIndex; private volatile bool _illegalToWrite; private volatile bool _writeClosed; private ulong? contentRequestLength; diff --git a/src/Stars.Services/FilteredAssetContainer.cs b/src/Stars.Services/FilteredAssetContainer.cs index 4aa24eb8..ace1455b 100644 --- a/src/Stars.Services/FilteredAssetContainer.cs +++ b/src/Stars.Services/FilteredAssetContainer.cs @@ -12,8 +12,8 @@ namespace Terradue.Stars.Services { public class FilteredAssetContainer : IAssetsContainer { - private IAssetsContainer assetsContainer; - private AssetFilters assetFilters; + private readonly IAssetsContainer assetsContainer; + private readonly AssetFilters assetFilters; public FilteredAssetContainer(IAssetsContainer assetsContainer, AssetFilters assetFilters) { diff --git a/src/Stars.Services/Model/Atom/AtomExtensions.cs b/src/Stars.Services/Model/Atom/AtomExtensions.cs index 1d04c0d8..1e7cc109 100644 --- a/src/Stars.Services/Model/Atom/AtomExtensions.cs +++ b/src/Stars.Services/Model/Atom/AtomExtensions.cs @@ -189,7 +189,7 @@ public static IGeometryObject FindGeometry(this AtomItem item) IGeometryObject savegeom = null; - savegeom = Terradue.Stars.Geometry.Atom.AtomExtensions.FindGeometry(item); + savegeom = Geometry.Atom.AtomExtensions.FindGeometry(item); if (savegeom == null) { diff --git a/src/Stars.Services/Model/Atom/AtomFeedCatalog.cs b/src/Stars.Services/Model/Atom/AtomFeedCatalog.cs index 6772c8c9..c4ddd6e3 100644 --- a/src/Stars.Services/Model/Atom/AtomFeedCatalog.cs +++ b/src/Stars.Services/Model/Atom/AtomFeedCatalog.cs @@ -64,7 +64,7 @@ public IReadOnlyList GetRoutes(IRouter router) public async Task GetStreamAsync(CancellationToken ct) { MemoryStream ms = new MemoryStream(); - return await Task.Run(() => + return await Task.Run(() => { var sw = XmlWriter.Create(ms); Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed); diff --git a/src/Stars.Services/Model/Atom/AtomItemNode.cs b/src/Stars.Services/Model/Atom/AtomItemNode.cs index 81ef7f22..e26b9838 100644 --- a/src/Stars.Services/Model/Atom/AtomItemNode.cs +++ b/src/Stars.Services/Model/Atom/AtomItemNode.cs @@ -22,7 +22,7 @@ namespace Terradue.Stars.Services.Model.Atom { public class AtomItemNode : IItem, IAssetsContainer, IStreamResource { - private AtomItem item; + private readonly AtomItem item; private readonly Uri sourceUri; public AtomItemNode(AtomItem item, Uri sourceUri) @@ -58,7 +58,7 @@ public IReadOnlyList GetRoutes() public async Task GetStreamAsync(CancellationToken ct) { - return await Task.Run(() => + return await Task.Run(() => { MemoryStream ms = new MemoryStream(); var sw = XmlWriter.Create(ms); diff --git a/src/Stars.Services/Model/Atom/AtomLinkAsset.cs b/src/Stars.Services/Model/Atom/AtomLinkAsset.cs index f1cd9802..7ee8132c 100644 --- a/src/Stars.Services/Model/Atom/AtomLinkAsset.cs +++ b/src/Stars.Services/Model/Atom/AtomLinkAsset.cs @@ -14,8 +14,8 @@ namespace Terradue.Stars.Services.Model.Atom { public class AtomLinkAsset : IAsset { - private SyndicationLink link; - private SyndicationItem item; + private readonly SyndicationLink link; + private readonly SyndicationItem item; public AtomLinkAsset(SyndicationLink link, SyndicationItem item) { diff --git a/src/Stars.Services/Model/Atom/AtomResourceLink.cs b/src/Stars.Services/Model/Atom/AtomResourceLink.cs index af23d7d6..30389785 100644 --- a/src/Stars.Services/Model/Atom/AtomResourceLink.cs +++ b/src/Stars.Services/Model/Atom/AtomResourceLink.cs @@ -12,7 +12,7 @@ namespace Terradue.Stars.Services.Model.Atom { public class AtomResourceLink : IResourceLink { - private SyndicationLink atomLink; + private readonly SyndicationLink atomLink; public AtomResourceLink(SyndicationLink l) { diff --git a/src/Stars.Services/Model/Atom/AtomRouter.cs b/src/Stars.Services/Model/Atom/AtomRouter.cs index 22f4a08a..0ae5ec3b 100644 --- a/src/Stars.Services/Model/Atom/AtomRouter.cs +++ b/src/Stars.Services/Model/Atom/AtomRouter.cs @@ -23,9 +23,9 @@ namespace Terradue.Stars.Services.Model.Atom public class AtomRouter : IRouter { - private static string[] supportedTypes = new string[] { "application/atom+xml", "application/xml", "text/xml" }; + private static readonly string[] supportedTypes = new string[] { "application/atom+xml", "application/xml", "text/xml" }; - private static string opensearchDescriptionType = "application/opensearchdescription+xml"; + private static readonly string opensearchDescriptionType = "application/opensearchdescription+xml"; private readonly IResourceServiceProvider resourceServiceProvider; diff --git a/src/Stars.Services/Model/Stac/StacNode.cs b/src/Stars.Services/Model/Stac/StacNode.cs index 34584977..e4998703 100644 --- a/src/Stars.Services/Model/Stac/StacNode.cs +++ b/src/Stars.Services/Model/Stac/StacNode.cs @@ -99,7 +99,7 @@ public IReadOnlyList GetLinks() public async Task GetStreamAsync(CancellationToken ct) { MemoryStream ms = new MemoryStream(); - return await Task.Run(() => + return await Task.Run(() => { var sw = new StreamWriter(ms); sw.Write(StacConvert.Serialize(stacObject)); diff --git a/src/Stars.Services/Model/Stac/StacResourceLink.cs b/src/Stars.Services/Model/Stac/StacResourceLink.cs index fd0fa1f9..49485b3d 100644 --- a/src/Stars.Services/Model/Stac/StacResourceLink.cs +++ b/src/Stars.Services/Model/Stac/StacResourceLink.cs @@ -12,7 +12,7 @@ namespace Terradue.Stars.Services.Model.Stac { internal class StacResourceLink : IResourceLink { - private StacLink stacLink; + private readonly StacLink stacLink; public StacResourceLink(StacLink l) { diff --git a/src/Stars.Services/Plugins/PluginPriorityAttribute.cs b/src/Stars.Services/Plugins/PluginPriorityAttribute.cs index bbcb35c7..8266f52d 100644 --- a/src/Stars.Services/Plugins/PluginPriorityAttribute.cs +++ b/src/Stars.Services/Plugins/PluginPriorityAttribute.cs @@ -8,7 +8,7 @@ namespace Terradue.Stars.Services.Plugins { public class PluginPriorityAttribute : Attribute { - private int v; + private readonly int v; public PluginPriorityAttribute(int v) { diff --git a/src/Stars.Services/Processing/Archive.cs b/src/Stars.Services/Processing/Archive.cs index 30a27c37..eab2de77 100644 --- a/src/Stars.Services/Processing/Archive.cs +++ b/src/Stars.Services/Processing/Archive.cs @@ -39,7 +39,7 @@ public abstract class Archive : ILocatable "application/zip" }; - internal async static Task Read(IAsset asset, ILogger logger, IResourceServiceProvider resourceServiceProvider, IFileSystem fileSystem, CancellationToken ct) + internal static async Task Read(IAsset asset, ILogger logger, IResourceServiceProvider resourceServiceProvider, IFileSystem fileSystem, CancellationToken ct) { IStreamResource streamableAsset = await resourceServiceProvider.GetStreamResourceAsync(asset, ct) ?? throw new InvalidDataException("Asset must be streamable to be read as an archive"); ArchiveType compression = FindCompression(asset); diff --git a/src/Stars.Services/Processing/GzipArchive.cs b/src/Stars.Services/Processing/GzipArchive.cs index 8f276034..6c693840 100644 --- a/src/Stars.Services/Processing/GzipArchive.cs +++ b/src/Stars.Services/Processing/GzipArchive.cs @@ -44,7 +44,7 @@ protected async Task GetStreamAsync(IAsset asset, CancellationToken ct) return BlockingStream.StartBufferedStreamAsync(stream, null, ct); } - public async override Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) + public override async Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) { var inputStream = await GetStreamAsync(asset, ct); string name = asset.ContentDisposition.FileName.Replace(".gz", ""); @@ -53,7 +53,7 @@ public async override Task ExtractToDestinationAsync(IDestinat try { - var newArchive = await Archive.Read(gzipEntryAsset, logger, resourceServiceProvider, fileSystem, ct); + var newArchive = await Read(gzipEntryAsset, logger, resourceServiceProvider, fileSystem, ct); return await newArchive.ExtractToDestinationAsync(destination, carrierManager, ct); } catch { } diff --git a/src/Stars.Services/Processing/GzipEntryAsset.cs b/src/Stars.Services/Processing/GzipEntryAsset.cs index 7946a790..81440016 100644 --- a/src/Stars.Services/Processing/GzipEntryAsset.cs +++ b/src/Stars.Services/Processing/GzipEntryAsset.cs @@ -15,8 +15,8 @@ namespace Terradue.Stars.Services.Processing { public class GzipEntryAsset : IAsset, IStreamResource { - private string name; - private Stream inputStream; + private readonly string name; + private readonly Stream inputStream; public GzipEntryAsset(string name, Stream inputStream) { @@ -80,7 +80,7 @@ public IStreamResource GetStreamable() public Task GetStreamAsync(CancellationToken ct) { - return Task.FromResult((Stream)inputStream); + return Task.FromResult((Stream)inputStream); } public Task GetStreamAsync(long start, CancellationToken ct, long end = -1) diff --git a/src/Stars.Services/Processing/TarArchiveAsset.cs b/src/Stars.Services/Processing/TarArchiveAsset.cs index 098b676d..535ea2ec 100644 --- a/src/Stars.Services/Processing/TarArchiveAsset.cs +++ b/src/Stars.Services/Processing/TarArchiveAsset.cs @@ -41,7 +41,7 @@ protected virtual async Task GetTarStreamAsync(IAsset asset, Cancellatio return BlockingStream.StartBufferedStreamAsync(stream, null, ct); } - public async override Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) + public override async Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) { IDictionary assets = await ExtractTarAsync(await GetTarStreamAsync(asset, ct), DeliverTarEntryAsync, destination, carrierManager, ct); return new GenericAssetContainer(destination, assets); diff --git a/src/Stars.Services/Processing/TarEntryAsset.cs b/src/Stars.Services/Processing/TarEntryAsset.cs index 26d93d28..a3b20c45 100644 --- a/src/Stars.Services/Processing/TarEntryAsset.cs +++ b/src/Stars.Services/Processing/TarEntryAsset.cs @@ -15,9 +15,9 @@ namespace Terradue.Stars.Services.Processing { public class TarEntryAsset : IAsset, IStreamResource { - private string name; - private ulong size; - private BlockingStream blockingStream; + private readonly string name; + private readonly ulong size; + private readonly BlockingStream blockingStream; public TarEntryAsset(string name, ulong size, BlockingStream blockingStream) { diff --git a/src/Stars.Services/Processing/ZipArchiveAsset.cs b/src/Stars.Services/Processing/ZipArchiveAsset.cs index 19756ce0..0cc6e7c0 100644 --- a/src/Stars.Services/Processing/ZipArchiveAsset.cs +++ b/src/Stars.Services/Processing/ZipArchiveAsset.cs @@ -122,10 +122,10 @@ public string AutodetectSubfolder() return Path.GetFileNameWithoutExtension(asset.Uri.ToString()); } - public async override Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) + public override async Task ExtractToDestinationAsync(IDestination destination, CarrierManager carrierManager, CancellationToken ct) { Dictionary assetsExtracted = new Dictionary(); - zipFile = Ionic.Zip.ZipFile.Read(await GetZipStreamAsync(asset, carrierManager, ct)); + zipFile = ZipFile.Read(await GetZipStreamAsync(asset, carrierManager, ct)); string subFolder = IsInternalArchive ? string.Empty : AutodetectSubfolder(); foreach (var archiveAsset in Assets) diff --git a/src/Stars.Services/Processing/ZipEntryAsset.cs b/src/Stars.Services/Processing/ZipEntryAsset.cs index 45d094e2..26c2cef4 100644 --- a/src/Stars.Services/Processing/ZipEntryAsset.cs +++ b/src/Stars.Services/Processing/ZipEntryAsset.cs @@ -16,7 +16,7 @@ namespace Terradue.Stars.Services.Processing { internal class ZipEntryAsset : IAsset, IStreamResource { - private ZipEntry entry; + private readonly ZipEntry entry; private readonly ZipFile zipFile; private readonly IAsset parentAsset; private readonly string parentAssetBaseDir; diff --git a/src/Stars.Services/Resources/AmazonCustomS3Config.cs b/src/Stars.Services/Resources/AmazonCustomS3Config.cs index 3afd96af..847dcd0e 100644 --- a/src/Stars.Services/Resources/AmazonCustomS3Config.cs +++ b/src/Stars.Services/Resources/AmazonCustomS3Config.cs @@ -23,7 +23,7 @@ public override string DetermineServiceURL() internal void ForceCustomRegion(string region) { _region = region; - base.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(_region); + RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(_region); } internal void SetServiceURL(string serviceURL) diff --git a/src/Stars.Services/Resources/HttpCachedHeaders.cs b/src/Stars.Services/Resources/HttpCachedHeaders.cs index b3582610..001ef920 100644 --- a/src/Stars.Services/Resources/HttpCachedHeaders.cs +++ b/src/Stars.Services/Resources/HttpCachedHeaders.cs @@ -57,8 +57,8 @@ public MediaTypeHeaderValue ContentType } set { - base.Remove("Content-Type"); - base.Add("Content-Type", value.ToString()); + Remove("Content-Type"); + Add("Content-Type", value.ToString()); } } @@ -74,8 +74,8 @@ public long? ContentLength } set { - base.Remove("Content-Length"); - base.Add("Content-Length", value.ToString()); + Remove("Content-Length"); + Add("Content-Length", value.ToString()); } } @@ -91,8 +91,8 @@ public ContentDispositionHeaderValue ContentDisposition } set { - base.Remove("Content-Disposition"); - base.Add("Content-Disposition", value.ToString()); + Remove("Content-Disposition"); + Add("Content-Disposition", value.ToString()); } } } diff --git a/src/Stars.Services/Resources/LocalDirectoryResource.cs b/src/Stars.Services/Resources/LocalDirectoryResource.cs index 38eaf220..2a1c0e47 100644 --- a/src/Stars.Services/Resources/LocalDirectoryResource.cs +++ b/src/Stars.Services/Resources/LocalDirectoryResource.cs @@ -13,7 +13,7 @@ namespace Terradue.Stars.Services.Router public class LocalDirectoryResource : IAssetsContainer { private readonly IFileSystem fileSystem; - private IDirectoryInfo dirInfo; + private readonly IDirectoryInfo dirInfo; public LocalDirectoryResource(IFileSystem fileSystem, string dirPath) { diff --git a/src/Stars.Services/Resources/LocalFileResource.cs b/src/Stars.Services/Resources/LocalFileResource.cs index 1d11e209..0365e8eb 100644 --- a/src/Stars.Services/Resources/LocalFileResource.cs +++ b/src/Stars.Services/Resources/LocalFileResource.cs @@ -17,8 +17,8 @@ namespace Terradue.Stars.Services.Router public class LocalFileResource : IStreamResource, IDeletableResource { private readonly ResourceType resourceType; - private IFileInfo fileInfo; - private List roles; + private readonly IFileInfo fileInfo; + private readonly List roles; public LocalFileResource(IFileSystem fileSystem, string filePath, ResourceType ResourceType, List roles = null) { diff --git a/src/Stars.Services/Resources/S3ClientFactory.cs b/src/Stars.Services/Resources/S3ClientFactory.cs index 521ca778..23761991 100644 --- a/src/Stars.Services/Resources/S3ClientFactory.cs +++ b/src/Stars.Services/Resources/S3ClientFactory.cs @@ -57,7 +57,7 @@ public IAmazonS3 CreateS3Client(IAsset asset) .GetProperty(Stac.Extensions.Storage.StorageStacExtension.RegionField); if (!string.IsNullOrEmpty(region)) { - s3Config.AmazonS3Config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(region); + s3Config.AmazonS3Config.RegionEndpoint = RegionEndpoint.GetBySystemName(region); } s3Config.AWSCredentials = GetConfiguredCredentials(s3Url); diff --git a/src/Stars.Services/Resources/S3Resource.cs b/src/Stars.Services/Resources/S3Resource.cs index 8ca4e2ea..56647519 100644 --- a/src/Stars.Services/Resources/S3Resource.cs +++ b/src/Stars.Services/Resources/S3Resource.cs @@ -18,7 +18,7 @@ namespace Terradue.Stars.Services.Resources { public class S3Resource : IStreamResource, IDeletableResource { - private S3Url s3Url; + private readonly S3Url s3Url; private bool? requester_pays; public S3Resource(S3Url url, IAmazonS3 client) diff --git a/src/Stars.Services/Resources/S3Url.cs b/src/Stars.Services/Resources/S3Url.cs index 68e36d9f..c2034dc7 100644 --- a/src/Stars.Services/Resources/S3Url.cs +++ b/src/Stars.Services/Resources/S3Url.cs @@ -36,10 +36,10 @@ public class S3Url : ICloneable private const string versionID = "versionId"; // Pattern used to parse multiple path and host style S3 endpoint URLs. - private static Regex s3URLPattern = new Regex(@"^(.+\.)?s3[.-](?:(accelerated|dualstack|website)[.-])?([a-z0-9-]+)\.(?:[a-z0-9-\.]+)"); + private static readonly Regex s3URLPattern = new Regex(@"^(.+\.)?s3[.-](?:(accelerated|dualstack|website)[.-])?([a-z0-9-]+)\.(?:[a-z0-9-\.]+)"); // Pattern to extract S3 bucket - private static Regex s3BucketRegex = new Regex(@"^s3://(?'bucket'[^/]+).*"); + private static readonly Regex s3BucketRegex = new Regex(@"^s3://(?'bucket'[^/]+).*"); public S3Url(string bucketName, string key) { @@ -229,7 +229,7 @@ public static S3Url ParseUri(Uri uri) public object Clone() { - return S3Url.ParseUri(Uri); + return ParseUri(Uri); } public void NormalizeKey() diff --git a/src/Stars.Services/Router/CachedWebResponse.cs b/src/Stars.Services/Router/CachedWebResponse.cs index 47b6d3c9..8f6f4f19 100644 --- a/src/Stars.Services/Router/CachedWebResponse.cs +++ b/src/Stars.Services/Router/CachedWebResponse.cs @@ -8,8 +8,7 @@ namespace Terradue.Stars.Services.Router { internal class CachedWebResponse : WebResponse { - - WebHeaderCollection headers = new WebHeaderCollection(); + private readonly WebHeaderCollection headers = new WebHeaderCollection(); public CachedWebResponse(WebResponse response) { diff --git a/src/Stars.Services/Router/RouterService.cs b/src/Stars.Services/Router/RouterService.cs index 3dbe8399..10370678 100644 --- a/src/Stars.Services/Router/RouterService.cs +++ b/src/Stars.Services/Router/RouterService.cs @@ -53,7 +53,7 @@ public async Task RouteAsync(IResource route, int recursivity, IRouter p ICatalog catalogNode = route as ICatalog; IRouter router = null; - // If route is not a catalog (there is no more routes fom that node) + // If route is not a catalog (there is no more routes from that node) if (catalogNode == null) { // If route is an Item @@ -62,6 +62,12 @@ public async Task RouteAsync(IResource route, int recursivity, IRouter p // Execute the function for the item and return; return await onItemFunction.Invoke(itemNode, prevRouter, state, ct); } + // If route is a Collection + if (route is ICollection collectionNode) + { + // Execute the function for the collection and return; + return await onCollectionFunction.Invoke(collectionNode, prevRouter, state, ct); + } // Ask the router manager if there is another router available for this route router = await routersManager.GetRouterAsync(route); // Definitively impossible to Route @@ -74,10 +80,17 @@ public async Task RouteAsync(IResource route, int recursivity, IRouter p { // New route from new router! var newRoute = await router.RouteAsync(route, ct); + // If route is an Item if (newRoute is IItem) { return await onItemFunction.Invoke(newRoute as IItem, prevRouter, state, ct); } + // If route is a Collection + if (newRoute is ICollection) + { + // Execute the function for the collection and return; + return await onCollectionFunction.Invoke(newRoute as ICollection, prevRouter, state, ct); + } catalogNode = newRoute as ICatalog; @@ -130,6 +143,12 @@ public void OnItem(Func> this.onItemFunction = onItemFunction; } + private Func> onCollectionFunction = (node, router, state, ct) => { return Task.FromResult(state); }; + public void OnCollection(Func> onCollectionFunction) + { + this.onCollectionFunction = onCollectionFunction; + } + private Func> onRoutingExceptionFunction = (route, router, e, state, ct) => { return Task.FromResult(state); }; public void OnRoutingException(Func> onRoutingException) { diff --git a/src/Stars.Services/StacResourceExtensions.cs b/src/Stars.Services/StacResourceExtensions.cs index 9c30d79c..1092d87b 100644 --- a/src/Stars.Services/StacResourceExtensions.cs +++ b/src/Stars.Services/StacResourceExtensions.cs @@ -30,6 +30,21 @@ public static void MergeAssets(this StacItem stacItem, IAssetsContainer assetCon } } + public static void MergeAssets(this StacCollection stacCollection, IAssetsContainer assetContainer, bool removeIfNotInContainer = false) + { + if (removeIfNotInContainer) + stacCollection.Assets.Clear(); + foreach (var asset in assetContainer.Assets) + { + if (stacCollection.Assets.ContainsKey(asset.Key)) + { + stacCollection.Assets.Remove(asset.Key); + } + // we must pass the previous parent url to make the asset uri absolute + stacCollection.Assets.Add(asset.Key, asset.Value.CreateAbsoluteStacAsset(stacCollection, assetContainer.Uri)); + } + } + public static void MergeAssets(this IDictionary assets, IReadOnlyDictionary assets2, bool removeIfNotInContainer = false) { if (removeIfNotInContainer) @@ -45,14 +60,14 @@ public static void MergeAssets(this IDictionary assets, IReadOnl } } - public static StacAsset CreateAbsoluteStacAsset(this IAsset asset, StacItem stacItem, Uri parentUrl) + public static StacAsset CreateAbsoluteStacAsset(this IAsset asset, IStacObject stacObject, Uri parentUrl) { StacAsset newAsset = null; if (asset is StacAssetAsset) - newAsset = new StacAsset((asset as StacAssetAsset).StacAsset, stacItem); + newAsset = new StacAsset((asset as StacAssetAsset).StacAsset, stacObject); else { - newAsset = new StacAsset(stacItem, asset.Uri, asset.Roles, asset.Title, asset.ContentType); + newAsset = new StacAsset(stacObject, asset.Uri, asset.Roles, asset.Title, asset.ContentType); newAsset.Properties.AddRange(asset.Properties); newAsset.FileExtension().Size = asset.ContentLength; } diff --git a/src/Stars.Services/StarsBuilder.cs b/src/Stars.Services/StarsBuilder.cs index 3aef9c3c..72761d78 100644 --- a/src/Stars.Services/StarsBuilder.cs +++ b/src/Stars.Services/StarsBuilder.cs @@ -8,7 +8,7 @@ namespace Terradue.Stars.Services { internal class StarsBuilder : IStarsBuilder { - private IServiceCollection services; + private readonly IServiceCollection services; public StarsBuilder(IServiceCollection services) { diff --git a/src/Stars.Services/StarsExtensions.cs b/src/Stars.Services/StarsExtensions.cs index 8e0794bd..0995513a 100644 --- a/src/Stars.Services/StarsExtensions.cs +++ b/src/Stars.Services/StarsExtensions.cs @@ -57,7 +57,7 @@ public static bool IsNullOrEmpty(this Array array) return (array == null || array.Length == 0); } - public async static Task ReadAsStringAsync(this IStreamResource streamable, CancellationToken ct) + public static async Task ReadAsStringAsync(this IStreamResource streamable, CancellationToken ct) { StreamReader sr = new StreamReader(await streamable.GetStreamAsync(ct)); return await sr.ReadToEndAsync(); diff --git a/src/Stars.Services/Store/StacStoreService.cs b/src/Stars.Services/Store/StacStoreService.cs index 4bc0ac7b..52ae6e81 100644 --- a/src/Stars.Services/Store/StacStoreService.cs +++ b/src/Stars.Services/Store/StacStoreService.cs @@ -150,6 +150,12 @@ public async Task StoreItemNodeAtDestinationAsync(StacItemNode sta return await _stacRouter.RouteAsync(await StoreResourceAtDestinationAsync(stacItemNode, destination, ct), ct) as StacItemNode; } + public async Task StoreCollectionNodeAtDestinationAsync(StacCollectionNode stacCollectionNode, IDestination destination, CancellationToken ct) + { + PrepareStacCatalogueForDestination(stacCollectionNode, destination); + return await _stacRouter.RouteAsync(await StoreResourceAtDestinationAsync(stacCollectionNode, destination, ct), ct) as StacCollectionNode; + } + public async Task StoreCatalogNodeAtDestinationAsync(StacCatalogNode stacCatalogNode, IDestination destination, CancellationToken ct) { PrepareStacCatalogueForDestination(stacCatalogNode, destination); diff --git a/src/Stars.Services/Supplier/Carrier/S3UploadStream.cs b/src/Stars.Services/Supplier/Carrier/S3UploadStream.cs index 93f352e9..3b39233c 100644 --- a/src/Stars.Services/Supplier/Carrier/S3UploadStream.cs +++ b/src/Stars.Services/Supplier/Carrier/S3UploadStream.cs @@ -18,10 +18,10 @@ public class S3UploadStream : Stream /* Note the that maximum size (as of now) of a file in S3 is 5TB so it isn't * safe to assume all uploads will work here. MAX_PART_SIZE times MAX_PART_COUNT * is ~50TB, which is too big for S3. */ - const long MIN_PART_LENGTH = 5L * 1024 * 1024; // all parts but the last this size or greater - const long MAX_PART_LENGTH = 5L * 1024 * 1024 * 1024; // 5GB max per PUT - const long MAX_PART_COUNT = 10000; // no more than 10,000 parts total - const long DEFAULT_PART_LENGTH = MIN_PART_LENGTH; + private const long MIN_PART_LENGTH = 5L * 1024 * 1024; // all parts but the last this size or greater + private const long MAX_PART_LENGTH = 5L * 1024 * 1024 * 1024; // 5GB max per PUT + private const long MAX_PART_COUNT = 10000; // no more than 10,000 parts total + private const long DEFAULT_PART_LENGTH = MIN_PART_LENGTH; internal class Metadata { @@ -40,8 +40,8 @@ internal class Metadata public ConcurrentDictionary PartETags = new ConcurrentDictionary(); } - Metadata _metadata = new Metadata(); - IAmazonS3 _s3 = null; + private Metadata _metadata = new Metadata(); + private readonly IAmazonS3 _s3 = null; public S3UploadStream(IAmazonS3 s3, string s3uri, long partLength = DEFAULT_PART_LENGTH) : this(s3, new Uri(s3uri), partLength) diff --git a/src/Stars.Services/Supplier/DeliveryQuotation.cs b/src/Stars.Services/Supplier/DeliveryQuotation.cs index 0fbeccec..bd2ccdd8 100644 --- a/src/Stars.Services/Supplier/DeliveryQuotation.cs +++ b/src/Stars.Services/Supplier/DeliveryQuotation.cs @@ -11,7 +11,7 @@ namespace Terradue.Stars.Services.Supplier { public class DeliveryQuotation : IDeliveryQuotation { - private IDictionary> assetsDeliveryQuotes; + private readonly IDictionary> assetsDeliveryQuotes; private readonly Dictionary assetsExceptions; public DeliveryQuotation(IDictionary> assetsQuotes, Dictionary assetsExceptions) diff --git a/src/Stars.Services/Supplier/GenericAsset.cs b/src/Stars.Services/Supplier/GenericAsset.cs index bb226ac2..e0049b01 100644 --- a/src/Stars.Services/Supplier/GenericAsset.cs +++ b/src/Stars.Services/Supplier/GenericAsset.cs @@ -12,11 +12,11 @@ namespace Terradue.Stars.Services.Supplier { public class GenericAsset : IAsset { - private IResource route; + private readonly IResource route; private readonly string title; private readonly IReadOnlyList roles; private Uri uri; - private Dictionary properties = new Dictionary(); + private readonly Dictionary properties = new Dictionary(); public GenericAsset(IResource route, string title, IReadOnlyList roles) { diff --git a/src/Stars.Services/Supplier/NoDelivery.cs b/src/Stars.Services/Supplier/NoDelivery.cs index 06c452f6..ec67d8c1 100644 --- a/src/Stars.Services/Supplier/NoDelivery.cs +++ b/src/Stars.Services/Supplier/NoDelivery.cs @@ -12,7 +12,7 @@ namespace Terradue.Stars.Services.Supplier { internal class NoDelivery : IDelivery { - private IResource route; + private readonly IResource route; private readonly ICarrier carrier; public NoDelivery(IResource route, ICarrier carrier) diff --git a/src/Stars.Services/Supplier/OrderVoucher.cs b/src/Stars.Services/Supplier/OrderVoucher.cs index 0e53ddf0..6b79bc18 100644 --- a/src/Stars.Services/Supplier/OrderVoucher.cs +++ b/src/Stars.Services/Supplier/OrderVoucher.cs @@ -18,7 +18,7 @@ namespace Terradue.Stars.Services.Supplier [JsonObject] public class OrderVoucher : IResource, IOrder, IAsset { - private IOrderable orderableRoute; + private readonly IOrderable orderableRoute; private readonly string orderId; public OrderVoucher(IOrderable route, string orderId) @@ -76,7 +76,7 @@ public OrderVoucher(IOrderable route, string orderId) public async Task GetStreamAsync(CancellationToken ct) { - return await Task.Run(() => + return await Task.Run(() => { MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); diff --git a/src/Stars.Services/ThirdParty/Egms/EgmsTimeSeriesOperationStatus.cs b/src/Stars.Services/ThirdParty/Egms/EgmsTimeSeriesOperationStatus.cs index 109b59b6..6344bc8e 100644 --- a/src/Stars.Services/ThirdParty/Egms/EgmsTimeSeriesOperationStatus.cs +++ b/src/Stars.Services/ThirdParty/Egms/EgmsTimeSeriesOperationStatus.cs @@ -11,8 +11,8 @@ namespace Terradue.Stars.Services.ThirdParty.Egms { internal class EgmsTimeSeriesOperationStatus : IAbstractTimeSeriesOperationStatus { - private StacCollection _collection; - private List _statuses; + private readonly StacCollection _collection; + private readonly List _statuses; public EgmsTimeSeriesOperationStatus(StacCollection collection, List statuses) { diff --git a/src/Stars.Services/ThirdParty/Titiler/TitilerService.cs b/src/Stars.Services/ThirdParty/Titiler/TitilerService.cs index 6911f55f..14d2f095 100644 --- a/src/Stars.Services/ThirdParty/Titiler/TitilerService.cs +++ b/src/Stars.Services/ThirdParty/Titiler/TitilerService.cs @@ -18,7 +18,7 @@ public class TitilerService : IThirdPartyService private readonly IOptions options; private readonly ILogger logger; - private static string[] TITILER_VALID_TYPE = new string[7] { + private static readonly string[] TITILER_VALID_TYPE = new string[7] { "image/vnd.stac.geotiff; cloud-optimized=true", "image/tiff; application=geotiff", "image/tiff", @@ -28,7 +28,7 @@ public class TitilerService : IThirdPartyService "application/x-hdf", }; - private static string[] OVERVIEW_NAMES = new string[] { "red", "green", "blue", "nir", "pan" }; + private static readonly string[] OVERVIEW_NAMES = new string[] { "red", "green", "blue", "nir", "pan" }; public TitilerService(IOptions options, ILogger logger) diff --git a/src/Stars.Services/Translator/DefaultStacTranslator.cs b/src/Stars.Services/Translator/DefaultStacTranslator.cs index ff967d0a..70c97939 100644 --- a/src/Stars.Services/Translator/DefaultStacTranslator.cs +++ b/src/Stars.Services/Translator/DefaultStacTranslator.cs @@ -20,7 +20,7 @@ namespace Terradue.Stars.Services.Translator [PluginPriority(10)] public class DefaultStacTranslator : ITranslator { - private ILogger logger; + private readonly ILogger logger; public int Priority { get; set; } public string Key { get => "DefaultStacTranslator"; set { } } diff --git a/src/Stars.Services/Translator/StacLinkTranslator.cs b/src/Stars.Services/Translator/StacLinkTranslator.cs index d2c58964..80d6277e 100644 --- a/src/Stars.Services/Translator/StacLinkTranslator.cs +++ b/src/Stars.Services/Translator/StacLinkTranslator.cs @@ -18,7 +18,7 @@ namespace Terradue.Stars.Services.Translator [PluginPriority(1)] public class StacLinkTranslator : ITranslator { - private ILogger logger; + private readonly ILogger logger; private readonly IResourceServiceProvider resourceServiceProvider; private readonly ICredentials credentials; @@ -51,7 +51,11 @@ public async Task TranslateAsync(IResource route, CancellationToken ct) wh var stacRoute = await resourceServiceProvider.CreateStreamResourceAsync(stacLink, ct); var stacCatalog = StacConvert.Deserialize(await stacRoute.ReadAsStringAsync(ct)); if (stacCatalog != null) + { + logger.LogInformation(string.Format("alternate STAC object found at {0}", stacLink.Uri)); return (T)(new StacCatalogNode(stacCatalog, stacRoute.Uri) as IResource); + + } } catch { } } @@ -71,7 +75,10 @@ public async Task TranslateAsync(IResource route, CancellationToken ct) wh var stacRoute = await resourceServiceProvider.CreateStreamResourceAsync(stacLink, ct); var stacItem = StacConvert.Deserialize(await stacRoute.ReadAsStringAsync(ct)); if (stacItem != null) + { + logger.LogInformation(string.Format("alternate STAC item found at {0}", stacLink.Uri)); return (T)(new StacItemNode(stacItem, stacRoute.Uri) as IResource); + } } catch { } } diff --git a/src/Stars.Tests/Atom2StacTests.cs b/src/Stars.Tests/Atom2StacTests.cs index af08d1b2..40801b8e 100644 --- a/src/Stars.Tests/Atom2StacTests.cs +++ b/src/Stars.Tests/Atom2StacTests.cs @@ -67,8 +67,8 @@ public async Task RemoteAtom2Stac() var stacItemNode = await translatorManager.TranslateAsync(resource, CancellationToken.None); Assert.Equal("S1A_IW_GRDH_1SDV_20211018T111323_20211018T111348_040173_04C21B_421A", stacItemNode.StacItem.Id); Assert.Equal(2, stacItemNode.StacItem.Assets.Count); - Assert.Equal(1, stacItemNode.StacItem.Assets.Where(a => a.Value.Roles.Contains("data")).Count()); - Assert.Equal(1, stacItemNode.StacItem.Assets.Where(a => a.Value.Roles.Contains("thumbnail")).Count()); + Assert.Single(stacItemNode.StacItem.Assets.Where(a => a.Value.Roles.Contains("data"))); + Assert.Single(stacItemNode.StacItem.Assets.Where(a => a.Value.Roles.Contains("thumbnail"))); Assert.Equal("radar", stacItemNode.StacItem.GetProperty("sensor_type")); } diff --git a/src/Stars.Tests/S3Tests.cs b/src/Stars.Tests/S3Tests.cs index 6aaf6530..a459aedc 100644 --- a/src/Stars.Tests/S3Tests.cs +++ b/src/Stars.Tests/S3Tests.cs @@ -43,7 +43,7 @@ public S3Tests(AssetService assetService, public void Test1() { S3ObjectDestination s3ObjectDestination = S3ObjectDestination.Create("s3://local-production-catalog/test.json"); - StacCatalogNode node = (StacCatalogNode)StacCatalogNode.Create(new StacCatalog("test", "test"), s3ObjectDestination.Uri); + StacCatalogNode node = (StacCatalogNode)StacNode.Create(new StacCatalog("test", "test"), s3ObjectDestination.Uri); Assert.Equal("s3://local-production-catalog/test.json", node.Uri.ToString()); } @@ -55,7 +55,7 @@ public async Task ImportAssetsS3toS3() var s3Resource = await resourceServiceProvider.CreateStreamResourceAsync(new GenericResource(new Uri("s3://local-acceptance-catalog/users/evova11/uploads/0HMD4AJ2DCT0E/500x477.tif")), CancellationToken.None); StacItem item = StacConvert.Deserialize(File.ReadAllText(Path.Join(Environment.CurrentDirectory, "../../../In/items/test502.json"))); S3ObjectDestination s3ObjectDestination = S3ObjectDestination.Create("s3://local-acceptance-catalog/calls/857/notifications/test502.json"); - StacItemNode itemNode = (StacItemNode)StacItemNode.Create(item, s3ObjectDestination.Uri); + StacItemNode itemNode = (StacItemNode)StacNode.Create(item, s3ObjectDestination.Uri); var importReport = await assetService.ImportAssetsAsync(itemNode, s3ObjectDestination, AssetFilters.SkipRelative, AssetChecks.None, CancellationToken.None); foreach (var ex in importReport.AssetsExceptions) { @@ -73,7 +73,7 @@ public async Task ImportAssetsS30SizedtoS3() var s3Resource = await resourceServiceProvider.CreateStreamResourceAsync(new GenericResource(new Uri("s3://local-acceptance-catalog2/indices_cog/cci_fss/CFD/GDA-AID-DR_UC7-ADBMON_Product_FSS-CFD-V01_IronDzud-Khuvsgul-1993.tif")), CancellationToken.None); StacItem item = StacConvert.Deserialize(File.ReadAllText(Path.Join(Environment.CurrentDirectory, "../../../In/items/cci_fss_CFD_1993.json"))); S3ObjectDestination s3ObjectDestination = S3ObjectDestination.Create("s3://local-acceptance-catalog2/indices_cog/copy/cci_fss_CFD_1993.json"); - StacItemNode itemNode = (StacItemNode)StacItemNode.Create(item, s3ObjectDestination.Uri); + StacItemNode itemNode = (StacItemNode)StacNode.Create(item, s3ObjectDestination.Uri); var importReport = await assetService.ImportAssetsAsync(itemNode, s3ObjectDestination, AssetFilters.SkipRelative, AssetChecks.None, CancellationToken.None); foreach (var ex in importReport.AssetsExceptions) { diff --git a/src/Stars.Tests/Startup.cs b/src/Stars.Tests/Startup.cs index 9fdcc321..61e107fa 100644 --- a/src/Stars.Tests/Startup.cs +++ b/src/Stars.Tests/Startup.cs @@ -64,7 +64,7 @@ public IConfiguration GetApplicationConfiguration() var builder = new ConfigurationBuilder() .AddNewtonsoftJsonFile("testsettings.json", optional: true) .AddNewtonsoftJsonFile(configFile.FullName, optional: false, reloadOnChange: false) - .AddNewtonsoftJsonFile(Path.Join(System.Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"), optional: true) + .AddNewtonsoftJsonFile(Path.Join(Environment.GetEnvironmentVariable("HOME"), ".config", "Stars", "usersettings.json"), optional: true) .AddEnvironmentVariables() .Build(); diff --git a/src/Stars.Tests/TestStreamable.cs b/src/Stars.Tests/TestStreamable.cs index dc27c6bc..3df82791 100644 --- a/src/Stars.Tests/TestStreamable.cs +++ b/src/Stars.Tests/TestStreamable.cs @@ -13,7 +13,7 @@ namespace Stars.Tests { internal class TestStreamable : IStreamResource { - private Stream stream; + private readonly Stream stream; private readonly ulong contentLength; public TestStreamable(Stream stream, ulong contentLength) @@ -24,15 +24,15 @@ public TestStreamable(Stream stream, ulong contentLength) public bool CanBeRanged => false; - public ContentType ContentType => new ContentType("application/octet-stream"); + public ContentType ContentType => new("application/octet-stream"); public ResourceType ResourceType => ResourceType.Asset; public ulong ContentLength => contentLength; - public ContentDisposition ContentDisposition => new ContentDisposition() { FileName = "test.bin" }; + public ContentDisposition ContentDisposition => new() { FileName = "test.bin" }; - public Uri Uri => new Uri("http://localhost/test.bin"); + public Uri Uri => new("http://localhost/test.bin"); public Task GetStreamAsync(CancellationToken ct) { diff --git a/src/Stars.Tests/TilerTests.cs b/src/Stars.Tests/TilerTests.cs index 12166849..cc570bf8 100644 --- a/src/Stars.Tests/TilerTests.cs +++ b/src/Stars.Tests/TilerTests.cs @@ -54,7 +54,7 @@ public async Task OverviewAssets() // Add TMS offering via titiler if possible var imageOfferingSet = starsAtomItem.TryAddTitilerOffering(stacItemNode, _titilerService); - Assert.True(starsAtomItem.ElementExtensions.Any(i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0")); + Assert.Contains(starsAtomItem.ElementExtensions, i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0"); } [Fact] @@ -69,7 +69,7 @@ public async Task SnowHeightTest() // Add TMS offering via titiler if possible var imageOfferingSet = starsAtomItem.TryAddTitilerOffering(stacItemNode, _titilerService); - Assert.True(starsAtomItem.ElementExtensions.Any(i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0")); + Assert.Contains(starsAtomItem.ElementExtensions, i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0"); } [Fact] @@ -88,7 +88,7 @@ public async Task SnowHeightTest2() // Add TMS offering via titiler if possible var imageOfferingSet = starsAtomItem.TryAddTitilerOffering(stacItemNode, _titilerService); - Assert.True(starsAtomItem.ElementExtensions.Any(i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0")); + Assert.Contains(starsAtomItem.ElementExtensions, i => i.OuterName == "offering" && i.OuterNamespace == "http://www.opengis.net/owc/1.0"); } [Fact] From 3d0f1fff70ee9096202d7e3446b16eec83678242 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 4 Jun 2024 12:18:59 +0200 Subject: [PATCH 2/3] chore: Refactor AllSuppliersSearchExpression method signature --- .../Suppliers/SearchExpressionSupplierTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs b/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs index 20552e73..e1f51aff 100644 --- a/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs +++ b/src/Stars.Data.Tests/Suppliers/SearchExpressionSupplierTests.cs @@ -37,8 +37,8 @@ public static IEnumerable AllSuppliersTestsData } } - [Theory, MemberData(nameof(AllSuppliersTestsData), DisableDiscoveryEnumeration = true)] - public async Task AllSuppliersSearchExpression(ISupplier supplier, string file) + [Theory, MemberData("AllSuppliersTestsData", DisableDiscoveryEnumeration = true)] + public async Task AllSuppliersSearchExpression(string key, ISupplier supplier, string file) { string json = File.ReadAllText(file); JObject jObject = JObject.Parse(json); From 3594f084f0bcfd83fe18598c5ce86e3bdd1b350b Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 4 Jun 2024 12:23:54 +0200 Subject: [PATCH 3/3] chore: Bump version to 2.24.0 --- CHANGELOG.md | 8 +++++++- src/Stars.Console/Terradue.Stars.Console.csproj | 2 +- src/Stars.Data/Terradue.Stars.Data.csproj | 2 +- src/Stars.Services/Terradue.Stars.Services.csproj | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5087015..95b6c5f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -## [2.23.0](https://github.com/Terradue/Stars/compare/2.22.8...2.23.0) +## [2.24.0](https://github.com/Terradue/Stars/compare/2.23.0...2.24.0) + +### Commits + +- Add Collection Node Copy [`7a98692`](https://github.com/Terradue/Stars/commit/7a98692a829c993d685f0e0277310900b9e438b9) + +## [2.23.0](https://github.com/Terradue/Stars/compare/2.22.8...2.23.0) - 2024-06-03 ### Merged diff --git a/src/Stars.Console/Terradue.Stars.Console.csproj b/src/Stars.Console/Terradue.Stars.Console.csproj index 1c789296..1c9f622c 100644 --- a/src/Stars.Console/Terradue.Stars.Console.csproj +++ b/src/Stars.Console/Terradue.Stars.Console.csproj @@ -2,7 +2,7 @@ Exe net6.0 - 2.23.0 + 2.24.0 Stars is a CLI for working with Spatio Temporal Catalog such as STAC but not only $(Version)-$(VersionSuffix) diff --git a/src/Stars.Data/Terradue.Stars.Data.csproj b/src/Stars.Data/Terradue.Stars.Data.csproj index be2d8206..6652590d 100644 --- a/src/Stars.Data/Terradue.Stars.Data.csproj +++ b/src/Stars.Data/Terradue.Stars.Data.csproj @@ -4,7 +4,7 @@ Terradue.Stars.Data Terradue.Stars.Data Collection of data Plugins for Terradue.Stars - 2.23.0 + 2.24.0 $(Version)-$(VersionSuffix) NU1603 diff --git a/src/Stars.Services/Terradue.Stars.Services.csproj b/src/Stars.Services/Terradue.Stars.Services.csproj index 7cbebe48..1e0938ca 100644 --- a/src/Stars.Services/Terradue.Stars.Services.csproj +++ b/src/Stars.Services/Terradue.Stars.Services.csproj @@ -3,7 +3,7 @@ netstandard2.0 Terradue.Stars Stars is a set of services for working with Spatio Temporal Catalog such as STAC but not only - 2.23.0 + 2.24.0 $(Version)-$(VersionSuffix) Terradue.Stars.Services