コード例 #1
0
        /// <summary>
        /// Delete multiple device identities.
        /// </summary>
        /// <param name="deviceIdentities">Collection of device identities to be deleted.</param>
        public async Task DeleteDeviceIdentitiesAsync(IEnumerable <DeviceIdentity> deviceIdentities)
        {
            SampleLogger.PrintHeader("DELETE DEVICE IDENTITIES");

            try
            {
                #region Snippet:IotHubDeleteDeviceIdentities

                Console.WriteLine($"Deleting bulk device identities");

                Response <BulkRegistryOperationResponse> response = await IoTHubServiceClient.Devices.DeleteIdentitiesAsync(deviceIdentities);

                var bulkResponse = response.Value;

                if (bulkResponse.IsSuccessful ?? true)
                {
                    SampleLogger.PrintSuccess("Successfully deleted the device identities");
                }
                else
                {
                    SampleLogger.PrintWarning("Failed to delete the device identities");

                    foreach (var bulkOperationError in bulkResponse.Errors)
                    {
                        SampleLogger.PrintWarning($"Device id that failed: {bulkOperationError.DeviceId}, error code: {bulkOperationError.ErrorCode}");
                    }
                }

                #endregion Snippet:IotHubDeleteDeviceIdentities
            }
            catch (Exception ex)
            {
                // Try to cleanup before exiting with fatal error.
                await CleanupHelper.DeleteAllDevicesInHubAsync(IoTHubServiceClient);

                SampleLogger.FatalError($"Failed to device identity due to:\n{ex}");
            }
        }