示例#1
0
        private async Task DeleteUpdateStepAsync(string provider, string name, string version)
        {
            Console.WriteLine("Deleting the update...");
            Operation <BinaryData> operationResponse = await _updatesClient.DeleteUpdateAsync(true, provider, name, version);

            string operationId = GetJobIdFromLocationHeader(operationResponse.GetRawResponse());

            Console.WriteLine($"Delete operation id: {operationId}");

            Console.WriteLine("Waiting for delete to finish...");
            var repeat = true;

            while (repeat)
            {
                Response getResponse = await _updatesClient.GetOperationAsync(operationId);

                var operationDoc = JsonDocument.Parse(getResponse.Content.ToMemory());
                switch (operationDoc.RootElement.GetProperty("status").GetString())
                {
                case "Succeeded":
                    Console.WriteLine();
                    repeat = false;
                    break;

                case "Failed":
                    throw new ApplicationException("Delete failed with error: \n" + JsonConvert.SerializeObject(operationDoc.RootElement.ToString(), Formatting.Indented));

                default:
                    Console.Write(".");
                    await Task.Delay(GetRetryAfterFromResponse(getResponse));

                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Device Update for IoT Hub Sample: Delete update version
        /// </summary>
        /// <param name="updateVersion">Update version to delete.</param>
        static async Task Main(string updateVersion)
        {
            Console.WriteLine("Device Update for IoT Hub Sample: Delete update version");
            Console.WriteLine();

            if (string.IsNullOrWhiteSpace(updateVersion))
            {
                throw new ArgumentException("You have to provider a valid update version.");
            }

            var credentials = new InteractiveBrowserCredential(Constant.TenantId, Constant.ClientId);
            var client      = new DeviceUpdateClient(Constant.AccountEndpoint, Constant.Instance, credentials);

            Console.WriteLine("Deleting update:");
            Console.WriteLine($"    Provider: {Constant.Provider}");
            Console.WriteLine($"    Name    : {Constant.Name}");
            Console.WriteLine($"    Version : {updateVersion}");

            try
            {
                var response = await client.DeleteUpdateAsync(true, Constant.Provider, Constant.Name, updateVersion);

                var doc = JsonDocument.Parse(response.Value.ToMemory());
                Console.WriteLine(doc.RootElement.GetProperty("status").ToString());
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine(e);
                throw;
            }
        }