Skip to content

Commit 2236736

Browse files
authored
Update model parser code snippets
The code was using an old parser version. Updated to match with latest
1 parent f5a7272 commit 2236736

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

articles/iot-pnp/concepts-model-parser.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The parser is available in NuGet.org with the ID: [Microsoft.Azure.DigitalTwins.
2323
dotnet add package Microsoft.Azure.DigitalTwins.Parser
2424
```
2525

26+
>Note: The latest version of the parser is `3.12.5`
27+
2628
## Use the parser to validate a model
2729

2830
The model you want to validate might be composed of one or more interfaces described in JSON files. You can use the parser to load all the files in a given folder and use the parser to validate all the files as a whole, including any references between the files:
@@ -52,40 +54,33 @@ The model you want to validate might be composed of one or more interfaces descr
5254
IReadOnlyDictionary<Dtmi, DTEntityInfo> parseResult = await modelParser.ParseAsync(modelJson);
5355
```
5456

55-
1. Check for validation errors. If the parser finds any errors, it throws an `AggregateException` with a list of detailed error messages:
57+
1. Check for validation errors. If the parser finds any errors, it throws an `ParsingException` with a list of errors:
5658

57-
```csharp
58-
try
59-
{
60-
IReadOnlyDictionary<Dtmi, DTEntityInfo> parseResult = await modelParser.ParseAsync(modelJson);
61-
}
62-
catch (AggregateException ae)
59+
```csharp
60+
try
61+
{
62+
IReadOnlyDictionary<Dtmi, DTEntityInfo> parseResult = await modelParser.ParseAsync(modelJson);
63+
}
64+
catch (ParsingException pex)
65+
{
66+
Console.WriteLine(pex.Message);
67+
foreach (var err in pex.Errors)
6368
{
64-
foreach (var e in ae.InnerExceptions)
65-
{
66-
Console.WriteLine(e.Message);
67-
}
69+
Console.WriteLine(err.PrimaryID);
70+
Console.WriteLine(err.Message);
6871
}
69-
```
72+
}
73+
```
7074

7175
1. Inspect the `Model`. If the validation succeeds, you can use the model parser API to inspect the model. The following code snippet shows how to iterate over all the models parsed and displays the existing properties:
7276

73-
```csharp
74-
foreach (var m in parseResult)
75-
{
76-
Console.WriteLine(m.Key);
77-
foreach (var item in m.Value.AsEnumerable<DTEntityInfo>())
78-
{
79-
var p = item as DTInterfaceInfo;
80-
if (p!=null)
81-
{
82-
Console.WriteLine($"\t{p.Id}");
83-
Console.WriteLine($"\t{p.Description.FirstOrDefault()}");
84-
}
85-
Console.WriteLine("--------------");
86-
}
87-
}
88-
```
77+
```csharp
78+
foreach (var item in parseResult)
79+
{
80+
Console.WriteLine($"\t{item.Key}");
81+
Console.WriteLine($"\t{item.Value.DisplayName?.Values.FirstOrDefault()}");
82+
}
83+
```
8984

9085
## Next steps
9186

0 commit comments

Comments
 (0)