public async Task <bool> DeleteDeviceGroupAsync(AzureSphereTenant tenant, AzureSphereDeviceGroup deviceGroup, CancellationToken cancellationToken)
        {
            Console.WriteLine("DeleteDeviceGroupAsync()");

            var jsonString = await MethodAsync($"v2/tenants/{tenant.Id}/devicegroups/{deviceGroup.Id}", Method.DELETE, null, null, cancellationToken);

            Console.WriteLine(jsonString);
            var operation = new AzureSphereOperation(JObject.Parse(jsonString));

            return(await GetAsyncOperation(tenant, operation.OperationId, cancellationToken));
        }
        public async Task <bool> PostDeployAsync(AzureSphereTenant tenant, AzureSphereDeviceGroup deviceGroup, HttpContent jsonContent,
                                                 CancellationToken cancellationToken)
        {
            Console.WriteLine("PostDeployAsync()");

            var jsonString = await MethodAsync($"v2/tenants/{tenant.Id}/devicegroups/{deviceGroup.Id}/deployments",
                                               Method.POST,
                                               jsonContent,
                                               null,
                                               cancellationToken);

            Console.WriteLine(jsonString);
            var operation = new AzureSphereOperation(JObject.Parse(jsonString));

            return(await GetAsyncOperation(tenant, operation.OperationId, cancellationToken));
        }
        public async Task <bool> PostCreateProductGroupAsync(AzureSphereTenant tenant, HttpContent jsonContent,
                                                             CancellationToken cancellationToken)
        {
            Console.WriteLine("PostCreateProductAsync()");

            var jsonString = await MethodAsync($"v2/tenants/{tenant.Id}/products",
                                               Method.POST,
                                               jsonContent,
                                               null,
                                               cancellationToken);

            Console.WriteLine(jsonString);
            var operation = new AzureSphereOperation(JObject.Parse(jsonString));

            return(await GetAsyncOperation(tenant, operation.OperationId, cancellationToken));
        }
        private async Task <bool> GetAsyncOperation(AzureSphereTenant tenant, string operationId, CancellationToken cancellationToken)
        {
            bool continueOperationAsync = true;
            bool ret = false;

            while (continueOperationAsync)
            {
                var jsonString = await MethodAsync($"v2/tenants/{tenant.Id}/operations/{operationId}",
                                                   Method.GET,
                                                   null,
                                                   null,
                                                   cancellationToken);

                Console.WriteLine("GetAsyncOperation()");
                Console.WriteLine(jsonString);
                var      operation = new AzureSphereOperation(JObject.Parse(jsonString));
                StateNum state     = (StateNum)operation.State;

                switch (state)
                {
                case StateNum.Complete:
                    ret = true;
                    continueOperationAsync = false;
                    break;

                case StateNum.Failed:
                    ret = false;
                    continueOperationAsync = false;
                    break;

                default:
                    break;
                }
            }
            return(ret);
        }