コード例 #1
0
        /// <summary>
        /// Delete multiple module identities.
        /// </summary>
        /// <param name="moduleIdentities">Collection of module identities to be deleted.</param>
        public async Task DeleteModuleIdentitiesAsync(IEnumerable <ModuleIdentity> moduleIdentities)
        {
            SampleLogger.PrintHeader("DELETE MODULE IDENTITIES");

            try
            {
                Console.WriteLine($"Deleting bulk module identities");

                #region Snippet:IotHubDeleteModuleIdentities

                Response <BulkRegistryOperationResponse> response = await IoTHubServiceClient.Modules.DeleteIdentitiesAsync(moduleIdentities);

                var bulkResponse = response.Value;

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

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

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

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