Skip to content

Commit

Permalink
make bo4e netstanard2.0 again to allow it in source generator (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoschaMetze authored Jun 25, 2024
1 parent f7dc51a commit 0d6545f
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 46 deletions.
24 changes: 12 additions & 12 deletions BO4E/BO/Zaehlzeitdefinition.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
using System;
using System.Runtime.ConstrainedExecution;
using System.Text.Json.Serialization;
using BO4E.COM;
using BO4E.ENUM;
using BO4E.meta;

using Newtonsoft.Json;

using ProtoBuf;

using System;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.ConstrainedExecution;
using System.Text.Json.Serialization;

using Verwendungszweck = BO4E.COM.Verwendungszweck;

namespace BO4E.BO
{
/// <summary>
/// Der NB bzw. LF nutzt Zählzeitdefinitionen für die Tarifierung von Werten.
/// <remarks>Zaehlzeitdefinitionen werden in der Marktkommunikation mit Prüfidentifikator 25001 (UTILTS) übermittelt</remarks>
/// Eine Zählzeitdefinition umfasst dabei eine Liste von möglichen Zählzeiten,
/// Eine Zählzeitdefinition umfasst dabei eine Liste von möglichen Zählzeiten,
/// den dazugehörigen Registern und der tatsächlich ausgerollten Zählzeit (wenn diese elektronisch übermittelt wird)
/// </summary>
[ProtoContract]
Expand All @@ -36,6 +31,7 @@ private DateTime _Beginndatum
get => Beginndatum?.UtcDateTime ?? DateTime.MinValue;
set => Beginndatum = DateTime.SpecifyKind(value, DateTimeKind.Utc);
}

/// <summary>
/// Der inklusive Zeitpunkt ab dem die Zaehlzeitdefinitionen ausgerollt sind
/// </summary>
Expand All @@ -55,6 +51,7 @@ private DateTime _Endedatum
get => Endedatum?.UtcDateTime ?? DateTime.MinValue;
set => Endedatum = DateTime.SpecifyKind(value, DateTimeKind.Utc);
}

/// <summary>
/// Der exklusive Zeitpunkt bis zu dem die Zaehlzeitdefinitionen ausgerollt sind
/// </summary>
Expand All @@ -74,6 +71,7 @@ private DateTime _Version
get => Version.UtcDateTime;
set => Version = DateTime.SpecifyKind(value, DateTimeKind.Utc);
}

/// <summary>
/// Version der Zählzeitdefinition als Datum
///</summary>
Expand Down Expand Up @@ -115,12 +113,14 @@ private DateTime _Version
/// <summary>
/// Liste der ausgerollten Zählzeiten
/// </summary>
[JsonProperty(Required = Required.Always, Order = 12, PropertyName = "ausgerollteZaehlzeiten")]
[JsonProperty(
Required = Required.Always,
Order = 12,
PropertyName = "ausgerollteZaehlzeiten"
)]
[JsonPropertyName("ausgerollteZaehlzeiten")]
[ProtoMember(12)]
[JsonPropertyOrder(12)]
public System.Collections.Generic.List<AusgerollteZaehlzeit> AusgerollteZaehlzeiten { get; set; }


}
}
9 changes: 7 additions & 2 deletions BO4E/BO4E.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>BO4E</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Hochfrequenz.BO4Enet</PackageId>
Expand All @@ -26,7 +26,7 @@
<IncludeSymbols>true</IncludeSymbols>
<DebugType>Embedded</DebugType>
<EmbedAllSources>True</EmbedAllSources>
<LangVersion>9</LangVersion>
<LangVersion>latest</LangVersion>
<DocumentationFile>BO4Enet.xml</DocumentationFile>
<Nullable>annotations</Nullable>
</PropertyGroup>
Expand Down Expand Up @@ -77,11 +77,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Enums.NET" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
<PackageReference Include="Polyfill" Version="5.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="SourceLink.Copy.PdbFiles" Version="2.8.3" PrivateAssets="All" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
20 changes: 12 additions & 8 deletions BO4E/meta/LenientConverters/LenientGeraetemerkmalGasConverter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using BO4E.ENUM;

using EnumsNET;
using Newtonsoft.Json;

using System;

