| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using System.Xml.Linq; |
| | 12 | | using Azure.Core; |
| | 13 | | using Azure.Core.Pipeline; |
| | 14 | | using Azure.Data.Tables.Models; |
| | 15 | |
|
| | 16 | | namespace Azure.Data.Tables |
| | 17 | | { |
| | 18 | | internal partial class ServiceRestClient |
| | 19 | | { |
| | 20 | | private string url; |
| | 21 | | private string version; |
| | 22 | | private ClientDiagnostics _clientDiagnostics; |
| | 23 | | private HttpPipeline _pipeline; |
| | 24 | |
|
| | 25 | | /// <summary> Initializes a new instance of ServiceRestClient. </summary> |
| | 26 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 27 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 28 | | /// <param name="url"> The URL of the service account or table that is the targe of the desired operation. </par |
| | 29 | | /// <param name="version"> Specifies the version of the operation to use for this request. </param> |
| | 30 | | /// <exception cref="ArgumentNullException"> <paramref name="url"/> or <paramref name="version"/> is null. </exc |
| 944 | 31 | | public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version |
| | 32 | | { |
| 944 | 33 | | if (url == null) |
| | 34 | | { |
| 0 | 35 | | throw new ArgumentNullException(nameof(url)); |
| | 36 | | } |
| 944 | 37 | | if (version == null) |
| | 38 | | { |
| 0 | 39 | | throw new ArgumentNullException(nameof(version)); |
| | 40 | | } |
| | 41 | |
|
| 944 | 42 | | this.url = url; |
| 944 | 43 | | this.version = version; |
| 944 | 44 | | _clientDiagnostics = clientDiagnostics; |
| 944 | 45 | | _pipeline = pipeline; |
| 944 | 46 | | } |
| | 47 | |
|
| | 48 | | internal HttpMessage CreateSetPropertiesRequest(TableServiceProperties tableServiceProperties, int? timeout, str |
| | 49 | | { |
| 4 | 50 | | var message = _pipeline.CreateMessage(); |
| 4 | 51 | | var request = message.Request; |
| 4 | 52 | | request.Method = RequestMethod.Put; |
| 4 | 53 | | var uri = new RawRequestUriBuilder(); |
| 4 | 54 | | uri.AppendRaw(url, false); |
| 4 | 55 | | uri.AppendPath("/", false); |
| 4 | 56 | | uri.AppendQuery("restype", "service", true); |
| 4 | 57 | | uri.AppendQuery("comp", "properties", true); |
| 4 | 58 | | if (timeout != null) |
| | 59 | | { |
| 0 | 60 | | uri.AppendQuery("timeout", timeout.Value, true); |
| | 61 | | } |
| 4 | 62 | | request.Uri = uri; |
| 4 | 63 | | request.Headers.Add("x-ms-version", version); |
| 4 | 64 | | if (requestId != null) |
| | 65 | | { |
| 0 | 66 | | request.Headers.Add("x-ms-client-request-id", requestId); |
| | 67 | | } |
| 4 | 68 | | request.Headers.Add("Content-Type", "application/xml"); |
| 4 | 69 | | var content = new XmlWriterContent(); |
| 4 | 70 | | content.XmlWriter.WriteObjectValue(tableServiceProperties, "StorageServiceProperties"); |
| 4 | 71 | | request.Content = content; |
| 4 | 72 | | return message; |
| | 73 | | } |
| | 74 | |
|
| | 75 | | /// <summary> Sets properties for an account's Table service endpoint, including properties for Analytics a |
| | 76 | | /// <param name="tableServiceProperties"> The Table Service properties. </param> |
| | 77 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 78 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 79 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 80 | | /// <exception cref="ArgumentNullException"> <paramref name="tableServiceProperties"/> is null. </exception> |
| | 81 | | public async Task<ResponseWithHeaders<ServiceSetPropertiesHeaders>> SetPropertiesAsync(TableServiceProperties ta |
| | 82 | | { |
| 2 | 83 | | if (tableServiceProperties == null) |
| | 84 | | { |
| 0 | 85 | | throw new ArgumentNullException(nameof(tableServiceProperties)); |
| | 86 | | } |
| | 87 | |
|
| 2 | 88 | | using var message = CreateSetPropertiesRequest(tableServiceProperties, timeout, requestId); |
| 2 | 89 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 90 | | var headers = new ServiceSetPropertiesHeaders(message.Response); |
| 2 | 91 | | switch (message.Response.Status) |
| | 92 | | { |
| | 93 | | case 202: |
| 2 | 94 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 95 | | default: |
| 0 | 96 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 97 | | } |
| 2 | 98 | | } |
| | 99 | |
|
| | 100 | | /// <summary> Sets properties for an account's Table service endpoint, including properties for Analytics a |
| | 101 | | /// <param name="tableServiceProperties"> The Table Service properties. </param> |
| | 102 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 103 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 104 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 105 | | /// <exception cref="ArgumentNullException"> <paramref name="tableServiceProperties"/> is null. </exception> |
| | 106 | | public ResponseWithHeaders<ServiceSetPropertiesHeaders> SetProperties(TableServiceProperties tableServicePropert |
| | 107 | | { |
| 2 | 108 | | if (tableServiceProperties == null) |
| | 109 | | { |
| 0 | 110 | | throw new ArgumentNullException(nameof(tableServiceProperties)); |
| | 111 | | } |
| | 112 | |
|
| 2 | 113 | | using var message = CreateSetPropertiesRequest(tableServiceProperties, timeout, requestId); |
| 2 | 114 | | _pipeline.Send(message, cancellationToken); |
| 2 | 115 | | var headers = new ServiceSetPropertiesHeaders(message.Response); |
| 2 | 116 | | switch (message.Response.Status) |
| | 117 | | { |
| | 118 | | case 202: |
| 2 | 119 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 120 | | default: |
| 0 | 121 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 122 | | } |
| 2 | 123 | | } |
| | 124 | |
|
| | 125 | | internal HttpMessage CreateGetPropertiesRequest(int? timeout, string requestId) |
| | 126 | | { |
| 24 | 127 | | var message = _pipeline.CreateMessage(); |
| 24 | 128 | | var request = message.Request; |
| 24 | 129 | | request.Method = RequestMethod.Get; |
| 24 | 130 | | var uri = new RawRequestUriBuilder(); |
| 24 | 131 | | uri.AppendRaw(url, false); |
| 24 | 132 | | uri.AppendPath("/", false); |
| 24 | 133 | | uri.AppendQuery("restype", "service", true); |
| 24 | 134 | | uri.AppendQuery("comp", "properties", true); |
| 24 | 135 | | if (timeout != null) |
| | 136 | | { |
| 0 | 137 | | uri.AppendQuery("timeout", timeout.Value, true); |
| | 138 | | } |
| 24 | 139 | | request.Uri = uri; |
| 24 | 140 | | request.Headers.Add("x-ms-version", version); |
| 24 | 141 | | if (requestId != null) |
| | 142 | | { |
| 0 | 143 | | request.Headers.Add("x-ms-client-request-id", requestId); |
| | 144 | | } |
| 24 | 145 | | return message; |
| | 146 | | } |
| | 147 | |
|
| | 148 | | /// <summary> Gets the properties of an account's Table service, including properties for Analytics and COR |
| | 149 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 150 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 151 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 152 | | public async Task<ResponseWithHeaders<TableServiceProperties, ServiceGetPropertiesHeaders>> GetPropertiesAsync(i |
| | 153 | | { |
| 12 | 154 | | using var message = CreateGetPropertiesRequest(timeout, requestId); |
| 12 | 155 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 12 | 156 | | var headers = new ServiceGetPropertiesHeaders(message.Response); |
| 12 | 157 | | switch (message.Response.Status) |
| | 158 | | { |
| | 159 | | case 200: |
| | 160 | | { |
| 12 | 161 | | TableServiceProperties value = default; |
| 12 | 162 | | var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); |
| 12 | 163 | | if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) |
| | 164 | | { |
| 12 | 165 | | value = TableServiceProperties.DeserializeTableServiceProperties(storageServicePropertiesEle |
| | 166 | | } |
| 12 | 167 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 168 | | } |
| | 169 | | default: |
| 0 | 170 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 171 | | } |
| 12 | 172 | | } |
| | 173 | |
|
| | 174 | | /// <summary> Gets the properties of an account's Table service, including properties for Analytics and COR |
| | 175 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 176 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 177 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 178 | | public ResponseWithHeaders<TableServiceProperties, ServiceGetPropertiesHeaders> GetProperties(int? timeout = nul |
| | 179 | | { |
| 12 | 180 | | using var message = CreateGetPropertiesRequest(timeout, requestId); |
| 12 | 181 | | _pipeline.Send(message, cancellationToken); |
| 12 | 182 | | var headers = new ServiceGetPropertiesHeaders(message.Response); |
| 12 | 183 | | switch (message.Response.Status) |
| | 184 | | { |
| | 185 | | case 200: |
| | 186 | | { |
| 12 | 187 | | TableServiceProperties value = default; |
| 12 | 188 | | var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); |
| 12 | 189 | | if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) |
| | 190 | | { |
| 12 | 191 | | value = TableServiceProperties.DeserializeTableServiceProperties(storageServicePropertiesEle |
| | 192 | | } |
| 12 | 193 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 194 | | } |
| | 195 | | default: |
| 0 | 196 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 197 | | } |
| 12 | 198 | | } |
| | 199 | |
|
| | 200 | | internal HttpMessage CreateGetStatisticsRequest(int? timeout, string requestId) |
| | 201 | | { |
| 4 | 202 | | var message = _pipeline.CreateMessage(); |
| 4 | 203 | | var request = message.Request; |
| 4 | 204 | | request.Method = RequestMethod.Get; |
| 4 | 205 | | var uri = new RawRequestUriBuilder(); |
| 4 | 206 | | uri.AppendRaw(url, false); |
| 4 | 207 | | uri.AppendPath("/", false); |
| 4 | 208 | | uri.AppendQuery("restype", "service", true); |
| 4 | 209 | | uri.AppendQuery("comp", "stats", true); |
| 4 | 210 | | if (timeout != null) |
| | 211 | | { |
| 0 | 212 | | uri.AppendQuery("timeout", timeout.Value, true); |
| | 213 | | } |
| 4 | 214 | | request.Uri = uri; |
| 4 | 215 | | request.Headers.Add("x-ms-version", version); |
| 4 | 216 | | if (requestId != null) |
| | 217 | | { |
| 0 | 218 | | request.Headers.Add("x-ms-client-request-id", requestId); |
| | 219 | | } |
| 4 | 220 | | return message; |
| | 221 | | } |
| | 222 | |
|
| | 223 | | /// <summary> Retrieves statistics related to replication for the Table service. It is only available on the sec |
| | 224 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 225 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 226 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 227 | | public async Task<ResponseWithHeaders<TableServiceStatistics, ServiceGetStatisticsHeaders>> GetStatisticsAsync(i |
| | 228 | | { |
| 2 | 229 | | using var message = CreateGetStatisticsRequest(timeout, requestId); |
| 2 | 230 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 231 | | var headers = new ServiceGetStatisticsHeaders(message.Response); |
| 2 | 232 | | switch (message.Response.Status) |
| | 233 | | { |
| | 234 | | case 200: |
| | 235 | | { |
| 2 | 236 | | TableServiceStatistics value = default; |
| 2 | 237 | | var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); |
| 2 | 238 | | if (document.Element("StorageServiceStats") is XElement storageServiceStatsElement) |
| | 239 | | { |
| 2 | 240 | | value = TableServiceStatistics.DeserializeTableServiceStatistics(storageServiceStatsElement) |
| | 241 | | } |
| 2 | 242 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 243 | | } |
| | 244 | | default: |
| 0 | 245 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 246 | | } |
| 2 | 247 | | } |
| | 248 | |
|
| | 249 | | /// <summary> Retrieves statistics related to replication for the Table service. It is only available on the sec |
| | 250 | | /// <param name="timeout"> The timeout parameter is expressed in seconds. </param> |
| | 251 | | /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recor |
| | 252 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 253 | | public ResponseWithHeaders<TableServiceStatistics, ServiceGetStatisticsHeaders> GetStatistics(int? timeout = nul |
| | 254 | | { |
| 2 | 255 | | using var message = CreateGetStatisticsRequest(timeout, requestId); |
| 2 | 256 | | _pipeline.Send(message, cancellationToken); |
| 2 | 257 | | var headers = new ServiceGetStatisticsHeaders(message.Response); |
| 2 | 258 | | switch (message.Response.Status) |
| | 259 | | { |
| | 260 | | case 200: |
| | 261 | | { |
| 2 | 262 | | TableServiceStatistics value = default; |
| 2 | 263 | | var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); |
| 2 | 264 | | if (document.Element("StorageServiceStats") is XElement storageServiceStatsElement) |
| | 265 | | { |
| 2 | 266 | | value = TableServiceStatistics.DeserializeTableServiceStatistics(storageServiceStatsElement) |
| | 267 | | } |
| 2 | 268 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 269 | | } |
| | 270 | | default: |
| 0 | 271 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 272 | | } |
| 2 | 273 | | } |
| | 274 | | } |
| | 275 | | } |