| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Search.Models |
| | 6 | | { |
| | 7 | | using Common; |
| | 8 | |
|
| | 9 | | public partial class AccessCondition |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Constructs an access condition such that an operation will be performed only if the resource's current ETag |
| | 13 | | /// matches the specified resource's ETag value. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="resource">A resource with an ETag value to check against the resource's ETag.</param> |
| | 16 | | /// <returns>An <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object that represents the If-Match |
| | 17 | | public static AccessCondition IfNotChanged(IResourceWithETag resource) |
| | 18 | | { |
| 40 | 19 | | Throw.IfArgumentNull(resource, nameof(resource)); |
| 38 | 20 | | Throw.IfArgumentNullOrEmpty(resource.ETag, $"{nameof(resource)}.{nameof(resource.ETag)}"); |
| | 21 | |
|
| 34 | 22 | | return AccessCondition.GenerateIfMatchCondition(resource.ETag); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Constructs an empty access condition. |
| | 27 | | /// </summary> |
| | 28 | | /// <returns>An empty <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object.</returns> |
| | 29 | | public static AccessCondition GenerateEmptyCondition() |
| | 30 | | { |
| 42 | 31 | | return new AccessCondition(); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Constructs an access condition such that an operation will be performed only if the resource exists. |
| | 36 | | /// </summary> |
| | 37 | | /// <returns>An <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object that represents a condition |
| | 38 | | /// <remarks>Setting this access condition modifies the request to include the HTTP <i>If-Match</i> conditional |
| | 39 | | public static AccessCondition GenerateIfExistsCondition() |
| | 40 | | { |
| 34 | 41 | | return new AccessCondition(ifMatch: "*"); |
| | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Constructs an access condition such that an operation will be performed only if the resource's current ETag |
| | 46 | | /// matches the specified ETag value. |
| | 47 | | /// </summary> |
| | 48 | | /// <param name="eTag">The ETag value to check against the resource's ETag.</param> |
| | 49 | | /// <returns>An <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object that represents the If-Match |
| | 50 | | public static AccessCondition GenerateIfMatchCondition(string eTag) |
| | 51 | | { |
| 40 | 52 | | Throw.IfArgumentNullOrEmpty(eTag, nameof(eTag)); |
| | 53 | |
|
| 36 | 54 | | return new AccessCondition(ifMatch: eTag); |
| | 55 | | } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// Constructs an access condition such that an operation will be performed only if the resource does not exist. |
| | 59 | | /// </summary> |
| | 60 | | /// <returns>An <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object that represents a condition |
| | 61 | | /// <remarks>Setting this access condition modifies the request to include the HTTP <i>If-None-Match</i> conditi |
| | 62 | | public static AccessCondition GenerateIfNotExistsCondition() |
| | 63 | | { |
| 18 | 64 | | return new AccessCondition(ifNoneMatch: "*"); |
| | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Constructs an access condition such that an operation will be performed only if the resource's current ETag |
| | 69 | | /// does not match the specified ETag value. |
| | 70 | | /// </summary> |
| | 71 | | /// <param name="eTag">The ETag value to check against the resource's ETag.</param> |
| | 72 | | /// <returns>An <see cref="Microsoft.Azure.Search.Models.AccessCondition" /> object that represents the If-None- |
| | 73 | | public static AccessCondition GenerateIfNoneMatchCondition(string eTag) |
| | 74 | | { |
| 6 | 75 | | Throw.IfArgumentNullOrEmpty(eTag, nameof(eTag)); |
| | 76 | |
|
| 2 | 77 | | return new AccessCondition(ifNoneMatch: eTag); |
| | 78 | | } |
| | 79 | | } |
| | 80 | | } |