Skip to content

Commit 8af493a

Browse files
authored
Merge pull request #134769 from dominicbetts/pr/rido-min/134742
Model parser update
2 parents 6712b52 + bb7e3df commit 8af493a

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: Understand the Digital Twins model parser | Microsoft Docs
3-
description: As a developer, learn how to use the DTDL parser to validate models
3+
description: As a developer, learn how to use the DTDL parser to validate models.
44
author: rido-min
55
ms.author: rmpablos
6-
ms.date: 04/29/2020
6+
ms.date: 10/21/2020
77
ms.topic: conceptual
88
ms.custom: mvc
99
ms.service: iot-pnp
1010
services: iot-pnp
11-
manager: peterpr
11+
1212
---
1313

1414
# Understand the digital twins model parser
@@ -23,9 +23,12 @@ 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]
27+
> At the time of writing, the parser version is `3.12.5`.
28+
2629
## Use the parser to validate a model
2730

28-
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:
31+
A model can 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:
2932

3033
1. Create an `IEnumerable<string>` with a list of all model contents:
3134

@@ -52,38 +55,31 @@ The model you want to validate might be composed of one or more interfaces descr
5255
IReadOnlyDictionary<Dtmi, DTEntityInfo> parseResult = await modelParser.ParseAsync(modelJson);
5356
```
5457

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

5760
```csharp
5861
try
5962
{
6063
IReadOnlyDictionary<Dtmi, DTEntityInfo> parseResult = await modelParser.ParseAsync(modelJson);
6164
}
62-
catch (AggregateException ae)
65+
catch (ParsingException pex)
6366
{
64-
foreach (var e in ae.InnerExceptions)
67+
Console.WriteLine(pex.Message);
68+
foreach (var err in pex.Errors)
6569
{
66-
Console.WriteLine(e.Message);
70+
Console.WriteLine(err.PrimaryID);
71+
Console.WriteLine(err.Message);
6772
}
6873
}
6974
```
7075

7176
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:
7277

7378
```csharp
74-
foreach (var m in parseResult)
79+
foreach (var item in parseResult)
7580
{
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-
}
81+
Console.WriteLine($"\t{item.Key}");
82+
Console.WriteLine($"\t{item.Value.DisplayName?.Values.FirstOrDefault()}");
8783
}
8884
```
8985

0 commit comments

Comments
 (0)