/// <summary> /// Add or get module identity /// </summary> private static async Task <ConnectionString> AddOrGetAsync(IIoTHubConfig config, string deviceId, string moduleId) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, new NewtonSoftJsonSerializer(), logger); try { await registry.CreateAsync(new DeviceTwinModel { Id = deviceId, Tags = new Dictionary <string, VariantValue> { [TwinProperty.Type] = IdentityType.Gateway }, Capabilities = new DeviceCapabilitiesModel { IotEdge = true } }, false, CancellationToken.None); } catch (ConflictingResourceException) { logger.Information("Gateway {deviceId} exists.", deviceId); } try { await registry.CreateAsync(new DeviceTwinModel { Id = deviceId, ModuleId = moduleId }, false, CancellationToken.None); } catch (ConflictingResourceException) { logger.Information("Module {moduleId} exists...", moduleId); } var cs = await registry.GetConnectionStringAsync(deviceId, moduleId); return(cs); }
/// <summary> /// Add or get module identity /// </summary> private static async Task <ConnectionString> AddOrGetAsync(IIoTHubConfig config, string deviceId, string moduleId) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); await registry.CreateAsync(new DeviceTwinModel { Id = deviceId, Tags = new Dictionary <string, JToken> { [TwinProperty.Type] = IdentityType.Gateway }, Capabilities = new DeviceCapabilitiesModel { IotEdge = true } }, true, CancellationToken.None); await registry.CreateAsync(new DeviceTwinModel { Id = deviceId, ModuleId = moduleId }, true, CancellationToken.None); var cs = await registry.GetConnectionStringAsync(deviceId, moduleId); return(cs); }
/// <summary> /// Get module connection string /// </summary> private static async Task GetAsync( IIoTHubConfig config, string deviceId, string moduleId) { var logger = ConsoleLogger.Create(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, new NewtonSoftJsonSerializer(), logger); var cs = await registry.GetConnectionStringAsync(deviceId, moduleId); Console.WriteLine(cs); }
/// <summary> /// Add or get supervisor identity /// </summary> private static async Task <ConnectionString> AddOrGetAsync(IIoTHubConfig config, string deviceId, string moduleId) { var logger = LogEx.Console(LogEventLevel.Error); var registry = new IoTHubServiceHttpClient(new HttpClient(logger), config, logger); await registry.CreateOrUpdateAsync(new DeviceTwinModel { Id = deviceId, ModuleId = moduleId, Capabilities = new DeviceCapabilitiesModel { IotEdge = true } }); var cs = await registry.GetConnectionStringAsync(deviceId, moduleId); return(cs); }