Skip to content

Commit 639960b

Browse files
authored
Implement ADR 23 for .NET (#1004)
This PR implements [ADR 23](https://github.com/Azure/iot-operations-sdks/blob/main/doc/dev/adr/0023-property-support.md), Property support, for C#. This includes optional aggregation, error modeling, dynamically itemized properties, and the cross product of these three features. Most changes are to the SchemaGenerator and the serialization T4 templates, which will be re-usable across target languages. Changes to the EnvoyGenerator and the communication T4 templates are almost exclusively related to .NET code generation. Other languages will follow. Only JSON serialization is fully supported. There is sketchy support for AVRO serialization, mainly just enough to enable the ProtocolCompiler to continue to build. Proper support for AVRO will await future development effort.
1 parent 7624c39 commit 639960b

File tree

70 files changed

+2197
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2197
-218
lines changed

codegen/src/Azure.Iot.Operations.ProtocolCompiler/Azure.Iot.Operations.ProtocolCompiler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="Azure.IoT.ModelsRepository" Version="1.0.0-preview.6" />
17-
<PackageReference Include="DTDLParser" Version="1.2.13-preview-g8a42f2082f" />
17+
<PackageReference Include="DTDLParser" Version="1.2.16-preview-gc368fb0828" />
1818
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
1919
<PackageReference Include="NuGet.Versioning" Version="6.13.2" />
2020
<PackageReference Include="System.CodeDom" Version="9.0.3" />

codegen/src/Azure.Iot.Operations.ProtocolCompiler/SchemasGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static bool GenerateSchemas(IReadOnlyDictionary<Dtmi, DTEntityInfo> model
2929
schemaGenerator.GenerateInterfaceAnnex(schemaWriter.Accept, sharedPrefix);
3030

3131
schemaGenerator.GenerateTelemetrySchemas(schemaWriter.Accept, sharedPrefix);
32+
schemaGenerator.GeneratePropertySchemas(schemaWriter.Accept, sharedPrefix);
3233
schemaGenerator.GenerateCommandSchemas(schemaWriter.Accept, sharedPrefix);
3334
schemaGenerator.GenerateObjects(schemaWriter.Accept, sharedPrefix);
3435
schemaGenerator.GenerateEnums(schemaWriter.Accept, sharedPrefix);

codegen/src/Azure.Iot.Operations.ProtocolCompilerLib/Azure.Iot.Operations.ProtocolCompilerLib.csproj

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<ItemGroup>
3535
<PackageReference Include="Azure.IoT.ModelsRepository" Version="1.0.0-preview.6" />
36-
<PackageReference Include="DTDLParser" Version="1.2.13-preview-g8a42f2082f" />
36+
<PackageReference Include="DTDLParser" Version="1.2.16-preview-gc368fb0828" />
3737
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
3838
<PackageReference Include="NuGet.Versioning" Version="6.13.2" />
3939
<PackageReference Include="System.CodeDom" Version="9.0.3" />
@@ -70,6 +70,11 @@
7070
<LastGenOutput>DotNetResponseExtension.cs</LastGenOutput>
7171
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
7272
</None>
73+
<None Update="T4\communication\dotnet\Error\t4\DotNetAggregateError.tt">
74+
<Generator>TextTemplatingFilePreprocessor</Generator>
75+
<LastGenOutput>DotNetAggregateError.cs</LastGenOutput>
76+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
77+
</None>
7378
<None Update="T4\communication\dotnet\Error\t4\DotNetError.tt">
7479
<Generator>TextTemplatingFilePreprocessor</Generator>
7580
<LastGenOutput>DotNetError.cs</LastGenOutput>
@@ -80,6 +85,16 @@
8085
<LastGenOutput>DotNetProject.cs</LastGenOutput>
8186
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
8287
</None>
88+
<None Update="T4\communication\dotnet\Property\t4\DotNetPropertyConsumer.tt">
89+
<Generator>TextTemplatingFilePreprocessor</Generator>
90+
<LastGenOutput>DotNetPropertyConsumer.cs</LastGenOutput>
91+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
92+
</None>
93+
<None Update="T4\communication\dotnet\Property\t4\DotNetPropertyMaintainer.tt">
94+
<Generator>TextTemplatingFilePreprocessor</Generator>
95+
<LastGenOutput>DotNetPropertyMaintainer.cs</LastGenOutput>
96+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
97+
</None>
8398
<None Update="T4\communication\dotnet\Serialization\t4\DotNetSerialization.tt">
8499
<Generator>TextTemplatingFilePreprocessor</Generator>
85100
<LastGenOutput>DotNetSerialization.cs</LastGenOutput>
@@ -410,6 +425,21 @@
410425
<LastGenOutput>ResultAvroSchema.cs</LastGenOutput>
411426
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
412427
</None>
428+
<None Update="T4\serialization\Property\t4\AggregateResponseJsonSchema.tt">
429+
<Generator>TextTemplatingFilePreprocessor</Generator>
430+
<LastGenOutput>AggregateResponseJsonSchema.cs</LastGenOutput>
431+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
432+
</None>
433+
<None Update="T4\serialization\Property\t4\PropertyAvroSchema.tt">
434+
<Generator>TextTemplatingFilePreprocessor</Generator>
435+
<LastGenOutput>PropertyAvroSchema.cs</LastGenOutput>
436+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
437+
</None>
438+
<None Update="T4\serialization\Property\t4\PropertyJsonSchema.tt">
439+
<Generator>TextTemplatingFilePreprocessor</Generator>
440+
<LastGenOutput>PropertyJsonSchema.cs</LastGenOutput>
441+
<CustomToolNamespace>Azure.Iot.Operations.ProtocolCompilerLib</CustomToolNamespace>
442+
</None>
413443
<None Update="T4\serialization\Telemetry\t4\TelemetryAvroSchema.tt">
414444
<Generator>TextTemplatingFilePreprocessor</Generator>
415445
<LastGenOutput>TelemetryAvroSchema.cs</LastGenOutput>
@@ -467,6 +497,11 @@
467497
<AutoGen>True</AutoGen>
468498
<DependentUpon>DotNetResponseExtension.tt</DependentUpon>
469499
</Compile>
500+
<Compile Update="T4\communication\dotnet\Error\t4\DotNetAggregateError.cs">
501+
<DesignTime>True</DesignTime>
502+
<AutoGen>True</AutoGen>
503+
<DependentUpon>DotNetAggregateError.tt</DependentUpon>
504+
</Compile>
470505
<Compile Update="T4\communication\dotnet\Error\t4\DotNetError.cs">
471506
<DesignTime>True</DesignTime>
472507
<AutoGen>True</AutoGen>
@@ -477,6 +512,16 @@
477512
<AutoGen>True</AutoGen>
478513
<DependentUpon>DotNetProject.tt</DependentUpon>
479514
</Compile>
515+
<Compile Update="T4\communication\dotnet\Property\t4\DotNetPropertyConsumer.cs">
516+
<DesignTime>True</DesignTime>
517+
<AutoGen>True</AutoGen>
518+
<DependentUpon>DotNetPropertyConsumer.tt</DependentUpon>
519+
</Compile>
520+
<Compile Update="T4\communication\dotnet\Property\t4\DotNetPropertyMaintainer.cs">
521+
<DesignTime>True</DesignTime>
522+
<AutoGen>True</AutoGen>
523+
<DependentUpon>DotNetPropertyMaintainer.tt</DependentUpon>
524+
</Compile>
480525
<Compile Update="T4\communication\dotnet\Serialization\t4\DotNetSerialization.cs">
481526
<DesignTime>True</DesignTime>
482527
<AutoGen>True</AutoGen>
@@ -807,6 +852,21 @@
807852
<AutoGen>True</AutoGen>
808853
<DependentUpon>ResultAvroSchema.tt</DependentUpon>
809854
</Compile>
855+
<Compile Update="T4\serialization\Property\t4\AggregateResponseJsonSchema.cs">
856+
<DesignTime>True</DesignTime>
857+
<AutoGen>True</AutoGen>
858+
<DependentUpon>AggregateResponseJsonSchema.tt</DependentUpon>
859+
</Compile>
860+
<Compile Update="T4\serialization\Property\t4\PropertyAvroSchema.cs">
861+
<DesignTime>True</DesignTime>
862+
<AutoGen>True</AutoGen>
863+
<DependentUpon>PropertyAvroSchema.tt</DependentUpon>
864+
</Compile>
865+
<Compile Update="T4\serialization\Property\t4\PropertyJsonSchema.cs">
866+
<DesignTime>True</DesignTime>
867+
<AutoGen>True</AutoGen>
868+
<DependentUpon>PropertyJsonSchema.tt</DependentUpon>
869+
</Compile>
810870
<Compile Update="T4\serialization\Telemetry\t4\TelemetryAvroSchema.cs">
811871
<DesignTime>True</DesignTime>
812872
<AutoGen>True</AutoGen>

codegen/src/Azure.Iot.Operations.ProtocolCompilerLib/CompositeGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static async Task<Dictionary<string, string>> GetCodeFilesForModelId(stri
2727

2828
Dictionary<string, string> schemaDict = new();
2929
schemaGenerator.GenerateTelemetrySchemas((schemaText, fileName, _) => { schemaDict[fileName] = schemaText; }, null);
30+
schemaGenerator.GeneratePropertySchemas((schemaText, fileName, _) => { schemaDict[fileName] = schemaText; }, null);
3031
schemaGenerator.GenerateCommandSchemas((schemaText, fileName, _) => { schemaDict[fileName] = schemaText; }, null);
3132
schemaGenerator.GenerateObjects((schemaText, fileName, _) => { schemaDict[fileName] = schemaText; }, null);
3233
schemaGenerator.GenerateEnums((schemaText, fileName, _) => { schemaDict[fileName] = schemaText; }, null);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Azure.Iot.Operations.ProtocolCompilerLib
2+
{
3+
public static class EnvoyNames
4+
{
5+
public static CodeName ReadRequesterEnvoyName = new CodeName(string.Empty, "read", "requester");
6+
7+
public static CodeName ReadResponderEnvoyName = new CodeName(string.Empty, "read", "responder");
8+
9+
public static CodeName WriteRequesterEnvoyName = new CodeName(string.Empty, "write", "requester");
10+
11+
public static CodeName WriteResponderEnvoyName = new CodeName(string.Empty, "write", "responder");
12+
}
13+
}

0 commit comments

Comments
 (0)