diff --git a/iothub/service/src/HttpRegistryManager.cs b/iothub/service/src/HttpRegistryManager.cs index bef9961e76..509608d8db 100644 --- a/iothub/service/src/HttpRegistryManager.cs +++ b/iothub/service/src/HttpRegistryManager.cs @@ -54,12 +54,12 @@ internal class HttpRegistryManager : RegistryManager private IHttpClientHelper _httpClientHelper; private readonly string _iotHubName; - internal HttpRegistryManager(IotHubConnectionString connectionString, HttpTransportSettings transportSettings) + internal HttpRegistryManager(IotHubConnectionProperties connectionProperties, HttpTransportSettings transportSettings) { - _iotHubName = connectionString.IotHubName; + _iotHubName = connectionProperties.IotHubName; _httpClientHelper = new HttpClientHelper( - connectionString.HttpsEndpoint, - connectionString, + connectionProperties.HttpsEndpoint, + connectionProperties, ExceptionHandlingHelper.GetDefaultErrorMapping(), s_defaultOperationTimeout, transportSettings.Proxy); @@ -735,7 +735,6 @@ public override Task UpdateDevices2Async(IEnumerabl { Logging.Exit(this, $"Updating multiple devices: count: {devices?.Count()} - Force update: {forceUpdate}", nameof(UpdateDevices2Async)); } - } public override Task RemoveDeviceAsync(string deviceId) @@ -937,7 +936,6 @@ public override Task GetRegistryStatisticsAsync(Cancellation return _httpClientHelper.GetAsync(GetStatisticsUri(), errorMappingOverrides, null, cancellationToken); } - catch (Exception ex) { Logging.Error(this, $"{nameof(GetRegistryStatisticsAsync)} threw an exception: {ex}", nameof(GetRegistryStatisticsAsync)); @@ -1037,7 +1035,6 @@ public override Task> GetModulesOnDeviceAsync(string deviceI try { - EnsureInstanceNotClosed(); return _httpClientHelper.GetAsync>( @@ -1473,7 +1470,6 @@ public override Task ImportDevicesAsync(JobProperties jobParamete Logging.Enter(this, $"Import Job running with {jobParameters}", nameof(ImportDevicesAsync)); try { - jobParameters.Type = JobType.ImportDevices; return CreateJobAsync(jobParameters, cancellationToken); } diff --git a/iothub/service/src/RegistryManager.cs b/iothub/service/src/RegistryManager.cs index be036bf286..71a8963a6e 100644 --- a/iothub/service/src/RegistryManager.cs +++ b/iothub/service/src/RegistryManager.cs @@ -7,6 +7,13 @@ using System.Threading.Tasks; using Microsoft.Azure.Devices.Shared; +#if !NET451 + +using Azure; +using Azure.Core; + +#endif + namespace Microsoft.Azure.Devices { /// @@ -46,6 +53,62 @@ public static RegistryManager CreateFromConnectionString(string connectionString return new HttpRegistryManager(iotHubConnectionString, transportSettings); } +#if !NET451 + + /// + /// Creates an instance of . + /// + /// IoT hub host name. + /// Azure Active Directory credentials to authenticate with IoT hub. See + /// The HTTP transport settings. + /// An instance of . + public static RegistryManager Create( + string hostName, + TokenCredential credential, + HttpTransportSettings transportSettings = default) + { + if (string.IsNullOrEmpty(hostName)) + { + throw new ArgumentNullException($"{nameof(hostName)} is null or empty"); + } + + if (credential == null) + { + throw new ArgumentNullException($"{nameof(credential)} is null"); + } + + var tokenCredentialProperties = new IotHubTokenCrendentialProperties(hostName, credential); + return new HttpRegistryManager(tokenCredentialProperties, transportSettings ?? new HttpTransportSettings()); + } + + /// + /// Creates an instance of . + /// + /// IoT hub host name. + /// Credential that generates a SAS token to authenticate with IoT hub. See + /// The HTTP transport settings. + /// An instance of . + public static RegistryManager Create( + string hostName, + IotHubSasCredential credential, + HttpTransportSettings transportSettings = default) + { + if (string.IsNullOrEmpty(hostName)) + { + throw new ArgumentNullException($"{nameof(hostName)} is null or empty"); + } + + if (credential == null) + { + throw new ArgumentNullException($"{nameof(credential)} is null"); + } + + var sasCredentialProperties = new IotHubSasCredentialProperties(hostName, credential); + return new HttpRegistryManager(sasCredentialProperties, transportSettings ?? new HttpTransportSettings()); + } + +#endif + /// public void Dispose() {