/// <summary> /// Clear registry /// </summary> private static async Task CleanupAsync(IIoTHubConfig config, bool includeSupervisors) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); var result = await registry.QueryAllDeviceTwinsAsync( "SELECT * from devices where IS_DEFINED(tags.DeviceType)"); foreach (var item in result) { Console.WriteLine($"Deleting {item.Id} {item.ModuleId ?? ""}"); await registry.DeleteAsync(item.Id, item.ModuleId, null, CancellationToken.None); } if (!includeSupervisors) { return; } var query = "SELECT * FROM devices.modules WHERE " + $"properties.reported.{TwinProperty.Type} = '{IdentityType.Supervisor}'"; var supers = await registry.QueryAllDeviceTwinsAsync(query); foreach (var item in supers) { Console.WriteLine($"Deleting {item.Id} {item.ModuleId ?? ""}"); await registry.DeleteAsync(item.Id, item.ModuleId, null, CancellationToken.None); } }
/// <summary> /// Clear registry /// </summary> private static async Task ClearSupervisorsAsync() { var logger = ConsoleOutLogger.Create(); var config = new IoTHubConfig(null); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); var query = "SELECT * FROM devices.modules WHERE " + $"properties.reported.{TwinProperty.Type} = '{IdentityType.Supervisor}'"; var supers = await registry.QueryAllDeviceTwinsAsync(query); foreach (var item in supers) { foreach (var tag in item.Tags.Keys.ToList()) { item.Tags[tag] = null; } foreach (var property in item.Properties.Desired.Keys.ToList()) { item.Properties.Desired[property] = null; } foreach (var property in item.Properties.Reported.Keys.ToList()) { if (!item.Properties.Desired.ContainsKey(property)) { item.Properties.Desired.Add(property, null); } } await registry.CreateAsync(item, true, CancellationToken.None); } }
/// <summary> /// Clear registry /// </summary> private static async Task ClearRegistryAsync() { var logger = ConsoleOutLogger.Create(); var config = new IoTHubConfig(null); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); var result = await registry.QueryAllDeviceTwinsAsync( "SELECT * from devices where IS_DEFINED(tags.DeviceType)"); foreach (var item in result) { await registry.DeleteAsync(item.Id, item.ModuleId, null, CancellationToken.None); } }
/// <summary> /// List all twin module identities /// </summary> private static async Task ListAsync(IIoTHubConfig config) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, new NewtonSoftJsonSerializer(), logger); var query = "SELECT * FROM devices.modules WHERE " + $"properties.reported.{TwinProperty.Type} = '{IdentityType.Supervisor}'"; var supers = await registry.QueryAllDeviceTwinsAsync(query); foreach (var item in supers) { Console.WriteLine($"{item.Id} {item.ModuleId}"); } }
/// <summary> /// List all twin module identities /// </summary> private static async Task ListAsync(IIoTHubConfig config) { var logger = LogEx.Console(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); var query = "SELECT * FROM devices.modules WHERE " + $"properties.reported.{TwinProperty.kType} = 'supervisor'"; var supers = await registry.QueryAllDeviceTwinsAsync(query); foreach (var item in supers) { Console.WriteLine($"{item.Id} {item.ModuleId}"); } }