Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix all warnings and make sure solution builds
  • Loading branch information
azabbasi committed Jun 10, 2020
commit 03a0a153f25a486147ad01a2ccf3d7cf7fe005ea
16 changes: 9 additions & 7 deletions sdk/iot/Azure.Iot.Hub.Service/src/DevicesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
Expand All @@ -15,6 +15,7 @@ namespace Azure.Iot.Hub.Service
/// <summary>
/// Device Client place holder
/// </summary>
//[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "String comes from the server.")]
public class DevicesClient
{
private const string ContinuationTokenHeader = "x-ms-continuation";
Expand Down Expand Up @@ -91,7 +92,7 @@ public virtual Response<DeviceIdentity> GetIdentity(string deviceId, Cancellatio
/// <summary>
/// Delete a single device identity.
/// </summary>
/// <param name="deviceIdentity">the device identity to delete. If no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.Unconditional"/> or equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/></param>
/// <param name="deviceIdentity">the device identity to delete. If no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.Unconditional"/> or equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>.</param>
/// <param name="precondition">The condition on which to delete the device.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The http response.</returns>
Expand All @@ -105,7 +106,7 @@ public virtual Task<Response> DeleteIdentityAsync(DeviceIdentity deviceIdentity,
/// <summary>
/// Delete a single device identity.
/// </summary>
/// <param name="deviceIdentity">the device identity to delete. If no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.Unconditional"/> or equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/></param>
/// <param name="deviceIdentity">the device identity to delete. If no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.Unconditional"/> or equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>.</param>
/// <param name="precondition">The condition on which to delete the device.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The http response.</returns>
Expand Down Expand Up @@ -322,6 +323,7 @@ public virtual Response<BulkRegistryOperationResponse> DeleteIdentities(IEnumera
return _registryManagerClient.BulkDeviceCrud(registryOperations, cancellationToken);
}


/// <summary>
/// List a set of device twins.
/// </summary>
Expand All @@ -336,7 +338,7 @@ async Task<Page<TwinData>> FirstPageFunc(int? pageSizeHint)
{
Query = "select * from devices"
};
Response<IReadOnlyList<TwinData>> response = await _registryManagerClient.QueryIotHubAsync(querySpecification, null, pageSizeHint?.ToString(), cancellationToken).ConfigureAwait(false);
Response<IReadOnlyList<TwinData>> response = await _registryManagerClient.QueryIotHubAsync(querySpecification, null, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);

return Page.FromValues(response.Value, continuationToken, response.GetRawResponse());
Expand All @@ -345,7 +347,7 @@ async Task<Page<TwinData>> FirstPageFunc(int? pageSizeHint)
async Task<Page<TwinData>> NextPageFunc(string nextLink, int? pageSizeHint)
{
var querySpecification = new QuerySpecification();
Response<IReadOnlyList<TwinData>> response = await _registryManagerClient.QueryIotHubAsync(querySpecification, nextLink, pageSizeHint?.ToString(), cancellationToken).ConfigureAwait(false);
Response<IReadOnlyList<TwinData>> response = await _registryManagerClient.QueryIotHubAsync(querySpecification, nextLink, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);
return Page.FromValues(response.Value, continuationToken, response.GetRawResponse());
}
Expand All @@ -368,7 +370,7 @@ Page<TwinData> FirstPageFunc(int? pageSizeHint)
Query = "select * from devices"
};

Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, null, pageSizeHint?.ToString(), cancellationToken);
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, null, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken);

response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);

Expand All @@ -378,7 +380,7 @@ Page<TwinData> FirstPageFunc(int? pageSizeHint)
Page<TwinData> NextPageFunc(string nextLink, int? pageSizeHint)
{
var querySpecification = new QuerySpecification();
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, nextLink, pageSizeHint?.ToString(), cancellationToken);
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, nextLink, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken);
response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);
return Page.FromValues(response.Value, continuationToken, response.GetRawResponse());
}
Expand Down
30 changes: 25 additions & 5 deletions sdk/iot/Azure.Iot.Hub.Service/src/IoTHubServiceClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.Core.Pipeline;

