Skip to content

Commit

Permalink
Follow Nexus changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Wilms committed Dec 17, 2024
1 parent 9810d48 commit 8d694a9
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
if: ${{ env.IS_RELEASE == 'true' }}
run: python build/create_tag_body.py

- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"

- name: Build
run: |
dotnet build -c Release /p:GeneratePackage=true src/Nexus.Sources.StructuredFile/Nexus.Sources.StructuredFile.csproj
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.0.0-beta.33 - 2024-12-17

- Follow Nexus changes

## v2.0.0-beta.28 - 2024-08-26

- Improved test coverage and fixed the core file resolution algorithm
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworkVersion>net8.0</TargetFrameworkVersion>
<TargetFrameworkVersion>net9.0</TargetFrameworkVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nexus.Extensibility" Version="2.0.0-beta.24">
<PackageReference Include="Nexus.Extensibility" Version="2.0.0-beta.33">
<!-- This is important! Took me 1 day to figure out why suddenly there are MissingMethodExceptions! -->
<ExcludeAssets>runtime;native</ExcludeAssets>
</PackageReference>
Expand Down
28 changes: 11 additions & 17 deletions src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ protected abstract Task<CatalogRegistration[]> GetCatalogRegistrationsAsync(
// [".../2020-01-01.dat", ".../2020-06-01.dat" ].

/// <summary>
/// Gets the requested <see cref="ResourceCatalog"/>.
/// Enriches the provided <see cref="ResourceCatalog"/>.
/// </summary>
/// <param name="catalogId">The catalog identifier.</param>
/// <param name="catalog">The catalog.</param>
/// <param name="cancellationToken">A token to cancel the current operation.</param>
/// <returns>The catalog request task.</returns>
protected abstract Task<ResourceCatalog> GetCatalogAsync(
string catalogId,
protected abstract Task<ResourceCatalog> EnrichCatalogAsync(
ResourceCatalog catalog,
CancellationToken cancellationToken);

/// <summary>
Expand Down Expand Up @@ -503,11 +503,11 @@ protected virtual async Task ReadAsync(
var originalName = catalogItem.Resource.Properties?
.GetStringValue(StructuredFileDataModelExtensions.OriginalNameKey)!;

return new StructuredFileReadRequest(
return new ReadRequest(
OriginalResourceName: originalName,
CatalogItem: request.CatalogItem,
Data: slicedData,
Status: slicedStatus,
OriginalName: originalName
Status: slicedStatus
);
}).ToArray();

Expand Down Expand Up @@ -579,7 +579,7 @@ protected virtual async Task ReadAsync(
/// <returns>The task.</returns>
protected abstract Task ReadAsync(
ReadInfo info,
StructuredFileReadRequest[] readRequests,
ReadRequest[] readRequests,
CancellationToken cancellationToken);

private protected Task<(DateTime RegularUtcFileBegin, (string FilePath, TimeSpan FileBeginOffset)[])>
Expand Down Expand Up @@ -736,11 +736,11 @@ Task<CatalogRegistration[]> IDataSource.GetCatalogRegistrationsAsync(
return GetCatalogRegistrationsAsync(path, cancellationToken);
}

async Task<ResourceCatalog> IDataSource.GetCatalogAsync(
string catalogId,
async Task<ResourceCatalog> IDataSource.EnrichCatalogAsync(
ResourceCatalog catalog,
CancellationToken cancellationToken)
{
var catalog = await GetCatalogAsync(catalogId, cancellationToken);
catalog = await EnrichCatalogAsync(catalog, cancellationToken);

if (catalog.Resources is not null)
{
Expand All @@ -751,12 +751,6 @@ async Task<ResourceCatalog> IDataSource.GetCatalogAsync(

if (string.IsNullOrWhiteSpace(fileSourceId))
throw new Exception($"The resource {resource.Id} is missing the file source property.");

// ensure original name
var originalName = resource.Properties?.GetStringValue(StructuredFileDataModelExtensions.OriginalNameKey);

if (string.IsNullOrWhiteSpace(originalName))
throw new Exception($"The resource {resource.Id} is missing the original name property.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,4 @@ public record ReadInfo(
long FileOffset,
long FileBlock,
long FileLength
);

/// <summary>
/// An read request with additional data.
/// </summary>
/// <param name="CatalogItem">The CatalogItem to be read.</param>
/// <param name="Data">The data buffer.</param>
/// <param name="Status">The status buffer. A value of 0x01 ('1') indicates that the corresponding value in the data buffer is valid, otherwise it is treated as System.Double.NaN.</param>
/// <param name="OriginalName">The original name of the resource to read.</param>
public record StructuredFileReadRequest(
CatalogItem CatalogItem,
Memory<byte> Data,
Memory<byte> Status,
string OriginalName
) : ReadRequest(CatalogItem, Data, Status);
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Nexus.Extensibility" Version="2.0.0-beta.24" />
<PackageReference Include="Nexus.Extensibility" Version="2.0.0-beta.33" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nexus.DataModel;
using Nexus.Extensibility;
using System.Text.Json;

namespace Nexus.Sources.Tests;
Expand Down Expand Up @@ -43,7 +44,7 @@ protected override Task<CatalogRegistration[]> GetCatalogRegistrationsAsync(stri
return Task.FromResult(new CatalogRegistration[] { new("/A/B/C", string.Empty) });
}

protected override Task<ResourceCatalog> GetCatalogAsync(string catalogId, CancellationToken cancellationToken)
protected override Task<ResourceCatalog> EnrichCatalogAsync(ResourceCatalog catalog, CancellationToken cancellationToken)
{
var representation = new Representation(
dataType: NexusDataType.INT64,
Expand All @@ -54,16 +55,15 @@ protected override Task<ResourceCatalog> GetCatalogAsync(string catalogId, Cance

var resource = new ResourceBuilder(id: "Resource1")
.WithFileSourceId(fileSourceId)
.WithOriginalName("Resource1")
.AddRepresentation(representation)
.Build();

var catalog = new ResourceCatalog(id: "/A/B/C", resources: new List<Resource>() { resource });
catalog = catalog.Merge(new ResourceCatalog(id: "/A/B/C", resources: new List<Resource>() { resource }));

return Task.FromResult(catalog);
}

protected override async Task ReadAsync(ReadInfo readInfo, StructuredFileReadRequest[] readRequests, CancellationToken cancellationToken)
protected override async Task ReadAsync(ReadInfo readInfo, ReadRequest[] readRequests, CancellationToken cancellationToken)
{
_onNewReadInfo?.Invoke(readInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public async Task CanRead_ReadInfos(string database, string beginString, string

await dataSource.SetContextAsync(context, NullLogger.Instance, CancellationToken.None);

var catalog = await dataSource.GetCatalogAsync("/A/B/C", CancellationToken.None);
var catalog = await dataSource.EnrichCatalogAsync(new("/A/B/C"), CancellationToken.None);
var resource = catalog.Resources![0];
var representation = resource.Representations![0];
var catalogItem = new CatalogItem(catalog, resource, representation, default);
Expand All @@ -327,7 +327,7 @@ public async Task CanRead_ReadInfos(string database, string beginString, string
var end = DateTime.ParseExact(endString, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
var (data, status) = ExtensibilityUtilities.CreateBuffers(representation, begin, end);

var request = new ReadRequest(catalogItem, data, status);
var request = new ReadRequest(resource.Id, catalogItem, data, status);

// Act
await dataSource.ReadAsync(
Expand Down Expand Up @@ -369,7 +369,7 @@ public async Task CanRead()

await dataSource.SetContextAsync(context, NullLogger.Instance, CancellationToken.None);

var catalog = await dataSource.GetCatalogAsync("/A/B/C", CancellationToken.None);
var catalog = await dataSource.EnrichCatalogAsync(new("/A/B/C"), CancellationToken.None);
var resource = catalog.Resources![0];
var representation = resource.Representations![0];
var catalogItem = new CatalogItem(catalog, resource, representation, default);
Expand Down Expand Up @@ -399,7 +399,7 @@ void GenerateData(DateTimeOffset dateTime, int length)
GenerateData(new DateTimeOffset(2020, 01, 02, 09, 40, 00, TimeSpan.Zero), length: 600);
GenerateData(new DateTimeOffset(2020, 01, 02, 09, 50, 00, TimeSpan.Zero), length: 600);

var request = new ReadRequest(catalogItem, data, status);
var request = new ReadRequest(resource.Id, catalogItem, data, status);

await dataSource.ReadAsync(
begin,
Expand Down Expand Up @@ -431,11 +431,11 @@ public async Task ReadSingleThrowsForInvalidTimePeriod(string beginString, strin

await dataSource.SetContextAsync(context, NullLogger.Instance, CancellationToken.None);

var catalog = await dataSource.GetCatalogAsync("/A/B/C", CancellationToken.None);
var catalog = await dataSource.EnrichCatalogAsync(new("/A/B/C"), CancellationToken.None);
var resource = catalog.Resources![0];
var representation = resource.Representations![0];
var catalogItem = new CatalogItem(catalog, resource, representation, default);
var request = new ReadRequest(catalogItem, default, default);
var request = new ReadRequest(resource.Id, catalogItem, default, default);

await Assert.ThrowsAsync<ArgumentException>(() =>
dataSource.ReadAsync(
Expand All @@ -444,6 +444,8 @@ await Assert.ThrowsAsync<ArgumentException>(() =>
[request],
default!,
default!,
CancellationToken.None));
CancellationToken.None
)
);
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "2.0.0",
"suffix": "beta.28"
"suffix": "beta.33"
}

0 comments on commit 8d694a9

Please sign in to comment.