/// <summary> /// Create multiple modules with an initial twin. A maximum of 100 creations can be done per call, /// and each creation must have a unique module identity. Multiple modules may be created on a single device. /// All devices that these new modules will belong to must already exist. /// For larger scale operations, consider using <see href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities">IoT Hub jobs</see>. /// </summary> /// <param name="modules">The pairs of modules and their twins that will be created. For fields such as deviceId /// where device and twin have a definition, the device value will override the twin value.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The result of the bulk operation and the http response <see cref="Response{T}"/>.</returns> public virtual Response <BulkRegistryOperationResponse> CreateIdentitiesWithTwin(IDictionary <ModuleIdentity, TwinData> modules, CancellationToken cancellationToken = default) { IEnumerable <ExportImportDevice> registryOperations = modules .Select(x => new ExportImportDevice() { Id = x.Key.DeviceId, ModuleId = x.Key.ModuleId, Authentication = x.Key.Authentication, ImportMode = ExportImportDeviceImportMode.Create }.WithTags(x.Value.Tags).WithPropertiesFrom(x.Value.Properties)); return(_devicesRestClient.BulkRegistryOperations(registryOperations, cancellationToken)); }
/// <summary> /// Create multiple devices with an initial twin. A maximum of 100 creations can be done per call, and each creation must have a unique device identity. For larger scale operations, consider using <see href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities">IoT Hub jobs</see>. /// </summary> /// <param name="devices">The pairs of devices and their twins that will be created. For fields such as deviceId /// where device and twin have a definition, the device value will override the twin value.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The result of the bulk operation and the http response <see cref="Response{T}"/>.</returns> public virtual Response <BulkRegistryOperationResponse> CreateIdentitiesWithTwin(IDictionary <DeviceIdentity, TwinData> devices, CancellationToken cancellationToken = default) { IEnumerable <ExportImportDevice> registryOperations = devices .Select(x => new ExportImportDevice() { Id = x.Key.DeviceId, Authentication = x.Key.Authentication, Capabilities = x.Key.Capabilities, DeviceScope = x.Key.DeviceScope, Status = string.Equals(ExportImportDeviceStatus.Disabled.ToString(), x.Key.Status?.ToString(), StringComparison.OrdinalIgnoreCase) ? ExportImportDeviceStatus.Disabled : ExportImportDeviceStatus.Enabled, StatusReason = x.Key.StatusReason, ImportMode = ExportImportDeviceImportMode.Create }.WithTags(x.Value.Tags).WithPropertiesFrom(x.Value.Properties).WithParentScopes(x.Key.ParentScopes)); return(_devicesRestClient.BulkRegistryOperations(registryOperations, cancellationToken)); }