Skip to content

Commit

Permalink
API accessors and naming updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drwill-ms committed Oct 17, 2022
1 parent b2fc709 commit fbc284b
Show file tree
Hide file tree
Showing 60 changed files with 242 additions and 238 deletions.
15 changes: 13 additions & 2 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ but users are still encouraged to migrate to version 2 when they have the chance
| Version 1 API | Equivalent version 2 API |
|:---|:---|
| `DeviceClient` | `IotHubDeviceClient` |
| `SetConnectionStatusChangesHandler` | `SetConnectionStatusChangeHandler` |
| `DeviceClient.SendEventAsync(...)` | `IotHubDeviceClient.SendTelemetryAsync(...)` |
| `DeviceClient.SendEventBatchAsync(...)` | `IotHubDeviceClient.SendTelemetryBatchAsync(...)` |
| `DeviceClient.SetConnectionStatusChangesHandler(...)` | `DeviceClient.ConnectionStatusChangeCallback` |
| `DeviceClient.SetReceiveMessageHandlerAsync(...)` | `DeviceClient.SetIncomingMessageCallbackAsync(...)` |
| `MessageResponse` | `MessageAcknowledgement` |
| `Message` | `IncomingMessage`, `OutgoingMessage` |
| `SetRetryPolicy(...)` | `IoTHubClientOptions.RetryPolicy` |
| `DeviceClient.SetRetryPolicy(...)` | `IotHubClientOptions.RetryPolicy` |
| `ExponentialBackOff` | `ExponentialBackOffRetryPolicy` |
| `Message.CreationTimeUtc` | `OutgoingMessage.CreatedOnUtc`, `IncomingMessage.CreatedOnUtc` |
| `Message.EnqueuedTimeUtc` | `OutgoingMessage.EnqueuedtimeUtc`, `IncomingMessage.EnqueuedTimeUtc` |
Expand Down Expand Up @@ -124,6 +127,7 @@ but users are still encouraged to migrate to version 2 when they have the chance
| `JobProperties.CreateForExportJob(...)` | `new JobProperties(Uri, bool)` |
| `RegistryManager.GetJobAsync(...)` | `IotHubServiceClient.Devices.GetJobAsync(...)` |
| `RegistryManager.CancelJobAsync(...)` | `IotHubServiceClient.Devices.CancelJobAsync(...)` |
| `JobProperties.Type` | `JobProperties.JobType` |

#### Other notable breaking changes

Expand All @@ -132,6 +136,8 @@ but users are still encouraged to migrate to version 2 when they have the chance
- `IotHubServiceClient.Query.CreateAsync<T>(...)` is now async.
- Call `QueryResponse<T>.MoveNextAsync()` in a loop (end when it returns `false`) and access `QueryResponse<T>.Current`.
- `JobProperties` properties that hold Azure Storage SAS URIs are now of type `System.Uri` instead of `string`.
- `JobProperties` has been split into several classes with only the necessary properties for the specified operation.
- See `ExportJobProperties`, `ImportJobProperties`, and `IotHubJobResponse`.

#### Notable additions

Expand Down Expand Up @@ -244,6 +250,11 @@ but users are still encouraged to migrate to version 2 when they have the chance
| `IndividualEnrollment.LastUpdatedDateTimeUtc` | `IndividualEnrollment.LastUpdatedOnUtc` |
| `Twin.StatusUpdatedOn` | `Twin.StatusUpdatedOnUtc` |
| `Twin.LastActivityOn` | `Twin.LastActiveOnUtc` |
| `X509Attestation.CreateFromCAReferences(...)` | `X509Attestation.CreateFromCaReferences(...)` |
| `X509Attestation.CAReferences` | `X509Attestation.CaReferences` |
| `X509CAReferences` | `X509CaReferences` |
| `X509CertificateInfo.SHA1Thumbprint` | `X509CertificateInfo.Sha1Thumbprint` |
| `X509CertificateInfo.SHA256Thumbprint` | `X509CertificateInfo.Sha256Thumbprint` |
| `TwinCollection.GetLastUpdatedOn()` | `TwinCollection.GetLastUpdatedOnUtc()` |
| `TwinCollectionArray.GetLastUpdatedOn()` | `TwinCollectionArray.GetLastUpdatedOnUtc()` |
| `TwinCollectionValue.GetLastUpdatedOn()` | `TwinCollectionValue.GetLastUpdatedOnUtc()` |
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/helpers/TestDeviceCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public async Task WaitForTwinCallbackAsync(CancellationToken ct)
public async Task SetMessageReceiveCallbackHandlerAsync()
{
await _deviceClient.OpenAsync().ConfigureAwait(false);
await _deviceClient.SetMessageCallbackAsync(OnC2dMessageReceivedAsync).ConfigureAwait(false);
await _deviceClient.SetIncomingMessageCallbackAsync(OnC2dMessageReceivedAsync).ConfigureAwait(false);
}

