Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Client to ModelsRepoClient #18862

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;

namespace Azure.Iot.ModelsRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class LocalModelFetcher : IModelFetcher
private readonly bool _tryExpanded;
private readonly ClientDiagnostics _clientDiagnostics;

public LocalModelFetcher(ClientDiagnostics clientDiagnostics, ResolverClientOptions clientOptions)
public LocalModelFetcher(ClientDiagnostics clientDiagnostics, ModelsRepoClientOptions clientOptions)
{
_clientDiagnostics = clientDiagnostics;
_tryExpanded = clientOptions.DependencyResolution == DependencyResolutionOption.TryFromExpanded;
Expand Down Expand Up @@ -50,7 +50,7 @@ public FetchResult Fetch(string dtmi, Uri repositoryUri, CancellationToken cance
cancellationToken.ThrowIfCancellationRequested();

string tryContentPath = work.Dequeue();
ResolverEventSource.Instance.FetchingModelContent(tryContentPath);
ModelsRepoEventSource.Instance.FetchingModelContent(tryContentPath);

if (File.Exists(tryContentPath))
{
Expand All @@ -61,7 +61,7 @@ public FetchResult Fetch(string dtmi, Uri repositoryUri, CancellationToken cance
};
}

ResolverEventSource.Instance.ErrorFetchingModelContent(tryContentPath);
ModelsRepoEventSource.Instance.ErrorFetchingModelContent(tryContentPath);
fnfError = string.Format(CultureInfo.CurrentCulture, ServiceStrings.ErrorFetchingModelContent, tryContentPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class RemoteModelFetcher : IModelFetcher
private readonly ClientDiagnostics _clientDiagnostics;
private readonly bool _tryExpanded;

public RemoteModelFetcher(ClientDiagnostics clientDiagnostics, ResolverClientOptions clientOptions)
public RemoteModelFetcher(ClientDiagnostics clientDiagnostics, ModelsRepoClientOptions clientOptions)
{
_pipeline = CreatePipeline(clientOptions);
_tryExpanded = clientOptions.DependencyResolution == DependencyResolutionOption.TryFromExpanded;
Expand All @@ -41,7 +41,7 @@ public FetchResult Fetch(string dtmi, Uri repositoryUri, CancellationToken cance
cancellationToken.ThrowIfCancellationRequested();

string tryContentPath = work.Dequeue();
ResolverEventSource.Instance.FetchingModelContent(tryContentPath);
ModelsRepoEventSource.Instance.FetchingModelContent(tryContentPath);

try
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task<FetchResult> FetchAsync(string dtmi, Uri repositoryUri, Cancel
cancellationToken.ThrowIfCancellationRequested();

string tryContentPath = work.Dequeue();
ResolverEventSource.Instance.FetchingModelContent(tryContentPath);
ModelsRepoEventSource.Instance.FetchingModelContent(tryContentPath);

try
{
Expand Down Expand Up @@ -211,7 +211,7 @@ private static async Task<string> GetContentAsync(Stream content, CancellationTo
return root.GetRawText();
}

private static HttpPipeline CreatePipeline(ResolverClientOptions options)
private static HttpPipeline CreatePipeline(ModelsRepoClientOptions options)
{
return HttpPipelineBuilder.Build(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,78 @@
namespace Azure.Iot.ModelsRepository
{
/// <summary>
/// The <c>ResolverClient</c> class supports DTDL model resolution providing functionality to
/// The <c>ModelsRepoClient</c> class supports DTDL model resolution providing functionality to
/// resolve models by retrieving model definitions and their dependencies.
/// </summary>
public class ResolverClient
public class ModelsRepoClient
{
private readonly RepositoryHandler _repositoryHandler;
private readonly ClientDiagnostics _clientDiagnostics;
private readonly ResolverClientOptions _clientOptions;
private readonly Uri _repositoryUri;

/// <summary>
/// Initializes the <c>ResolverClient</c> with default client options while pointing to
/// Initializes the <c>ModelsRepoClient</c> with default client options while pointing to
/// the Azure IoT Plug and Play Model repository https://devicemodels.azure.com for resolution.
/// </summary>
public ResolverClient() : this(new Uri(DefaultModelsRepository), new ResolverClientOptions()) { }
public ModelsRepoClient() : this(new Uri(DefaultModelsRepository), new ModelsRepoClientOptions()) { }

/// <summary>
/// Initializes the <c>ResolverClient</c> with default client options while pointing to
/// Initializes the <c>ModelsRepoClient</c> with default client options while pointing to
/// a custom <paramref name="repositoryUri"/> for resolution.
/// </summary>
/// <param name="repositoryUri">
/// The model repository <c>Uri</c> value. This can be a remote endpoint or local directory.
/// </param>
public ResolverClient(Uri repositoryUri) : this(repositoryUri, new ResolverClientOptions()) { }
public ModelsRepoClient(Uri repositoryUri) : this(repositoryUri, new ModelsRepoClientOptions()) { }

/// <summary>
/// Initializes the <c>ResolverClient</c> with custom client <paramref name="options"/> while pointing to
/// Initializes the <c>ModelsRepoClient</c> with custom client <paramref name="options"/> while pointing to
/// the Azure IoT Plug and Play Model repository https://devicemodels.azure.com for resolution.
/// </summary>
/// <param name="options">
/// <c>ResolverClientOptions</c> to configure resolution and client behavior.
/// <c>ModelsRepoClientOptions</c> to configure resolution and client behavior.
/// </param>
public ResolverClient(ResolverClientOptions options) : this(new Uri(DefaultModelsRepository), options) { }
public ModelsRepoClient(ModelsRepoClientOptions options) : this(new Uri(DefaultModelsRepository), options) { }

/// <summary>
/// Initializes the <c>ResolverClient</c> with default client options while pointing to
/// Initializes the <c>ModelsRepoClient</c> with default client options while pointing to
/// a custom <paramref name="repositoryUriStr"/> for resolution.
/// </summary>
/// <param name="repositoryUriStr">
/// The model repository <c>Uri</c> in string format. This can be a remote endpoint or local directory.
/// </param>
public ResolverClient(string repositoryUriStr) : this(repositoryUriStr, new ResolverClientOptions()) { }
public ModelsRepoClient(string repositoryUriStr) : this(repositoryUriStr, new ModelsRepoClientOptions()) { }

/// <summary>
/// Initializes the <c>ResolverClient</c> with custom client <paramref name="options"/> while pointing to
/// Initializes the <c>ModelsRepoClient</c> with custom client <paramref name="options"/> while pointing to
/// a custom <paramref name="repositoryUriStr"/> for resolution.
/// </summary>
/// <param name="repositoryUriStr">
/// The model repository <c>Uri</c> in string format. This can be a remote endpoint or local directory.
/// </param>
/// <param name="options">
/// <c>ResolverClientOptions</c> to configure resolution and client behavior.
/// <c>ModelsRepoClientOptions</c> to configure resolution and client behavior.
/// </param>
public ResolverClient(string repositoryUriStr, ResolverClientOptions options)
public ModelsRepoClient(string repositoryUriStr, ModelsRepoClientOptions options)
: this(new Uri(repositoryUriStr), options) { }

/// <summary>
/// Initializes the <c>ResolverClient</c> with custom client <paramref name="options"/> while pointing to
/// Initializes the <c>ModelsRepoClient</c> with custom client <paramref name="options"/> while pointing to
/// a custom <paramref name="repositoryUri"/> for resolution.
/// </summary>
/// <param name="repositoryUri">
/// The model repository <c>Uri</c>. This can be a remote endpoint or local directory.
/// </param>
/// <param name="options">
/// <c>ResolverClientOptions</c> to configure resolution and client behavior.
/// <c>ModelsRepoClientOptions</c> to configure resolution and client behavior.
/// </param>
public ResolverClient(Uri repositoryUri, ResolverClientOptions options)
public ModelsRepoClient(Uri repositoryUri, ModelsRepoClientOptions options)
{
Argument.AssertNotNull(options, nameof(options));

_clientOptions = options;
ClientOptions = options;
RepositoryUri = repositoryUri;
_clientDiagnostics = new ClientDiagnostics(options);
_repositoryUri = repositoryUri;
_repositoryHandler = new RepositoryHandler(_repositoryUri, _clientDiagnostics, _clientOptions);
_repositoryHandler = new RepositoryHandler(RepositoryUri, _clientDiagnostics, ClientOptions);
}

/// <summary>
Expand All @@ -104,7 +102,7 @@ public ResolverClient(Uri repositoryUri, ResolverClientOptions options)
Justification = "<Pending>")]
public virtual async Task<IDictionary<string, string>> ResolveAsync(string dtmi, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ResolverClient)}.{nameof(Resolve)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ModelsRepoClient)}.{nameof(Resolve)}");
scope.Start();
try
{
Expand Down Expand Up @@ -133,7 +131,7 @@ public virtual async Task<IDictionary<string, string>> ResolveAsync(string dtmi,
Justification = "<Pending>")]
public virtual IDictionary<string, string> Resolve(string dtmi, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ResolverClient)}.{nameof(Resolve)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ModelsRepoClient)}.{nameof(Resolve)}");
scope.Start();

try
Expand All @@ -160,7 +158,7 @@ public virtual IDictionary<string, string> Resolve(string dtmi, CancellationToke
[SuppressMessage("Usage", "AZC0015:Unexpected client method return type.", Justification = "<Pending>")]
public virtual async Task<IDictionary<string, string>> ResolveAsync(IEnumerable<string> dtmis, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ResolverClient)}.{nameof(Resolve)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ModelsRepoClient)}.{nameof(Resolve)}");
scope.Start();

try
Expand All @@ -187,7 +185,7 @@ public virtual async Task<IDictionary<string, string>> ResolveAsync(IEnumerable<
[SuppressMessage("Usage", "AZC0015:Unexpected client method return type.", Justification = "<Pending>")]
public virtual IDictionary<string, string> Resolve(IEnumerable<string> dtmis, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ResolverClient)}.{nameof(Resolve)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ModelsRepoClient)}.{nameof(Resolve)}");
scope.Start();

try
Expand All @@ -207,14 +205,14 @@ public virtual IDictionary<string, string> Resolve(IEnumerable<string> dtmis, Ca
public static bool IsValidDtmi(string dtmi) => DtmiConventions.IsDtmi(dtmi);

/// <summary>
/// Gets the <c>Uri</c> associated with the ResolverClient instance.
/// Gets the <c>Uri</c> associated with the ModelsRepoClient instance.
/// </summary>
public Uri RepositoryUri => _repositoryUri;
public Uri RepositoryUri { get; }

/// <summary>
/// Gets the <c>ResolverClientOptions</c> associated with the ResolverClient instance.
/// Gets the <c>ModelsRepoClientOptions</c> associated with the ModelsRepoClient instance.
/// </summary>
public ResolverClientOptions ClientOptions => _clientOptions;
public ModelsRepoClientOptions ClientOptions { get; }

/// <summary>
/// Azure Device Models Repository used by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Azure.Iot.ModelsRepository
/// <summary>
/// Options that allow configuration of requests sent to the ModelRepositoryService.
/// </summary>
public class ResolverClientOptions : ClientOptions
public class ModelsRepoClientOptions : ClientOptions
{
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_02_11;

Expand All @@ -33,14 +33,14 @@ public enum ServiceVersion
public ServiceVersion Version { get; }

/// <summary>
/// Initializes a new instance of the <see cref="ResolverClientOptions"/> class.
/// Initializes a new instance of the <see cref="ModelsRepoClientOptions"/> class.
/// </summary>
/// <param name="version">
/// The <see cref="ServiceVersion"/> of the service API used when
/// making requests.
/// </param>
/// <param name="resolutionOption">The dependency processing options.</param>
public ResolverClientOptions(
public ModelsRepoClientOptions(
ServiceVersion version = LatestVersion,
DependencyResolutionOption resolutionOption = DependencyResolutionOption.Enabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Azure.Iot.ModelsRepository
{
[EventSource(Name = EventSourceName)]
internal sealed class ResolverEventSource : EventSource
internal sealed class ModelsRepoEventSource : EventSource
{
private const string EventSourceName = ModelRepositoryConstants.ModelRepositoryEventSourceName;

Expand All @@ -26,9 +26,9 @@ internal sealed class ResolverEventSource : EventSource
private const int ErrorFetchingModelContentEventId = 4004;
private const int IncorrectDtmiCasingEventId = 4006;

public static ResolverEventSource Instance { get; } = new ResolverEventSource();
public static ModelsRepoEventSource Instance { get; } = new ModelsRepoEventSource();

private ResolverEventSource()
private ModelsRepoEventSource()
: base(EventSourceName,
EventSourceSettings.Default,
AzureEventSourceListener.TraitName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal class RepositoryHandler
private readonly Guid _clientId;
private readonly ClientDiagnostics _clientDiagnostics;
private readonly Uri _repositoryUri;
private readonly ResolverClientOptions _clientOptions;
private readonly ModelsRepoClientOptions _clientOptions;

public RepositoryHandler(Uri repositoryUri, ClientDiagnostics clientDiagnostics, ResolverClientOptions options)
public RepositoryHandler(Uri repositoryUri, ClientDiagnostics clientDiagnostics, ModelsRepoClientOptions options)
{
Argument.AssertNotNull(options, nameof(options));

Expand All @@ -33,7 +33,7 @@ public RepositoryHandler(Uri repositoryUri, ClientDiagnostics clientDiagnostics,

_repositoryUri = repositoryUri;

ResolverEventSource.Instance.InitFetcher(_clientId, repositoryUri.Scheme);
ModelsRepoEventSource.Instance.InitFetcher(_clientId, repositoryUri.Scheme);
}

public async Task<IDictionary<string, string>> ProcessAsync(string dtmi, CancellationToken cancellationToken)
Expand Down Expand Up @@ -68,11 +68,11 @@ private async Task<IDictionary<string, string>> ProcessAsync(IEnumerable<string>
string targetDtmi = toProcessModels.Dequeue();
if (processedModels.ContainsKey(targetDtmi))
{
ResolverEventSource.Instance.SkippingPreprocessedDtmi(targetDtmi);
ModelsRepoEventSource.Instance.SkippingPreprocessedDtmi(targetDtmi);
continue;
}

ResolverEventSource.Instance.ProcessingDtmi(targetDtmi);
ModelsRepoEventSource.Instance.ProcessingDtmi(targetDtmi);

FetchResult result = async
? await FetchAsync(targetDtmi, cancellationToken).ConfigureAwait(false)
Expand Down Expand Up @@ -101,7 +101,7 @@ private async Task<IDictionary<string, string>> ProcessAsync(IEnumerable<string>

if (dependencies.Count > 0)
{
ResolverEventSource.Instance.DiscoveredDependencies(string.Join("\", \"", dependencies));
ModelsRepoEventSource.Instance.DiscoveredDependencies(string.Join("\", \"", dependencies));
}

foreach (string dep in dependencies)
Expand All @@ -113,7 +113,7 @@ private async Task<IDictionary<string, string>> ProcessAsync(IEnumerable<string>
string parsedDtmi = metadata.Id;
if (!parsedDtmi.Equals(targetDtmi, StringComparison.Ordinal))
{
ResolverEventSource.Instance.IncorrectDtmiCasing(targetDtmi, parsedDtmi);
ModelsRepoEventSource.Instance.IncorrectDtmiCasing(targetDtmi, parsedDtmi);
string formatErrorMsg = string.Format(CultureInfo.CurrentCulture, ServiceStrings.IncorrectDtmiCasing, targetDtmi, parsedDtmi);
throw new ResolverException(targetDtmi, formatErrorMsg, new FormatException(formatErrorMsg));
}
Expand Down Expand Up @@ -155,7 +155,7 @@ private static Queue<string> PrepareWork(IEnumerable<string> dtmis)
{
if (!DtmiConventions.IsDtmi(dtmi))
{
ResolverEventSource.Instance.InvalidDtmiInput(dtmi);
ModelsRepoEventSource.Instance.InvalidDtmiInput(dtmi);
string invalidArgMsg = string.Format(CultureInfo.CurrentCulture, ServiceStrings.InvalidDtmiFormat, dtmi);
throw new ResolverException(dtmi, invalidArgMsg, new ArgumentException(invalidArgMsg));
}
Expand Down
Loading