Exemple #1
0
        /// <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 Task <Response <BulkRegistryOperationResponse> > CreateIdentitiesWithTwinAsync(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,
                Tags           = x.Value.Tags,
                Properties     = new PropertyContainer(x.Value.Properties?.Desired, x.Value.Properties?.Reported),
                ImportMode     = ExportImportDeviceImportMode.Create
            });

            return(_registryManagerClient.BulkDeviceCrudAsync(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 Task <Response <BulkRegistryOperationResponse> > CreateIdentitiesWithTwinAsync(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,
                ParentScopes   = x.Key.ParentScopes,
                Status         = string.Equals(ExportImportDeviceStatus.Disabled.ToString(), x.Key.Status?.ToString(), StringComparison.OrdinalIgnoreCase)
                                ? ExportImportDeviceStatus.Disabled
                                : ExportImportDeviceStatus.Enabled,
                StatusReason = x.Key.StatusReason,
                Tags         = x.Value.Tags,
                Properties   = new PropertyContainer(x.Value.Properties?.Desired, x.Value.Properties?.Reported),
                ImportMode   = ExportImportDeviceImportMode.Create
            });

            return(_registryManagerClient.BulkDeviceCrudAsync(registryOperations, cancellationToken));
        }