public async Task UnsetMessageReceiveCallbackHandlerAsync()
{
await _deviceClient.OpenAsync().ConfigureAwait(false);
await _deviceClient.SetMessageCallbackAsync(null).ConfigureAwait(false);
await _deviceClient.SetIncomingMessageCallbackAsync(null).ConfigureAwait(false);
}

private Task<MessageAcknowledgement> OnC2dMessageReceivedAsync(IncomingMessage message)
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/helpers/templates/FaultInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static bool FaultShouldDisconnect(string faultType)
faultDelay,
faultDuration);

await deviceClient.SendEventAsync(faultInjectionMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(faultInjectionMessage, cts.Token).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IotHubClientException hubEx && hubEx.IsTransient)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static class FaultInjectionPoolingOverAmqp
logger.Trace($"{nameof(FaultInjectionPoolingOverAmqp)}: {testDevices.First().Id} Requesting fault injection type={faultType} reason={reason}, delay={faultDelay}, duration={faultDuration}");
faultInjectionDuration.Start();
OutgoingMessage faultInjectionMessage = FaultInjection.ComposeErrorInjectionProperties(faultType, reason, faultDelay, faultDuration);
await deviceClients.First().SendEventAsync(faultInjectionMessage).ConfigureAwait(false);
await deviceClients.First().SendTelemetryAsync(faultInjectionMessage).ConfigureAwait(false);

logger.Trace($"{nameof(FaultInjection)}: Waiting for fault injection to be active: {faultDelay} seconds.");
await Task.Delay(faultDelay).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/CombinedClientOperationsPoolAmqpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
// D2C Operation
Logger.Trace($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 1: Send D2C for device={testDevice.Id}");
var message = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
Task sendD2cMessage = deviceClient.SendEventAsync(message);
Task sendD2cMessage = deviceClient.SendTelemetryAsync(message);
clientOperations.Add(sendD2cMessage);

// C2D Operation
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private async Task SendMessageTestAsync(IotHubClientTransportSettings transportS
using IotHubDeviceClient deviceClient = testDevice.CreateDeviceClient(new IotHubClientOptions(transportSetting));
await deviceClient.OpenAsync().ConfigureAwait(false);
var message = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
await deviceClient.SendEventAsync(message).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message).ConfigureAwait(false);
await deviceClient.CloseAsync().ConfigureAwait(false);
}

Expand Down
10 changes: 5 additions & 5 deletions e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task IotHubDeviceClient_TokenConnectionDoubleRelease_Ok()

Logger.Trace($"{deviceId}: DeviceClient SendEventAsync.");
var testMessage = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

Logger.Trace($"{deviceId}: DeviceClient CloseAsync.");
await deviceClient.CloseAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -166,7 +166,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
var timeout = TimeSpan.FromSeconds(sasTokenTimeToLive.TotalSeconds * 2);
using var cts1 = new CancellationTokenSource(timeout);
await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventAsync(message, cts1.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts1.Token).ConfigureAwait(false);

// Wait for the Token to expire.

Expand All @@ -179,7 +179,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
// Test that the client is able to send messages
Logger.Trace($"[{testDevice.Id}]: SendEventAsync (2)");
using var cts2 = new CancellationTokenSource(timeout);
await deviceClient.SendEventAsync(message, cts2.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts2.Token).ConfigureAwait(false);
}

