Skip to content

Commit

Permalink
A handful of renames for yet to be released ModelsRepositoryClient. (#…
Browse files Browse the repository at this point in the history
…19390)

* A handful of changes for yet to be released ModelsRepositoryClient.
* Apply PR feedback.
* Update code snippets in samples.
* Update API surface and add script for future.
  • Loading branch information
digimaun authored Mar 9, 2021
1 parent 793d94a commit 629c70d
Show file tree
Hide file tree
Showing 32 changed files with 240 additions and 241 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Azure.Iot.ModelsRepository
{
public enum DependencyResolutionOption
public enum ModelDependencyResolution
{
Disabled = 0,
Enabled = 1,
Expand All @@ -11,17 +11,16 @@ public partial class ModelsRepositoryClient
public ModelsRepositoryClient() { }
public ModelsRepositoryClient(Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions options) { }
public ModelsRepositoryClient(System.Uri repositoryUri, Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions options = null) { }
public static System.Uri DefaultModelsRepository { get { throw null; } }
public System.Uri RepositoryUri { get { throw null; } }
public virtual System.Collections.Generic.IDictionary<string, string> GetModels(System.Collections.Generic.IEnumerable<string> dtmis, Azure.Iot.ModelsRepository.DependencyResolutionOption? resolutionOption = default(Azure.Iot.ModelsRepository.DependencyResolutionOption?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Collections.Generic.IDictionary<string, string> GetModels(string dtmi, Azure.Iot.ModelsRepository.DependencyResolutionOption? resolutionOption = default(Azure.Iot.ModelsRepository.DependencyResolutionOption?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, string>> GetModelsAsync(System.Collections.Generic.IEnumerable<string> dtmis, Azure.Iot.ModelsRepository.DependencyResolutionOption? resolutionOption = default(Azure.Iot.ModelsRepository.DependencyResolutionOption?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, string>> GetModelsAsync(string dtmi, Azure.Iot.ModelsRepository.DependencyResolutionOption? resolutionOption = default(Azure.Iot.ModelsRepository.DependencyResolutionOption?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Collections.Generic.IDictionary<string, string> GetModels(System.Collections.Generic.IEnumerable<string> dtmis, Azure.Iot.ModelsRepository.ModelDependencyResolution? dependencyResolution = default(Azure.Iot.ModelsRepository.ModelDependencyResolution?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Collections.Generic.IDictionary<string, string> GetModels(string dtmi, Azure.Iot.ModelsRepository.ModelDependencyResolution? dependencyResolution = default(Azure.Iot.ModelsRepository.ModelDependencyResolution?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, string>> GetModelsAsync(System.Collections.Generic.IEnumerable<string> dtmis, Azure.Iot.ModelsRepository.ModelDependencyResolution? dependencyResolution = default(Azure.Iot.ModelsRepository.ModelDependencyResolution?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, string>> GetModelsAsync(string dtmi, Azure.Iot.ModelsRepository.ModelDependencyResolution? dependencyResolution = default(Azure.Iot.ModelsRepository.ModelDependencyResolution?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class ModelsRepositoryClientOptions : Azure.Core.ClientOptions
{
public ModelsRepositoryClientOptions(Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions.ServiceVersion version = Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions.ServiceVersion.V2021_02_11, Azure.Iot.ModelsRepository.DependencyResolutionOption resolutionOption = Azure.Iot.ModelsRepository.DependencyResolutionOption.Enabled) { }
public Azure.Iot.ModelsRepository.DependencyResolutionOption DependencyResolution { get { throw null; } }
public ModelsRepositoryClientOptions(Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions.ServiceVersion version = Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions.ServiceVersion.V2021_02_11, Azure.Iot.ModelsRepository.ModelDependencyResolution dependencyResolution = Azure.Iot.ModelsRepository.ModelDependencyResolution.Enabled) { }
public Azure.Iot.ModelsRepository.ModelDependencyResolution DependencyResolution { get { throw null; } }
public Azure.Iot.ModelsRepository.ModelsRepositoryClientOptions.ServiceVersion Version { get { throw null; } }
public enum ServiceVersion
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static void ClientInitialization()
#region Snippet:ModelsRepositorySamplesCreateServiceClientWithGlobalEndpoint

// When no URI is provided for instantiation, the Azure IoT Models Repository global endpoint
// https://devicemodels.azure.com/ is used and the dependency model resolution option is set to TryFromExpanded.
// https://devicemodels.azure.com/ is used and the model dependency resolution
// configuration is set to TryFromExpanded.
var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions());
Console.WriteLine($"Initialized client pointing to global endpoint: {client.RepositoryUri}");

Expand All @@ -38,7 +39,7 @@ public static void ClientInitialization()
// The client will also work with a local filesystem URI. This example shows initalization
// with a local URI and disabling model dependency resolution.
client = new ModelsRepositoryClient(new Uri(ClientSamplesLocalModelsRepository),
new ModelsRepositoryClientOptions(resolutionOption: DependencyResolutionOption.Disabled));
new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled));
Console.WriteLine($"Initialized client pointing to local path: {client.RepositoryUri}");

#endregion Snippet:ModelsRepositorySamplesCreateServiceClientWithLocalRepository
Expand All @@ -52,7 +53,7 @@ public static async Task GetModelsFromGlobalRepoAsync()
var client = new ModelsRepositoryClient();

// The output of GetModelsAsync() will include at least the definition for the target dtmi.
// If the dependency model resolution option is not disabled, then models in which the
// If the model dependency resolution configuration is not disabled, then models in which the
// target dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
Expand All @@ -73,7 +74,7 @@ public static async Task GetMultipleModelsFromGlobalRepoAsync()

// When given an IEnumerable of dtmis, the output of GetModelsAsync() will include at
// least the definitions of each dtmi enumerated in the IEnumerable.
// If the dependency model resolution option is not disabled, then models in which each
// If the model dependency resolution configuration is not disabled, then models in which each
// enumerated dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmis = new[] { "dtmi:com:example:TemperatureController;1", "dtmi:com:example:azuresphere:sampledevice;1" };
IDictionary<string, string> models = await client.GetModelsAsync(dtmis).ConfigureAwait(false);
Expand All @@ -94,7 +95,7 @@ public static async Task GetModelsFromLocalRepoAsync()
var client = new ModelsRepositoryClient(new Uri(ClientSamplesLocalModelsRepository));

// The output of GetModelsAsync() will include at least the definition for the target dtmi.
// If the dependency model resolution option is not disabled, then models in which the
// If the model dependency resolution configuration is not disabled, then models in which the
// target dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task ParseAndGetModelsWithExtensionAsync()
{
#region Snippet:ModelsRepositorySamplesParserIntegrationParseAndGetModelsAsync

var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions(resolutionOption: DependencyResolutionOption.Disabled));
var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled));
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
var parser = new ModelParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The samples project demonstrates the following:

```C# Snippet:ModelsRepositorySamplesCreateServiceClientWithGlobalEndpoint
// When no URI is provided for instantiation, the Azure IoT Models Repository global endpoint
// https://devicemodels.azure.com/ is used and the dependency model resolution option is set to TryFromExpanded.
// https://devicemodels.azure.com/ is used and the model dependency resolution
// configuration is set to TryFromExpanded.
var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions());
Console.WriteLine($"Initialized client pointing to global endpoint: {client.RepositoryUri}");
```
Expand All @@ -27,7 +28,7 @@ Console.WriteLine($"Initialized client pointing to global endpoint: {client.Repo
// The client will also work with a local filesystem URI. This example shows initalization
// with a local URI and disabling model dependency resolution.
client = new ModelsRepositoryClient(new Uri(ClientSamplesLocalModelsRepository),
new ModelsRepositoryClientOptions(resolutionOption: DependencyResolutionOption.Disabled));
new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled));
Console.WriteLine($"Initialized client pointing to local path: {client.RepositoryUri}");
```

Expand All @@ -53,7 +54,7 @@ After publishing, your model(s) will be available for consumption from the globa
var client = new ModelsRepositoryClient();

// The output of GetModelsAsync() will include at least the definition for the target dtmi.
// If the dependency model resolution option is not disabled, then models in which the
// If the model dependency resolution configuration is not disabled, then models in which the
// target dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
Expand All @@ -72,7 +73,7 @@ To support this workflow and similar use cases, the client supports initializati
var client = new ModelsRepositoryClient(new Uri(ClientSamplesLocalModelsRepository));

// The output of GetModelsAsync() will include at least the definition for the target dtmi.
// If the dependency model resolution option is not disabled, then models in which the
// If the model dependency resolution configuration is not disabled, then models in which the
// target dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
Expand All @@ -91,7 +92,7 @@ var client = new ModelsRepositoryClient();

// When given an IEnumerable of dtmis, the output of GetModelsAsync() will include at
// least the definitions of each dtmi enumerated in the IEnumerable.
// If the dependency model resolution option is not disabled, then models in which each
// If the model dependency resolution configuration is not disabled, then models in which each
// enumerated dtmi depends on will also be included in the returned IDictionary<string, string>.
var dtmis = new[] { "dtmi:com:example:TemperatureController;1", "dtmi:com:example:azuresphere:sampledevice;1" };
IDictionary<string, string> models = await client.GetModelsAsync(dtmis).ConfigureAwait(false);
Expand Down Expand Up @@ -121,7 +122,7 @@ Alternatively, the following snippet shows parsing a model, then fetching depend
This is achieved by configuring the `ModelParser` to use the sample [ParserDtmiResolver][modelsrepository_sample_extension] client extension.

```C# Snippet:ModelsRepositorySamplesParserIntegrationParseAndGetModelsAsync
var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions(resolutionOption: DependencyResolutionOption.Disabled));
var client = new ModelsRepositoryClient(new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled));
var dtmi = "dtmi:com:example:TemperatureController;1";
IDictionary<string, string> models = await client.GetModelsAsync(dtmi).ConfigureAwait(false);
var parser = new ModelParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
namespace Azure.Iot.ModelsRepository.Fetchers
{
/// <summary>
/// The LocalModelFetcher is an implementation of IModelFetcher
/// The FileModelFetcher is an implementation of IModelFetcher
/// for supporting local filesystem based model content fetching.
/// </summary>
internal class LocalModelFetcher : IModelFetcher
internal class FileModelFetcher : IModelFetcher
{
private readonly ClientDiagnostics _clientDiagnostics;

public LocalModelFetcher(ClientDiagnostics clientDiagnostics)
public FileModelFetcher(ClientDiagnostics clientDiagnostics)
{
_clientDiagnostics = clientDiagnostics;
}

public Task<FetchResult> FetchAsync(string dtmi, Uri repositoryUri, DependencyResolutionOption resolutionOption, CancellationToken cancellationToken = default)
public Task<FetchResult> FetchAsync(string dtmi, Uri repositoryUri, ModelDependencyResolution dependencyResolution, CancellationToken cancellationToken = default)
{
return Task.FromResult(Fetch(dtmi, repositoryUri, resolutionOption, cancellationToken));
return Task.FromResult(Fetch(dtmi, repositoryUri, dependencyResolution, cancellationToken));
}

public FetchResult Fetch(string dtmi, Uri repositoryUri, DependencyResolutionOption resolutionOption, CancellationToken cancellationToken = default)
public FetchResult Fetch(string dtmi, Uri repositoryUri, ModelDependencyResolution dependencyResolution, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope("LocalModelFetcher.Fetch");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(FileModelFetcher)}.{nameof(Fetch)}");
scope.Start();

try
{
var work = new Queue<string>();
if (resolutionOption == DependencyResolutionOption.TryFromExpanded)
if (dependencyResolution == ModelDependencyResolution.TryFromExpanded)
{
work.Enqueue(GetPath(dtmi, repositoryUri, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
namespace Azure.Iot.ModelsRepository.Fetchers
{
/// <summary>
/// The RemoteModelFetcher is an implementation of IModelFetcher
/// The HttpModelFetcher is an implementation of IModelFetcher
/// for supporting http[s] based model content fetching.
/// </summary>
internal class RemoteModelFetcher : IModelFetcher
internal class HttpModelFetcher : IModelFetcher
{
private readonly HttpPipeline _pipeline;
private readonly ClientDiagnostics _clientDiagnostics;

public RemoteModelFetcher(ClientDiagnostics clientDiagnostics, ModelsRepositoryClientOptions clientOptions)
public HttpModelFetcher(ClientDiagnostics clientDiagnostics, ModelsRepositoryClientOptions clientOptions)
{
_pipeline = CreatePipeline(clientOptions);
_clientDiagnostics = clientDiagnostics;
}

public FetchResult Fetch(
string dtmi, Uri repositoryUri, DependencyResolutionOption resolutionOption, CancellationToken cancellationToken = default)
string dtmi, Uri repositoryUri, ModelDependencyResolution dependencyResolution, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope("RemoteModelFetcher.Fetch");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(HttpModelFetcher)}.{nameof(Fetch)}");
scope.Start();
try
{
Queue<string> work = PrepareWork(dtmi, repositoryUri, resolutionOption == DependencyResolutionOption.TryFromExpanded);
Queue<string> work = PrepareWork(dtmi, repositoryUri, dependencyResolution == ModelDependencyResolution.TryFromExpanded);

string remoteFetchError = string.Empty;

Expand Down Expand Up @@ -74,13 +74,13 @@ public FetchResult Fetch(
}

public async Task<FetchResult> FetchAsync(
string dtmi, Uri repositoryUri, DependencyResolutionOption resolutionOption, CancellationToken cancellationToken = default)
string dtmi, Uri repositoryUri, ModelDependencyResolution dependencyResolution, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope("RemoteModelFetcher.Fetch");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(HttpModelFetcher)}.{nameof(Fetch)}");
scope.Start();
try
{
Queue<string> work = PrepareWork(dtmi, repositoryUri, resolutionOption == DependencyResolutionOption.TryFromExpanded);
Queue<string> work = PrepareWork(dtmi, repositoryUri, dependencyResolution == ModelDependencyResolution.TryFromExpanded);

string remoteFetchError = string.Empty;
RequestFailedException requestFailedExceptionThrown = null;
Expand Down Expand Up @@ -165,7 +165,7 @@ private static string GetPath(string dtmi, Uri repositoryUri, bool expanded = fa

private string EvaluatePath(string path, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope("RemoteModelFetcher.EvaluatePath");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(HttpModelFetcher)}.{nameof(EvaluatePath)}");
scope.Start();

try
Expand Down Expand Up @@ -193,7 +193,7 @@ private string EvaluatePath(string path, CancellationToken cancellationToken = d

private async Task<string> EvaluatePathAsync(string path, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope("RemoteModelFetcher.EvaluatePath");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(HttpModelFetcher)}.{nameof(EvaluatePath)}");
scope.Start();

try
Expand Down
Loading

0 comments on commit 629c70d

Please sign in to comment.