Skip to content

Commit

Permalink
Merge pull request #38 from MagmaWorks/task/common-serialization
Browse files Browse the repository at this point in the history
Single common serialization
  • Loading branch information
kpne authored Nov 5, 2024
2 parents f8d4d01 + 1ded648 commit b321dbd
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 71 deletions.
6 changes: 4 additions & 2 deletions Countries/Countries/ICountry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MagmaWorks.Taxonomy.Countries
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Countries
{
public interface ICountry
public interface ICountry : ITaxonomySerializable
{
/// <summary>
/// Country name
Expand Down
4 changes: 4 additions & 0 deletions Countries/Countries/MagmaWorks.Taxonomy.Countries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Countries/CountryTests/CountryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\Countries\MagmaWorks.Taxonomy.Countries.csproj" />
<ProjectReference Include="..\Serialization\MagmaWorks.Taxonomy.Serialization.Countries.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Loads/Cases/MagmaWorks.Taxonomy.Cases.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Loads/ICases/ICase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MagmaWorks.Taxonomy.Loads
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Loads
{
public interface ICase
public interface ICase : ITaxonomySerializable
{
string Name { get; }
}
Expand Down
2 changes: 1 addition & 1 deletion Loads/ICases/MagmaWorks.Taxonomy.ICases.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -49,6 +48,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
<ProjectReference Include="..\..\Standards\IStandards\MagmaWorks.Taxonomy.IStandards.csproj" />
<ProjectReference Include="..\ILoads\MagmaWorks.Taxonomy.ILoads.csproj" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Loads/ILoads/ILoad.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using OasysUnits;
using MagmaWorks.Taxonomy.Serialization;
using OasysUnits;

namespace MagmaWorks.Taxonomy.Loads
{
public interface ILoad
public interface ILoad : ITaxonomySerializable
{
string Label { get; }
ILoad Factor(Ratio factor);
Expand Down
4 changes: 4 additions & 0 deletions Loads/ILoads/MagmaWorks.Taxonomy.ILoads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Loads/LoadTests/LoadTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\Cases\MagmaWorks.Taxonomy.Cases.csproj" />
<ProjectReference Include="..\ICases\MagmaWorks.Taxonomy.ICases.csproj" />
<ProjectReference Include="..\Loads\MagmaWorks.Taxonomy.Loads.csproj" />
Expand Down
1 change: 0 additions & 1 deletion Loads/Loads/MagmaWorks.Taxonomy.Loads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Materials/IMaterials/IMaterial.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MagmaWorks.Taxonomy.Materials
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Materials
{
public interface IMaterial
public interface IMaterial : ITaxonomySerializable
{
MaterialType Type { get; }
}
Expand Down
1 change: 1 addition & 0 deletions Materials/IMaterials/MagmaWorks.Taxonomy.IMaterials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
<ProjectReference Include="..\..\Standards\IStandards\MagmaWorks.Taxonomy.IStandards.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Materials/MaterialTests/MaterialTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -22,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\..\Standards\IStandards\MagmaWorks.Taxonomy.IStandards.csproj" />
<ProjectReference Include="..\..\Standards\Serialization\MagmaWorks.Taxonomy.Serialization.Standards.csproj" />
<ProjectReference Include="..\..\Standards\Standards\MagmaWorks.Taxonomy.Standards.csproj" />
Expand Down
1 change: 0 additions & 1 deletion Materials/Materials/MagmaWorks.Taxonomy.Materials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Profiles/IProfiles/IProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MagmaWorks.Taxonomy.Profiles
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Profiles
{
public interface IProfile { }
public interface IProfile : ITaxonomySerializable { }
}
4 changes: 4 additions & 0 deletions Profiles/IProfiles/MagmaWorks.Taxonomy.IProfiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Profiles/ProfileTests/ProfileTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -22,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\CatalogueProfiles\MagmaWorks.Taxonomy.Profiles.Catalogue.csproj" />
<ProjectReference Include="..\IProfiles\MagmaWorks.Taxonomy.IProfiles.csproj" />
<ProjectReference Include="..\Profiles\MagmaWorks.Taxonomy.Profiles.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion Sections/ISections/ISection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using MagmaWorks.Taxonomy.Materials;
using MagmaWorks.Taxonomy.Profiles;
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Sections
{
public interface ISection
public interface ISection : ITaxonomySerializable
{
IMaterial Material { get; }
IProfile Profile { get; }
Expand Down
1 change: 1 addition & 0 deletions Sections/SectionTests/SectionTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<ProjectReference Include="..\..\Profiles\CatalogueProfiles\MagmaWorks.Taxonomy.Profiles.Catalogue.csproj" />
<ProjectReference Include="..\..\Profiles\IProfiles\MagmaWorks.Taxonomy.IProfiles.csproj" />
<ProjectReference Include="..\..\Profiles\Profiles\MagmaWorks.Taxonomy.Profiles.csproj" />
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\..\Standards\Standards\MagmaWorks.Taxonomy.Standards.csproj" />
<ProjectReference Include="..\ISections\MagmaWorks.Taxonomy.ISections.csproj" />
<ProjectReference Include="..\Sections\MagmaWorks.Taxonomy.Sections.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions Serialization/ISerialization/ITaxonomySerializable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace MagmaWorks.Taxonomy.Serialization
{
public interface ITaxonomySerializable { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<MinVerMinimumMajorMinor>0.0</MinVerMinimumMajorMinor>
<MinVerDefaultPreReleaseIdentifiers>preview</MinVerDefaultPreReleaseIdentifiers>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net48;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Platforms>AnyCPU</Platforms>
<RootNamespace>MagmaWorks.Taxonomy.Serialization</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<Title>MagmaWorks Taxonomy Serialization Interfaces</Title>
<Company>Whitby Wood</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/MagmaWorks/Taxonomy/</RepositoryUrl>
<PackageIcon>MagmaWorks.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\..\Licenses\UnitsNet">
<Pack>True</Pack>
<PackagePath>\Licenses\</PackagePath>
</None>
<None Include="..\..\MagmaWorks.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Serialization/Serialization/JsonSerializationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace MagmaWorks.Taxonomy.Serialization
{
public static class JsonSerializationExtensions
{
public static string ToJson<T>(this T taxonomyObject, JsonSerializerSettings? settings = null) where T : ITaxonomySerializable
{
settings ??= TaxonomyJsonSerializer.Settings;
return JsonConvert.SerializeObject(taxonomyObject, Formatting.Indented, settings);
}

public static T? FromJson<T>(this string json, JsonSerializerSettings? settings = null) where T : ITaxonomySerializable
{
settings ??= TaxonomyJsonSerializer.Settings;
return JsonConvert.DeserializeObject<T>(json, settings);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions Serialization/Serialization/TaxonomyJsonSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Newtonsoft.Json;

namespace MagmaWorks.Taxonomy.Serialization
{
internal static class TaxonomyJsonSerializer
{
internal static JsonSerializerSettings Settings
{
get
{
var settings = new JsonSerializerSettings
{
Converters = {
new Newtonsoft.Json.Converters.StringEnumConverter(),
new OasysUnits.Serialization.JsonNet.OasysUnitsIQuantityJsonConverter(),
},
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
};
return settings;
}
}
}
}
6 changes: 4 additions & 2 deletions Stages/IStages/IStage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MagmaWorks.Taxonomy.Stages
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Stages
{
public interface IStage
public interface IStage : ITaxonomySerializable
{
string Name { get; }
string Description { get; }
Expand Down
1 change: 1 addition & 0 deletions Stages/IStages/MagmaWorks.Taxonomy.IStages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Countries\Countries\MagmaWorks.Taxonomy.Countries.csproj" />
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Stages/StageTests/StageTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\Serialization\MagmaWorks.Taxonomy.Serialization.csproj" />
<ProjectReference Include="..\IStages\MagmaWorks.Taxonomy.IStages.csproj" />
<ProjectReference Include="..\Serialization\MagmaWorks.Taxonomy.Serialization.Stages.csproj" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Standards/IStandards/IStandard.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using MagmaWorks.Taxonomy.Serialization;

namespace MagmaWorks.Taxonomy.Standards
{
public interface IStandard
public interface IStandard : ITaxonomySerializable
{
StandardBody Body { get; }
Enum Code { get; }
Expand Down
5 changes: 4 additions & 1 deletion Standards/IStandards/MagmaWorks.Taxonomy.IStandards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OasysUnits" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -48,4 +47,8 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Serialization\ISerialization\MagmaWorks.Taxonomy.ISerialization.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit b321dbd

Please sign in to comment.