Skip to content

Commit 733e79a

Browse files
azabbasidigimaun
andauthored
(modelsRepo): Initial commit: Azure.Iot.ModelsRepository (Azure#18998)
* Initial Commit - Bring ModelRepository Project to the mono repo (Azure#18706) * Use resx file and update formattings. * Add client diagnostics - Add sync APIs to RemoteFetcher and LocalFetcher (Azure#18807) * Add async methods to the ResolverClient (Azure#18814) * Add support for recorded tests. (Azure#18836) * Add support for recorded tests. * Make strings constants * Update file names to include plural models * Refactor RepositoryHandler and ResolverClient (Azure#18857) * Refactor ModelQuery (Azure#18843) * Refactor ModelQuery. * Combine constant files. * Rename Client to ModelsRepoClient (Azure#18862) * Remove ResolverException in favor of RequestFailedException (Azure#18874) * Remove ResolverException in favor of RequestFailedException. Adds more docstrings. * Rename Repo to Repository and minor changes / Import samples project (Azure#18986) * Format changes/Remove resx file. * Add first draft of readme. Add comment for dtmi validation. (Azure#18987) * Add comment for dtmi validation. * Fix links. * Add diagnostic event info. * Source link specifically pointing to 'src' folder. * Use fluent assertion * Use playback as default * fix Links and root service directory casing Co-authored-by: Paymaun <[email protected]>
1 parent 36b4daa commit 733e79a

File tree

94 files changed

+6044
-0
lines changed

Some content is hidden

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

94 files changed

+6044
-0
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@
261261
# ServiceLabel: %Digital Twins %Service Attention
262262
/sdk/digitaltwins/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi
263263

264+
# PRLabel: %IoT Models Repository
265+
# ServiceLabel: %IoT Models Repository %Service Attention
266+
/sdk/modelsrepository/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi @digimaun
267+
264268
# PRLabel: %TimeSeriesInsights
265269
# ServiceLabel: %TimeSeriesInsights %Service Attention
266270
/sdk/timeseriesinsights/ @drwill-ms @timtay-microsoft @abhipsaMisra @vinagesh @azabbasi @bikamani @barustum @jamdavi @yeskarthik @rasidhan @dmdenmsft
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
launchSettings.json
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30717.126
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Iot.ModelsRepository", "src\Azure.Iot.ModelsRepository.csproj", "{5E11A377-0D20-49F8-952B-50390196EF4B}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Iot.ModelsRepository.Tests", "tests\Azure.Iot.ModelsRepository.Tests.csproj", "{092E6CE2-9998-428C-A801-2BAB4E14A577}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelsRepositoryClientSamples", "samples\ModelsRepositoryClientSamples\ModelsRepositoryClientSamples.csproj", "{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{5E11A377-0D20-49F8-952B-50390196EF4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5E11A377-0D20-49F8-952B-50390196EF4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5E11A377-0D20-49F8-952B-50390196EF4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{5E11A377-0D20-49F8-952B-50390196EF4B}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{092E6CE2-9998-428C-A801-2BAB4E14A577}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{1FC8A3EA-3C0D-4DDF-B710-A7091F2CEBB1}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{51E4AB9E-46F3-450C-B52A-C4C6378E8BA3}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {671D1EFB-2BB9-4846-91EF-A3FB1FF9DDA6}
42+
EndGlobalSection
43+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Release History
2+
3+
## 1.0.0-preview.1 (Unreleased)
4+
5+
### New features
6+
7+
- Initial preview of Azure.Iot.ModelsRepository SDK
8+
9+
### Breaking changes
10+
11+
- N/A
12+
13+
### Added
14+
15+
- N/A
16+
17+
### Fixes and improvements
18+
19+
- N/A
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
5+
<section name="SteveCadwallader.CodeMaid.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
6+
</sectionGroup>
7+
</configSections>
8+
<userSettings>
9+
<SteveCadwallader.CodeMaid.Properties.Settings>
10+
<setting name="Cleaning_AutoCleanupOnFileSave" serializeAs="String">
11+
<value>True</value>
12+
</setting>
13+
<setting name="Formatting_CommentXmlSpaceSingleTags" serializeAs="String">
14+
<value>True</value>
15+
</setting>
16+
<setting name="Cleaning_InsertEndOfFileTrailingNewLine" serializeAs="String">
17+
<value>True</value>
18+
</setting>
19+
<setting name="Formatting_CommentWrapColumn" serializeAs="String">
20+
<value>120</value>
21+
</setting>
22+
<setting name="Formatting_CommentRunDuringCleanup" serializeAs="String">
23+
<value>False</value>
24+
</setting>
25+
<setting name="Cleaning_UpdateFileHeaderCSharp" serializeAs="String">
26+
<value>// Copyright (c) Microsoft Corporation. All rights reserved.
27+
// Licensed under the MIT License.
28+
</value>
29+
</setting>
30+
<setting name="Reorganizing_PrimaryOrderByAccessLevel" serializeAs="String">
31+
<value>True</value>
32+
</setting>
33+
<setting name="Cleaning_PerformPartialCleanupOnExternal" serializeAs="String">
34+
<value>1</value>
35+
</setting>
36+
<setting name="Progressing_ShowBuildProgressOnBuildStart" serializeAs="String">
37+
<value>False</value>
38+
</setting>
39+
</SteveCadwallader.CodeMaid.Properties.Settings>
40+
</userSettings>
41+
</configuration>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!--
3+
Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props
4+
-->
5+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
6+
</Project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Azure IoT Models Repository client library for .NET
2+
3+
This library provides functionality for interacting with the [Azure IoT Models Repository][modelsrepository_iot_endpoint]. It also aims to provide a consistent experience working with digital twin model repositories following Azure IoT conventions.
4+
5+
[Source code][source] | Package (nuget)
6+
7+
## Getting started
8+
9+
The complete Microsoft Azure SDK can be downloaded from the [Microsoft Azure downloads][microsoft_sdk_download] page, and it ships with support for building deployment packages, integrating with tooling, rich command-line tooling, and more.
10+
11+
For the best development experience, developers should use the official Microsoft NuGet packages for libraries. NuGet packages are regularly updated with new functionality and bug fixes.
12+
13+
### Install the package
14+
15+
Install the Azure IoT Models Repository client library for .NET with [NuGet][nuget]:
16+
17+
```PowerShell
18+
Install-Package Azure.Iot.ModelsRepository
19+
```
20+
21+
View the package details at nuget.org.
22+
23+
### Prerequisites
24+
25+
- A models repository following [Azure IoT conventions][modelsrepository_conventions]
26+
- The models repository can be located on the local filesystem or hosted on a webserver.
27+
- Azure IoT hosts the global [Azure IoT Models Repository][modelsrepository_iot_endpoint] which the client will point to by default if no URI is provided.
28+
29+
### Authenticate the client
30+
31+
Currently no authentication mechanisms are supported in the client. The global endpoint is not tied to an Azure subscription and does not support auth. All models published are meant for anonymous public consumption.
32+
33+
## Key concepts
34+
35+
The Azure IoT Models Repository enables builders to manage and share digital twin models. The models are [JSON-LD][json_ld_reference] documents defined using the Digital Twins Definition Language ([DTDL][dtdlv2_reference]).
36+
37+
The repository defines a pattern to store DTDL interfaces in a directory structure based on the Digital Twin Model Identifier (DTMI). You can locate an interface in the repository by converting the DTMI to a relative path. For example, the DTMI "`dtmi:com:example:Thermostat;1`" translates to `/dtmi/com/example/thermostat-1.json`.
38+
39+
### Thread safety
40+
41+
We guarantee that all client instance methods are thread-safe and independent of each other. See thread safety [guideline][thread_safety_guideline]. This ensures that the recommendation of reusing client instances is always safe, even across threads.
42+
43+
### Additional concepts
44+
45+
<!-- CLIENT COMMON BAR -->
46+
[Client options](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
47+
[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
48+
[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
49+
[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
50+
[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md) |
51+
[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#mocking) |
52+
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
53+
<!-- CLIENT COMMON BAR -->
54+
55+
## Examples
56+
57+
You can familiarize yourself with the client using [samples for IoT Models Repository][modelsrepository_samples].
58+
59+
## Troubleshooting
60+
61+
All service operations will throw RequestFailedException on failure, with helpful error codes and other information. The client also produces diagnostic events and logging which can be listened to with an [EventListener][eventsourcelistener_reference].
62+
63+
## Next steps
64+
65+
See implementation examples with our [code samples][modelsrepository_samples].
66+
67+
## Contributing
68+
69+
This project welcomes contributions and suggestions.
70+
Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution.
71+
For details, visit <https://cla.microsoft.com>
72+
73+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment).
74+
Simply follow the instructions provided by the bot.
75+
You will only need to do this once across all repos using our CLA.
76+
77+
This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct].
78+
For more information see the [Code of Conduct FAQ][code_of_conduct_faq] or contact [email protected] with any additional questions or comments.
79+
80+
<!-- LINKS -->
81+
[microsoft_sdk_download]: https://azure.microsoft.com/downloads/?sdk=net
82+
[azure_sdk_target_frameworks]: https://github.com/azure/azure-sdk-for-net#target-frameworks
83+
[source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/modelsrepository/Azure.Iot.ModelsRepository/src
84+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
85+
[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/
86+
[nuget]: https://www.nuget.org/
87+
[azure_core_library]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core
88+
[modelsrepository_conventions]: https://github.com/Azure/iot-plugandplay-models-tools/wiki
89+
[modelsrepository_iot_endpoint]: https://devicemodels.azure.com/
90+
[modelsrepository_samples]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/modelsrepository/Azure.Iot.ModelsRepository/samples
91+
[thread_safety_guideline]: https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety
92+
[json_ld_reference]: https://json-ld.org
93+
[dtdlv2_reference]: https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md
94+
[eventsourcelistener_reference]: https://docs.microsoft.com/dotnet/api/azure.core.diagnostics.azureeventsourcelistener?view=azure-dotnet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>Azure.Iot.ModelsRepository.Samples</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<AdditionalFiles Include="..\readme.md" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\Azure.Iot.ModelsRepository.csproj" />
14+
</ItemGroup>
15+
</Project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core.Diagnostics;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics.Tracing;
8+
using System.Net;
9+
using System.Threading.Tasks;
10+
11+
namespace Azure.Iot.ModelsRepository.Samples
12+
{
13+
public class Program
14+
{
15+
public static async Task Main(string[] args)
16+
{
17+
// Forward all the events written to the console output with a specific format.
18+
using AzureEventSourceListener listener = new AzureEventSourceListener(
19+
(e, message) =>
20+
Console.WriteLine("[{0:HH:mm:ss:fff}][{1}] {2}", DateTimeOffset.Now, e.Level, message),
21+
level: EventLevel.Verbose);
22+
23+
await ResolveExistingAsync();
24+
await TryResolveButNotFoundAsync();
25+
}
26+
27+
private static async Task ResolveExistingAsync()
28+
{
29+
var dtmi = "dtmi:com:example:TemperatureController;1";
30+
var client = new ModelsRepositoryClient();
31+
32+
IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false);
33+
34+
Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces.");
35+
}
36+
37+
private static async Task TryResolveButNotFoundAsync()
38+
{
39+
var dtmi = "dtmi:com:example:NotFound;1";
40+
var client = new ModelsRepositoryClient();
41+
42+
try
43+
{
44+
IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false);
45+
Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces.");
46+
}
47+
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
48+
{
49+
Console.WriteLine($"{dtmi} was not found in the default public models repository: {ex.Message}");
50+
}
51+
}
52+
}
53+
}

sdk/modelsrepository/Azure.Iot.ModelsRepository/samples/readme.md

Whitespace-only changes.

0 commit comments

Comments
 (0)