-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Repo to Repository and minor changes / Import samples project (#…
- Loading branch information
Showing
17 changed files
with
231 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...delsRepository/samples/ModelsRepositoryClientSamples/ModelsRepositoryClientSamples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1;net5.0</TargetFramework> | ||
<RootNamespace>Azure.Iot.ModelsRepository.Samples</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="..\readme.md" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Azure.Iot.ModelsRepository.csproj" /> | ||
</ItemGroup> | ||
</Project> |
52 changes: 52 additions & 0 deletions
52
...elsrepository/Azure.Iot.ModelsRepository/samples/ModelsRepositoryClientSamples/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Core.Diagnostics; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Tracing; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Iot.ModelsRepository.Samples | ||
{ | ||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
// Forward all the events written to the console output with a specific format. | ||
using AzureEventSourceListener listener = new AzureEventSourceListener( | ||
(e, message) => Console.WriteLine("[{0:HH:mm:ss:fff}][{1}] {2}", DateTimeOffset.Now, e.Level, message), | ||
level: EventLevel.Verbose); | ||
|
||
await ResolveExistingAsync(); | ||
await TryResolveButNotFoundAsync(); | ||
} | ||
|
||
private static async Task ResolveExistingAsync() | ||
{ | ||
var dtmi = "dtmi:com:example:TemperatureController;1"; | ||
var client = new ModelsRepositoryClient(); | ||
|
||
IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false); | ||
|
||
Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces."); | ||
} | ||
|
||
private static async Task TryResolveButNotFoundAsync() | ||
{ | ||
var dtmi = "dtmi:com:example:NotFound;1"; | ||
var client = new ModelsRepositoryClient(); | ||
|
||
try | ||
{ | ||
IDictionary<string, string> models = await client.ResolveAsync(dtmi).ConfigureAwait(false); | ||
Console.WriteLine($"{dtmi} resolved in {models.Count} interfaces."); | ||
} | ||
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound) | ||
{ | ||
Console.WriteLine($"{dtmi} was not found in the default public models repository: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.