private async Task IotHubDeviceClient_TokenIsRefreshed_Internal(IotHubClientTransportSettings transportSettings, TimeSpan ttl)
Expand Down Expand Up @@ -228,7 +228,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
await deviceClient.OpenAsync(cts.Token).ConfigureAwait(false);

Logger.Trace($"[{DateTime.UtcNow}] SendEventAsync (1)");
await deviceClient.SendEventAsync(message, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts.Token).ConfigureAwait(false);
await refresher.WaitForTokenRefreshAsync(cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException ex)
Expand All @@ -254,7 +254,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
try
{
Logger.Trace($"[{DateTime.UtcNow}] SendEventAsync (2)");
await deviceClient.SendEventAsync(message, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts.Token).ConfigureAwait(false);
await refresher.WaitForTokenRefreshAsync(cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ private async Task TestSecurityMessageModuleAsync(IotHubClientTransportSettings
await deviceClient.OpenAsync().ConfigureAwait(false);

OutgoingMessage testMessage = ComposeD2CSecurityTestMessage();
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

private async Task SendSingleSecurityMessageModuleAsync(
IotHubModuleClient moduleClient)
{
await moduleClient.OpenAsync().ConfigureAwait(false);
OutgoingMessage testMessage = ComposeD2CSecurityTestMessage();
await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false);
await moduleClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

protected override void Dispose(bool disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe

Logger.Trace($"{nameof(FaultInjectionPoolAmqpTests)}.{testDevice.Id}: payload='{payload}' p1Value='{p1Value}'");
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
await deviceClient.SendEventAsync(testMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage, cts.Token).ConfigureAwait(false);
}

await FaultInjectionPoolingOverAmqp
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static async Task VerifyReceivedC2dMessageAsync(IotHubDeviceClient dc, st
c2dMessageReceived.TrySetResult(message);
return Task.FromResult(MessageAcknowledgement.Complete);
};
await dc.SetMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);
await dc.SetIncomingMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);

IncomingMessage receivedMessage = await TaskCompletionSourceHelper.GetTaskCompletionSourceResultAsync(c2dMessageReceived, cts.Token).ConfigureAwait(false);

Expand Down Expand Up @@ -319,7 +319,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)

// This will make the client unsubscribe from the mqtt c2d topic/close the amqp c2d link. Neither event
// should close the connection as a whole, though.
await deviceClient.SetMessageCallbackAsync(null).ConfigureAwait(false);
await deviceClient.SetIncomingMessageCallbackAsync(null).ConfigureAwait(false);

await Task.Delay(1000).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/messaging/MessageSendE2EPoolAmqpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
{
OutgoingMessage testMessage = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string payload, out string p1Value);
Logger.Trace($"{nameof(MessageSendE2EPoolAmqpTests)}.{testDevice.Id}: messageId='{testMessage.MessageId}' payload='{payload}' p1Value='{p1Value}'");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

await PoolingOverAmqp
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/iothub/messaging/MessageSendE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static async Task SendSingleMessageAsync(IotHubDeviceClient deviceClient,
? ComposeD2cTestMessage(logger, out string _, out string _)
: ComposeD2cTestMessageOfSpecifiedSize(messageSize, logger, out string _, out string _);

await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

public static async Task SendBatchMessagesAsync(IotHubDeviceClient deviceClient, MsTestLogger logger)
Expand All @@ -218,14 +218,14 @@ public static async Task SendBatchMessagesAsync(IotHubDeviceClient deviceClient,
}

await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false);
await deviceClient.SendTelemetryBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false);
}

private async Task SendSingleMessageModuleAsync(IotHubModuleClient moduleClient)
{
OutgoingMessage testMessage = ComposeD2cTestMessage(Logger, out string _, out string _);

await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false);
await moduleClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

private async Task OpenCloseOpenThenSendSingleMessage(TestDeviceType type, IotHubClientTransportSettings transportSettings, int messageSize = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
{
OutgoingMessage testMessage = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
using var cts = new CancellationTokenSource(operationTimeout);
await deviceClient.SendEventAsync(testMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage, cts.Token).ConfigureAwait(false);
};

await FaultInjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static async Task TestDeviceClientInvalidServiceCertificate(IotHubClient
new IotHubClientOptions(transportSettings));
var testMessage = new OutgoingMessage();
await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
await deviceClient.CloseAsync().ConfigureAwait(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/MessageFeedbackReceiverE2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task MessageFeedbackReceiver_Operation(IotHubTransportProtocol prot
c2dMessageReceived.TrySetResult(true);
return Task.FromResult(MessageAcknowledgement.Complete);
};
await deviceClient.SetMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);
await deviceClient.SetIncomingMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);

