/// <summary> /// Update a module's twin. /// </summary> /// <param name="twinUpdate">The properties to update. Any existing properties not referenced by this patch will be unaffected by this patch.</param> /// <param name="precondition">The condition for which this operation will execute.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The new representation of the module's twin and the http response <see cref="Response{T}"/>.</returns> public virtual Response <TwinData> UpdateTwin(TwinData twinUpdate, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(twinUpdate, nameof(twinUpdate)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, twinUpdate.Etag); return(_modulesRestClient.UpdateTwin(twinUpdate.DeviceId, twinUpdate.ModuleId, twinUpdate, ifMatchHeaderValue, cancellationToken)); }
/// <summary> /// Create or update a twin configuration on the IoT Hub for automatic device/module management /// </summary> /// <param name="configuration">Twin configuration to update</param> /// <param name="precondition">The condition on which to perform this operation</param> /// In case of create, the condition must be equal to <see cref="IfMatchPrecondition.IfMatch"/>. /// In case of update, if no ETag is present on the twin configuration, then the condition must be equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>. /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The created automatic device/module management twin configuration</returns> public virtual Response <TwinConfiguration> CreateOrUpdateConfiguration(TwinConfiguration configuration, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(configuration, nameof(configuration)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, configuration.Etag); return(_configurationRestClient.CreateOrUpdate(configuration.Id, configuration, ifMatchHeaderValue, cancellationToken)); }
/// <summary> /// Deletes a twin configuration on the IoT Hub for automatic device/module management /// </summary> /// <param name="configuration">Twin configuration to delete</param> /// <param name="precondition">The condition on which to perform this operation. If no ETag is present on the twin configuration, then the condition must be equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>."/>.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The http response <see cref="Response{T}"/>.</returns> public virtual Task <Response> DeleteConfigurationAsync(TwinConfiguration configuration, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(configuration, nameof(configuration)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, configuration.Etag); return(_configurationRestClient.DeleteAsync(configuration.Id, ifMatchHeaderValue, cancellationToken)); }
/// <summary> /// Create a module identity. /// </summary> /// <param name="moduleIdentity">The module identity to create or update.</param> /// <param name="precondition">The condition on which to perform this operation. /// In case of create, the condition must be equal to <see cref="IfMatchPrecondition.IfMatch"/>. /// In case of update, if no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>. /// </param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The created module identity and the http response <see cref="Response{T}"/>.</returns> public virtual Response <ModuleIdentity> CreateOrUpdateIdentity( ModuleIdentity moduleIdentity, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(moduleIdentity, nameof(moduleIdentity)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, moduleIdentity.Etag); return(_modulesRestClient.CreateOrUpdateIdentity(moduleIdentity.DeviceId, moduleIdentity.ModuleId, moduleIdentity, ifMatchHeaderValue, cancellationToken)); }
/// <summary> /// Create or update a device identity. /// </summary> /// <param name="deviceIdentity">the device identity to create or update.</param> /// <param name="precondition">The condition on which to perform this operation. /// In case of create, the condition must be equal to <see cref="IfMatchPrecondition.IfMatch"/>. /// In case of update, if no ETag is present on the device, then the condition must be equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>. /// </param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The created device identity and the http response <see cref="Response{T}"/>.</returns> /// <code snippet="Snippet:IotHubCreateDeviceIdentity"> /// Response<DeviceIdentity> response = await IoTHubServiceClient.Devices.CreateOrUpdateIdentityAsync(deviceIdentity); /// /// SampleLogger.PrintSuccess($"Successfully create a new device identity with Id: '{response.Value.DeviceId}', ETag: '{response.Value.Etag}'"); /// </code> /// <code snippet="Snippet:IotHubUpdateDeviceIdentity"> /// Response<DeviceIdentity> getResponse = await IoTHubServiceClient.Devices.GetIdentityAsync(deviceId); /// /// DeviceIdentity deviceIdentity = getResponse.Value; /// Console.WriteLine($"Current device identity: DeviceId: '{deviceIdentity.DeviceId}', Status: '{deviceIdentity.Status}', ETag: '{deviceIdentity.Etag}'"); /// /// Console.WriteLine($"Updating device identity with Id: '{deviceIdentity.DeviceId}'. Disabling device so it cannot connect to IoT Hub."); /// deviceIdentity.Status = DeviceStatus.Disabled; /// /// Response<DeviceIdentity> response = await IoTHubServiceClient.Devices.CreateOrUpdateIdentityAsync(deviceIdentity); /// /// DeviceIdentity updatedDevice = response.Value; /// /// SampleLogger.PrintSuccess($"Successfully updated device identity: DeviceId: '{updatedDevice.DeviceId}', DeviceId: '{updatedDevice.DeviceId}', Status: '{updatedDevice.Status}', ETag: '{updatedDevice.Etag}'"); /// </code> public virtual Task <Response <DeviceIdentity> > CreateOrUpdateIdentityAsync( DeviceIdentity deviceIdentity, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(deviceIdentity, nameof(deviceIdentity)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, deviceIdentity.Etag); return(_devicesRestClient.CreateOrUpdateIdentityAsync(deviceIdentity.DeviceId, deviceIdentity, ifMatchHeaderValue, cancellationToken)); }
/// <summary> /// Delete a single module identity. /// </summary> /// <param name="moduleIdentity">The module identity to delete. If no ETag is present on the module identity, then the condition must be equal to <see cref="IfMatchPrecondition.UnconditionalIfMatch"/>.</param> /// <param name="precondition">The condition on which to delete the module identity.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The http response <see cref="Response{T}"/>.</returns> public virtual Response DeleteIdentity( ModuleIdentity moduleIdentity, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(moduleIdentity, nameof(moduleIdentity)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, moduleIdentity.Etag); return(_registryManagerClient.DeleteModule(moduleIdentity.DeviceId, moduleIdentity.ModuleId, ifMatchHeaderValue, cancellationToken)); }
/// <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.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 <see cref="Response{T}"/>.</returns> public virtual Task <Response> DeleteIdentityAsync( DeviceIdentity deviceIdentity, IfMatchPrecondition precondition = IfMatchPrecondition.IfMatch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(deviceIdentity, nameof(deviceIdentity)); string ifMatchHeaderValue = IfMatchPreconditionExtensions.GetIfMatchHeaderValue(precondition, deviceIdentity.Etag); return(_registryManagerClient.DeleteDeviceAsync(deviceIdentity.DeviceId, ifMatchHeaderValue, cancellationToken)); }