|
| 1 | +// ----------------------------------------------------------------------------------------- |
| 2 | +// <copyright file="AccessCondition.cs" company="Microsoft"> |
| 3 | +// Copyright 2012 Microsoft Corporation |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// </copyright> |
| 16 | +// ----------------------------------------------------------------------------------------- |
| 17 | + |
| 18 | +namespace Microsoft.WindowsAzure.Storage |
| 19 | +{ |
| 20 | + using System; |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Represents a set of access conditions to be used for operations against the storage services. |
| 24 | + /// </summary> |
| 25 | + public sealed class AccessCondition |
| 26 | + { |
| 27 | + /// <summary> |
| 28 | + /// Time for IfModifiedSince. |
| 29 | + /// </summary> |
| 30 | + private DateTimeOffset? ifModifiedSinceDateTime; |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Time for IfUnmodifiedSince. |
| 34 | + /// </summary> |
| 35 | + private DateTimeOffset? ifNotModifiedSinceDateTime; |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Gets or sets an "etag" that must match the ETag of a resource. |
| 39 | + /// </summary> |
| 40 | + /// <value>A quoted ETag string. If <c>null</c>, no condition exists.</value> |
| 41 | + public string IfMatchETag |
| 42 | + { |
| 43 | + get; |
| 44 | + set; |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Gets or sets an ETag that must not match the ETag of a resource. |
| 49 | + /// </summary> |
| 50 | + /// <value>A quoted ETag string, or <c>"*"</c> to match any ETag. If null, no condition exists.</value> |
| 51 | + public string IfNoneMatchETag |
| 52 | + { |
| 53 | + get; |
| 54 | + set; |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Gets or sets a time that must be before the last modification of a resource. |
| 59 | + /// </summary> |
| 60 | + /// <value>A <c>DateTimeOffset</c> in UTC, or null if no condition exists.</value> |
| 61 | + public DateTimeOffset? IfModifiedSinceTime |
| 62 | + { |
| 63 | + get |
| 64 | + { |
| 65 | + return this.ifModifiedSinceDateTime; |
| 66 | + } |
| 67 | + |
| 68 | + set |
| 69 | + { |
| 70 | + this.ifModifiedSinceDateTime = value.HasValue ? value.Value.ToUniversalTime() : value; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Gets or sets a time that must not be before the last modification of a resource. |
| 76 | + /// </summary> |
| 77 | + /// <value>A <c>DateTimeOffset</c> in UTC, or null if no condition exists.</value> |
| 78 | + public DateTimeOffset? IfNotModifiedSinceTime |
| 79 | + { |
| 80 | + get |
| 81 | + { |
| 82 | + return this.ifNotModifiedSinceDateTime; |
| 83 | + } |
| 84 | + |
| 85 | + set |
| 86 | + { |
| 87 | + this.ifNotModifiedSinceDateTime = value.HasValue ? value.Value.ToUniversalTime() : value; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Gets or sets a lease ID that must match the lease on a resource. |
| 93 | + /// </summary> |
| 94 | + /// <value>A lease ID, or null if no condition exists.</value> |
| 95 | + public string LeaseId |
| 96 | + { |
| 97 | + get; |
| 98 | + set; |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Constructs an empty access condition. |
| 103 | + /// </summary> |
| 104 | + /// <returns>An empty access condition.</returns> |
| 105 | + public static AccessCondition GenerateEmptyCondition() |
| 106 | + { |
| 107 | + return new AccessCondition(); |
| 108 | + } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Constructs an access condition such that an operation will be performed only if the resource's ETag value |
| 112 | + /// matches the specified ETag value. |
| 113 | + /// </summary> |
| 114 | + /// <param name="etag">The ETag value that must be matched.</param> |
| 115 | + /// <returns>An <c>AccessCondition</c> object that represents the If-Match condition.</returns> |
| 116 | + public static AccessCondition GenerateIfMatchCondition(string etag) |
| 117 | + { |
| 118 | + return new AccessCondition { IfMatchETag = etag }; |
| 119 | + } |
| 120 | + |
| 121 | + /// <summary> |
| 122 | + /// Constructs an access condition such that an operation will be performed only if the resource has been |
| 123 | + /// modified since the specified time. |
| 124 | + /// </summary> |
| 125 | + /// <param name="modifiedTime">The time that must be before the last modified time of the resource.</param> |
| 126 | + /// <returns>An <c>AccessCondition</c> object that represents the If-Modified-Since condition.</returns> |
| 127 | + public static AccessCondition GenerateIfModifiedSinceCondition(DateTimeOffset modifiedTime) |
| 128 | + { |
| 129 | + return new AccessCondition { IfModifiedSinceTime = modifiedTime }; |
| 130 | + } |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Constructs an access condition such that an operation will be performed only if the resource's ETag value |
| 134 | + /// does not match the specified ETag value. |
| 135 | + /// </summary> |
| 136 | + /// <param name="etag">The ETag value that must be matched, or <c>"*"</c>.</param> |
| 137 | + /// <returns>An <c>AccessCondition</c> object that represents the If-None-Match condition.</returns> |
| 138 | + /// <remarks> |
| 139 | + /// If <c>"*"</c> is specified as the parameter then this condition requires that the resource does not exist. |
| 140 | + /// </remarks> |
| 141 | + public static AccessCondition GenerateIfNoneMatchCondition(string etag) |
| 142 | + { |
| 143 | + return new AccessCondition { IfNoneMatchETag = etag }; |
| 144 | + } |
| 145 | + |
| 146 | + /// <summary> |
| 147 | + /// Constructs an access condition such that an operation will be performed only if the resource has not been |
| 148 | + /// modified since the specified time. |
| 149 | + /// </summary> |
| 150 | + /// <param name="modifiedTime">The time that must not be before the last modified time of the resource.</param> |
| 151 | + /// <returns>An <c>AccessCondition</c> object that represents the If-Unmodified-Since condition.</returns> |
| 152 | + public static AccessCondition GenerateIfNotModifiedSinceCondition(DateTimeOffset modifiedTime) |
| 153 | + { |
| 154 | + return new AccessCondition { IfNotModifiedSinceTime = modifiedTime }; |
| 155 | + } |
| 156 | + |
| 157 | + /// <summary> |
| 158 | + /// Constructs an access condition such that an operation will be performed only if the lease ID on the |
| 159 | + /// resource matches the specified lease ID. |
| 160 | + /// </summary> |
| 161 | + /// <param name="leaseId">The lease ID that must match the lease ID of the resource.</param> |
| 162 | + /// <returns>An <c>AccessCondition</c> object that represents the lease condition.</returns> |
| 163 | + public static AccessCondition GenerateLeaseCondition(string leaseId) |
| 164 | + { |
| 165 | + return new AccessCondition { LeaseId = leaseId }; |
| 166 | + } |
| 167 | + } |
| 168 | +} |
0 commit comments