namespace Azure.Iot.Hub.Service
{
Expand All @@ -10,6 +12,12 @@ namespace Azure.Iot.Hub.Service
/// </summary>
public class IoTHubServiceClient
{
private readonly HttpPipeline _httpPipeline;
private readonly ClientDiagnostics _clientDiagnostics;
private readonly RegistryManagerRestClient _registryManagerRestClient;
private readonly TwinRestClient _twinRestClient;
private readonly DeviceMethodRestClient _deviceMethodRestClient;

/// <summary>
/// place holder for Devices
/// </summary>
Expand All @@ -35,23 +43,35 @@ public class IoTHubServiceClient
/// </summary>
public JobsClient Jobs { get; private set; }

protected IoTHubServiceClient()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IoTHubServiceClient"/> class.
/// </summary>
public IoTHubServiceClient()
: this(new IoTHubServiceClientOptions())
public IoTHubServiceClient(Uri endpoint)
: this(endpoint, new IoTHubServiceClientOptions())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IoTHubServiceClient"/> class.
/// </summary>
public IoTHubServiceClient(IoTHubServiceClientOptions options)
public IoTHubServiceClient(Uri endpoint, IoTHubServiceClientOptions options)
{
Argument.AssertNotNull(options, nameof(options));

Devices = new DevicesClient();
Modules = new ModulesClient();
_clientDiagnostics = new ClientDiagnostics(options);
_httpPipeline = HttpPipelineBuilder.Build(options);

_registryManagerRestClient = new RegistryManagerRestClient(_clientDiagnostics, _httpPipeline, endpoint, options.GetVersionString());
_twinRestClient = new TwinRestClient(_clientDiagnostics, _httpPipeline, null, options.GetVersionString());
_deviceMethodRestClient = new DeviceMethodRestClient(_clientDiagnostics, _httpPipeline, endpoint, options.GetVersionString());

Devices = new DevicesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);
Modules = new ModulesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);

Statistics = new StatisticsClient();
Messages = new CloudToDeviceMessagesClient();
Files = new FilesClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ public class IoTHubServiceClientOptions : ClientOptions
/// The versions of IoTHub Service supported by this client
/// library.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Service version is not controlled by the SDK")]
public enum ServiceVersion
{
/// <summary>
/// 2020-03-13
/// </summary>
#pragma warning disable CA1707 // Identifiers should not contain underscores
V2020_03_13 = 1
#pragma warning restore CA1707 // Identifiers should not contain underscores
}

/// <summary>
Expand Down
9 changes: 5 additions & 4 deletions sdk/iot/Azure.Iot.Hub.Service/src/ModulesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
Expand Down Expand Up @@ -167,7 +168,7 @@ async Task<Page<TwinData>> FirstPageFunc(int? pageSizeHint)
};

Response<IReadOnlyList<TwinData>> response =
await _registryManagerClient.QueryIotHubAsync(querySpecification, null, pageSizeHint?.ToString(), cancellationToken).ConfigureAwait(false);
await _registryManagerClient.QueryIotHubAsync(querySpecification, null, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);

response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);

Expand All @@ -179,7 +180,7 @@ async Task<Page<TwinData>> NextPageFunc(string nextLink, int? pageSizeHint)
var querySpecification = new QuerySpecification();

Response<IReadOnlyList<TwinData>> response =
await _registryManagerClient.QueryIotHubAsync(querySpecification, nextLink, pageSizeHint?.ToString(), cancellationToken).ConfigureAwait(false);
await _registryManagerClient.QueryIotHubAsync(querySpecification, nextLink, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);

response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);
return Page.FromValues(response.Value, continuationToken, response.GetRawResponse());
Expand All @@ -203,7 +204,7 @@ Page<TwinData> FirstPageFunc(int? pageSizeHint)
Query = "select * from modules"
};

Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, null, pageSizeHint?.ToString(), cancellationToken);
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, null, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken);

response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);

Expand All @@ -213,7 +214,7 @@ Page<TwinData> FirstPageFunc(int? pageSizeHint)
Page<TwinData> NextPageFunc(string nextLink, int? pageSizeHint)
{
var querySpecification = new QuerySpecification();
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, nextLink, pageSizeHint?.ToString(), cancellationToken);
Response<IReadOnlyList<TwinData>> response = _registryManagerClient.QueryIotHub(querySpecification, nextLink, pageSizeHint?.ToString(CultureInfo.InvariantCulture), cancellationToken);
response.GetRawResponse().Headers.TryGetValue(ContinuationTokenHeader, out string continuationToken);
return Page.FromValues(response.Value, continuationToken, response.GetRawResponse());
}
Expand Down