< Summary

Class:Azure.Iot.Hub.Service.ConfigurationRestClient
Assembly:Azure.Iot.Hub.Service
File(s):C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\ConfigurationRestClient.cs
Covered lines:0
Uncovered lines:208
Coverable lines:208
Total lines:482
Line coverage:0% (0 of 208)
Covered branches:0
Total branches:66
Branch coverage:0% (0 of 66)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
CreateGetRequest(...)-0%100%
GetAsync()-0%0%
Get(...)-0%0%
CreateCreateOrUpdateRequest(...)-0%0%
CreateOrUpdateAsync()-0%0%
CreateOrUpdate(...)-0%0%
CreateDeleteRequest(...)-0%0%
DeleteAsync()-0%0%
Delete(...)-0%0%
CreateGetConfigurationsRequest(...)-0%0%
GetConfigurationsAsync()-0%0%
GetConfigurations(...)-0%0%
CreateTestQueriesRequest(...)-0%100%
TestQueriesAsync()-0%0%
TestQueries(...)-0%0%
CreateApplyOnEdgeDeviceRequest(...)-0%100%
ApplyOnEdgeDeviceAsync()-0%0%
ApplyOnEdgeDevice(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\ConfigurationRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Collections.Generic;
 10using System.Text.Json;
 11using System.Threading;
 12using System.Threading.Tasks;
 13using Azure;
 14using Azure.Core;
 15using Azure.Core.Pipeline;
 16using Azure.Iot.Hub.Service.Models;
 17
 18namespace Azure.Iot.Hub.Service
 19{
 20    internal partial class ConfigurationRestClient
 21    {
 22        private Uri endpoint;
 23        private string apiVersion;
 24        private ClientDiagnostics _clientDiagnostics;
 25        private HttpPipeline _pipeline;
 26
 27        /// <summary> Initializes a new instance of ConfigurationRestClient. </summary>
 28        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 29        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 30        /// <param name="endpoint"> server parameter. </param>
 31        /// <param name="apiVersion"> Api Version. </param>
 32        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 033        public ConfigurationRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, 
 34        {
 035            endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net");
 036            if (apiVersion == null)
 37            {
 038                throw new ArgumentNullException(nameof(apiVersion));
 39            }
 40
 041            this.endpoint = endpoint;
 042            this.apiVersion = apiVersion;
 043            _clientDiagnostics = clientDiagnostics;
 044            _pipeline = pipeline;
 045        }
 46
 47        internal HttpMessage CreateGetRequest(string id)
 48        {
 049            var message = _pipeline.CreateMessage();
 050            var request = message.Request;
 051            request.Method = RequestMethod.Get;
 052            var uri = new RawRequestUriBuilder();
 053            uri.Reset(endpoint);
 054            uri.AppendPath("/configurations/", false);
 055            uri.AppendPath(id, true);
 056            uri.AppendQuery("api-version", apiVersion, true);
 057            request.Uri = uri;
 058            return message;
 59        }
 60
 61        /// <summary> Gets a configuration on the IoT Hub for automatic device/module management. </summary>
 62        /// <param name="id"> The unique identifier of the configuration. </param>
 63        /// <param name="cancellationToken"> The cancellation token to use. </param>
 64        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 65        public async Task<Response<TwinConfiguration>> GetAsync(string id, CancellationToken cancellationToken = default
 66        {
 067            if (id == null)
 68            {
 069                throw new ArgumentNullException(nameof(id));
 70            }
 71
 072            using var message = CreateGetRequest(id);
 073            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 074            switch (message.Response.Status)
 75            {
 76                case 200:
 77                    {
 78                        TwinConfiguration value = default;
 079                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 080                        value = TwinConfiguration.DeserializeTwinConfiguration(document.RootElement);
 081                        return Response.FromValue(value, message.Response);
 82                    }
 83                default:
 084                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 85            }
 086        }
 87
 88        /// <summary> Gets a configuration on the IoT Hub for automatic device/module management. </summary>
 89        /// <param name="id"> The unique identifier of the configuration. </param>
 90        /// <param name="cancellationToken"> The cancellation token to use. </param>
 91        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 92        public Response<TwinConfiguration> Get(string id, CancellationToken cancellationToken = default)
 93        {
 094            if (id == null)
 95            {
 096                throw new ArgumentNullException(nameof(id));
 97            }
 98
 099            using var message = CreateGetRequest(id);
 0100            _pipeline.Send(message, cancellationToken);
 0101            switch (message.Response.Status)
 102            {
 103                case 200:
 104                    {
 105                        TwinConfiguration value = default;
 0106                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0107                        value = TwinConfiguration.DeserializeTwinConfiguration(document.RootElement);
 0108                        return Response.FromValue(value, message.Response);
 109                    }
 110                default:
 0111                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 112            }
 0113        }
 114
 115        internal HttpMessage CreateCreateOrUpdateRequest(string id, TwinConfiguration configuration, string ifMatch)
 116        {
 0117            var message = _pipeline.CreateMessage();
 0118            var request = message.Request;
 0119            request.Method = RequestMethod.Put;
 0120            var uri = new RawRequestUriBuilder();
 0121            uri.Reset(endpoint);
 0122            uri.AppendPath("/configurations/", false);
 0123            uri.AppendPath(id, true);
 0124            uri.AppendQuery("api-version", apiVersion, true);
 0125            request.Uri = uri;
 0126            if (ifMatch != null)
 127            {
 0128                request.Headers.Add("If-Match", ifMatch);
 129            }
 0130            request.Headers.Add("Content-Type", "application/json");
 0131            var content = new Utf8JsonRequestContent();
 0132            content.JsonWriter.WriteObjectValue(configuration);
 0133            request.Content = content;
 0134            return message;
 135        }
 136
 137        /// <summary> Creates or updates a configuration on the IoT Hub for automatic device/module management. Configur
 138        /// <param name="id"> The unique identifier of the configuration. </param>
 139        /// <param name="configuration"> The configuration to be created or updated. </param>
 140        /// <param name="ifMatch"> The string representing a weak ETag for configuration, as per RFC7232. This should no
 141        /// <param name="cancellationToken"> The cancellation token to use. </param>
 142        /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="configuration"/> is null. 
 143        public async Task<Response<TwinConfiguration>> CreateOrUpdateAsync(string id, TwinConfiguration configuration, s
 144        {
 0145            if (id == null)
 146            {
 0147                throw new ArgumentNullException(nameof(id));
 148            }
 0149            if (configuration == null)
 150            {
 0151                throw new ArgumentNullException(nameof(configuration));
 152            }
 153
 0154            using var message = CreateCreateOrUpdateRequest(id, configuration, ifMatch);
 0155            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0156            switch (message.Response.Status)
 157            {
 158                case 200:
 159                case 201:
 160                    {
 161                        TwinConfiguration value = default;
 0162                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0163                        value = TwinConfiguration.DeserializeTwinConfiguration(document.RootElement);
 0164                        return Response.FromValue(value, message.Response);
 165                    }
 166                default:
 0167                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 168            }
 0169        }
 170
 171        /// <summary> Creates or updates a configuration on the IoT Hub for automatic device/module management. Configur
 172        /// <param name="id"> The unique identifier of the configuration. </param>
 173        /// <param name="configuration"> The configuration to be created or updated. </param>
 174        /// <param name="ifMatch"> The string representing a weak ETag for configuration, as per RFC7232. This should no
 175        /// <param name="cancellationToken"> The cancellation token to use. </param>
 176        /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="configuration"/> is null. 
 177        public Response<TwinConfiguration> CreateOrUpdate(string id, TwinConfiguration configuration, string ifMatch = n
 178        {
 0179            if (id == null)
 180            {
 0181                throw new ArgumentNullException(nameof(id));
 182            }
 0183            if (configuration == null)
 184            {
 0185                throw new ArgumentNullException(nameof(configuration));
 186            }
 187
 0188            using var message = CreateCreateOrUpdateRequest(id, configuration, ifMatch);
 0189            _pipeline.Send(message, cancellationToken);
 0190            switch (message.Response.Status)
 191            {
 192                case 200:
 193                case 201:
 194                    {
 195                        TwinConfiguration value = default;
 0196                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0197                        value = TwinConfiguration.DeserializeTwinConfiguration(document.RootElement);
 0198                        return Response.FromValue(value, message.Response);
 199                    }
 200                default:
 0201                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 202            }
 0203        }
 204
 205        internal HttpMessage CreateDeleteRequest(string id, string ifMatch)
 206        {
 0207            var message = _pipeline.CreateMessage();
 0208            var request = message.Request;
 0209            request.Method = RequestMethod.Delete;
 0210            var uri = new RawRequestUriBuilder();
 0211            uri.Reset(endpoint);
 0212            uri.AppendPath("/configurations/", false);
 0213            uri.AppendPath(id, true);
 0214            uri.AppendQuery("api-version", apiVersion, true);
 0215            request.Uri = uri;
 0216            if (ifMatch != null)
 217            {
 0218                request.Headers.Add("If-Match", ifMatch);
 219            }
 0220            return message;
 221        }
 222
 223        /// <summary> Deletes a configuration on the IoT Hub for automatic device/module management. </summary>
 224        /// <param name="id"> The unique identifier of the configuration. </param>
 225        /// <param name="ifMatch"> The string representing a weak ETag for configuration, as per RFC7232. The delete ope
 226        /// <param name="cancellationToken"> The cancellation token to use. </param>
 227        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 228        public async Task<Response> DeleteAsync(string id, string ifMatch = null, CancellationToken cancellationToken = 
 229        {
 0230            if (id == null)
 231            {
 0232                throw new ArgumentNullException(nameof(id));
 233            }
 234
 0235            using var message = CreateDeleteRequest(id, ifMatch);
 0236            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0237            switch (message.Response.Status)
 238            {
 239                case 204:
 0240                    return message.Response;
 241                default:
 0242                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 243            }
 0244        }
 245
 246        /// <summary> Deletes a configuration on the IoT Hub for automatic device/module management. </summary>
 247        /// <param name="id"> The unique identifier of the configuration. </param>
 248        /// <param name="ifMatch"> The string representing a weak ETag for configuration, as per RFC7232. The delete ope
 249        /// <param name="cancellationToken"> The cancellation token to use. </param>
 250        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 251        public Response Delete(string id, string ifMatch = null, CancellationToken cancellationToken = default)
 252        {
 0253            if (id == null)
 254            {
 0255                throw new ArgumentNullException(nameof(id));
 256            }
 257
 0258            using var message = CreateDeleteRequest(id, ifMatch);
 0259            _pipeline.Send(message, cancellationToken);
 0260            switch (message.Response.Status)
 261            {
 262                case 204:
 0263                    return message.Response;
 264                default:
 0265                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 266            }
 0267        }
 268
 269        internal HttpMessage CreateGetConfigurationsRequest(int? top)
 270        {
 0271            var message = _pipeline.CreateMessage();
 0272            var request = message.Request;
 0273            request.Method = RequestMethod.Get;
 0274            var uri = new RawRequestUriBuilder();
 0275            uri.Reset(endpoint);
 0276            uri.AppendPath("/configurations", false);
 0277            if (top != null)
 278            {
 0279                uri.AppendQuery("top", top.Value, true);
 280            }
 0281            uri.AppendQuery("api-version", apiVersion, true);
 0282            request.Uri = uri;
 0283            return message;
 284        }
 285
 286        /// <summary> Gets configurations on the IoT Hub for automatic device/module management. Pagination is not suppo
 287        /// <param name="top"> The number of configurations to retrieve. Value will be overridden if greater than the ma
 288        /// <param name="cancellationToken"> The cancellation token to use. </param>
 289        public async Task<Response<IReadOnlyList<TwinConfiguration>>> GetConfigurationsAsync(int? top = null, Cancellati
 290        {
 0291            using var message = CreateGetConfigurationsRequest(top);
 0292            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0293            switch (message.Response.Status)
 294            {
 295                case 200:
 296                    {
 297                        IReadOnlyList<TwinConfiguration> value = default;
 0298                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0299                        List<TwinConfiguration> array = new List<TwinConfiguration>();
 0300                        foreach (var item in document.RootElement.EnumerateArray())
 301                        {
 0302                            array.Add(TwinConfiguration.DeserializeTwinConfiguration(item));
 303                        }
 0304                        value = array;
 0305                        return Response.FromValue(value, message.Response);
 306                    }
 307                default:
 0308                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 309            }
 0310        }
 311
 312        /// <summary> Gets configurations on the IoT Hub for automatic device/module management. Pagination is not suppo
 313        /// <param name="top"> The number of configurations to retrieve. Value will be overridden if greater than the ma
 314        /// <param name="cancellationToken"> The cancellation token to use. </param>
 315        public Response<IReadOnlyList<TwinConfiguration>> GetConfigurations(int? top = null, CancellationToken cancellat
 316        {
 0317            using var message = CreateGetConfigurationsRequest(top);
 0318            _pipeline.Send(message, cancellationToken);
 0319            switch (message.Response.Status)
 320            {
 321                case 200:
 322                    {
 323                        IReadOnlyList<TwinConfiguration> value = default;
 0324                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0325                        List<TwinConfiguration> array = new List<TwinConfiguration>();
 0326                        foreach (var item in document.RootElement.EnumerateArray())
 327                        {
 0328                            array.Add(TwinConfiguration.DeserializeTwinConfiguration(item));
 329                        }
 0330                        value = array;
 0331                        return Response.FromValue(value, message.Response);
 332                    }
 333                default:
 0334                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 335            }
 0336        }
 337
 338        internal HttpMessage CreateTestQueriesRequest(ConfigurationQueriesTestInput input)
 339        {
 0340            var message = _pipeline.CreateMessage();
 0341            var request = message.Request;
 0342            request.Method = RequestMethod.Post;
 0343            var uri = new RawRequestUriBuilder();
 0344            uri.Reset(endpoint);
 0345            uri.AppendPath("/configurations/testQueries", false);
 0346            uri.AppendQuery("api-version", apiVersion, true);
 0347            request.Uri = uri;
 0348            request.Headers.Add("Content-Type", "application/json");
 0349            var content = new Utf8JsonRequestContent();
 0350            content.JsonWriter.WriteObjectValue(input);
 0351            request.Content = content;
 0352            return message;
 353        }
 354
 355        /// <summary> Validates target condition and custom metric queries for a configuration on the IoT Hub. </summary
 356        /// <param name="input"> The configuration for target condition and custom metric queries. </param>
 357        /// <param name="cancellationToken"> The cancellation token to use. </param>
 358        /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception>
 359        public async Task<Response<ConfigurationQueriesTestResponse>> TestQueriesAsync(ConfigurationQueriesTestInput inp
 360        {
 0361            if (input == null)
 362            {
 0363                throw new ArgumentNullException(nameof(input));
 364            }
 365
 0366            using var message = CreateTestQueriesRequest(input);
 0367            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0368            switch (message.Response.Status)
 369            {
 370                case 200:
 371                    {
 372                        ConfigurationQueriesTestResponse value = default;
 0373                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0374                        value = ConfigurationQueriesTestResponse.DeserializeConfigurationQueriesTestResponse(document.Ro
 0375                        return Response.FromValue(value, message.Response);
 376                    }
 377                default:
 0378                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 379            }
 0380        }
 381
 382        /// <summary> Validates target condition and custom metric queries for a configuration on the IoT Hub. </summary
 383        /// <param name="input"> The configuration for target condition and custom metric queries. </param>
 384        /// <param name="cancellationToken"> The cancellation token to use. </param>
 385        /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception>
 386        public Response<ConfigurationQueriesTestResponse> TestQueries(ConfigurationQueriesTestInput input, CancellationT
 387        {
 0388            if (input == null)
 389            {
 0390                throw new ArgumentNullException(nameof(input));
 391            }
 392
 0393            using var message = CreateTestQueriesRequest(input);
 0394            _pipeline.Send(message, cancellationToken);
 0395            switch (message.Response.Status)
 396            {
 397                case 200:
 398                    {
 399                        ConfigurationQueriesTestResponse value = default;
 0400                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0401                        value = ConfigurationQueriesTestResponse.DeserializeConfigurationQueriesTestResponse(document.Ro
 0402                        return Response.FromValue(value, message.Response);
 403                    }
 404                default:
 0405                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 406            }
 0407        }
 408
 409        internal HttpMessage CreateApplyOnEdgeDeviceRequest(string id, ConfigurationContent content)
 410        {
 0411            var message = _pipeline.CreateMessage();
 0412            var request = message.Request;
 0413            request.Method = RequestMethod.Post;
 0414            var uri = new RawRequestUriBuilder();
 0415            uri.Reset(endpoint);
 0416            uri.AppendPath("/devices/", false);
 0417            uri.AppendPath(id, true);
 0418            uri.AppendPath("/applyConfigurationContent", false);
 0419            uri.AppendQuery("api-version", apiVersion, true);
 0420            request.Uri = uri;
 0421            request.Headers.Add("Content-Type", "application/json");
 0422            var content0 = new Utf8JsonRequestContent();
 0423            content0.JsonWriter.WriteObjectValue(content);
 0424            request.Content = content0;
 0425            return message;
 426        }
 427
 428        /// <summary> Applies the configuration content to an edge device. </summary>
 429        /// <param name="id"> The unique identifier of the edge device. </param>
 430        /// <param name="content"> The configuration content. </param>
 431        /// <param name="cancellationToken"> The cancellation token to use. </param>
 432        /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="content"/> is null. </exce
 433        public async Task<Response> ApplyOnEdgeDeviceAsync(string id, ConfigurationContent content, CancellationToken ca
 434        {
 0435            if (id == null)
 436            {
 0437                throw new ArgumentNullException(nameof(id));
 438            }
 0439            if (content == null)
 440            {
 0441                throw new ArgumentNullException(nameof(content));
 442            }
 443
 0444            using var message = CreateApplyOnEdgeDeviceRequest(id, content);
 0445            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0446            switch (message.Response.Status)
 447            {
 448                case 204:
 0449                    return message.Response;
 450                default:
 0451                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 452            }
 0453        }
 454
 455        /// <summary> Applies the configuration content to an edge device. </summary>
 456        /// <param name="id"> The unique identifier of the edge device. </param>
 457        /// <param name="content"> The configuration content. </param>
 458        /// <param name="cancellationToken"> The cancellation token to use. </param>
 459        /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="content"/> is null. </exce
 460        public Response ApplyOnEdgeDevice(string id, ConfigurationContent content, CancellationToken cancellationToken =
 461        {
 0462            if (id == null)
 463            {
 0464                throw new ArgumentNullException(nameof(id));
 465            }
 0466            if (content == null)
 467            {
 0468                throw new ArgumentNullException(nameof(content));
 469            }
 470
 0471            using var message = CreateApplyOnEdgeDeviceRequest(id, content);
 0472            _pipeline.Send(message, cancellationToken);
 0473            switch (message.Response.Status)
 474            {
 475                case 204:
 0476                    return message.Response;
 477                default:
 0478                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 479            }
 0480        }
 481    }
 482}