Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link resolution #8

Merged
merged 15 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/src" # Location of package manifests
schedule:
interval: "daily"
groups:
nuget-dependencies:
patterns:
- "*"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
groups:
actions-dependencies:
patterns:
- "*"
36 changes: 36 additions & 0 deletions .github/workflows/code-ql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
84 changes: 84 additions & 0 deletions .github/workflows/dotnet-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: .NET Continuous Deployment

on:
push:
branches: [ master ]
paths:
- src/UniversalDiveDataFormat/**
workflow_dispatch:
jobs:

test:
name: Test Project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Run tests
run: dotnet test --logger GitHubActions ./src/UniversalDiveDataFormat.sln

semantic-release:
needs: test
name: Create a Package Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Need the full commit history for conventional commit
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
- name: Create Nuget Package
run: dotnet build -c Release ./src/UniversalDiveDataFormat/UniversalDiveDataFormat.csproj && dotnet pack -c Release -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} -o . ./src/UniversalDiveDataFormat/UniversalDiveDataFormat.csproj
- name: Upload Package for Publishing
uses: actions/upload-artifact@v4
with:
name: PackedLib
path: ./*.nupkg


github-publish:
needs: semantic-release
name: Publish to Github
runs-on: ubuntu-latest
steps:
- name: Download built project
uses: actions/download-artifact@v4
with:
name: PackedLib
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Push Package to GitHub
run: dotnet nuget push --api-key ${{secrets.GITHUB_TOKEN}} --source "https://nuget.pkg.github.com/hughesjs/index.json" *.nupkg


nuget-publish:
needs: semantic-release
name: Publish to Nuget
runs-on: ubuntu-latest
steps:
- name: Download built project
uses: actions/download-artifact@v4
with:
name: PackedLib
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Push Package to Nuget
run: dotnet nuget push --api-key ${{secrets.NUGET_KEY}} --source "https://api.nuget.org/v3/index.json" *.nupkg
20 changes: 20 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: .NET Continuous Integration

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

jobs:
test:
name: Test Project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Run tests
run: dotnet test --logger GitHubActions ./src/UniversalDiveDataFormat.sln
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

This is a C# library for reading and writing the [Universal Dive Data Format](https://www.streit.cc/extern/uddf_v321/en/index.html).

Currently, the library primarily consists of the Models required to deserialize UDDF files using the [XmlSerializer](https://docs.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer?view=net-7.0).
Currently, the library primarily consists of the Models required to deserialize UDDF files using either the built-in [XmlSerializer](https://docs.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer?view=net-7.0) or the custom `UddfDeserilizer`.

The `UddfDeserializer` resolves all links within the UDDF file and maps them onto the object graph.

If you use the built-in `XmlSerializer`, you have to use the `LinkResolutionService` to resolve these links.

Future versions might include extra services for enforcing constraints and validation.

Expand All @@ -28,9 +32,7 @@ dotnet add package UniversalDiveDataFormat
using System.Xml.Serialization;
using UniversalDiveDataFormat.Models;

// Deserialize a complete UDDF file
var serializer = new XmlSerializer(typeof(UniversalDiveDataFormat.Models.UniversalDiveDataFormatRoot));
var uddf = serializer.Deserialize(File.OpenRead("my_dive_log.uddf"));
UniversalDiveDataFormatRoot uddf = _uddfDeserialiser.Deserialise<UniversalDiveDataFormatRoot>(xml);
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using Xunit;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Models;
namespace UniversalDiveDataFormat.Tests.Models;

public class BuiltTests
{
private const string Xml = """
<built>
<shipyard>Blohm & Voss</shipyard>
<shipyard>Blohm &amp; Voss</shipyard>
<launchingdate>
<datetime>1943-06-14</datetime>
</launchingdate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using Xunit;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Models;
namespace UniversalDiveDataFormat.Tests.Models;

public class DiveComputerAlarmTests
{
Expand All @@ -23,6 +23,6 @@ public void CanReadDcAlarm()
DiveComputerAlarm dcAlarm = serializer.Deserialize<DiveComputerAlarm>(Xml);
dcAlarm.PeriodInSeconds.ShouldBe(10.0f);
dcAlarm.AlarmType.ShouldBe(1);
dcAlarm.Acknowledge.ShouldBeNull();
dcAlarm.Acknowledge.ShouldNotBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UniversalDiveDataFormat.ExtensionMethods;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Tests;
namespace UniversalDiveDataFormat.Tests.Models;

public class ExposureToAltitudeTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UniversalDiveDataFormat.ExtensionMethods;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Tests;
namespace UniversalDiveDataFormat.Tests.Models;

public class GlobalAlarmsTests
{
Expand Down
23 changes: 23 additions & 0 deletions src/UniversalDiveDataFormat.Tests/Models/LaunchingDateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Tests.Models;

public class LaunchingDateTests
{
private const string Xml = """
<launchingdate>
<datetime>1943-06-14</datetime>
</launchingdate>
""";

[Fact]
public void CanReadLaunchingDate()
{
XmlSerializer serializer = new(typeof(LaunchingDate));
LaunchingDate launchingDate = serializer.Deserialize<LaunchingDate>(Xml);
launchingDate.DateTime.ShouldBe(new(1943, 6, 14));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using Xunit;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Models;
namespace UniversalDiveDataFormat.Tests.Models;

public class SetDiveComputerAlarmTimeTests
{
private const string Xml = """
<setdcalarmtime>
<datetime>T14:37:00</datetime>
<datetime>2022-01-01T14:37:00</datetime>
<dcalarm>
<!-- duration 10 seconds -->
<period>10.0</period>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UniversalDiveDataFormat.ExtensionMethods;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Tests;
namespace UniversalDiveDataFormat.Tests.Models;

public class SetDiveComputerDecoModelTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using Xunit;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Models;
namespace UniversalDiveDataFormat.Tests.Models;

public class ShipDimensionTests
{
Expand All @@ -13,7 +13,7 @@ public class ShipDimensionTests
<beam>12.6</beam>
<draught>5.7</draught>
<displacement>123456.7</displacement>
<tonnage>170000.0</tonnag>
<tonnage>170000.0</tonnage>
</shipdimension>
""";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Xml.Serialization;
using Shouldly;
using UniversalDiveDataFormat.ExtensionMethods;
using Xunit;
using UniversalDiveDataFormat.Models;

namespace UniversalDiveDataFormat.Models;
namespace UniversalDiveDataFormat.Tests.Models;

public class WreckTests
{
Expand All @@ -13,7 +13,7 @@ public class WreckTests
<shiptype>tanker</shiptype>
<nationality>German</nationality>
<built>
<shipyard>Blohm & Voss</shipyard>
<shipyard>Blohm &amp; Voss</shipyard>
<launchingdate>
<datetime>1943-06-14</datetime>
</launchingdate>
Expand All @@ -25,7 +25,7 @@ public class WreckTests
<displacement>123456.7</displacement>
</shipdimension>
<sunk>
<datetime>1985-05-24T15:46</datetime>
<datetime>1985-05-24T15:46:00</datetime>
</sunk>
<notes>
<!-- here additional remarks and/or photos, videos of the wreck -->
Expand Down
Loading