implement | (parallel) operator in StatusApi.csproj

This commit is contained in:
ig 2023-03-01 08:07:26 +01:00
parent 2070fce4ec
commit f1003c2877
23 changed files with 229 additions and 25 deletions

View File

@ -4,6 +4,7 @@
<s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=AMPT/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=AMPT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=arctan/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=backfill/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=backfill/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=beaglebone/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=beaglebone/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CCGX/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=CCGX/@EntryIndexedValue">True</s:Boolean>

View File

@ -1,7 +1,14 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record BatteryStatus(DcPhase Dc) : DeviceStatus, IDcConnection; using T = BatteryStatus;
[OpParallel]
public partial record BatteryStatus : DeviceStatus, IDcConnection
{
public required DcPhase Dc { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = BatteryStatus;
[GeneratedCode("generate.sh", "1")]
public partial record BatteryStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -4,5 +4,5 @@ namespace InnovEnergy.Lib.StatusApi.Connections;
public interface IAc3Connection public interface IAc3Connection
{ {
Ac1Phase Ac3 { get; } Ac3Phase Ac { get; }
} }

View File

@ -1,8 +1,14 @@
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record DcDcConverterStatus(DcPhase Left, DcPhase Right) : DeviceStatus; [OpParallel]
public partial record DcDcConverterStatus : DeviceStatus
{
public required DcPhase Left { get; init; }
public required DcPhase Right { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = DcDcConverterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record DcDcConverterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -0,0 +1,5 @@
namespace InnovEnergy.Lib.StatusApi.Generator;
[AttributeUsage(AttributeTargets.Class)]
internal class OpParallelAttribute : Attribute
{}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = Template;
[GeneratedCode("generate.sh", "1")]
public partial record Template
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
scriptDir=$( dirname -- "$0"; )
cd "$scriptDir/.." || exit
for path in $(grep -e '\[OpParallel\]' -l *.cs)
do
file=$(basename -- "$path")
class="${file%.*}"
echo "generating $file"
sed "s/Template/$class/g" "./Generator/Template.txt" > "./$class.generated.cs"
done

View File

@ -1,8 +1,14 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public record MpptStatus(DcPhase Dc, IReadOnlyList<DcPhase> Strings) : IDcConnection, IPvConnection; [OpParallel]
public partial record MpptStatus : IDcConnection, IPvConnection
{
public required DcPhase Dc { get; init; }
public required IReadOnlyList<DcPhase> Strings { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = MpptStatus;
[GeneratedCode("generate.sh", "1")]
public partial record MpptStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -1,6 +1,11 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record PowerMeterStatus(Ac1Phase Ac3) : DeviceStatus, IAc3Connection; [OpParallel]
public partial record PowerMeterStatus : DeviceStatus, IAc3Connection
{
public required Ac3Phase Ac { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = PowerMeterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record PowerMeterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -1,9 +1,15 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record SinglePhaseInverterStatus(Ac1Phase Ac, DcPhase Dc) : [OpParallel]
public partial record SinglePhaseInverterStatus :
DeviceStatus, DeviceStatus,
IAc1Connection, IAc1Connection,
IDcConnection; IDcConnection
{
public required Ac1Phase Ac { get; init; }
public required DcPhase Dc { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = SinglePhaseInverterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record SinglePhaseInverterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -1,9 +1,15 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record SinglePhasePvInverterStatus(Ac1Phase Ac, IReadOnlyList<DcPhase> Strings) : [OpParallel]
public partial record SinglePhasePvInverterStatus :
DeviceStatus, DeviceStatus,
IAc1Connection, IAc1Connection,
IPvConnection; IPvConnection
{
public required Ac1Phase Ac { get; init; }
public required IReadOnlyList<DcPhase> Strings { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = SinglePhasePvInverterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record SinglePhasePvInverterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -3,9 +3,13 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="../Protocols/Modbus/Modbus.csproj" /> <ProjectReference Include="../Protocols/Modbus/Modbus.csproj" />
<ProjectReference Include="..\Units\Units.csproj" /> <ProjectReference Include="../Units/Units.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="./Generator/generate.sh" />
</Target>
</Project> </Project>

View File

@ -1,10 +1,16 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record ThreePhaseInverterStatus(Ac1Phase Ac3, DcPhase Dc) : [OpParallel]
public partial record ThreePhaseInverterStatus :
DeviceStatus, DeviceStatus,
IAc3Connection, IAc3Connection,
IDcConnection; IDcConnection
{
public required Ac3Phase Ac { get; init; }
public required DcPhase Dc { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = ThreePhaseInverterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record ThreePhaseInverterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -1,9 +1,15 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.StatusApi.Generator;
using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi; namespace InnovEnergy.Lib.StatusApi;
public abstract record ThreePhasePvInverterStatus(Ac1Phase Ac3, IReadOnlyList<DcPhase> Strings) : [OpParallel]
public partial record ThreePhasePvInverterStatus :
DeviceStatus, DeviceStatus,
IAc3Connection, IAc3Connection,
IPvConnection; IPvConnection
{
public required Ac3Phase Ac { get; init; }
public required IReadOnlyList<DcPhase> Strings { get; init; }
}

View File

@ -0,0 +1,16 @@
#nullable enable // Auto-generated code requires an explicit '#nullable' directive in source.
using System.CodeDom.Compiler;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
using T = ThreePhasePvInverterStatus;
[GeneratedCode("generate.sh", "1")]
public partial record ThreePhasePvInverterStatus
{
private static readonly Func<T, T, T> OpParallel = "|".CreateBinaryOpForProps<T>();
public static T operator |(T left, T right) => OpParallel(left, right);
}

View File

@ -1,11 +0,0 @@
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.StatusApi;
public static class Utils
{
public static Decimal Round3(this Decimal d)
{
return d.RoundToSignificantFigures(3);
}
}