namespace BO4E.meta.LenientConverters
{
/// <summary>
Expand All @@ -18,12 +17,17 @@ public class LenientGeraetemerkmalGasConverter : JsonConverter
/// <inheritdoc cref="JsonConverter.CanConvert(Type)" />
public override bool CanConvert(Type objectType)
{
return objectType == typeof(BO4E.ENUM.Geraetemerkmal) || objectType == typeof(BO4E.ENUM.Geraetemerkmal?);
return objectType == typeof(BO4E.ENUM.Geraetemerkmal)
|| objectType == typeof(BO4E.ENUM.Geraetemerkmal?);
}

/// <inheritdoc cref="JsonConverter.ReadJson(JsonReader, Type, object, JsonSerializer)" />
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
public override object ReadJson(
JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer
)
{
string rawValue;
switch (reader.Value)
Expand All @@ -40,15 +44,15 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

try
{
return Enum.Parse<Geraetemerkmal>(rawValue);
return Enums.Parse<Geraetemerkmal>(rawValue);
}
catch (ArgumentException) when (rawValue.StartsWith("G"))
{
if (rawValue == "G2Period5")
{
return Geraetemerkmal.GAS_G2P5;
}
return Enum.Parse<Geraetemerkmal>("GAS_" + rawValue);
return Enums.Parse<Geraetemerkmal>("GAS_" + rawValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BO4E.ENUM;

using System;
using System.Text.Json;
using BO4E.ENUM;
using EnumsNET;
using System.Text.RegularExpressions;

namespace BO4E.meta.LenientConverters
Expand All @@ -10,12 +10,17 @@ namespace BO4E.meta.LenientConverters
/// The lenient ZaehlergroesseGasConverter allows for transforming strings that do not contain the prefix "GAS_" into valid <see cref="BO4E.ENUM.Geraetemerkmal"/>
/// </summary>
/// <remarks>The main symptom for its usage is "Error converting value "G4" to type Geraetemerkmal"</remarks>
public class LenientSystemTextGeraetemerkmalGasConverter : System.Text.Json.Serialization.JsonConverter<Geraetemerkmal>
public class LenientSystemTextGeraetemerkmalGasConverter
: System.Text.Json.Serialization.JsonConverter<Geraetemerkmal>
{
/// <summary>
/// <inheritdoc cref="System.Text.Json.Serialization.JsonConverter{T}.Read"/>
/// </summary>
public override Geraetemerkmal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override Geraetemerkmal Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
if (reader.TokenType == JsonTokenType.Number)
{
Expand All @@ -24,15 +29,15 @@ public override Geraetemerkmal Read(ref Utf8JsonReader reader, Type typeToConver
var rawString = reader.GetString();
try
{
return Enum.Parse<Geraetemerkmal>(rawString);
return Enums.Parse<Geraetemerkmal>(rawString);
}
catch (ArgumentException) when (rawString.StartsWith("G"))
{
if (rawString == "G2Period5")
{
return Geraetemerkmal.GAS_G2P5;
}
return Enum.Parse<Geraetemerkmal>("GAS_" + rawString);
return Enums.Parse<Geraetemerkmal>("GAS_" + rawString);
}
}

Expand All @@ -44,7 +49,11 @@ public override Geraetemerkmal Read(ref Utf8JsonReader reader, Type typeToConver
/// <summary>
/// <inheritdoc cref="System.Text.Json.Serialization.JsonConverter{T}.Write"/>
/// </summary>
public override void Write(Utf8JsonWriter writer, Geraetemerkmal value, JsonSerializerOptions options)
public override void Write(
Utf8JsonWriter writer,
Geraetemerkmal value,
JsonSerializerOptions options
)
{
var stringValue = value.ToString();
var match = GasPrefixRegex.Match(stringValue);
Expand All @@ -62,12 +71,17 @@ public override void Write(Utf8JsonWriter writer, Geraetemerkmal value, JsonSeri
/// The lenient ZaehlergroesseGasConverter allows for transforming strings that do not contain the prefix "GAS_" into valid nullable <see cref="BO4E.ENUM.Geraetemerkmal"/>
/// </summary>
/// <remarks>The main symptom for its usage is "Error converting value "G4" to type Geraetemerkmal"</remarks>
public class LenientSystemTextNullableGeraetemerkmalGasConverter : System.Text.Json.Serialization.JsonConverter<Geraetemerkmal?>
public class LenientSystemTextNullableGeraetemerkmalGasConverter
: System.Text.Json.Serialization.JsonConverter<Geraetemerkmal?>
{
/// <summary>
/// <inheritdoc cref="System.Text.Json.Serialization.JsonConverter{T}.Read"/>
/// </summary>
public override Geraetemerkmal? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override Geraetemerkmal? Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
if (reader.TokenType == JsonTokenType.Number)
{
Expand All @@ -80,15 +94,15 @@ public class LenientSystemTextNullableGeraetemerkmalGasConverter : System.Text.J
}
try
{
return Enum.Parse<Geraetemerkmal>(rawString);
return Enums.Parse<Geraetemerkmal>(rawString);
}
catch (ArgumentException) when (rawString.StartsWith("G"))
{
if (rawString == "G2Period5")
{
return Geraetemerkmal.GAS_G2P5;
}
return Enum.Parse<Geraetemerkmal>("GAS_" + rawString);
return Enums.Parse<Geraetemerkmal>("GAS_" + rawString);
}
}

Expand All @@ -100,7 +114,11 @@ public class LenientSystemTextNullableGeraetemerkmalGasConverter : System.Text.J
/// <summary>
/// <inheritdoc cref="System.Text.Json.Serialization.JsonConverter{T}.Write"/>
/// </summary>
public override void Write(Utf8JsonWriter writer, Geraetemerkmal? value, JsonSerializerOptions options)
public override void Write(
Utf8JsonWriter writer,
Geraetemerkmal? value,
JsonSerializerOptions options
)
{
if (value.HasValue)
{
Expand Down
6 changes: 4 additions & 2 deletions BO4E/meta/NonOfficialCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public enum NonOfficialCategory
[EnumMember(Value = "REGULATORY_REQUIREMENTS")]
REGULATORY_REQUIREMENTS,

#pragma warning disable CS0419 // Zweideutige Referenz im cref-Attribut
/// <summary>
/// an information or field is no longer necessary or outdated (please use <see cref="System.ObsoleteAttribute" />
/// an information or field is no longer necessary or outdated (please use <see cref="ObsoleteAttribute" />
/// too). Hochfrequenz favors removal of this field from the official BO4E standard.
/// </summary>
[Obsolete("Hochfrequenz favours the removal of this field/property from BO4E.")]
#pragma warning restore CS0419 // Zweideutige Referenz im cref-Attribut
[EnumMember(Value = "PROPOSED_DELETION")]
PROPOSED_DELETION,

Expand All @@ -46,4 +48,4 @@ public enum NonOfficialCategory
[EnumMember(Value = "CUSTOMER_REQUIREMENTS")]
CUSTOMER_REQUIREMENTS,
}
}
}
2 changes: 2 additions & 0 deletions BO4E/protobuf-files/bo4e.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ message Messprodukt {
Zaehlzeitregister Zaehlzeiten = 1021;
bool ZweiteMessung = 1022;
bool WerteuebermittlungAnNB = 1023;
EMobilitaetsart EMobilitaetsart = 1024;
}
enum MesstechnischeEinordnung {
option (.protobuf_net.enumopt).namespace = "BO4E.ENUM";
Expand Down Expand Up @@ -2020,6 +2021,7 @@ message Zaehlwerk {
int32 AnzahlAblesungen = 1020;
Zaehlzeitregister Zaehlzeiten = 1021;
string Konfiguration = 1022;
EMobilitaetsart EMobilitaetsart = 1023;
}
message Zaehlzeitregister {
option (.protobuf_net.msgopt).namespace = "BO4E.COM";
Expand Down
14 changes: 9 additions & 5 deletions TestBO4E.Extensions/TestBO4E.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="JsonDiffPatch.Net" Version="2.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 9 additions & 5 deletions TestBO4E.Reporting/TestBO4E.Reporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="JsonDiffPatch.Net" Version="2.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions json-schema-files/BO4E.BO.Angebot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,18 @@
"boolean",
"null"
]
},
"emobilitaetsart": {
"type": [
"string",
"null"
],
"enum": [
null,
"WALLBOX",
"E_MOBILITAETSLADESAEULE",
"LADEPARK"
]
}
}
},
Expand Down Expand Up @@ -4443,6 +4455,18 @@
"string",
"null"
]
},
"emobilitaetsart": {
"type": [
"string",
"null"
],
"enum": [
null,
"WALLBOX",
"E_MOBILITAETSLADESAEULE",
"LADEPARK"
]
}
}
},
Expand Down

0 comments on commit 0d6545f

Please sign in to comment.