1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License. See License.txt in the project root for license information.
3+ // Code generated by Microsoft (R) AutoRest Code Generator.
4+ // Changes may cause incorrect behavior and will be lost if the code is regenerated.
5+
6+ namespace Microsoft . Azure . Management . DeviceProvisioningServices
7+ {
8+ using System . Linq ;
9+ using Microsoft . Rest ;
10+ using Microsoft . Rest . Azure ;
11+ using Models ;
12+
13+ /// <summary>
14+ /// DpsCertificatesOperations operations.
15+ /// </summary>
16+ internal partial class DpsCertificatesOperations : Microsoft . Rest . IServiceOperations < IotDpsClient > , IDpsCertificatesOperations
17+ {
18+ /// <summary>
19+ /// Initializes a new instance of the DpsCertificatesOperations class.
20+ /// </summary>
21+ /// <param name='client'>
22+ /// Reference to the service client.
23+ /// </param>
24+ /// <exception cref="System.ArgumentNullException">
25+ /// Thrown when a required parameter is null
26+ /// </exception>
27+ internal DpsCertificatesOperations ( IotDpsClient client )
28+ {
29+ if ( client == null )
30+ {
31+ throw new System . ArgumentNullException ( "client" ) ;
32+ }
33+ this . Client = client ;
34+ }
35+
36+ /// <summary>
37+ /// Gets a reference to the IotDpsClient
38+ /// </summary>
39+ public IotDpsClient Client { get ; private set ; }
40+
41+ /// <summary>
42+ /// Get all the certificates tied to the provisioning service.
43+ /// </summary>
44+ /// <param name='resourceGroupName'>
45+ /// Name of resource group.
46+ /// </param>
47+ /// <param name='provisioningServiceName'>
48+ /// Name of provisioning service to retrieve certificates for.
49+ /// </param>
50+ /// <param name='customHeaders'>
51+ /// Headers that will be added to request.
52+ /// </param>
53+ /// <param name='cancellationToken'>
54+ /// The cancellation token.
55+ /// </param>
56+ /// <exception cref="Microsoft.Rest.Azure.CloudException">
57+ /// Thrown when the operation returned an invalid status code
58+ /// </exception>
59+ /// <exception cref="Microsoft.Rest.SerializationException">
60+ /// Thrown when unable to deserialize the response
61+ /// </exception>
62+ /// <exception cref="Microsoft.Rest.ValidationException">
63+ /// Thrown when a required parameter is null
64+ /// </exception>
65+ /// <exception cref="System.ArgumentNullException">
66+ /// Thrown when a required parameter is null
67+ /// </exception>
68+ /// <return>
69+ /// A response object containing the response body and response headers.
70+ /// </return>
71+ public async System . Threading . Tasks . Task < Microsoft . Rest . Azure . AzureOperationResponse < CertificateListDescription > > ListWithHttpMessagesAsync ( string resourceGroupName , string provisioningServiceName , System . Collections . Generic . Dictionary < string , System . Collections . Generic . List < string > > customHeaders = null , System . Threading . CancellationToken cancellationToken = default ( System . Threading . CancellationToken ) )
72+ {
73+
74+
75+
76+
77+ if ( this . Client . SubscriptionId == null )
78+ {
79+ throw new Microsoft . Rest . ValidationException ( Microsoft . Rest . ValidationRules . CannotBeNull , "this.Client.SubscriptionId" ) ;
80+ }
81+
82+ if ( resourceGroupName == null )
83+ {
84+ throw new Microsoft . Rest . ValidationException ( Microsoft . Rest . ValidationRules . CannotBeNull , "resourceGroupName" ) ;
85+ }
86+
87+ if ( provisioningServiceName == null )
88+ {
89+ throw new Microsoft . Rest . ValidationException ( Microsoft . Rest . ValidationRules . CannotBeNull , "provisioningServiceName" ) ;
90+ }
91+
92+ if ( this . Client . ApiVersion == null )
93+ {
94+ throw new Microsoft . Rest . ValidationException ( Microsoft . Rest . ValidationRules . CannotBeNull , "this.Client.ApiVersion" ) ;
95+ }
96+
97+ // Tracing
98+ bool _shouldTrace = Microsoft . Rest . ServiceClientTracing . IsEnabled ;
99+ string _invocationId = null ;
100+ if ( _shouldTrace )
101+ {
102+ _invocationId = Microsoft . Rest . ServiceClientTracing . NextInvocationId . ToString ( ) ;
103+ System . Collections . Generic . Dictionary < string , object > tracingParameters = new System . Collections . Generic . Dictionary < string , object > ( ) ;
104+ tracingParameters . Add ( "resourceGroupName" , resourceGroupName ) ;
105+ tracingParameters . Add ( "provisioningServiceName" , provisioningServiceName ) ;
106+
107+
108+ tracingParameters . Add ( "cancellationToken" , cancellationToken ) ;
109+ Microsoft . Rest . ServiceClientTracing . Enter ( _invocationId , this , "List" , tracingParameters ) ;
110+ }
111+ // Construct URL
112+
113+ var _baseUrl = this . Client . BaseUri . AbsoluteUri ;
114+ var _url = new System . Uri ( new System . Uri ( _baseUrl + ( _baseUrl . EndsWith ( "/" ) ? "" : "/" ) ) , "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates" ) . ToString ( ) ;
115+ _url = _url . Replace ( "{subscriptionId}" , System . Uri . EscapeDataString ( this . Client . SubscriptionId ) ) ;
116+ _url = _url . Replace ( "{resourceGroupName}" , System . Uri . EscapeDataString ( resourceGroupName ) ) ;
117+ _url = _url . Replace ( "{provisioningServiceName}" , System . Uri . EscapeDataString ( provisioningServiceName ) ) ;
118+
119+ System . Collections . Generic . List < string > _queryParameters = new System . Collections . Generic . List < string > ( ) ;
120+ if ( this . Client . ApiVersion != null )
121+ {
122+ _queryParameters . Add ( string . Format ( "api-version={0}" , System . Uri . EscapeDataString ( this . Client . ApiVersion ) ) ) ;
123+ }
124+ if ( _queryParameters . Count > 0 )
125+ {
126+ _url += ( _url . Contains ( "?" ) ? "&" : "?" ) + string . Join ( "&" , _queryParameters ) ;
127+ }
128+ // Create HTTP transport objects
129+ var _httpRequest = new System . Net . Http . HttpRequestMessage ( ) ;
130+ System . Net . Http . HttpResponseMessage _httpResponse = null ;
131+ _httpRequest . Method = new System . Net . Http . HttpMethod ( "GET" ) ;
132+ _httpRequest . RequestUri = new System . Uri ( _url ) ;
133+ // Set Headers
134+ if ( this . Client . GenerateClientRequestId != null && this . Client . GenerateClientRequestId . Value )
135+ {
136+ _httpRequest . Headers . TryAddWithoutValidation ( "x-ms-client-request-id" , System . Guid . NewGuid ( ) . ToString ( ) ) ;
137+ }
138+ if ( this . Client . AcceptLanguage != null )
139+ {
140+ if ( _httpRequest . Headers . Contains ( "accept-language" ) )
141+ {
142+ _httpRequest . Headers . Remove ( "accept-language" ) ;
143+ }
144+ _httpRequest . Headers . TryAddWithoutValidation ( "accept-language" , this . Client . AcceptLanguage ) ;
145+ }
146+
147+ if ( customHeaders != null )
148+ {
149+ foreach ( var _header in customHeaders )
150+ {
151+ if ( _httpRequest . Headers . Contains ( _header . Key ) )
152+ {
153+ _httpRequest . Headers . Remove ( _header . Key ) ;
154+ }
155+ _httpRequest . Headers . TryAddWithoutValidation ( _header . Key , _header . Value ) ;
156+ }
157+ }
158+ // Serialize Request
159+ string _requestContent = null ;
160+ // Set Credentials
161+ if ( this . Client . Credentials != null )
162+ {
163+ cancellationToken . ThrowIfCancellationRequested ( ) ;
164+ await this . Client . Credentials . ProcessHttpRequestAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
165+ }
166+ // Send Request
167+ if ( _shouldTrace )
168+ {
169+ Microsoft . Rest . ServiceClientTracing . SendRequest ( _invocationId , _httpRequest ) ;
170+ }
171+ cancellationToken . ThrowIfCancellationRequested ( ) ;
172+ _httpResponse = await this . Client . HttpClient . SendAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
173+ if ( _shouldTrace )
174+ {
175+ Microsoft . Rest . ServiceClientTracing . ReceiveResponse ( _invocationId , _httpResponse ) ;
176+ }
177+
178+ System . Net . HttpStatusCode _statusCode = _httpResponse . StatusCode ;
179+ cancellationToken . ThrowIfCancellationRequested ( ) ;
180+ string _responseContent = null ;
181+
182+ if ( ( int ) _statusCode != 200 )
183+ {
184+ var ex = new ErrorDetailsException ( string . Format ( "Operation returned an invalid status code '{0}'" , _statusCode ) ) ;
185+ try
186+ {
187+ _responseContent = await _httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
188+ ErrorDetails _errorBody = Microsoft . Rest . Serialization . SafeJsonConvert . DeserializeObject < ErrorDetails > ( _responseContent , this . Client . DeserializationSettings ) ;
189+ if ( _errorBody != null )
190+ {
191+ ex . Body = _errorBody ;
192+ }
193+ }
194+ catch ( Newtonsoft . Json . JsonException )
195+ {
196+ // Ignore the exception
197+ }
198+ ex . Request = new Microsoft . Rest . HttpRequestMessageWrapper ( _httpRequest , _requestContent ) ;
199+ ex . Response = new Microsoft . Rest . HttpResponseMessageWrapper ( _httpResponse , _responseContent ) ;
200+ if ( _shouldTrace )
201+ {
202+ Microsoft . Rest . ServiceClientTracing . Error ( _invocationId , ex ) ;
203+ }
204+ _httpRequest . Dispose ( ) ;
205+ if ( _httpResponse != null )
206+ {
207+ _httpResponse . Dispose ( ) ;
208+ }
209+ throw ex ;
210+ }
211+ // Create Result
212+ var _result = new Microsoft . Rest . Azure . AzureOperationResponse < CertificateListDescription > ( ) ;
213+ _result . Request = _httpRequest ;
214+ _result . Response = _httpResponse ;
215+
216+ if ( _httpResponse . Headers . Contains ( "x-ms-request-id" ) )
217+ {
218+ _result . RequestId = _httpResponse . Headers . GetValues ( "x-ms-request-id" ) . FirstOrDefault ( ) ;
219+ }
220+ // Deserialize Response
221+ if ( ( int ) _statusCode == 200 )
222+ {
223+ _responseContent = await _httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
224+ try
225+ {
226+ _result . Body = Microsoft . Rest . Serialization . SafeJsonConvert . DeserializeObject < CertificateListDescription > ( _responseContent , this . Client . DeserializationSettings ) ;
227+ }
228+ catch ( Newtonsoft . Json . JsonException ex )
229+ {
230+ _httpRequest . Dispose ( ) ;
231+ if ( _httpResponse != null )
232+ {
233+ _httpResponse . Dispose ( ) ;
234+ }
235+ throw new Microsoft . Rest . SerializationException ( "Unable to deserialize the response." , _responseContent , ex ) ;
236+ }
237+ }
238+ if ( _shouldTrace )
239+ {
240+ Microsoft . Rest . ServiceClientTracing . Exit ( _invocationId , _result ) ;
241+ }
242+ return _result ;
243+
244+
245+
246+
247+
248+ }
249+ }
250+ }
0 commit comments