| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq.Expressions; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using Azure.Core; |
| | 10 | | using Azure.Core.Pipeline; |
| | 11 | | using Azure.Data.Tables.Models; |
| | 12 | | using Azure.Data.Tables.Queryable; |
| | 13 | | using Azure.Data.Tables.Sas; |
| | 14 | |
|
| | 15 | | namespace Azure.Data.Tables |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// The <see cref="TableClient"/> allows you to interact with Azure Storage |
| | 19 | | /// Tables. |
| | 20 | | /// </summary> |
| | 21 | | public class TableClient |
| | 22 | | { |
| | 23 | | private readonly string _table; |
| | 24 | | private readonly OdataMetadataFormat _format; |
| | 25 | | private readonly ClientDiagnostics _diagnostics; |
| | 26 | | private readonly TableRestClient _tableOperations; |
| | 27 | | private readonly string _version; |
| | 28 | | private readonly bool _isPremiumEndpoint; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the <see cref="TableClient"/>. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="tableName">The name of the table with which this client instance will interact.</param> |
| | 34 | | /// <param name="endpoint"> |
| | 35 | | /// A <see cref="Uri"/> referencing the table service account. |
| | 36 | | /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}. |
| | 37 | | /// </param> |
| | 38 | | /// <param name="options"> |
| | 39 | | /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that |
| | 40 | | /// </param> |
| | 41 | | /// <exception cref="ArgumentException"><paramref name="endpoint"/> is not https.</exception> |
| | 42 | | public TableClient(string tableName, Uri endpoint, TableClientOptions options = null) |
| 8 | 43 | | : this(tableName, endpoint, default(TableSharedKeyPipelinePolicy), options) |
| | 44 | | { |
| 8 | 45 | | Argument.AssertNotNull(tableName, nameof(tableName)); |
| | 46 | |
|
| 8 | 47 | | if (endpoint.Scheme != "https") |
| | 48 | | { |
| 4 | 49 | | throw new ArgumentException("Cannot use TokenCredential without HTTPS.", nameof(endpoint)); |
| | 50 | | } |
| 4 | 51 | | } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Initializes a new instance of the <see cref="TableClient"/>. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name="tableName">The name of the table with which this client instance will interact.</param> |
| | 57 | | /// <param name="endpoint"> |
| | 58 | | /// A <see cref="Uri"/> referencing the table service account. |
| | 59 | | /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}. |
| | 60 | | /// </param> |
| | 61 | | /// <param name="credential">The shared key credential used to sign requests.</param> |
| | 62 | | /// <exception cref="ArgumentNullException"><paramref name="tableName"/> or <paramref name="credential"/> is nul |
| | 63 | | public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential credential) |
| 20 | 64 | | : this(tableName, endpoint, new TableSharedKeyPipelinePolicy(credential), null) |
| | 65 | | { |
| 12 | 66 | | Argument.AssertNotNull(tableName, nameof(tableName)); |
| 12 | 67 | | Argument.AssertNotNull(credential, nameof(credential)); |
| 8 | 68 | | } |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// Initializes a new instance of the <see cref="TableClient"/>. |
| | 72 | | /// </summary> |
| | 73 | | /// <param name="tableName">The name of the table with which this client instance will interact.</param> |
| | 74 | | /// <param name="endpoint"> |
| | 75 | | /// A <see cref="Uri"/> referencing the table service account. |
| | 76 | | /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}. |
| | 77 | | /// </param> |
| | 78 | | /// <param name="credential">The shared key credential used to sign requests.</param> |
| | 79 | | /// <param name="options"> |
| | 80 | | /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that |
| | 81 | | /// </param> |
| | 82 | | /// <exception cref="ArgumentNullException"><paramref name="tableName"/> or <paramref name="credential"/> is nul |
| | 83 | | public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential credential, TableClientOptions optio |
| 4 | 84 | | : this(tableName, endpoint, new TableSharedKeyPipelinePolicy(credential), options) |
| | 85 | | { |
| 4 | 86 | | Argument.AssertNotNull(tableName, nameof(tableName)); |
| 4 | 87 | | Argument.AssertNotNull(credential, nameof(credential)); |
| 4 | 88 | | } |
| | 89 | |
|
| 32 | 90 | | internal TableClient(string tableName, Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions opt |
| | 91 | | { |
| 32 | 92 | | Argument.AssertNotNull(tableName, nameof(tableName)); |
| 28 | 93 | | Argument.AssertNotNull(endpoint, nameof(endpoint)); |
| | 94 | |
|
| 24 | 95 | | options ??= new TableClientOptions(); |
| 24 | 96 | | HttpPipeline pipeline = HttpPipelineBuilder.Build(options, policy); |
| | 97 | |
|
| 24 | 98 | | _diagnostics = new ClientDiagnostics(options); |
| 24 | 99 | | _tableOperations = new TableRestClient(_diagnostics, pipeline, endpoint.ToString()); |
| 24 | 100 | | _version = options.VersionString; |
| 24 | 101 | | _table = tableName; |
| 24 | 102 | | _format = OdataMetadataFormat.ApplicationJsonOdataFullmetadata; |
| 24 | 103 | | _isPremiumEndpoint = TableServiceClient.IsPremiumEndpoint(endpoint); |
| | 104 | | ; |
| 24 | 105 | | } |
| | 106 | |
|
| 408 | 107 | | internal TableClient(string table, TableRestClient tableOperations, string version, ClientDiagnostics diagnostic |
| | 108 | | { |
| 408 | 109 | | _tableOperations = tableOperations; |
| 408 | 110 | | _version = version; |
| 408 | 111 | | _table = table; |
| 408 | 112 | | _format = OdataMetadataFormat.ApplicationJsonOdataFullmetadata; |
| 408 | 113 | | _diagnostics = diagnostics; |
| 408 | 114 | | _isPremiumEndpoint = isPremiumEndpoint; |
| 408 | 115 | | } |
| | 116 | |
|
| | 117 | | /// <summary> |
| | 118 | | /// Initializes a new instance of the <see cref="TableClient"/> |
| | 119 | | /// class for mocking. |
| | 120 | | /// </summary> |
| 408 | 121 | | protected TableClient() |
| 408 | 122 | | { } |
| | 123 | |
|
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Gets a <see cref="TableSasBuilder"/> instance scoped to the current table. |
| | 127 | | /// </summary> |
| | 128 | | /// <param name="permissions"><see cref="TableSasPermissions"/> containing the allowed permissions.</param> |
| | 129 | | /// <param name="expiresOn">The time at which the shared access signature becomes invalid.</param> |
| | 130 | | /// <returns>An instance of <see cref="TableSasBuilder"/>.</returns> |
| | 131 | | public virtual TableSasBuilder GetSasBuilder(TableSasPermissions permissions, DateTimeOffset expiresOn) |
| | 132 | | { |
| 12 | 133 | | return new TableSasBuilder(_table, permissions, expiresOn) { Version = _version }; |
| | 134 | | } |
| | 135 | |
|
| | 136 | | /// <summary> |
| | 137 | | /// Gets a <see cref="TableSasBuilder"/> instance scoped to the current table. |
| | 138 | | /// </summary> |
| | 139 | | /// <param name="rawPermissions">The permissions associated with the shared access signature. This string should |
| | 140 | | /// <param name="expiresOn">The time at which the shared access signature becomes invalid.</param> |
| | 141 | | /// <returns>An instance of <see cref="TableSasBuilder"/>.</returns> |
| | 142 | | public virtual TableSasBuilder GetSasBuilder(string rawPermissions, DateTimeOffset expiresOn) |
| | 143 | | { |
| 4 | 144 | | return new TableSasBuilder(_table, rawPermissions, expiresOn) { Version = _version }; |
| | 145 | | } |
| | 146 | |
|
| | 147 | | /// <summary> |
| | 148 | | /// Creates the current table. |
| | 149 | | /// </summary> |
| | 150 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 151 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 152 | | /// <returns>A <see cref="TableItem"/> containing properties of the table</returns> |
| | 153 | | public virtual Response<TableItem> Create(CancellationToken cancellationToken = default) |
| | 154 | | { |
| 4 | 155 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Create)}"); |
| 4 | 156 | | scope.Start(); |
| | 157 | | try |
| | 158 | | { |
| 4 | 159 | | var response = _tableOperations.Create(new TableProperties() { TableName = _table }, null, queryOptions: |
| 4 | 160 | | return Response.FromValue(response.Value as TableItem, response.GetRawResponse()); |
| | 161 | | } |
| 0 | 162 | | catch (Exception ex) |
| | 163 | | { |
| 0 | 164 | | scope.Failed(ex); |
| 0 | 165 | | throw; |
| | 166 | | } |
| 4 | 167 | | } |
| | 168 | |
|
| | 169 | | /// <summary> |
| | 170 | | /// Creates the current table. |
| | 171 | | /// </summary> |
| | 172 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 173 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 174 | | /// <returns>A <see cref="TableItem"/> containing properties of the table</returns> |
| | 175 | | public virtual async Task<Response<TableItem>> CreateAsync(CancellationToken cancellationToken = default) |
| | 176 | | { |
| 4 | 177 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Create)}"); |
| 4 | 178 | | scope.Start(); |
| | 179 | | try |
| | 180 | | { |
| 4 | 181 | | var response = await _tableOperations.CreateAsync(new TableProperties() { TableName = _table }, null, qu |
| 4 | 182 | | return Response.FromValue(response.Value as TableItem, response.GetRawResponse()); |
| | 183 | | } |
| 0 | 184 | | catch (Exception ex) |
| | 185 | | { |
| 0 | 186 | | scope.Failed(ex); |
| 0 | 187 | | throw; |
| | 188 | | } |
| 4 | 189 | | } |
| | 190 | |
|
| | 191 | | /// <summary> |
| | 192 | | /// Deletes the current table. |
| | 193 | | /// </summary> |
| | 194 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 195 | | /// <returns></returns> |
| | 196 | | public virtual Response Delete(CancellationToken cancellationToken = default) |
| | 197 | | { |
| 4 | 198 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Delete)}"); |
| 4 | 199 | | scope.Start(); |
| | 200 | | try |
| | 201 | | { |
| 4 | 202 | | return _tableOperations.Delete(table: _table, null, cancellationToken: cancellationToken); |
| | 203 | | } |
| 0 | 204 | | catch (Exception ex) |
| | 205 | | { |
| 0 | 206 | | scope.Failed(ex); |
| 0 | 207 | | throw; |
| | 208 | | } |
| 4 | 209 | | } |
| | 210 | |
|
| | 211 | | /// <summary> |
| | 212 | | /// Deletes the current table. |
| | 213 | | /// </summary> |
| | 214 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 215 | | /// <returns></returns> |
| | 216 | | public virtual async Task<Response> DeleteAsync(CancellationToken cancellationToken = default) |
| | 217 | | { |
| 4 | 218 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Delete)}"); |
| 4 | 219 | | scope.Start(); |
| | 220 | | try |
| | 221 | | { |
| 4 | 222 | | return await _tableOperations.DeleteAsync(table: _table, null, cancellationToken: cancellationToken).Con |
| | 223 | | } |
| 0 | 224 | | catch (Exception ex) |
| | 225 | | { |
| 0 | 226 | | scope.Failed(ex); |
| 0 | 227 | | throw; |
| | 228 | | } |
| 4 | 229 | | } |
| | 230 | |
|
| | 231 | | /// <summary> |
| | 232 | | /// Creates a Table Entity into the Table. |
| | 233 | | /// </summary> |
| | 234 | | /// <param name="entity">The entity to create.</param> |
| | 235 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 236 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 237 | | /// <returns>The created Table entity.</returns> |
| | 238 | | /// <exception cref="RequestFailedException">Exception thrown if entity already exists.</exception> |
| | 239 | | public virtual async Task<Response<T>> CreateEntityAsync<T>(T entity, CancellationToken cancellationToken = defa |
| | 240 | | { |
| 854 | 241 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 852 | 242 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 852 | 243 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 852 | 244 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(CreateEntity)}"); |
| 852 | 245 | | scope.Start(); |
| | 246 | | try |
| | 247 | | { |
| 852 | 248 | | var response = await _tableOperations.InsertEntityAsync(_table, |
| 852 | 249 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 852 | 250 | | queryOptions: new QueryOptions() { Format = _format }, |
| 852 | 251 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 252 | |
|
| 852 | 253 | | var result = ((Dictionary<string, object>)response.Value).ToTableEntity<T>(); |
| 852 | 254 | | return Response.FromValue(result, response.GetRawResponse()); |
| | 255 | | } |
| 0 | 256 | | catch (Exception ex) |
| | 257 | | { |
| 0 | 258 | | scope.Failed(ex); |
| 0 | 259 | | throw; |
| | 260 | | } |
| 852 | 261 | | } |
| | 262 | |
|
| | 263 | | /// <summary> |
| | 264 | | /// Creates a Table Entity into the Table. |
| | 265 | | /// </summary> |
| | 266 | | /// <param name="entity">The entity to create.</param> |
| | 267 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 268 | | /// <returns>The created Table entity.</returns> |
| | 269 | | /// <exception cref="RequestFailedException">Exception thrown if entity already exists.</exception> |
| | 270 | | public virtual Response<T> CreateEntity<T>(T entity, CancellationToken cancellationToken = default) where T : cl |
| | 271 | | { |
| 854 | 272 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 852 | 273 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 852 | 274 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 852 | 275 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(CreateEntity)}"); |
| 852 | 276 | | scope.Start(); |
| | 277 | | try |
| | 278 | | { |
| 852 | 279 | | var response = _tableOperations.InsertEntity(_table, |
| 852 | 280 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 852 | 281 | | queryOptions: new QueryOptions() { Format = _format }, |
| 852 | 282 | | cancellationToken: cancellationToken); |
| | 283 | |
|
| 852 | 284 | | var result = ((Dictionary<string, object>)response.Value).ToTableEntity<T>(); |
| 852 | 285 | | return Response.FromValue(result, response.GetRawResponse()); |
| | 286 | | } |
| 0 | 287 | | catch (Exception ex) |
| | 288 | | { |
| 0 | 289 | | scope.Failed(ex); |
| 0 | 290 | | throw; |
| | 291 | | } |
| 852 | 292 | | } |
| | 293 | |
|
| | 294 | | /// <summary> |
| | 295 | | /// Gets the specified table entity. |
| | 296 | | /// </summary> |
| | 297 | | /// <param name="partitionKey">The partitionKey that identifies the table entity.</param> |
| | 298 | | /// <param name="rowKey">The rowKey that identifies the table entity.</param> |
| | 299 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 300 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 301 | | /// <exception cref="RequestFailedException">Exception thrown if the entity doesn't exist.</exception> |
| | 302 | | /// <exception cref="ArgumentNullException"><paramref name="partitionKey"/> or <paramref name="rowKey"/> is null |
| | 303 | | public virtual Response<T> GetEntity<T>(string partitionKey, string rowKey, CancellationToken cancellationToken |
| | 304 | | { |
| 4 | 305 | | Argument.AssertNotNull("message", nameof(partitionKey)); |
| 4 | 306 | | Argument.AssertNotNull("message", nameof(rowKey)); |
| | 307 | |
|
| 4 | 308 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(GetEntity)}"); |
| 4 | 309 | | scope.Start(); |
| | 310 | | try |
| | 311 | | { |
| 4 | 312 | | var response = _tableOperations.QueryEntitiesWithPartitionAndRowKey( |
| 4 | 313 | | _table, |
| 4 | 314 | | partitionKey, |
| 4 | 315 | | rowKey, |
| 4 | 316 | | queryOptions: new QueryOptions() { Format = _format }, |
| 4 | 317 | | cancellationToken: cancellationToken); |
| | 318 | |
|
| 4 | 319 | | var result = ((Dictionary<string, object>)response.Value).ToTableEntity<T>(); |
| 4 | 320 | | return Response.FromValue(result, response.GetRawResponse()); |
| | 321 | | } |
| 0 | 322 | | catch (Exception ex) |
| | 323 | | { |
| 0 | 324 | | scope.Failed(ex); |
| 0 | 325 | | throw; |
| | 326 | | } |
| 4 | 327 | | } |
| | 328 | |
|
| | 329 | | /// <summary> |
| | 330 | | /// Gets the specified table entity. |
| | 331 | | /// </summary> |
| | 332 | | /// <param name="partitionKey">The partitionKey that identifies the table entity.</param> |
| | 333 | | /// <param name="rowKey">The rowKey that identifies the table entity.</param> |
| | 334 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 335 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 336 | | /// <exception cref="RequestFailedException">Exception thrown if the entity doesn't exist.</exception> |
| | 337 | | /// <exception cref="ArgumentNullException"><paramref name="partitionKey"/> or <paramref name="rowKey"/> is null |
| | 338 | | public virtual async Task<Response<T>> GetEntityAsync<T>(string partitionKey, string rowKey, CancellationToken c |
| | 339 | | { |
| 4 | 340 | | Argument.AssertNotNull("message", nameof(partitionKey)); |
| 4 | 341 | | Argument.AssertNotNull("message", nameof(rowKey)); |
| | 342 | |
|
| 4 | 343 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(GetEntity)}"); |
| 4 | 344 | | scope.Start(); |
| | 345 | | try |
| | 346 | | { |
| 4 | 347 | | var response = await _tableOperations.QueryEntitiesWithPartitionAndRowKeyAsync( |
| 4 | 348 | | _table, |
| 4 | 349 | | partitionKey, |
| 4 | 350 | | rowKey, |
| 4 | 351 | | queryOptions: new QueryOptions() { Format = _format }, |
| 4 | 352 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 353 | |
|
| 4 | 354 | | var result = ((Dictionary<string, object>)response.Value).ToTableEntity<T>(); |
| 4 | 355 | | return Response.FromValue(result, response.GetRawResponse()); |
| | 356 | | } |
| 0 | 357 | | catch (Exception ex) |
| | 358 | | { |
| 0 | 359 | | scope.Failed(ex); |
| 0 | 360 | | throw; |
| | 361 | | } |
| 4 | 362 | | } |
| | 363 | |
|
| | 364 | | /// <summary> |
| | 365 | | /// Replaces the specified table entity, if it exists. Creates the entity if it does not exist. |
| | 366 | | /// </summary> |
| | 367 | | /// <param name="entity">The entity to upsert.</param> |
| | 368 | | /// <param name="mode">An enum that determines which upsert operation to perform.</param> |
| | 369 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 370 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 371 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 372 | | public virtual async Task<Response> UpsertEntityAsync<T>(T entity, TableUpdateMode mode = TableUpdateMode.Merge, |
| | 373 | | { |
| 72 | 374 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 70 | 375 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 68 | 376 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 66 | 377 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(UpsertEntity)}"); |
| 66 | 378 | | scope.Start(); |
| | 379 | | try |
| | 380 | | { |
| 66 | 381 | | if (mode == TableUpdateMode.Replace) |
| | 382 | | { |
| 62 | 383 | | return await _tableOperations.UpdateEntityAsync(_table, |
| 62 | 384 | | entity.PartitionKey, |
| 62 | 385 | | entity.RowKey, |
| 62 | 386 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 62 | 387 | | queryOptions: new QueryOptions() { Format = _format }, |
| 62 | 388 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 389 | | } |
| 4 | 390 | | else if (mode == TableUpdateMode.Merge) |
| | 391 | | { |
| 4 | 392 | | return await _tableOperations.MergeEntityAsync(_table, |
| 4 | 393 | | entity.PartitionKey, |
| 4 | 394 | | entity.RowKey, |
| 4 | 395 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 4 | 396 | | queryOptions: new QueryOptions() { Format = _format }, |
| 4 | 397 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 398 | | } |
| | 399 | | else |
| | 400 | | { |
| 0 | 401 | | throw new ArgumentException($"Unexpected value for {nameof(mode)}: {mode}"); |
| | 402 | | } |
| | 403 | | } |
| 4 | 404 | | catch (Exception ex) |
| | 405 | | { |
| 4 | 406 | | scope.Failed(ex); |
| 4 | 407 | | throw; |
| | 408 | | } |
| 62 | 409 | | } |
| | 410 | |
|
| | 411 | | /// <summary> |
| | 412 | | /// Replaces the specified table entity, if it exists. Creates the entity if it does not exist. |
| | 413 | | /// </summary> |
| | 414 | | /// <param name="entity">The entity to upsert.</param> |
| | 415 | | /// <param name="mode">An enum that determines which upsert operation to perform.</param> |
| | 416 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 417 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 418 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 419 | | public virtual Response UpsertEntity<T>(T entity, TableUpdateMode mode = TableUpdateMode.Merge, CancellationToke |
| | 420 | | { |
| 72 | 421 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 70 | 422 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 68 | 423 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 66 | 424 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(UpsertEntity)}"); |
| 66 | 425 | | scope.Start(); |
| | 426 | | try |
| | 427 | | { |
| 66 | 428 | | if (mode == TableUpdateMode.Replace) |
| | 429 | | { |
| 62 | 430 | | return _tableOperations.UpdateEntity(_table, |
| 62 | 431 | | entity.PartitionKey, |
| 62 | 432 | | entity.RowKey, |
| 62 | 433 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 62 | 434 | | queryOptions: new QueryOptions() { Format = _format }, |
| 62 | 435 | | cancellationToken: cancellationToken); |
| | 436 | | } |
| 4 | 437 | | else if (mode == TableUpdateMode.Merge) |
| | 438 | | { |
| 4 | 439 | | return _tableOperations.MergeEntity(_table, |
| 4 | 440 | | entity.PartitionKey, |
| 4 | 441 | | entity.RowKey, |
| 4 | 442 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 4 | 443 | | queryOptions: new QueryOptions() { Format = _format }, |
| 4 | 444 | | cancellationToken: cancellationToken); |
| | 445 | | } |
| | 446 | | else |
| | 447 | | { |
| 0 | 448 | | throw new ArgumentException($"Unexpected value for {nameof(mode)}: {mode}"); |
| | 449 | | } |
| | 450 | | } |
| 4 | 451 | | catch (Exception ex) |
| | 452 | | { |
| 4 | 453 | | scope.Failed(ex); |
| 4 | 454 | | throw; |
| | 455 | | } |
| 62 | 456 | | } |
| | 457 | |
|
| | 458 | | /// <summary> |
| | 459 | | /// Replaces the specified table entity, if it exists. |
| | 460 | | /// </summary> |
| | 461 | | /// <param name="entity">The entity to update.</param> |
| | 462 | | /// <param name="ifMatch">The If-Match value to be used for optimistic concurrency.</param> |
| | 463 | | /// <param name="mode">An enum that determines which upsert operation to perform.</param> |
| | 464 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 465 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 466 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 467 | | public virtual async Task<Response> UpdateEntityAsync<T>(T entity, string ifMatch, TableUpdateMode mode = TableU |
| | 468 | | { |
| 44 | 469 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 42 | 470 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 40 | 471 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 38 | 472 | | Argument.AssertNotNullOrWhiteSpace(ifMatch, nameof(ifMatch)); |
| 36 | 473 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(UpdateEntity)}"); |
| 36 | 474 | | scope.Start(); |
| | 475 | | try |
| | 476 | | { |
| 36 | 477 | | if (mode == TableUpdateMode.Replace) |
| | 478 | | { |
| 24 | 479 | | return await _tableOperations.UpdateEntityAsync(_table, |
| 24 | 480 | | entity.PartitionKey, |
| 24 | 481 | | entity.RowKey, |
| 24 | 482 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 24 | 483 | | ifMatch: ifMatch, |
| 24 | 484 | | queryOptions: new QueryOptions() { Format = _format }, |
| 24 | 485 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 486 | | } |
| 12 | 487 | | else if (mode == TableUpdateMode.Merge) |
| | 488 | | { |
| 12 | 489 | | return await _tableOperations.MergeEntityAsync(_table, |
| 12 | 490 | | entity.PartitionKey, |
| 12 | 491 | | entity.RowKey, |
| 12 | 492 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 12 | 493 | | ifMatch: ifMatch, |
| 12 | 494 | | queryOptions: new QueryOptions() { Format = _format }, |
| 12 | 495 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 496 | | } |
| | 497 | | else |
| | 498 | | { |
| 0 | 499 | | throw new ArgumentException($"Unexpected value for {nameof(mode)}: {mode}"); |
| | 500 | | } |
| | 501 | | } |
| 12 | 502 | | catch (Exception ex) |
| | 503 | | { |
| 12 | 504 | | scope.Failed(ex); |
| 12 | 505 | | throw; |
| | 506 | | } |
| 24 | 507 | | } |
| | 508 | |
|
| | 509 | | /// <summary> |
| | 510 | | /// Replaces the specified table entity, if it exists. |
| | 511 | | /// </summary> |
| | 512 | | /// <param name="entity">The entity to update.</param> |
| | 513 | | /// <param name="ifMatch">The If-Match value to be used for optimistic concurrency.</param> |
| | 514 | | /// <param name="mode">An enum that determines which upsert operation to perform.</param> |
| | 515 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 516 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 517 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 518 | | public virtual Response UpdateEntity<T>(T entity, string ifMatch, TableUpdateMode mode = TableUpdateMode.Merge, |
| | 519 | | { |
| 44 | 520 | | Argument.AssertNotNull(entity, nameof(entity)); |
| 42 | 521 | | Argument.AssertNotNull(entity?.PartitionKey, nameof(entity.PartitionKey)); |
| 40 | 522 | | Argument.AssertNotNull(entity?.RowKey, nameof(entity.RowKey)); |
| 38 | 523 | | Argument.AssertNotNullOrWhiteSpace(ifMatch, nameof(ifMatch)); |
| 36 | 524 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(UpdateEntity)}"); |
| 36 | 525 | | scope.Start(); |
| | 526 | | try |
| | 527 | | { |
| 36 | 528 | | if (mode == TableUpdateMode.Replace) |
| | 529 | | { |
| 24 | 530 | | return _tableOperations.UpdateEntity(_table, |
| 24 | 531 | | entity.PartitionKey, |
| 24 | 532 | | entity.RowKey, |
| 24 | 533 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 24 | 534 | | ifMatch: ifMatch, |
| 24 | 535 | | queryOptions: new QueryOptions() { Format = _format }, |
| 24 | 536 | | cancellationToken: cancellationToken); |
| | 537 | | } |
| 12 | 538 | | else if (mode == TableUpdateMode.Merge) |
| | 539 | | { |
| 12 | 540 | | return _tableOperations.MergeEntity(_table, |
| 12 | 541 | | entity.PartitionKey, |
| 12 | 542 | | entity.RowKey, |
| 12 | 543 | | tableEntityProperties: entity.ToOdataAnnotatedDictionary(), |
| 12 | 544 | | ifMatch: ifMatch, |
| 12 | 545 | | queryOptions: new QueryOptions() { Format = _format }, |
| 12 | 546 | | cancellationToken: cancellationToken); |
| | 547 | | } |
| | 548 | | else |
| | 549 | | { |
| 0 | 550 | | throw new ArgumentException($"Unexpected value for {nameof(mode)}: {mode}"); |
| | 551 | | } |
| | 552 | | } |
| 12 | 553 | | catch (Exception ex) |
| | 554 | | { |
| 12 | 555 | | scope.Failed(ex); |
| 12 | 556 | | throw; |
| | 557 | | } |
| 24 | 558 | | } |
| | 559 | |
|
| | 560 | | /// <summary> |
| | 561 | | /// Queries entities in the table. |
| | 562 | | /// </summary> |
| | 563 | | /// <param name="filter">Returns only entities that satisfy the specified filter.</param> |
| | 564 | | /// <param name="maxPerPage">The maximum number of entities that will be returned per page.</param> |
| | 565 | | /// <param name="select">Selects which set of entity properties to return in the result set.</param> |
| | 566 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 567 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 568 | | public virtual AsyncPageable<T> QueryAsync<T>(Expression<Func<T, bool>> filter, int? maxPerPage = null, IEnumera |
| | 569 | | { |
| 192 | 570 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}"); |
| 192 | 571 | | scope.Start(); |
| | 572 | | try |
| | 573 | | { |
| 192 | 574 | | return QueryAsync<T>(Bind(filter), maxPerPage, select, cancellationToken); |
| | 575 | | } |
| 0 | 576 | | catch (Exception ex) |
| | 577 | | { |
| 0 | 578 | | scope.Failed(ex); |
| 0 | 579 | | throw; |
| | 580 | | } |
| 192 | 581 | | } |
| | 582 | |
|
| | 583 | | /// <summary> |
| | 584 | | /// Queries entities in the table. |
| | 585 | | /// </summary> |
| | 586 | | /// <param name="filter">Returns only entities that satisfy the specified filter.</param> |
| | 587 | | /// <param name="maxPerPage">The maximum number of entities that will be returned per page.</param> |
| | 588 | | /// <param name="select">Selects which set of entity properties to return in the result set.</param> |
| | 589 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 590 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 591 | | public virtual Pageable<T> Query<T>(Expression<Func<T, bool>> filter, int? maxPerPage = null, IEnumerable<string |
| | 592 | | { |
| 192 | 593 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}"); |
| 192 | 594 | | scope.Start(); |
| | 595 | | try |
| | 596 | | { |
| 192 | 597 | | return Query<T>(Bind(filter), maxPerPage, select, cancellationToken); |
| | 598 | | } |
| 0 | 599 | | catch (Exception ex) |
| | 600 | | { |
| 0 | 601 | | scope.Failed(ex); |
| 0 | 602 | | throw; |
| | 603 | | } |
| 192 | 604 | | } |
| | 605 | |
|
| | 606 | | /// <summary> |
| | 607 | | /// Queries entities in the table. |
| | 608 | | /// </summary> |
| | 609 | | /// <param name="filter">Returns only entities that satisfy the specified filter.</param> |
| | 610 | | /// <param name="maxPerPage">The maximum number of entities that will be returned per page.</param> |
| | 611 | | /// <param name="select">Selects which set of entity properties to return in the result set.</param> |
| | 612 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 613 | | /// <returns></returns> |
| | 614 | | public virtual AsyncPageable<T> QueryAsync<T>(string filter = null, int? maxPerPage = null, IEnumerable<string> |
| | 615 | | { |
| 334 | 616 | | string selectArg = select == null ? null : string.Join(",", select); |
| | 617 | |
|
| 334 | 618 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}"); |
| 334 | 619 | | scope.Start(); |
| | 620 | | try |
| | 621 | | { |
| 334 | 622 | | return PageableHelpers.CreateAsyncEnumerable(async _ => |
| 334 | 623 | | { |
| 668 | 624 | | var response = await _tableOperations.QueryEntitiesAsync( |
| 668 | 625 | | _table, |
| 668 | 626 | | queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = sel |
| 668 | 627 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| 334 | 628 | |
|
| 668 | 629 | | return Page.FromValues(response.Value.Value.ToTableEntityList<T>(), |
| 668 | 630 | | CreateContinuationTokenFromHeaders(response.Headers), |
| 668 | 631 | | response.GetRawResponse()); |
| 668 | 632 | | }, async (continuationToken, _) => |
| 334 | 633 | | { |
| 366 | 634 | | var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken); |
| 334 | 635 | |
|
| 366 | 636 | | var response = await _tableOperations.QueryEntitiesAsync( |
| 366 | 637 | | _table, |
| 366 | 638 | | queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = sel |
| 366 | 639 | | nextPartitionKey: NextPartitionKey, |
| 366 | 640 | | nextRowKey: NextRowKey, |
| 366 | 641 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| 334 | 642 | |
|
| 366 | 643 | | return Page.FromValues(response.Value.Value.ToTableEntityList<T>(), |
| 366 | 644 | | CreateContinuationTokenFromHeaders(response.Headers), |
| 366 | 645 | | response.GetRawResponse()); |
| 366 | 646 | | }); |
| | 647 | | } |
| 0 | 648 | | catch (Exception ex) |
| | 649 | | { |
| 0 | 650 | | scope.Failed(ex); |
| 0 | 651 | | throw; |
| | 652 | | } |
| 334 | 653 | | } |
| | 654 | |
|
| | 655 | |
|
| | 656 | | /// <summary> |
| | 657 | | /// Queries entities in the table. |
| | 658 | | /// </summary> |
| | 659 | | /// <param name="filter">Returns only entities that satisfy the specified filter.</param> |
| | 660 | | /// <param name="maxPerPage">The maximum number of entities that will be returned per page.</param> |
| | 661 | | /// <param name="select">Selects which set of entity properties to return in the result set.</param> |
| | 662 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 663 | |
|
| | 664 | | public virtual Pageable<T> Query<T>(string filter = null, int? maxPerPage = null, IEnumerable<string> select = n |
| | 665 | | { |
| 334 | 666 | | string selectArg = select == null ? null : string.Join(",", select); |
| | 667 | |
|
| 334 | 668 | | return PageableHelpers.CreateEnumerable((int? _) => |
| 334 | 669 | | { |
| 668 | 670 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}"); |
| 668 | 671 | | scope.Start(); |
| 334 | 672 | | try |
| 334 | 673 | | { |
| 668 | 674 | | var response = _tableOperations.QueryEntities(_table, |
| 668 | 675 | | queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = |
| 668 | 676 | | cancellationToken: cancellationToken); |
| 334 | 677 | |
|
| 668 | 678 | | return Page.FromValues( |
| 668 | 679 | | response.Value.Value.ToTableEntityList<T>(), |
| 668 | 680 | | CreateContinuationTokenFromHeaders(response.Headers), |
| 668 | 681 | | response.GetRawResponse()); |
| 334 | 682 | | } |
| 0 | 683 | | catch (Exception ex) |
| 334 | 684 | | { |
| 0 | 685 | | scope.Failed(ex); |
| 0 | 686 | | throw; |
| 334 | 687 | | } |
| 668 | 688 | | }, (continuationToken, _) => |
| 334 | 689 | | { |
| 366 | 690 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(Query)}"); |
| 366 | 691 | | scope.Start(); |
| 334 | 692 | | try |
| 334 | 693 | | { |
| 366 | 694 | | var (NextPartitionKey, NextRowKey) = ParseContinuationToken(continuationToken); |
| 334 | 695 | |
|
| 366 | 696 | | var response = _tableOperations.QueryEntities( |
| 366 | 697 | | _table, |
| 366 | 698 | | queryOptions: new QueryOptions() { Format = _format, Top = maxPerPage, Filter = filter, Select = |
| 366 | 699 | | nextPartitionKey: NextPartitionKey, |
| 366 | 700 | | nextRowKey: NextRowKey, |
| 366 | 701 | | cancellationToken: cancellationToken); |
| 334 | 702 | |
|
| 366 | 703 | | return Page.FromValues(response.Value.Value.ToTableEntityList<T>(), |
| 366 | 704 | | CreateContinuationTokenFromHeaders(response.Headers), |
| 366 | 705 | | response.GetRawResponse()); |
| 334 | 706 | | } |
| 0 | 707 | | catch (Exception ex) |
| 334 | 708 | | { |
| 0 | 709 | | scope.Failed(ex); |
| 0 | 710 | | throw; |
| 334 | 711 | | } |
| 366 | 712 | | }); |
| | 713 | | } |
| | 714 | |
|
| | 715 | | /// <summary> |
| | 716 | | /// Deletes the specified table entity. |
| | 717 | | /// </summary> |
| | 718 | | /// <param name="partitionKey">The partitionKey that identifies the table entity.</param> |
| | 719 | | /// <param name="rowKey">The rowKey that identifies the table entity.</param> |
| | 720 | | /// <param name="ifMatch">The If-Match value to be used for optimistic concurrency.</param> |
| | 721 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 722 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 723 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 724 | | public virtual async Task<Response> DeleteEntityAsync(string partitionKey, string rowKey, string ifMatch = "*", |
| | 725 | | { |
| 24 | 726 | | Argument.AssertNotNull(partitionKey, nameof(partitionKey)); |
| 24 | 727 | | Argument.AssertNotNull(rowKey, nameof(rowKey)); |
| 24 | 728 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(DeleteEntity)}"); |
| 24 | 729 | | scope.Start(); |
| | 730 | | try |
| | 731 | | { |
| 24 | 732 | | return await _tableOperations.DeleteEntityAsync(_table, |
| 24 | 733 | | partitionKey, |
| 24 | 734 | | rowKey, |
| 24 | 735 | | ifMatch: ifMatch, |
| 24 | 736 | | queryOptions: new QueryOptions() { Format = _format }, |
| 24 | 737 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 738 | | } |
| 8 | 739 | | catch (Exception ex) |
| | 740 | | { |
| 8 | 741 | | scope.Failed(ex); |
| 8 | 742 | | throw; |
| | 743 | | } |
| 16 | 744 | | } |
| | 745 | |
|
| | 746 | | /// <summary> |
| | 747 | | /// Deletes the specified table entity. |
| | 748 | | /// </summary> |
| | 749 | | /// <param name="partitionKey">The partitionKey that identifies the table entity.</param> |
| | 750 | | /// <param name="rowKey">The rowKey that identifies the table entity.</param> |
| | 751 | | /// <param name="ifMatch">The If-Match value to be used for optimistic concurrency. The default is to delete unc |
| | 752 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 753 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 754 | | /// <returns>The <see cref="Response"/> indicating the result of the operation.</returns> |
| | 755 | | public virtual Response DeleteEntity(string partitionKey, string rowKey, string ifMatch = "*", CancellationToken |
| | 756 | | { |
| 24 | 757 | | Argument.AssertNotNull(partitionKey, nameof(partitionKey)); |
| 24 | 758 | | Argument.AssertNotNull(rowKey, nameof(rowKey)); |
| 24 | 759 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(DeleteEntity)}"); |
| 24 | 760 | | scope.Start(); |
| | 761 | | try |
| | 762 | | { |
| 24 | 763 | | return _tableOperations.DeleteEntity(_table, |
| 24 | 764 | | partitionKey, |
| 24 | 765 | | rowKey, |
| 24 | 766 | | ifMatch: ifMatch, |
| 24 | 767 | | queryOptions: new QueryOptions() { Format = _format }, |
| 24 | 768 | | cancellationToken: cancellationToken); |
| | 769 | | } |
| 8 | 770 | | catch (Exception ex) |
| | 771 | | { |
| 8 | 772 | | scope.Failed(ex); |
| 8 | 773 | | throw; |
| | 774 | | } |
| 16 | 775 | | } |
| | 776 | |
|
| | 777 | | /// <summary> Retrieves details about any stored access policies specified on the table that may be used with Sh |
| | 778 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 779 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 780 | | public virtual async Task<Response<IReadOnlyList<SignedIdentifier>>> GetAccessPolicyAsync(CancellationToken canc |
| | 781 | | { |
| 2 | 782 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(GetAccessPolicy)}"); |
| 2 | 783 | | scope.Start(); |
| | 784 | | try |
| | 785 | | { |
| 2 | 786 | | var response = await _tableOperations.GetAccessPolicyAsync(_table, cancellationToken: cancellationToken) |
| 2 | 787 | | return Response.FromValue(response.Value, response.GetRawResponse()); |
| | 788 | | } |
| 0 | 789 | | catch (Exception ex) |
| | 790 | | { |
| 0 | 791 | | scope.Failed(ex); |
| 0 | 792 | | throw; |
| | 793 | | } |
| 2 | 794 | | } |
| | 795 | |
|
| | 796 | | /// <summary> Retrieves details about any stored access policies specified on the table that may be used with Sh |
| | 797 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 798 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 799 | | public virtual Response<IReadOnlyList<SignedIdentifier>> GetAccessPolicy(CancellationToken cancellationToken = d |
| | 800 | | { |
| 2 | 801 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(GetAccessPolicy)}"); |
| 2 | 802 | | scope.Start(); |
| | 803 | | try |
| | 804 | | { |
| 2 | 805 | | var response = _tableOperations.GetAccessPolicy(_table, cancellationToken: cancellationToken); |
| 2 | 806 | | return Response.FromValue(response.Value, response.GetRawResponse()); |
| | 807 | | } |
| 0 | 808 | | catch (Exception ex) |
| | 809 | | { |
| 0 | 810 | | scope.Failed(ex); |
| 0 | 811 | | throw; |
| | 812 | | } |
| 2 | 813 | | } |
| | 814 | |
|
| | 815 | | /// <summary> sets stored access policies for the table that may be used with Shared Access Signatures. </summar |
| | 816 | | /// <param name="tableAcl"> the access policies for the table. </param> |
| | 817 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 818 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 819 | | public virtual async Task<Response> SetAccessPolicyAsync(IEnumerable<SignedIdentifier> tableAcl = null, Cancella |
| | 820 | | { |
| 2 | 821 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(SetAccessPolicy)}"); |
| 2 | 822 | | scope.Start(); |
| | 823 | | try |
| | 824 | | { |
| 2 | 825 | | return await _tableOperations.SetAccessPolicyAsync(_table, tableAcl: tableAcl, cancellationToken: cancel |
| | 826 | | } |
| 0 | 827 | | catch (Exception ex) |
| | 828 | | { |
| 0 | 829 | | scope.Failed(ex); |
| 0 | 830 | | throw; |
| | 831 | | } |
| 2 | 832 | | } |
| | 833 | |
|
| | 834 | | /// <summary> sets stored access policies for the table that may be used with Shared Access Signatures. </summar |
| | 835 | | /// <param name="tableAcl"> the access policies for the table. </param> |
| | 836 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 837 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 838 | | public virtual Response SetAccessPolicy(IEnumerable<SignedIdentifier> tableAcl, CancellationToken cancellationTo |
| | 839 | | { |
| 2 | 840 | | using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TableClient)}.{nameof(SetAccessPolicy)}"); |
| 2 | 841 | | scope.Start(); |
| | 842 | | try |
| | 843 | | { |
| 2 | 844 | | return _tableOperations.SetAccessPolicy(_table, tableAcl: tableAcl, cancellationToken: cancellationToken |
| | 845 | | } |
| 0 | 846 | | catch (Exception ex) |
| | 847 | | { |
| 0 | 848 | | scope.Failed(ex); |
| 0 | 849 | | throw; |
| | 850 | | } |
| 2 | 851 | | } |
| | 852 | |
|
| | 853 | | /// <summary> |
| | 854 | | /// Creates an Odata filter query string from the provided expression. |
| | 855 | | /// </summary> |
| | 856 | | /// <typeparam name="T">The type of the entity being queried. Typically this will be derrived from <see cref="IT |
| | 857 | | /// <param name="filter">A filter expresssion.</param> |
| | 858 | | /// <returns>The string representation of the filter expression.</returns> |
| 76 | 859 | | public static string CreateQueryFilter<T>(Expression<Func<T, bool>> filter) => Bind(filter); |
| | 860 | |
|
| | 861 | | internal static string Bind(Expression expression) |
| | 862 | | { |
| 460 | 863 | | Argument.AssertNotNull(expression, nameof(expression)); |
| | 864 | |
|
| 460 | 865 | | Dictionary<Expression, Expression> normalizerRewrites = new Dictionary<Expression, Expression>(ReferenceEqua |
| | 866 | |
|
| | 867 | | // Evaluate any local evaluatable expressions ( lambdas etc) |
| 460 | 868 | | Expression partialEvaluatedExpression = Evaluator.PartialEval(expression); |
| | 869 | |
|
| | 870 | | // Normalize expression, replace String Comparisons etc. |
| 460 | 871 | | Expression normalizedExpression = ExpressionNormalizer.Normalize(partialEvaluatedExpression, normalizerRewri |
| | 872 | |
|
| | 873 | | // Parse the Bound expression into sub components, i.e. take count, filter, select columns, request options, |
| 460 | 874 | | ExpressionParser parser = new ExpressionParser(); |
| 460 | 875 | | parser.Translate(normalizedExpression); |
| | 876 | |
|
| | 877 | | // Return the FilterString. |
| 460 | 878 | | return parser.FilterString == "true" ? null : parser.FilterString; |
| | 879 | | } |
| | 880 | |
|
| | 881 | | private static string CreateContinuationTokenFromHeaders(TableQueryEntitiesHeaders headers) |
| | 882 | | { |
| 732 | 883 | | if (headers.XMsContinuationNextPartitionKey == null && headers.XMsContinuationNextRowKey == null) |
| | 884 | | { |
| 668 | 885 | | return null; |
| | 886 | | } |
| | 887 | | else |
| | 888 | | { |
| 64 | 889 | | return $"{headers.XMsContinuationNextPartitionKey} {headers.XMsContinuationNextRowKey}"; |
| | 890 | | } |
| | 891 | | } |
| | 892 | |
|
| | 893 | | private static (string NextPartitionKey, string NextRowKey) ParseContinuationToken(string continuationToken) |
| | 894 | | { |
| | 895 | | // There were no headers passed and the continuation token contains just the space delimiter |
| 64 | 896 | | if (continuationToken?.Length <= 1) |
| | 897 | | { |
| 0 | 898 | | return (null, null); |
| | 899 | | } |
| | 900 | |
|
| 64 | 901 | | var tokens = continuationToken.Split(' '); |
| 64 | 902 | | return (tokens[0], tokens.Length > 1 ? tokens[1] : null); |
| | 903 | | } |
| | 904 | | } |
| | 905 | | } |