await Task
.WhenAny(
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/provisioning/ProvisioningE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public static ProvisioningClientOptions CreateProvisioningClientOptionsFromName(
Logger.Trace("DeviceClient SendEventAsync.");

var testMessage = new OutgoingMessage("TestMessage");
await iotClient.SendEventAsync(testMessage).ConfigureAwait(false);
await iotClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

if (sendReportedPropertiesUpdate)
{
Expand Down
14 changes: 7 additions & 7 deletions e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ await RetryOperationHelper
attestationMechanism.Type.Should().Be(AttestationMechanismType.X509);

var x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
x509Attestation.GetPrimaryX509CertificateInfo().SHA1Thumbprint.Should().Be(((X509Attestation)individualEnrollment.Attestation).GetPrimaryX509CertificateInfo().SHA1Thumbprint);
x509Attestation.GetSecondaryX509CertificateInfo().SHA1Thumbprint.Should().Be(((X509Attestation)individualEnrollment.Attestation).GetSecondaryX509CertificateInfo().SHA1Thumbprint);
x509Attestation.GetPrimaryX509CertificateInfo().Sha1Thumbprint.Should().Be(((X509Attestation)individualEnrollment.Attestation).GetPrimaryX509CertificateInfo().Sha1Thumbprint);
x509Attestation.GetSecondaryX509CertificateInfo().Sha1Thumbprint.Should().Be(((X509Attestation)individualEnrollment.Attestation).GetSecondaryX509CertificateInfo().Sha1Thumbprint);
}
}
finally
Expand Down Expand Up @@ -261,12 +261,12 @@ await RetryOperationHelper
attestationMechanism.Type.Should().Be(AttestationMechanismType.X509);

var x509Attestation = (X509Attestation)attestationMechanism.GetAttestation();
x509Attestation.GetPrimaryX509CertificateInfo().SHA1Thumbprint
x509Attestation.GetPrimaryX509CertificateInfo().Sha1Thumbprint
.Should()
.Be(((X509Attestation)enrollmentGroup.Attestation).GetPrimaryX509CertificateInfo().SHA1Thumbprint);
x509Attestation.GetSecondaryX509CertificateInfo().SHA1Thumbprint
.Be(((X509Attestation)enrollmentGroup.Attestation).GetPrimaryX509CertificateInfo().Sha1Thumbprint);
x509Attestation.GetSecondaryX509CertificateInfo().Sha1Thumbprint
.Should()
.Be(((X509Attestation)enrollmentGroup.Attestation).GetSecondaryX509CertificateInfo().SHA1Thumbprint);
.Be(((X509Attestation)enrollmentGroup.Attestation).GetSecondaryX509CertificateInfo().Sha1Thumbprint);
}
}
finally
Expand All @@ -291,7 +291,7 @@ private static async Task ProvisioningServiceClient_IndividualEnrollments_Query_
while (query.HasNext())
{
QueryResult queryResult = await query.NextAsync().ConfigureAwait(false);
Assert.AreEqual(queryResult.Type, QueryResultType.Enrollment);
Assert.AreEqual(queryResult.QueryType, QueryResultType.Enrollment);
}
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/test/provisioning/ReprovisioningE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public async Task ProvisioningDeviceClient_ReprovisioningBlockingWorks_MqttWs_Sy
Logger.Trace("DeviceClient SendEventAsync.");

var message = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(message).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message).ConfigureAwait(false);

if (transportProtocolSupportsTwinOperations)
{
Expand Down Expand Up @@ -879,7 +879,7 @@ await RetryOperationHelper
Logger.Trace("DeviceClient SendEventAsync.");

var testMessage = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

// Twin can be configured to revert back to default twin when provisioned, or to keep twin
// from previous hub's records.
Expand Down

0 comments on commit fbc284b

Please sign in to comment.