Ejemplo n.º 1
0
        public virtual DeviceUpdateInstanceCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string instanceName, DeviceUpdateInstanceData instance, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(instanceName, nameof(instanceName));
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            using var scope = _deviceUpdateInstanceInstancesClientDiagnostics.CreateScope("DeviceUpdateInstanceCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _deviceUpdateInstanceInstancesRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, instanceName, instance, cancellationToken);
                var operation = new DeviceUpdateInstanceCreateOrUpdateOperation(ArmClient, _deviceUpdateInstanceInstancesClientDiagnostics, Pipeline, _deviceUpdateInstanceInstancesRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, instanceName, instance).Request, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async Task CreateInstances()
        {
            #region Snippet:Managing_Instances_CreateAnInstance
            // Create a new account
            string accountName             = "myAccount";
            DeviceUpdateAccountData input1 = new DeviceUpdateAccountData(AzureLocation.WestUS2);
            DeviceUpdateAccountCreateOrUpdateOperation lro1 = await resourceGroup.GetDeviceUpdateAccounts().CreateOrUpdateAsync(true, 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(AzureLocation.WestUS2);
            input2.IotHubs.Add(new IotHubSettings("/subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/..."));
            DeviceUpdateInstanceCreateOrUpdateOperation lro2 = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(true, instanceName, input2);

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