1717 /// </summary>
1818 internal partial class GalleriesOperations : IServiceOperations < ComputeManagementClient > , IGalleriesOperations
1919 {
20+ public async Task < AzureOperationResponse < Gallery > > GetWithHttpMessagesAsync ( string resourceGroupName , string galleryName , string select , Dictionary < string , List < string > > customHeaders , CancellationToken cancellationToken = default ( CancellationToken ) )
21+ {
22+ if ( Client . SubscriptionId == null )
23+ {
24+ throw new ValidationException ( ValidationRules . CannotBeNull , "this.Client.SubscriptionId" ) ;
25+ }
26+ if ( resourceGroupName == null )
27+ {
28+ throw new ValidationException ( ValidationRules . CannotBeNull , "resourceGroupName" ) ;
29+ }
30+ if ( galleryName == null )
31+ {
32+ throw new ValidationException ( ValidationRules . CannotBeNull , "galleryName" ) ;
33+ }
34+ string apiVersion = "2021-10-01" ;
35+ // Tracing
36+ bool _shouldTrace = ServiceClientTracing . IsEnabled ;
37+ string _invocationId = null ;
38+ if ( _shouldTrace )
39+ {
40+ _invocationId = ServiceClientTracing . NextInvocationId . ToString ( ) ;
41+ Dictionary < string , object > tracingParameters = new Dictionary < string , object > ( ) ;
42+ tracingParameters . Add ( "resourceGroupName" , resourceGroupName ) ;
43+ tracingParameters . Add ( "galleryName" , galleryName ) ;
44+ tracingParameters . Add ( "apiVersion" , apiVersion ) ;
45+ tracingParameters . Add ( "select" , select ) ;
46+ tracingParameters . Add ( "cancellationToken" , cancellationToken ) ;
47+ ServiceClientTracing . Enter ( _invocationId , this , "Get" , tracingParameters ) ;
48+ }
49+ // Construct URL
50+ var _baseUrl = Client . BaseUri . AbsoluteUri ;
51+ var _url = new System . Uri ( new System . Uri ( _baseUrl + ( _baseUrl . EndsWith ( "/" ) ? "" : "/" ) ) , "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}" ) . ToString ( ) ;
52+ _url = _url . Replace ( "{subscriptionId}" , System . Uri . EscapeDataString ( Client . SubscriptionId ) ) ;
53+ _url = _url . Replace ( "{resourceGroupName}" , System . Uri . EscapeDataString ( resourceGroupName ) ) ;
54+ _url = _url . Replace ( "{galleryName}" , System . Uri . EscapeDataString ( galleryName ) ) ;
55+ List < string > _queryParameters = new List < string > ( ) ;
56+ if ( apiVersion != null )
57+ {
58+ _queryParameters . Add ( string . Format ( "api-version={0}" , System . Uri . EscapeDataString ( apiVersion ) ) ) ;
59+ }
60+ if ( select != null )
61+ {
62+ _queryParameters . Add ( string . Format ( "$select={0}" , System . Uri . EscapeDataString ( select ) ) ) ;
63+ }
64+ if ( _queryParameters . Count > 0 )
65+ {
66+ _url += ( _url . Contains ( "?" ) ? "&" : "?" ) + string . Join ( "&" , _queryParameters ) ;
67+ }
68+ // Create HTTP transport objects
69+ var _httpRequest = new HttpRequestMessage ( ) ;
70+ HttpResponseMessage _httpResponse = null ;
71+ _httpRequest . Method = new HttpMethod ( "GET" ) ;
72+ _httpRequest . RequestUri = new System . Uri ( _url ) ;
73+ // Set Headers
74+ if ( Client . GenerateClientRequestId != null && Client . GenerateClientRequestId . Value )
75+ {
76+ _httpRequest . Headers . TryAddWithoutValidation ( "x-ms-client-request-id" , System . Guid . NewGuid ( ) . ToString ( ) ) ;
77+ }
78+ if ( Client . AcceptLanguage != null )
79+ {
80+ if ( _httpRequest . Headers . Contains ( "accept-language" ) )
81+ {
82+ _httpRequest . Headers . Remove ( "accept-language" ) ;
83+ }
84+ _httpRequest . Headers . TryAddWithoutValidation ( "accept-language" , Client . AcceptLanguage ) ;
85+ }
86+
87+
88+ if ( customHeaders != null )
89+ {
90+ foreach ( var _header in customHeaders )
91+ {
92+ if ( _httpRequest . Headers . Contains ( _header . Key ) )
93+ {
94+ _httpRequest . Headers . Remove ( _header . Key ) ;
95+ }
96+ _httpRequest . Headers . TryAddWithoutValidation ( _header . Key , _header . Value ) ;
97+ }
98+ }
99+
100+ // Serialize Request
101+ string _requestContent = null ;
102+ // Set Credentials
103+ if ( Client . Credentials != null )
104+ {
105+ cancellationToken . ThrowIfCancellationRequested ( ) ;
106+ await Client . Credentials . ProcessHttpRequestAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
107+ }
108+ // Send Request
109+ if ( _shouldTrace )
110+ {
111+ ServiceClientTracing . SendRequest ( _invocationId , _httpRequest ) ;
112+ }
113+ cancellationToken . ThrowIfCancellationRequested ( ) ;
114+ _httpResponse = await Client . HttpClient . SendAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
115+ if ( _shouldTrace )
116+ {
117+ ServiceClientTracing . ReceiveResponse ( _invocationId , _httpResponse ) ;
118+ }
119+ HttpStatusCode _statusCode = _httpResponse . StatusCode ;
120+ cancellationToken . ThrowIfCancellationRequested ( ) ;
121+ string _responseContent = null ;
122+ if ( ( int ) _statusCode != 200 )
123+ {
124+ var ex = new CloudException ( string . Format ( "Operation returned an invalid status code '{0}'" , _statusCode ) ) ;
125+ try
126+ {
127+ _responseContent = await _httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
128+ CloudError _errorBody = Rest . Serialization . SafeJsonConvert . DeserializeObject < CloudError > ( _responseContent , Client . DeserializationSettings ) ;
129+ if ( _errorBody != null )
130+ {
131+ ex = new CloudException ( _errorBody . Message ) ;
132+ ex . Body = _errorBody ;
133+ }
134+ }
135+ catch ( JsonException )
136+ {
137+ // Ignore the exception
138+ }
139+ ex . Request = new HttpRequestMessageWrapper ( _httpRequest , _requestContent ) ;
140+ ex . Response = new HttpResponseMessageWrapper ( _httpResponse , _responseContent ) ;
141+ if ( _httpResponse . Headers . Contains ( "x-ms-request-id" ) )
142+ {
143+ ex . RequestId = _httpResponse . Headers . GetValues ( "x-ms-request-id" ) . FirstOrDefault ( ) ;
144+ }
145+ if ( _shouldTrace )
146+ {
147+ ServiceClientTracing . Error ( _invocationId , ex ) ;
148+ }
149+ _httpRequest . Dispose ( ) ;
150+ if ( _httpResponse != null )
151+ {
152+ _httpResponse . Dispose ( ) ;
153+ }
154+ throw ex ;
155+ }
156+ // Create Result
157+ var _result = new AzureOperationResponse < Gallery > ( ) ;
158+ _result . Request = _httpRequest ;
159+ _result . Response = _httpResponse ;
160+ if ( _httpResponse . Headers . Contains ( "x-ms-request-id" ) )
161+ {
162+ _result . RequestId = _httpResponse . Headers . GetValues ( "x-ms-request-id" ) . FirstOrDefault ( ) ;
163+ }
164+ // Deserialize Response
165+ if ( ( int ) _statusCode == 200 )
166+ {
167+ _responseContent = await _httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
168+ try
169+ {
170+ _result . Body = Rest . Serialization . SafeJsonConvert . DeserializeObject < Gallery > ( _responseContent , Client . DeserializationSettings ) ;
171+ }
172+ catch ( JsonException ex )
173+ {
174+ _httpRequest . Dispose ( ) ;
175+ if ( _httpResponse != null )
176+ {
177+ _httpResponse . Dispose ( ) ;
178+ }
179+ throw new SerializationException ( "Unable to deserialize the response." , _responseContent , ex ) ;
180+ }
181+ }
182+ if ( _shouldTrace )
183+ {
184+ ServiceClientTracing . Exit ( _invocationId , _result ) ;
185+ }
186+ return _result ;
187+ }
20188 /// <summary>
21189 /// Retrieves information about a Shared Image Gallery.
22190 /// </summary>
@@ -113,4 +281,4 @@ public async Task<AzureOperationResponse<Gallery>> GetWithHttpMessagesAsync(stri
113281 return await GetWithHttpMessagesAsync ( resourceGroupName , galleryName , default ( string ) , customHeaders , cancellationToken ) ;
114282 }
115283 }
116- }
284+ }
0 commit comments