Esempio n. 1
0
        public async virtual Task <DeviceUpdateInstanceCreateOperation> CreateOrUpdateAsync(string instanceName, DeviceUpdateInstanceData instance, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (instanceName == null)
            {
                throw new ArgumentNullException(nameof(instanceName));
            }
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            using var scope = _clientDiagnostics.CreateScope("DeviceUpdateInstanceCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _deviceUpdateInstancesRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, instanceName, instance, cancellationToken).ConfigureAwait(false);

                var operation = new DeviceUpdateInstanceCreateOperation(Parent, _clientDiagnostics, Pipeline, _deviceUpdateInstancesRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, instanceName, instance).Request, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Esempio n. 2
0
        public async Task CreateInstances()
        {
            #region Snippet:Managing_Instances_CreateAnInstance
            // Create a new account
            string accountName = "myAccount";
            DeviceUpdateAccountData            input1 = new DeviceUpdateAccountData(Location.WestUS2);
            DeviceUpdateAccountCreateOperation lro1   = await resourceGroup.GetDeviceUpdateAccounts().CreateOrUpdateAsync(accountName, input1);

            DeviceUpdateAccount account = lro1.Value;
            // Get the instance collection from the specific account and create an instance
            string instanceName             = "myInstance";
            DeviceUpdateInstanceData input2 = new DeviceUpdateInstanceData(Location.WestUS2);
            input2.IotHubs.Add(new IotHubSettings("/subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/..."));
            DeviceUpdateInstanceCreateOperation lro2 = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(instanceName, input2);

            DeviceUpdateInstance instance = lro2.Value;
            #endregion Snippet:Managing_Instances_CreateAnInstance
        }