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
Address comments
  • Loading branch information
azabbasi committed Jun 18, 2020
commit 2d00ceca99ca6ab5b7dda46e080b19861be69f79
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<DeviceIdentity> CreateDeviceIdentityAsync(string deviceId)
// Call APIs to create the device identity.
Response<DeviceIdentity> response = await IoTHubServiceClient.Devices.CreateOrUpdateIdentityAsync(deviceIdentity);

SampleLogger.PrintSuccessfulEvent($"Successfully create a new device identity with Id: '{deviceId}'");
SampleLogger.PrintSuccess($"Successfully create a new device identity with Id: '{deviceId}'");

return response.Value;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task<ModuleIdentity> CreateModuleIdentityAsync(DeviceIdentity devic
// Call APIs to create the module identity.
Response<ModuleIdentity> response = await IoTHubServiceClient.Modules.CreateOrUpdateIdentityAsync(moduleIdentity);

SampleLogger.PrintSuccessfulEvent($"Successfully create a new module identity with Id: '{moduleId}'");
SampleLogger.PrintSuccess($"Successfully created a new module identity with Id: '{moduleId}'");

return response.Value;
}
Expand Down Expand Up @@ -150,6 +150,10 @@ public Task InvokeMethodAsync()
return Task.CompletedTask;
}

/// <summary>
/// Deletes a module identity
/// </summary>
/// <param name="moduleIdentity">Module identity to delete</param>
public async Task DeleteModuleIdentityAsync(ModuleIdentity moduleIdentity)
{
SampleLogger.PrintHeader("DELETE MODULE IDENTITY");
Expand All @@ -159,9 +163,10 @@ public async Task DeleteModuleIdentityAsync(ModuleIdentity moduleIdentity)
Console.WriteLine($"Deleting module identity with Id: '{moduleIdentity.ModuleId}'");

// Call APIs to delete the module identity.
// We use UnconditionalIfMatch to force delete the Module Identity (disregard the IfMatch ETag)
Response response = await IoTHubServiceClient.Modules.DeleteIdentityAsync(moduleIdentity, IfMatchPrecondition.UnconditionalIfMatch);

SampleLogger.PrintSuccessfulEvent($"Successfully deleted module identity with Id: '{moduleIdentity.ModuleId}'");
SampleLogger.PrintSuccess($"Successfully deleted module identity with Id: '{moduleIdentity.ModuleId}'");
}
catch (Exception ex)
{
Expand All @@ -172,7 +177,7 @@ public async Task DeleteModuleIdentityAsync(ModuleIdentity moduleIdentity)
/// <summary>
/// Deletes a device identity
/// </summary>
/// <param name="deviceId">Device identity to delete</param>
/// <param name="deviceIdentity">Device identity to delete</param>
public async Task DeleteDeviceIdentityAsync(DeviceIdentity deviceIdentity)
{
SampleLogger.PrintHeader("DELETE DEVICE IDENTITY");
Expand All @@ -182,9 +187,10 @@ public async Task DeleteDeviceIdentityAsync(DeviceIdentity deviceIdentity)
Console.WriteLine($"Deleting device identity with Id: '{deviceIdentity.DeviceId}'");

// Call APIs to delete the device identity.
// We use UnconditionalIfMatch to force delete the Device Identity (disregard the IfMatch ETag)
Response response = await IoTHubServiceClient.Devices.DeleteIdentityAsync(deviceIdentity, IfMatchPrecondition.UnconditionalIfMatch);

SampleLogger.PrintSuccessfulEvent($"Successfully deleted device identity with Id: '{deviceIdentity.DeviceId}'");
SampleLogger.PrintSuccess($"Successfully deleted device identity with Id: '{deviceIdentity.DeviceId}'");
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ internal static void FatalError(string message)
Environment.Exit(0);
}

internal static void PrintSuccessfulEvent(string message)
internal static void PrintSuccess(string message)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($"\n{message}");
Console.WriteLine($"{message}");
Console.ResetColor();
}

Expand Down