| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Buffers; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.ComponentModel; |
| | 8 | | using System.Diagnostics; |
| | 9 | | using System.Globalization; |
| | 10 | | using System.IO; |
| | 11 | | using System.Runtime.InteropServices; |
| | 12 | | using System.Text; |
| | 13 | | using System.Threading; |
| | 14 | | using System.Threading.Tasks; |
| | 15 | | using Azure.Core; |
| | 16 | | using Azure.Core.Pipeline; |
| | 17 | | using Azure.Storage.Files.Shares.Models; |
| | 18 | | using Azure.Storage.Shared; |
| | 19 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 20 | |
|
| | 21 | | namespace Azure.Storage.Files.Shares |
| | 22 | | { |
| | 23 | | /// <summary> |
| | 24 | | /// The <see cref="ShareFileClient"/> allows you to manipulate Azure Storage files. |
| | 25 | | /// </summary> |
| | 26 | | public class ShareFileClient |
| | 27 | | { |
| | 28 | | /// <summary> |
| | 29 | | /// The directory's primary <see cref="Uri"/> endpoint. |
| | 30 | | /// </summary> |
| | 31 | | private readonly Uri _uri; |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets the directory's primary <see cref="Uri"/> endpoint. |
| | 35 | | /// </summary> |
| 1996 | 36 | | public virtual Uri Uri => _uri; |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 40 | | /// every request. |
| | 41 | | /// </summary> |
| | 42 | | private readonly HttpPipeline _pipeline; |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets the <see cref="HttpPipeline"/> transport pipeline used to send |
| | 46 | | /// every request. |
| | 47 | | /// </summary> |
| 3794 | 48 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// The version of the service to use when sending requests. |
| | 52 | | /// </summary> |
| | 53 | | private readonly ShareClientOptions.ServiceVersion _version; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// The version of the service to use when sending requests. |
| | 57 | | /// </summary> |
| 1858 | 58 | | internal virtual ShareClientOptions.ServiceVersion Version => _version; |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 62 | | /// every request. |
| | 63 | | /// </summary> |
| | 64 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 68 | | /// every request. |
| | 69 | | /// </summary> |
| 1876 | 70 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The Storage account name corresponding to the file client. |
| | 74 | | /// </summary> |
| | 75 | | private string _accountName; |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Gets the Storage account name corresponding to the file client. |
| | 79 | | /// </summary> |
| | 80 | | public virtual string AccountName |
| | 81 | | { |
| | 82 | | get |
| | 83 | | { |
| 4 | 84 | | SetNameFieldsIfNull(); |
| 4 | 85 | | return _accountName; |
| | 86 | | } |
| | 87 | | } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// The share name corresponding to the file client. |
| | 91 | | /// </summary> |
| | 92 | | private string _shareName; |
| | 93 | |
|
| | 94 | | /// <summary> |
| | 95 | | /// Gets the share name corresponding to the file client. |
| | 96 | | /// </summary> |
| | 97 | | public virtual string ShareName |
| | 98 | | { |
| | 99 | | get |
| | 100 | | { |
| 4 | 101 | | SetNameFieldsIfNull(); |
| 4 | 102 | | return _shareName; |
| | 103 | | } |
| | 104 | | } |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// The name of the file. |
| | 108 | | /// </summary> |
| | 109 | | private string _name; |
| | 110 | |
|
| | 111 | | /// <summary> |
| | 112 | | /// Gets the name of the file. |
| | 113 | | /// </summary> |
| | 114 | | public virtual string Name |
| | 115 | | { |
| | 116 | | get |
| | 117 | | { |
| 60 | 118 | | SetNameFieldsIfNull(); |
| 60 | 119 | | return _name; |
| | 120 | | } |
| | 121 | | } |
| | 122 | |
|
| | 123 | | /// <summary> |
| | 124 | | /// The path of the file. |
| | 125 | | /// </summary> |
| | 126 | | private string _path; |
| | 127 | |
|
| | 128 | | /// <summary> |
| | 129 | | /// Gets the path of the file. |
| | 130 | | /// </summary> |
| | 131 | | public virtual string Path |
| | 132 | | { |
| | 133 | | get |
| | 134 | | { |
| 54 | 135 | | SetNameFieldsIfNull(); |
| 54 | 136 | | return _path; |
| | 137 | | } |
| | 138 | | } |
| | 139 | |
|
| | 140 | | //const string fileType = "file"; |
| | 141 | |
|
| | 142 | | //// FileMaxUploadRangeBytes indicates the maximum number of bytes that can be sent in a call to UploadRange. |
| | 143 | | //public const Int64 FileMaxUploadRangeBytes = 4 * Constants.MB; // 4MB |
| | 144 | |
|
| | 145 | | //// FileMaxSizeInBytes indicates the maxiumum file size, in bytes. |
| | 146 | | //public const Int64 FileMaxSizeInBytes = 1 * Constants.TB; // 1TB |
| | 147 | |
|
| | 148 | | #region ctors |
| | 149 | | /// <summary> |
| | 150 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> |
| | 151 | | /// class for mocking. |
| | 152 | | /// </summary> |
| 314 | 153 | | protected ShareFileClient() |
| | 154 | | { |
| 314 | 155 | | } |
| | 156 | |
|
| | 157 | | /// <summary> |
| | 158 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> class. |
| | 159 | | /// </summary> |
| | 160 | | /// <param name="connectionString"> |
| | 161 | | /// A connection string includes the authentication information |
| | 162 | | /// required for your application to access data in an Azure Storage |
| | 163 | | /// account at runtime. |
| | 164 | | /// |
| | 165 | | /// For more information, see |
| | 166 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 167 | | /// Configure Azure Storage connection strings</see> |
| | 168 | | /// </param> |
| | 169 | | /// <param name="shareName"> |
| | 170 | | /// The name of the share in the storage account to reference. |
| | 171 | | /// </param> |
| | 172 | | /// <param name="filePath"> |
| | 173 | | /// The path of the file in the storage account to reference. |
| | 174 | | /// </param> |
| | 175 | | public ShareFileClient(string connectionString, string shareName, string filePath) |
| 0 | 176 | | : this(connectionString, shareName, filePath, null) |
| | 177 | | { |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | /// <summary> |
| | 181 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> class. |
| | 182 | | /// </summary> |
| | 183 | | /// <param name="connectionString"> |
| | 184 | | /// A connection string includes the authentication information |
| | 185 | | /// required for your application to access data in an Azure Storage |
| | 186 | | /// account at runtime. |
| | 187 | | /// |
| | 188 | | /// For more information, see |
| | 189 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 190 | | /// Configure Azure Storage connection strings</see> |
| | 191 | | /// </param> |
| | 192 | | /// <param name="shareName"> |
| | 193 | | /// The name of the share in the storage account to reference. |
| | 194 | | /// </param> |
| | 195 | | /// <param name="filePath"> |
| | 196 | | /// The path of the file in the storage account to reference. |
| | 197 | | /// </param> |
| | 198 | | /// <param name="options"> |
| | 199 | | /// Optional <see cref="ShareClientOptions"/> that define the transport |
| | 200 | | /// pipeline policies for authentication, retries, etc., that are |
| | 201 | | /// applied to every request. |
| | 202 | | /// </param> |
| 20 | 203 | | public ShareFileClient(string connectionString, string shareName, string filePath, ShareClientOptions options) |
| | 204 | | { |
| 20 | 205 | | options ??= new ShareClientOptions(); |
| 20 | 206 | | var conn = StorageConnectionString.Parse(connectionString); |
| 20 | 207 | | var builder = |
| 20 | 208 | | new ShareUriBuilder(conn.FileEndpoint) |
| 20 | 209 | | { |
| 20 | 210 | | ShareName = shareName, |
| 20 | 211 | | DirectoryOrFilePath = filePath |
| 20 | 212 | | }; |
| 20 | 213 | | _uri = builder.ToUri(); |
| 20 | 214 | | _pipeline = options.Build(conn.Credentials); |
| 20 | 215 | | _version = options.Version; |
| 20 | 216 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 20 | 217 | | } |
| | 218 | |
|
| | 219 | | /// <summary> |
| | 220 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> class. |
| | 221 | | /// </summary> |
| | 222 | | /// <param name="fileUri"> |
| | 223 | | /// A <see cref="Uri"/> referencing the file that includes the |
| | 224 | | /// name of the account, the name of the share, and the path of the |
| | 225 | | /// file. |
| | 226 | | /// </param> |
| | 227 | | /// <param name="options"> |
| | 228 | | /// Optional <see cref="ShareClientOptions"/> that define the transport |
| | 229 | | /// pipeline policies for authentication, retries, etc., that are |
| | 230 | | /// applied to every request. |
| | 231 | | /// </param> |
| | 232 | | public ShareFileClient(Uri fileUri, ShareClientOptions options = default) |
| 16 | 233 | | : this(fileUri, (HttpPipelinePolicy)null, options) |
| | 234 | | { |
| 16 | 235 | | } |
| | 236 | |
|
| | 237 | | /// <summary> |
| | 238 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> class. |
| | 239 | | /// </summary> |
| | 240 | | /// <param name="fileUri"> |
| | 241 | | /// A <see cref="Uri"/> referencing the file that includes the |
| | 242 | | /// name of the account, the name of the share, and the path of the |
| | 243 | | /// file. |
| | 244 | | /// </param> |
| | 245 | | /// <param name="credential"> |
| | 246 | | /// The shared key credential used to sign requests. |
| | 247 | | /// </param> |
| | 248 | | /// <param name="options"> |
| | 249 | | /// Optional <see cref="ShareClientOptions"/> that define the transport |
| | 250 | | /// pipeline policies for authentication, retries, etc., that are |
| | 251 | | /// applied to every request. |
| | 252 | | /// </param> |
| | 253 | | public ShareFileClient(Uri fileUri, StorageSharedKeyCredential credential, ShareClientOptions options = default) |
| 0 | 254 | | : this(fileUri, credential.AsPolicy(), options) |
| | 255 | | { |
| 0 | 256 | | } |
| | 257 | |
|
| | 258 | | /// <summary> |
| | 259 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> |
| | 260 | | /// class. |
| | 261 | | /// </summary> |
| | 262 | | /// <param name="fileUri"> |
| | 263 | | /// A <see cref="Uri"/> referencing the file that includes the |
| | 264 | | /// name of the account, the name of the share, and the path of the |
| | 265 | | /// file. |
| | 266 | | /// </param> |
| | 267 | | /// <param name="authentication"> |
| | 268 | | /// An optional authentication policy used to sign requests. |
| | 269 | | /// </param> |
| | 270 | | /// <param name="options"> |
| | 271 | | /// Optional client options that define the transport pipeline |
| | 272 | | /// policies for authentication, retries, etc., that are applied to |
| | 273 | | /// every request. |
| | 274 | | /// </param> |
| 16 | 275 | | internal ShareFileClient(Uri fileUri, HttpPipelinePolicy authentication, ShareClientOptions options) |
| | 276 | | { |
| 16 | 277 | | options ??= new ShareClientOptions(); |
| 16 | 278 | | _uri = fileUri; |
| 16 | 279 | | _pipeline = options.Build(authentication); |
| 16 | 280 | | _version = options.Version; |
| 16 | 281 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 16 | 282 | | } |
| | 283 | |
|
| | 284 | | /// <summary> |
| | 285 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> class. |
| | 286 | | /// </summary> |
| | 287 | | /// <param name="fileUri"> |
| | 288 | | /// A <see cref="Uri"/> referencing the file that includes the |
| | 289 | | /// name of the account, the name of the share, and the path of the file. |
| | 290 | | /// </param> |
| | 291 | | /// <param name="pipeline"> |
| | 292 | | /// The transport pipeline used to send every request. |
| | 293 | | /// </param> |
| | 294 | | /// <param name="version"> |
| | 295 | | /// The version of the service to use when sending requests. |
| | 296 | | /// </param> |
| | 297 | | /// <param name="clientDiagnostics"> |
| | 298 | | /// The <see cref="ClientDiagnostics"/> instance used to create |
| | 299 | | /// diagnostic scopes every request. |
| | 300 | | /// </param> |
| 326 | 301 | | internal ShareFileClient(Uri fileUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDi |
| | 302 | | { |
| 326 | 303 | | _uri = fileUri; |
| 326 | 304 | | _pipeline = pipeline; |
| 326 | 305 | | _version = version; |
| 326 | 306 | | _clientDiagnostics = clientDiagnostics; |
| 326 | 307 | | } |
| | 308 | | #endregion ctors |
| | 309 | |
|
| | 310 | | /// <summary> |
| | 311 | | /// Initializes a new instance of the <see cref="ShareFileClient"/> |
| | 312 | | /// class with an identical <see cref="Uri"/> source but the specified |
| | 313 | | /// <paramref name="shareSnapshot"/> timestamp. |
| | 314 | | /// |
| | 315 | | /// For more information, see |
| | 316 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/snapshot-share"> |
| | 317 | | /// Snapshot Share</see>. |
| | 318 | | /// </summary> |
| | 319 | | /// <remarks> |
| | 320 | | /// Pass null or empty string to remove the snapshot returning a URL to the base file. |
| | 321 | | /// </remarks> |
| | 322 | | /// <param name="shareSnapshot"> |
| | 323 | | /// The snapshot identifier. |
| | 324 | | /// </param> |
| | 325 | | /// <returns> |
| | 326 | | /// A new <see cref="ShareFileClient"/> instance. |
| | 327 | | /// </returns> |
| | 328 | | public virtual ShareFileClient WithSnapshot(string shareSnapshot) |
| | 329 | | { |
| 4 | 330 | | var builder = new ShareUriBuilder(Uri) { Snapshot = shareSnapshot }; |
| 4 | 331 | | return new ShareFileClient(builder.ToUri(), Pipeline, Version, ClientDiagnostics); |
| | 332 | | } |
| | 333 | |
|
| | 334 | | /// <summary> |
| | 335 | | /// Sets the various name fields if they are currently null. |
| | 336 | | /// </summary> |
| | 337 | | private void SetNameFieldsIfNull() |
| | 338 | | { |
| 122 | 339 | | if (_name == null || _shareName == null || _accountName == null || _path == null) |
| | 340 | | { |
| 50 | 341 | | var builder = new ShareUriBuilder(Uri); |
| 50 | 342 | | _name = builder.LastDirectoryOrFileName; |
| 50 | 343 | | _shareName = builder.ShareName; |
| 50 | 344 | | _accountName = builder.AccountName; |
| 50 | 345 | | _path = builder.DirectoryOrFilePath; |
| | 346 | | } |
| 122 | 347 | | } |
| | 348 | |
|
| | 349 | | #region Create |
| | 350 | | /// <summary> |
| | 351 | | /// Creates a new file or replaces an existing file. |
| | 352 | | /// |
| | 353 | | /// For more information, see |
| | 354 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file"> |
| | 355 | | /// Create File</see>. |
| | 356 | | /// </summary> |
| | 357 | | /// <remarks> |
| | 358 | | /// This method only initializes the file. |
| | 359 | | /// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequest |
| | 360 | | /// </remarks> |
| | 361 | | /// <param name="maxSize"> |
| | 362 | | /// Required. Specifies the maximum size for the file. |
| | 363 | | /// </param> |
| | 364 | | /// <param name="httpHeaders"> |
| | 365 | | /// Optional standard HTTP header properties that can be set for the file. |
| | 366 | | /// </param> |
| | 367 | | /// <param name="metadata"> |
| | 368 | | /// Optional custom metadata to set for the file. |
| | 369 | | /// </param> |
| | 370 | | /// <param name="smbProperties"> |
| | 371 | | /// Optional SMB properties to set for the file. |
| | 372 | | /// </param> |
| | 373 | | /// <param name="filePermission"> |
| | 374 | | /// Optional file permission to set for the file. |
| | 375 | | /// </param> |
| | 376 | | /// <param name="conditions"> |
| | 377 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 378 | | /// on creating the file. |
| | 379 | | /// </param> |
| | 380 | | /// <param name="cancellationToken"> |
| | 381 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 382 | | /// notifications that the operation should be cancelled. |
| | 383 | | /// </param> |
| | 384 | | /// <returns> |
| | 385 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 386 | | /// state of the file. |
| | 387 | | /// </returns> |
| | 388 | | /// <remarks> |
| | 389 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 390 | | /// a failure occurs. |
| | 391 | | /// </remarks> |
| | 392 | | public virtual Response<ShareFileInfo> Create( |
| | 393 | | long maxSize, |
| | 394 | | ShareFileHttpHeaders httpHeaders = default, |
| | 395 | | Metadata metadata = default, |
| | 396 | | FileSmbProperties smbProperties = default, |
| | 397 | | string filePermission = default, |
| | 398 | | ShareFileRequestConditions conditions = default, |
| | 399 | | CancellationToken cancellationToken = default) => |
| 125 | 400 | | CreateInternal( |
| 125 | 401 | | maxSize, |
| 125 | 402 | | httpHeaders, |
| 125 | 403 | | metadata, |
| 125 | 404 | | smbProperties, |
| 125 | 405 | | filePermission, |
| 125 | 406 | | conditions, |
| 125 | 407 | | async: false, |
| 125 | 408 | | cancellationToken) |
| 125 | 409 | | .EnsureCompleted(); |
| | 410 | |
|
| | 411 | | /// <summary> |
| | 412 | | /// Creates a new file or replaces an existing file. |
| | 413 | | /// |
| | 414 | | /// For more information, see |
| | 415 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file"> |
| | 416 | | /// Create File</see>. |
| | 417 | | /// </summary> |
| | 418 | | /// <remarks> |
| | 419 | | /// This method only initializes the file. |
| | 420 | | /// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequest |
| | 421 | | /// </remarks> |
| | 422 | | /// <param name="maxSize"> |
| | 423 | | /// Required. Specifies the maximum size for the file. |
| | 424 | | /// </param> |
| | 425 | | /// <param name="httpHeaders"> |
| | 426 | | /// Optional standard HTTP header properties that can be set for the file. |
| | 427 | | /// </param> |
| | 428 | | /// <param name="metadata"> |
| | 429 | | /// Optional custom metadata to set for the file. |
| | 430 | | /// </param> |
| | 431 | | /// <param name="smbProperties"> |
| | 432 | | /// Optional SMB properties to set for the file. |
| | 433 | | /// </param> |
| | 434 | | /// <param name="filePermission"> |
| | 435 | | /// Optional file permission to set for the file. |
| | 436 | | /// </param> |
| | 437 | | /// <param name="cancellationToken"> |
| | 438 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 439 | | /// notifications that the operation should be cancelled. |
| | 440 | | /// </param> |
| | 441 | | /// <returns> |
| | 442 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 443 | | /// state of the file. |
| | 444 | | /// </returns> |
| | 445 | | /// <remarks> |
| | 446 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 447 | | /// a failure occurs. |
| | 448 | | /// </remarks> |
| | 449 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 450 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 451 | | public virtual Response<ShareFileInfo> Create( |
| | 452 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 453 | | long maxSize, |
| | 454 | | ShareFileHttpHeaders httpHeaders, |
| | 455 | | Metadata metadata, |
| | 456 | | FileSmbProperties smbProperties, |
| | 457 | | string filePermission, |
| | 458 | | CancellationToken cancellationToken) => |
| 0 | 459 | | CreateInternal( |
| 0 | 460 | | maxSize, |
| 0 | 461 | | httpHeaders, |
| 0 | 462 | | metadata, |
| 0 | 463 | | smbProperties, |
| 0 | 464 | | filePermission, |
| 0 | 465 | | conditions: default, |
| 0 | 466 | | async: false, |
| 0 | 467 | | cancellationToken) |
| 0 | 468 | | .EnsureCompleted(); |
| | 469 | |
|
| | 470 | | /// <summary> |
| | 471 | | /// Creates a new file or replaces an existing file. |
| | 472 | | /// |
| | 473 | | /// For more information, see |
| | 474 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file"> |
| | 475 | | /// Create File</see>. |
| | 476 | | /// </summary> |
| | 477 | | /// <remarks> |
| | 478 | | /// This method only initializes the file. |
| | 479 | | /// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequest |
| | 480 | | /// </remarks> |
| | 481 | | /// <param name="maxSize"> |
| | 482 | | /// Required. Specifies the maximum size for the file. |
| | 483 | | /// </param> |
| | 484 | | /// <param name="httpHeaders"> |
| | 485 | | /// Optional standard HTTP header properties that can be set for the file. |
| | 486 | | /// </param> |
| | 487 | | /// <param name="metadata"> |
| | 488 | | /// Optional custom metadata to set for the file. |
| | 489 | | /// </param> |
| | 490 | | /// <param name="smbProperties"> |
| | 491 | | /// Optional SMB properties to set for the file. |
| | 492 | | /// </param> |
| | 493 | | /// <param name="filePermission"> |
| | 494 | | /// Optional file permission to set for the file. |
| | 495 | | /// </param> |
| | 496 | | /// <param name="conditions"> |
| | 497 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 498 | | /// on creating the file. |
| | 499 | | /// </param> |
| | 500 | | /// <param name="cancellationToken"> |
| | 501 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 502 | | /// notifications that the operation should be cancelled. |
| | 503 | | /// </param> |
| | 504 | | /// <returns> |
| | 505 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 506 | | /// state of the file. |
| | 507 | | /// </returns> |
| | 508 | | /// <remarks> |
| | 509 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 510 | | /// a failure occurs. |
| | 511 | | /// </remarks> |
| | 512 | | public virtual async Task<Response<ShareFileInfo>> CreateAsync( |
| | 513 | | long maxSize, |
| | 514 | | ShareFileHttpHeaders httpHeaders = default, |
| | 515 | | Metadata metadata = default, |
| | 516 | | FileSmbProperties smbProperties = default, |
| | 517 | | string filePermission = default, |
| | 518 | | ShareFileRequestConditions conditions = default, |
| | 519 | | CancellationToken cancellationToken = default) => |
| 125 | 520 | | await CreateInternal( |
| 125 | 521 | | maxSize, |
| 125 | 522 | | httpHeaders, |
| 125 | 523 | | metadata, |
| 125 | 524 | | smbProperties, |
| 125 | 525 | | filePermission, |
| 125 | 526 | | conditions, |
| 125 | 527 | | async: true, |
| 125 | 528 | | cancellationToken) |
| 125 | 529 | | .ConfigureAwait(false); |
| | 530 | |
|
| | 531 | | /// <summary> |
| | 532 | | /// Creates a new file or replaces an existing file. |
| | 533 | | /// |
| | 534 | | /// For more information, see |
| | 535 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file"> |
| | 536 | | /// Create File</see>. |
| | 537 | | /// </summary> |
| | 538 | | /// <remarks> |
| | 539 | | /// This method only initializes the file. |
| | 540 | | /// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequest |
| | 541 | | /// </remarks> |
| | 542 | | /// <param name="maxSize"> |
| | 543 | | /// Required. Specifies the maximum size for the file. |
| | 544 | | /// </param> |
| | 545 | | /// <param name="httpHeaders"> |
| | 546 | | /// Optional standard HTTP header properties that can be set for the file. |
| | 547 | | /// </param> |
| | 548 | | /// <param name="metadata"> |
| | 549 | | /// Optional custom metadata to set for the file. |
| | 550 | | /// </param> |
| | 551 | | /// <param name="smbProperties"> |
| | 552 | | /// Optional SMB properties to set for the file. |
| | 553 | | /// </param> |
| | 554 | | /// <param name="filePermission"> |
| | 555 | | /// Optional file permission to set for the file. |
| | 556 | | /// </param> |
| | 557 | | /// <param name="cancellationToken"> |
| | 558 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 559 | | /// notifications that the operation should be cancelled. |
| | 560 | | /// </param> |
| | 561 | | /// <returns> |
| | 562 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 563 | | /// state of the file. |
| | 564 | | /// </returns> |
| | 565 | | /// <remarks> |
| | 566 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 567 | | /// a failure occurs. |
| | 568 | | /// </remarks> |
| | 569 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 570 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 571 | | public virtual async Task<Response<ShareFileInfo>> CreateAsync( |
| | 572 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 573 | | long maxSize, |
| | 574 | | ShareFileHttpHeaders httpHeaders, |
| | 575 | | Metadata metadata, |
| | 576 | | FileSmbProperties smbProperties, |
| | 577 | | string filePermission, |
| | 578 | | CancellationToken cancellationToken) => |
| 0 | 579 | | await CreateInternal( |
| 0 | 580 | | maxSize, |
| 0 | 581 | | httpHeaders, |
| 0 | 582 | | metadata, |
| 0 | 583 | | smbProperties, |
| 0 | 584 | | filePermission, |
| 0 | 585 | | conditions: default, |
| 0 | 586 | | async: true, |
| 0 | 587 | | cancellationToken) |
| 0 | 588 | | .ConfigureAwait(false); |
| | 589 | |
|
| | 590 | | /// <summary> |
| | 591 | | /// Creates a new file or replaces an existing file. |
| | 592 | | /// |
| | 593 | | /// For more information, see |
| | 594 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-file"> |
| | 595 | | /// Create File</see>. |
| | 596 | | /// </summary> |
| | 597 | | /// <remarks> |
| | 598 | | /// This method only initializes the file. |
| | 599 | | /// To add content, use <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequest |
| | 600 | | /// </remarks> |
| | 601 | | /// <param name="maxSize"> |
| | 602 | | /// Required. Specifies the maximum size for the file. |
| | 603 | | /// </param> |
| | 604 | | /// <param name="httpHeaders"> |
| | 605 | | /// Optional standard HTTP header properties that can be set for the file. |
| | 606 | | /// </param> |
| | 607 | | /// <param name="metadata"> |
| | 608 | | /// Optional custom metadata to set for the file. |
| | 609 | | /// </param> |
| | 610 | | /// <param name="smbProperties"> |
| | 611 | | /// Optional SMB properties to set for the file. |
| | 612 | | /// </param> |
| | 613 | | /// <param name="filePermission"> |
| | 614 | | /// Optional file permission to set on the file. |
| | 615 | | /// </param> |
| | 616 | | /// <param name="conditions"> |
| | 617 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 618 | | /// on creating the file. |
| | 619 | | /// </param> |
| | 620 | | /// <param name="async"> |
| | 621 | | /// Whether to invoke the operation asynchronously. |
| | 622 | | /// </param> |
| | 623 | | /// <param name="cancellationToken"> |
| | 624 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 625 | | /// notifications that the operation should be cancelled. |
| | 626 | | /// </param> |
| | 627 | | /// <param name="operationName"> |
| | 628 | | /// Optional. To indicate if the name of the operation. |
| | 629 | | /// </param> |
| | 630 | | /// <returns> |
| | 631 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 632 | | /// state of the file. |
| | 633 | | /// </returns> |
| | 634 | | /// <remarks> |
| | 635 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 636 | | /// a failure occurs. |
| | 637 | | /// </remarks> |
| | 638 | | private async Task<Response<ShareFileInfo>> CreateInternal( |
| | 639 | | long maxSize, |
| | 640 | | ShareFileHttpHeaders httpHeaders, |
| | 641 | | Metadata metadata, |
| | 642 | | FileSmbProperties smbProperties, |
| | 643 | | string filePermission, |
| | 644 | | ShareFileRequestConditions conditions, |
| | 645 | | bool async, |
| | 646 | | CancellationToken cancellationToken, |
| | 647 | | string operationName = default) |
| | 648 | | { |
| 250 | 649 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 650 | | { |
| | 651 | | Pipeline.LogMethodEnter( |
| | 652 | | nameof(ShareFileClient), |
| | 653 | | message: |
| | 654 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 655 | | $"{nameof(maxSize)}: {maxSize}\n" + |
| | 656 | | $"{nameof(httpHeaders)}: {httpHeaders}"); |
| | 657 | | try |
| | 658 | | { |
| 250 | 659 | | FileSmbProperties smbProps = smbProperties ?? new FileSmbProperties(); |
| | 660 | |
|
| 250 | 661 | | ShareExtensions.AssertValidFilePermissionAndKey(filePermission, smbProps.FilePermissionKey); |
| | 662 | |
|
| 246 | 663 | | if (filePermission == null && smbProps.FilePermissionKey == null) |
| | 664 | | { |
| 242 | 665 | | filePermission = Constants.File.FilePermissionInherit; |
| | 666 | | } |
| | 667 | |
|
| 246 | 668 | | Response<RawStorageFileInfo> response = await FileRestClient.File.CreateAsync( |
| 246 | 669 | | ClientDiagnostics, |
| 246 | 670 | | Pipeline, |
| 246 | 671 | | Uri, |
| 246 | 672 | | version: Version.ToVersionString(), |
| 246 | 673 | | fileContentLength: maxSize, |
| 246 | 674 | | fileContentType: httpHeaders?.ContentType, |
| 246 | 675 | | fileContentEncoding: httpHeaders?.ContentEncoding, |
| 246 | 676 | | fileContentLanguage: httpHeaders?.ContentLanguage, |
| 246 | 677 | | fileCacheControl: httpHeaders?.CacheControl, |
| 246 | 678 | | fileContentHash: httpHeaders?.ContentHash, |
| 246 | 679 | | fileContentDisposition: httpHeaders?.ContentDisposition, |
| 246 | 680 | | metadata: metadata, |
| 246 | 681 | | fileAttributes: smbProps.FileAttributes?.ToAttributesString() ?? Constants.File.FileAttributesNo |
| 246 | 682 | | filePermission: filePermission, |
| 246 | 683 | | fileCreationTime: smbProps.FileCreatedOn.ToFileDateTimeString() ?? Constants.File.FileTimeNow, |
| 246 | 684 | | fileLastWriteTime: smbProps.FileLastWrittenOn.ToFileDateTimeString() ?? Constants.File.FileTimeN |
| 246 | 685 | | filePermissionKey: smbProps.FilePermissionKey, |
| 246 | 686 | | leaseId: conditions?.LeaseId, |
| 246 | 687 | | async: async, |
| 246 | 688 | | cancellationToken: cancellationToken, |
| 246 | 689 | | operationName: operationName ?? $"{nameof(ShareFileClient)}.{nameof(Create)}") |
| 246 | 690 | | .ConfigureAwait(false); |
| | 691 | |
|
| 242 | 692 | | return Response.FromValue(new ShareFileInfo(response.Value), response.GetRawResponse()); |
| | 693 | | } |
| 8 | 694 | | catch (Exception ex) |
| | 695 | | { |
| | 696 | | Pipeline.LogException(ex); |
| 8 | 697 | | throw; |
| | 698 | | } |
| | 699 | | finally |
| | 700 | | { |
| | 701 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 702 | | } |
| | 703 | | } |
| 242 | 704 | | } |
| | 705 | | #endregion Create |
| | 706 | |
|
| | 707 | | #region Exists |
| | 708 | | /// <summary> |
| | 709 | | /// The <see cref="Exists"/> operation can be called on a |
| | 710 | | /// <see cref="ShareFileClient"/> to see if the associated file |
| | 711 | | /// exists in the share on the storage account. |
| | 712 | | /// </summary> |
| | 713 | | /// <param name="cancellationToken"> |
| | 714 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 715 | | /// notifications that the operation should be cancelled. |
| | 716 | | /// </param> |
| | 717 | | /// <returns> |
| | 718 | | /// Returns true if the file exists. |
| | 719 | | /// </returns> |
| | 720 | | /// <remarks> |
| | 721 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 722 | | /// a failure occurs. |
| | 723 | | /// </remarks> |
| | 724 | | public virtual Response<bool> Exists( |
| | 725 | | CancellationToken cancellationToken = default) => |
| 4 | 726 | | ExistsInternal( |
| 4 | 727 | | async: false, |
| 4 | 728 | | cancellationToken: cancellationToken).EnsureCompleted(); |
| | 729 | |
|
| | 730 | | /// <summary> |
| | 731 | | /// The <see cref="Exists"/> operation can be called on a |
| | 732 | | /// <see cref="ShareFileClient"/> to see if the associated file |
| | 733 | | /// exists in the share on the storage account. |
| | 734 | | /// </summary> |
| | 735 | | /// <param name="cancellationToken"> |
| | 736 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 737 | | /// notifications that the operation should be cancelled. |
| | 738 | | /// </param> |
| | 739 | | /// <returns> |
| | 740 | | /// Returns true if the file exists. |
| | 741 | | /// </returns> |
| | 742 | | /// <remarks> |
| | 743 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 744 | | /// a failure occurs. |
| | 745 | | /// </remarks> |
| | 746 | | public virtual async Task<Response<bool>> ExistsAsync( |
| | 747 | | CancellationToken cancellationToken = default) => |
| 4 | 748 | | await ExistsInternal( |
| 4 | 749 | | async: true, |
| 4 | 750 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | 751 | |
|
| | 752 | | /// <summary> |
| | 753 | | /// The <see cref="ExistsInternal"/> operation can be called on a |
| | 754 | | /// <see cref="ShareFileClient"/> to see if the associated file |
| | 755 | | /// exists in the share on the storage account. |
| | 756 | | /// </summary> |
| | 757 | | /// <param name="async"> |
| | 758 | | /// Whether to invoke the operation asynchronously. |
| | 759 | | /// </param> |
| | 760 | | /// <param name="cancellationToken"> |
| | 761 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 762 | | /// notifications that the operation should be cancelled. |
| | 763 | | /// </param> |
| | 764 | | /// <param name="operationName"> |
| | 765 | | /// Optional. To indicate if the name of the operation. |
| | 766 | | /// </param> |
| | 767 | | /// <returns> |
| | 768 | | /// Returns true if the file exists. |
| | 769 | | /// </returns> |
| | 770 | | /// <remarks> |
| | 771 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 772 | | /// a failure occurs. |
| | 773 | | /// </remarks> |
| | 774 | | private async Task<Response<bool>> ExistsInternal( |
| | 775 | | bool async, |
| | 776 | | CancellationToken cancellationToken, |
| | 777 | | string operationName = default) |
| | 778 | | { |
| 8 | 779 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 780 | | { |
| | 781 | | Pipeline.LogMethodEnter( |
| | 782 | | nameof(ShareFileClient), |
| | 783 | | message: |
| | 784 | | $"{nameof(Uri)}: {Uri}"); |
| | 785 | |
|
| | 786 | | try |
| | 787 | | { |
| 8 | 788 | | Response<ShareFileProperties> response = await GetPropertiesInternal( |
| 8 | 789 | | conditions: default, |
| 8 | 790 | | async: async, |
| 8 | 791 | | cancellationToken: cancellationToken, |
| 8 | 792 | | operationName: operationName ?? $"{nameof(ShareFileClient)}.{nameof(Exists)}") |
| 8 | 793 | | .ConfigureAwait(false); |
| | 794 | |
|
| 2 | 795 | | return Response.FromValue(true, response.GetRawResponse()); |
| | 796 | | } |
| | 797 | | catch (RequestFailedException storageRequestFailedException) |
| 6 | 798 | | when (storageRequestFailedException.ErrorCode == ShareErrorCode.ResourceNotFound |
| 6 | 799 | | || storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound) |
| | 800 | | { |
| 4 | 801 | | return Response.FromValue(false, default); |
| | 802 | | } |
| 2 | 803 | | catch (Exception ex) |
| | 804 | | { |
| | 805 | | Pipeline.LogException(ex); |
| 2 | 806 | | throw; |
| | 807 | | } |
| | 808 | | finally |
| | 809 | | { |
| | 810 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 811 | | } |
| | 812 | | } |
| 6 | 813 | | } |
| | 814 | | #endregion Exists |
| | 815 | |
|
| | 816 | | #region DeleteIfExists |
| | 817 | | /// <summary> |
| | 818 | | /// The <see cref="DeleteIfExists"/> operation immediately removes the file from the storage account, |
| | 819 | | /// if it exists. |
| | 820 | | /// |
| | 821 | | /// For more information, see |
| | 822 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 823 | | /// Delete File</see>. |
| | 824 | | /// </summary> |
| | 825 | | /// <param name="conditions"> |
| | 826 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 827 | | /// on creating the file. |
| | 828 | | /// </param> |
| | 829 | | /// <param name="cancellationToken"> |
| | 830 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 831 | | /// notifications that the operation should be cancelled. |
| | 832 | | /// </param> |
| | 833 | | /// <returns> |
| | 834 | | /// True if the file existed. |
| | 835 | | /// </returns> |
| | 836 | | /// <remarks> |
| | 837 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 838 | | /// a failure occurs. |
| | 839 | | /// </remarks> |
| | 840 | | public virtual Response<bool> DeleteIfExists( |
| | 841 | | ShareFileRequestConditions conditions = default, |
| | 842 | | CancellationToken cancellationToken = default) => |
| 4 | 843 | | DeleteIfExistsInternal( |
| 4 | 844 | | conditions, |
| 4 | 845 | | async: false, |
| 4 | 846 | | cancellationToken: cancellationToken) |
| 4 | 847 | | .EnsureCompleted(); |
| | 848 | |
|
| | 849 | | /// <summary> |
| | 850 | | /// The <see cref="DeleteIfExists"/> operation immediately removes the file from the storage account, |
| | 851 | | /// if it exists. |
| | 852 | | /// |
| | 853 | | /// For more information, see |
| | 854 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 855 | | /// Delete File</see>. |
| | 856 | | /// </summary> |
| | 857 | | /// <param name="conditions"> |
| | 858 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 859 | | /// on creating the file. |
| | 860 | | /// </param> |
| | 861 | | /// <param name="cancellationToken"> |
| | 862 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 863 | | /// notifications that the operation should be cancelled. |
| | 864 | | /// </param> |
| | 865 | | /// <returns> |
| | 866 | | /// True if the file existed. |
| | 867 | | /// </returns> |
| | 868 | | /// <remarks> |
| | 869 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 870 | | /// a failure occurs. |
| | 871 | | /// </remarks> |
| | 872 | | public virtual async Task<Response<bool>> DeleteIfExistsAsync( |
| | 873 | | ShareFileRequestConditions conditions = default, |
| | 874 | | CancellationToken cancellationToken = default) => |
| 4 | 875 | | await DeleteIfExistsInternal( |
| 4 | 876 | | conditions, |
| 4 | 877 | | async: true, |
| 4 | 878 | | cancellationToken: cancellationToken) |
| 4 | 879 | | .ConfigureAwait(false); |
| | 880 | |
|
| | 881 | | /// <summary> |
| | 882 | | /// The <see cref="DeleteIfExistsInternal"/> operation immediately removes the file from the storage account, |
| | 883 | | /// if it exists. |
| | 884 | | /// |
| | 885 | | /// For more information, see |
| | 886 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 887 | | /// Delete File</see>. |
| | 888 | | /// </summary> |
| | 889 | | /// <param name="conditions"> |
| | 890 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 891 | | /// on creating the file. |
| | 892 | | /// </param> |
| | 893 | | /// <param name="async"> |
| | 894 | | /// Whether to invoke the operation asynchronously. |
| | 895 | | /// </param> |
| | 896 | | /// <param name="cancellationToken"> |
| | 897 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 898 | | /// notifications that the operation should be cancelled. |
| | 899 | | /// </param> |
| | 900 | | /// <returns> |
| | 901 | | /// True if the file existed. |
| | 902 | | /// </returns> |
| | 903 | | /// <remarks> |
| | 904 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 905 | | /// a failure occurs. |
| | 906 | | /// </remarks> |
| | 907 | | private async Task<Response<bool>> DeleteIfExistsInternal( |
| | 908 | | ShareFileRequestConditions conditions, |
| | 909 | | bool async, |
| | 910 | | CancellationToken cancellationToken) |
| | 911 | | { |
| 8 | 912 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 913 | | { |
| | 914 | | Pipeline.LogMethodEnter( |
| | 915 | | nameof(ShareFileClient), |
| | 916 | | message: |
| | 917 | | $"{nameof(Uri)}: {Uri}"); |
| | 918 | | try |
| | 919 | | { |
| 8 | 920 | | Response response = await DeleteInternal( |
| 8 | 921 | | conditions, |
| 8 | 922 | | async, |
| 8 | 923 | | cancellationToken, |
| 8 | 924 | | operationName: $"{nameof(ShareFileClient)}.{nameof(DeleteIfExists)}") |
| 8 | 925 | | .ConfigureAwait(false); |
| 2 | 926 | | return Response.FromValue(true, response); |
| | 927 | | } |
| | 928 | | catch (RequestFailedException storageRequestFailedException) |
| 6 | 929 | | when (storageRequestFailedException.ErrorCode == ShareErrorCode.ResourceNotFound |
| 6 | 930 | | || storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound) |
| | 931 | | { |
| 4 | 932 | | return Response.FromValue(false, default); |
| | 933 | | } |
| 2 | 934 | | catch (Exception ex) |
| | 935 | | { |
| | 936 | | Pipeline.LogException(ex); |
| 2 | 937 | | throw; |
| | 938 | | } |
| | 939 | | finally |
| | 940 | | { |
| | 941 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 942 | | } |
| | 943 | | } |
| 6 | 944 | | } |
| | 945 | | #endregion DeleteIfExists |
| | 946 | |
|
| | 947 | | #region StartCopy |
| | 948 | | /// <summary> |
| | 949 | | /// Copies a blob or file to a destination file within the storage account. |
| | 950 | | /// |
| | 951 | | /// For more information, see |
| | 952 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file"> |
| | 953 | | /// Copy File</see>. |
| | 954 | | /// </summary> |
| | 955 | | /// <param name="sourceUri"> |
| | 956 | | /// Required. Specifies the URL of the source file or blob. |
| | 957 | | /// </param> |
| | 958 | | /// <param name="metadata"> |
| | 959 | | /// Optional custom metadata to set for the file. |
| | 960 | | /// </param> |
| | 961 | | /// <param name="smbProperties"> |
| | 962 | | /// Optional SMB paramters to set on the target file. |
| | 963 | | /// </param> |
| | 964 | | /// <param name="filePermission"> |
| | 965 | | /// Optional file permission to set for the file. |
| | 966 | | /// </param> |
| | 967 | | /// <param name="filePermissionCopyMode"> |
| | 968 | | /// Specifies the option to copy file security descriptor from source file or |
| | 969 | | /// to set it using the value which is defined by the header value of FilePermission |
| | 970 | | /// or FilePermissionKey. |
| | 971 | | /// </param> |
| | 972 | | /// <param name="ignoreReadOnly"> |
| | 973 | | /// Optional boolean specifying to overwrite the target file if it already |
| | 974 | | /// exists and has read-only attribute set. |
| | 975 | | /// </param> |
| | 976 | | /// <param name="setArchiveAttribute"> |
| | 977 | | /// Optional boolean Specifying to set archive attribute on a target file. True |
| | 978 | | /// means archive attribute will be set on a target file despite attribute |
| | 979 | | /// overrides or a source file state. |
| | 980 | | /// </param> |
| | 981 | | /// <param name="conditions"> |
| | 982 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 983 | | /// on creating the file. |
| | 984 | | /// </param> |
| | 985 | | /// <param name="cancellationToken"> |
| | 986 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 987 | | /// notifications that the operation should be cancelled. |
| | 988 | | /// </param> |
| | 989 | | /// <returns> |
| | 990 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 991 | | /// state of the file copy. |
| | 992 | | /// </returns> |
| | 993 | | /// <remarks> |
| | 994 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 995 | | /// a failure occurs. |
| | 996 | | /// </remarks> |
| | 997 | | public virtual Response<ShareFileCopyInfo> StartCopy( |
| | 998 | | Uri sourceUri, |
| | 999 | | Metadata metadata = default, |
| | 1000 | | FileSmbProperties smbProperties = default, |
| | 1001 | | string filePermission = default, |
| | 1002 | | PermissionCopyMode? filePermissionCopyMode = default, |
| | 1003 | | bool? ignoreReadOnly = default, |
| | 1004 | | bool? setArchiveAttribute = default, |
| | 1005 | | ShareFileRequestConditions conditions = default, |
| | 1006 | | CancellationToken cancellationToken = default) => |
| 12 | 1007 | | StartCopyInternal( |
| 12 | 1008 | | sourceUri, |
| 12 | 1009 | | metadata, |
| 12 | 1010 | | smbProperties, |
| 12 | 1011 | | filePermission, |
| 12 | 1012 | | filePermissionCopyMode, |
| 12 | 1013 | | ignoreReadOnly, |
| 12 | 1014 | | setArchiveAttribute, |
| 12 | 1015 | | conditions, |
| 12 | 1016 | | async: false, |
| 12 | 1017 | | cancellationToken) |
| 12 | 1018 | | .EnsureCompleted(); |
| | 1019 | |
|
| | 1020 | | /// <summary> |
| | 1021 | | /// Copies a blob or file to a destination file within the storage account. |
| | 1022 | | /// |
| | 1023 | | /// For more information, see |
| | 1024 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file"> |
| | 1025 | | /// Copy File</see>. |
| | 1026 | | /// </summary> |
| | 1027 | | /// <param name="sourceUri"> |
| | 1028 | | /// Required. Specifies the URL of the source file or blob. |
| | 1029 | | /// </param> |
| | 1030 | | /// <param name="metadata"> |
| | 1031 | | /// Optional custom metadata to set for the file. |
| | 1032 | | /// </param> |
| | 1033 | | /// <param name="cancellationToken"> |
| | 1034 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1035 | | /// notifications that the operation should be cancelled. |
| | 1036 | | /// </param> |
| | 1037 | | /// <returns> |
| | 1038 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 1039 | | /// state of the file copy. |
| | 1040 | | /// </returns> |
| | 1041 | | /// <remarks> |
| | 1042 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1043 | | /// a failure occurs. |
| | 1044 | | /// </remarks> |
| | 1045 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1046 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1047 | | public virtual Response<ShareFileCopyInfo> StartCopy( |
| | 1048 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1049 | | Uri sourceUri, |
| | 1050 | | Metadata metadata, |
| | 1051 | | CancellationToken cancellationToken) => |
| 0 | 1052 | | StartCopyInternal( |
| 0 | 1053 | | sourceUri, |
| 0 | 1054 | | metadata, |
| 0 | 1055 | | smbProperties: default, |
| 0 | 1056 | | filePermission: default, |
| 0 | 1057 | | filePermissionCopyMode: default, |
| 0 | 1058 | | ignoreReadOnly: default, |
| 0 | 1059 | | setArchiveAttribute: default, |
| 0 | 1060 | | conditions: default, |
| 0 | 1061 | | async: false, |
| 0 | 1062 | | cancellationToken) |
| 0 | 1063 | | .EnsureCompleted(); |
| | 1064 | |
|
| | 1065 | | /// <summary> |
| | 1066 | | /// Copies a blob or file to a destination file within the storage account. |
| | 1067 | | /// |
| | 1068 | | /// For more information, see |
| | 1069 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file"> |
| | 1070 | | /// Copy File</see>. |
| | 1071 | | /// </summary> |
| | 1072 | | /// <param name="sourceUri"> |
| | 1073 | | /// Required. Specifies the URL of the source file or blob. |
| | 1074 | | /// </param> |
| | 1075 | | /// <param name="metadata"> |
| | 1076 | | /// Optional custom metadata to set for the file. |
| | 1077 | | /// </param> |
| | 1078 | | /// <param name="smbProperties"> |
| | 1079 | | /// Optional SMB properties to set on the target file. |
| | 1080 | | /// </param> |
| | 1081 | | /// <param name="filePermission"> |
| | 1082 | | /// Optional file permission to set for the file. |
| | 1083 | | /// </param> |
| | 1084 | | /// <param name="filePermissionCopyMode"> |
| | 1085 | | /// Specifies the option to copy file security descriptor from source file or |
| | 1086 | | /// to set it using the value which is defined by the header value of FilePermission |
| | 1087 | | /// or FilePermissionKey. |
| | 1088 | | /// </param> |
| | 1089 | | /// <param name="ignoreReadOnly"> |
| | 1090 | | /// Optional boolean specifying to overwrite the target file if it already |
| | 1091 | | /// exists and has read-only attribute set. |
| | 1092 | | /// </param> |
| | 1093 | | /// <param name="setArchiveAttribute"> |
| | 1094 | | /// Optional boolean Specifying to set archive attribute on a target file. True |
| | 1095 | | /// means archive attribute will be set on a target file despite attribute |
| | 1096 | | /// overrides or a source file state. |
| | 1097 | | /// </param> |
| | 1098 | | /// <param name="conditions"> |
| | 1099 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1100 | | /// on creating the file. |
| | 1101 | | /// </param> |
| | 1102 | | /// <param name="cancellationToken"> |
| | 1103 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1104 | | /// notifications that the operation should be cancelled. |
| | 1105 | | /// </param> |
| | 1106 | | /// <returns> |
| | 1107 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 1108 | | /// state of the file copy. |
| | 1109 | | /// </returns> |
| | 1110 | | /// <remarks> |
| | 1111 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1112 | | /// a failure occurs. |
| | 1113 | | /// </remarks> |
| | 1114 | | public virtual async Task<Response<ShareFileCopyInfo>> StartCopyAsync( |
| | 1115 | | Uri sourceUri, |
| | 1116 | | Metadata metadata = default, |
| | 1117 | | FileSmbProperties smbProperties = default, |
| | 1118 | | string filePermission = default, |
| | 1119 | | PermissionCopyMode? filePermissionCopyMode = default, |
| | 1120 | | bool? ignoreReadOnly = default, |
| | 1121 | | bool? setArchiveAttribute = default, |
| | 1122 | | ShareFileRequestConditions conditions = default, |
| | 1123 | | CancellationToken cancellationToken = default) => |
| 12 | 1124 | | await StartCopyInternal( |
| 12 | 1125 | | sourceUri, |
| 12 | 1126 | | metadata, |
| 12 | 1127 | | smbProperties, |
| 12 | 1128 | | filePermission, |
| 12 | 1129 | | filePermissionCopyMode, |
| 12 | 1130 | | ignoreReadOnly, |
| 12 | 1131 | | setArchiveAttribute, |
| 12 | 1132 | | conditions, |
| 12 | 1133 | | async: true, |
| 12 | 1134 | | cancellationToken). |
| 12 | 1135 | | ConfigureAwait(false); |
| | 1136 | |
|
| | 1137 | | /// <summary> |
| | 1138 | | /// Copies a blob or file to a destination file within the storage account. |
| | 1139 | | /// |
| | 1140 | | /// For more information, see |
| | 1141 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file"> |
| | 1142 | | /// Copy File</see>. |
| | 1143 | | /// </summary> |
| | 1144 | | /// <param name="sourceUri"> |
| | 1145 | | /// Required. Specifies the URL of the source file or blob. |
| | 1146 | | /// </param> |
| | 1147 | | /// <param name="metadata"> |
| | 1148 | | /// Optional custom metadata to set for the file. |
| | 1149 | | /// </param> |
| | 1150 | | /// <param name="cancellationToken"> |
| | 1151 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1152 | | /// notifications that the operation should be cancelled. |
| | 1153 | | /// </param> |
| | 1154 | | /// <returns> |
| | 1155 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 1156 | | /// state of the file copy. |
| | 1157 | | /// </returns> |
| | 1158 | | /// <remarks> |
| | 1159 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1160 | | /// a failure occurs. |
| | 1161 | | /// </remarks> |
| | 1162 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1163 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1164 | | public virtual async Task<Response<ShareFileCopyInfo>> StartCopyAsync( |
| | 1165 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1166 | | Uri sourceUri, |
| | 1167 | | Metadata metadata, |
| | 1168 | | CancellationToken cancellationToken) => |
| 0 | 1169 | | await StartCopyInternal( |
| 0 | 1170 | | sourceUri, |
| 0 | 1171 | | metadata, |
| 0 | 1172 | | smbProperties: default, |
| 0 | 1173 | | filePermission: default, |
| 0 | 1174 | | filePermissionCopyMode: default, |
| 0 | 1175 | | ignoreReadOnly: default, |
| 0 | 1176 | | setArchiveAttribute: default, |
| 0 | 1177 | | conditions: default, |
| 0 | 1178 | | async: true, |
| 0 | 1179 | | cancellationToken). |
| 0 | 1180 | | ConfigureAwait(false); |
| | 1181 | |
|
| | 1182 | | /// <summary> |
| | 1183 | | /// Copies a blob or file to a destination file within the storage account. |
| | 1184 | | /// |
| | 1185 | | /// For more information, see |
| | 1186 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file"> |
| | 1187 | | /// Copy File</see>. |
| | 1188 | | /// </summary> |
| | 1189 | | /// <param name="sourceUri"> |
| | 1190 | | /// Required. Specifies the URL of the source file or blob. |
| | 1191 | | /// </param> |
| | 1192 | | /// <param name="metadata"> |
| | 1193 | | /// Optional custom metadata to set for the file. |
| | 1194 | | /// </param> |
| | 1195 | | /// <param name="smbProperties"> |
| | 1196 | | /// Optional SMB properties to set on the target file. |
| | 1197 | | /// </param> |
| | 1198 | | /// <param name="filePermission"> |
| | 1199 | | /// Optional file permission to set for the file. |
| | 1200 | | /// </param> |
| | 1201 | | /// <param name="filePermissionCopyMode"> |
| | 1202 | | /// Specifies the option to copy file security descriptor from source file or |
| | 1203 | | /// to set it using the value which is defined by the header value of FilePermission |
| | 1204 | | /// or FilePermissionKey. |
| | 1205 | | /// </param> |
| | 1206 | | /// <param name="ignoreReadOnly"> |
| | 1207 | | /// Optional boolean specifying to overwrite the target file if it already |
| | 1208 | | /// exists and has read-only attribute set. |
| | 1209 | | /// </param> |
| | 1210 | | /// <param name="setArchiveAttribute"> |
| | 1211 | | /// Optional boolean Specifying to set archive attribute on a target file. True |
| | 1212 | | /// means archive attribute will be set on a target file despite attribute |
| | 1213 | | /// overrides or a source file state. |
| | 1214 | | /// </param> |
| | 1215 | | /// <param name="conditions"> |
| | 1216 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1217 | | /// on creating the file. |
| | 1218 | | /// </param> |
| | 1219 | | /// <param name="async"> |
| | 1220 | | /// Whether to invoke the operation asynchronously. |
| | 1221 | | /// </param> |
| | 1222 | | /// <param name="cancellationToken"> |
| | 1223 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1224 | | /// notifications that the operation should be cancelled. |
| | 1225 | | /// </param> |
| | 1226 | | /// <returns> |
| | 1227 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 1228 | | /// state of the file copy. |
| | 1229 | | /// </returns> |
| | 1230 | | /// <remarks> |
| | 1231 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1232 | | /// a failure occurs. |
| | 1233 | | /// </remarks> |
| | 1234 | | private async Task<Response<ShareFileCopyInfo>> StartCopyInternal( |
| | 1235 | | Uri sourceUri, |
| | 1236 | | Metadata metadata, |
| | 1237 | | FileSmbProperties smbProperties, |
| | 1238 | | string filePermission, |
| | 1239 | | PermissionCopyMode? filePermissionCopyMode, |
| | 1240 | | bool? ignoreReadOnly, |
| | 1241 | | bool? setArchiveAttribute, |
| | 1242 | | ShareFileRequestConditions conditions, |
| | 1243 | | bool async, |
| | 1244 | | CancellationToken cancellationToken) |
| | 1245 | | { |
| 24 | 1246 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 1247 | | { |
| | 1248 | | Pipeline.LogMethodEnter( |
| | 1249 | | nameof(ShareFileClient), |
| | 1250 | | message: |
| | 1251 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1252 | | $"{nameof(sourceUri)}: {sourceUri}"); |
| | 1253 | | try |
| | 1254 | | { |
| 24 | 1255 | | return await FileRestClient.File.StartCopyAsync( |
| 24 | 1256 | | ClientDiagnostics, |
| 24 | 1257 | | Pipeline, |
| 24 | 1258 | | Uri, |
| 24 | 1259 | | version: Version.ToVersionString(), |
| 24 | 1260 | | copySource: sourceUri, |
| 24 | 1261 | | metadata: metadata, |
| 24 | 1262 | | leaseId: conditions?.LeaseId, |
| 24 | 1263 | | filePermission: filePermission, |
| 24 | 1264 | | filePermissionKey: smbProperties?.FilePermissionKey, |
| 24 | 1265 | | filePermissionCopyMode: filePermissionCopyMode, |
| 24 | 1266 | | ignoreReadOnly: ignoreReadOnly, |
| 24 | 1267 | | fileAttributes: smbProperties?.FileAttributes?.ToAttributesString(), |
| 24 | 1268 | | fileCreationTime: smbProperties?.FileCreatedOn.ToFileDateTimeString(), |
| 24 | 1269 | | fileLastWriteTime: smbProperties?.FileLastWrittenOn.ToFileDateTimeString(), |
| 24 | 1270 | | setArchiveAttribute: setArchiveAttribute, |
| 24 | 1271 | | async: async, |
| 24 | 1272 | | cancellationToken: cancellationToken, |
| 24 | 1273 | | operationName: $"{nameof(ShareFileClient)}.{nameof(StartCopy)}") |
| 24 | 1274 | | .ConfigureAwait(false); |
| | 1275 | | } |
| 4 | 1276 | | catch (Exception ex) |
| | 1277 | | { |
| | 1278 | | Pipeline.LogException(ex); |
| 4 | 1279 | | throw; |
| | 1280 | | } |
| | 1281 | | finally |
| | 1282 | | { |
| | 1283 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 1284 | | } |
| | 1285 | | } |
| 20 | 1286 | | } |
| | 1287 | | #endregion StartCopy |
| | 1288 | |
|
| | 1289 | | // TODO The REST documentation say "full metadata", not "empty". Doc bug? |
| | 1290 | |
|
| | 1291 | | #region AbortCopy |
| | 1292 | | /// <summary> |
| | 1293 | | /// Attempts to cancel a pending copy that was previously started and leaves a destination file with zero length |
| | 1294 | | /// |
| | 1295 | | /// For more information, see |
| | 1296 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/abort-copy-file"> |
| | 1297 | | /// Abort Copy File</see>. |
| | 1298 | | /// </summary> |
| | 1299 | | /// <param name="copyId"> |
| | 1300 | | /// String identifier for the copy operation. |
| | 1301 | | /// </param> |
| | 1302 | | /// <param name="conditions"> |
| | 1303 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1304 | | /// on creating the file. |
| | 1305 | | /// </param> |
| | 1306 | | /// <param name="cancellationToken"> |
| | 1307 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1308 | | /// notifications that the operation should be cancelled. |
| | 1309 | | /// </param> |
| | 1310 | | /// <returns> |
| | 1311 | | /// A <see cref="Response"/> on successfully aborting. |
| | 1312 | | /// </returns> |
| | 1313 | | /// <remarks> |
| | 1314 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1315 | | /// a failure occurs. |
| | 1316 | | /// </remarks> |
| | 1317 | | public virtual Response AbortCopy( |
| | 1318 | | string copyId, |
| | 1319 | | ShareFileRequestConditions conditions = default, |
| | 1320 | | CancellationToken cancellationToken = default) => |
| 4 | 1321 | | AbortCopyInternal( |
| 4 | 1322 | | copyId, |
| 4 | 1323 | | conditions, |
| 4 | 1324 | | async: false, |
| 4 | 1325 | | cancellationToken) |
| 4 | 1326 | | .EnsureCompleted(); |
| | 1327 | |
|
| | 1328 | | /// <summary> |
| | 1329 | | /// Attempts to cancel a pending copy that was previously started and leaves a destination file with zero length |
| | 1330 | | /// |
| | 1331 | | /// For more information, see |
| | 1332 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/abort-copy-file"> |
| | 1333 | | /// Abort Copy File</see>. |
| | 1334 | | /// </summary> |
| | 1335 | | /// <param name="copyId"> |
| | 1336 | | /// String identifier for the copy operation. |
| | 1337 | | /// </param> |
| | 1338 | | /// <param name="cancellationToken"> |
| | 1339 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1340 | | /// notifications that the operation should be cancelled. |
| | 1341 | | /// </param> |
| | 1342 | | /// <returns> |
| | 1343 | | /// A <see cref="Response"/> on successfully aborting. |
| | 1344 | | /// </returns> |
| | 1345 | | /// <remarks> |
| | 1346 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1347 | | /// a failure occurs. |
| | 1348 | | /// </remarks> |
| | 1349 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1350 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1351 | | public virtual Response AbortCopy( |
| | 1352 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1353 | | string copyId, |
| | 1354 | | CancellationToken cancellationToken) => |
| 0 | 1355 | | AbortCopyInternal( |
| 0 | 1356 | | copyId, |
| 0 | 1357 | | conditions: default, |
| 0 | 1358 | | async: false, |
| 0 | 1359 | | cancellationToken) |
| 0 | 1360 | | .EnsureCompleted(); |
| | 1361 | |
|
| | 1362 | | /// <summary> |
| | 1363 | | /// Attempts to cancel a pending copy that was previously started and leaves a destination file with zero length |
| | 1364 | | /// |
| | 1365 | | /// For more information, see |
| | 1366 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/abort-copy-file"> |
| | 1367 | | /// Abort Copy File</see>. |
| | 1368 | | /// </summary> |
| | 1369 | | /// <param name="copyId"> |
| | 1370 | | /// String identifier for the copy operation. |
| | 1371 | | /// </param> |
| | 1372 | | /// <param name="conditions"> |
| | 1373 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1374 | | /// on creating the file. |
| | 1375 | | /// </param> |
| | 1376 | | /// <param name="cancellationToken"> |
| | 1377 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1378 | | /// notifications that the operation should be cancelled. |
| | 1379 | | /// </param> |
| | 1380 | | /// <returns> |
| | 1381 | | /// A <see cref="Response"/> on successfully aborting. |
| | 1382 | | /// </returns> |
| | 1383 | | /// <remarks> |
| | 1384 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1385 | | /// a failure occurs. |
| | 1386 | | /// </remarks> |
| | 1387 | | public virtual async Task<Response> AbortCopyAsync( |
| | 1388 | | string copyId, |
| | 1389 | | ShareFileRequestConditions conditions = default, |
| | 1390 | | CancellationToken cancellationToken = default) => |
| 4 | 1391 | | await AbortCopyInternal( |
| 4 | 1392 | | copyId, |
| 4 | 1393 | | conditions, |
| 4 | 1394 | | async: true, |
| 4 | 1395 | | cancellationToken) |
| 4 | 1396 | | .ConfigureAwait(false); |
| | 1397 | |
|
| | 1398 | | /// <summary> |
| | 1399 | | /// Attempts to cancel a pending copy that was previously started and leaves a destination file with zero length |
| | 1400 | | /// |
| | 1401 | | /// For more information, see |
| | 1402 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/abort-copy-file"> |
| | 1403 | | /// Abort Copy File</see>. |
| | 1404 | | /// </summary> |
| | 1405 | | /// <param name="copyId"> |
| | 1406 | | /// String identifier for the copy operation. |
| | 1407 | | /// </param> |
| | 1408 | | /// <param name="cancellationToken"> |
| | 1409 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1410 | | /// notifications that the operation should be cancelled. |
| | 1411 | | /// </param> |
| | 1412 | | /// <returns> |
| | 1413 | | /// A <see cref="Response"/> on successfully aborting. |
| | 1414 | | /// </returns> |
| | 1415 | | /// <remarks> |
| | 1416 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1417 | | /// a failure occurs. |
| | 1418 | | /// </remarks> |
| | 1419 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1420 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1421 | | public virtual async Task<Response> AbortCopyAsync( |
| | 1422 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1423 | | string copyId, |
| | 1424 | | CancellationToken cancellationToken) => |
| 0 | 1425 | | await AbortCopyInternal( |
| 0 | 1426 | | copyId, |
| 0 | 1427 | | conditions: default, |
| 0 | 1428 | | async: true, |
| 0 | 1429 | | cancellationToken) |
| 0 | 1430 | | .ConfigureAwait(false); |
| | 1431 | |
|
| | 1432 | | /// <summary> |
| | 1433 | | /// Attempts to cancel a pending copy that was previously started and leaves a destination file with zero length |
| | 1434 | | /// |
| | 1435 | | /// For more information, see |
| | 1436 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/abort-copy-file"> |
| | 1437 | | /// Abort Copy File</see>. |
| | 1438 | | /// </summary> |
| | 1439 | | /// <param name="copyId"> |
| | 1440 | | /// String identifier for the copy operation. |
| | 1441 | | /// </param> |
| | 1442 | | /// <param name="conditions"> |
| | 1443 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1444 | | /// on creating the file. |
| | 1445 | | /// </param> |
| | 1446 | | /// <param name="async"> |
| | 1447 | | /// Whether to invoke the operation asynchronously. |
| | 1448 | | /// </param> |
| | 1449 | | /// <param name="cancellationToken"> |
| | 1450 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1451 | | /// notifications that the operation should be cancelled. |
| | 1452 | | /// </param> |
| | 1453 | | /// <returns> |
| | 1454 | | /// A <see cref="Response"/> on successfully aborting. |
| | 1455 | | /// </returns> |
| | 1456 | | /// <remarks> |
| | 1457 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1458 | | /// a failure occurs. |
| | 1459 | | /// </remarks> |
| | 1460 | | private async Task<Response> AbortCopyInternal( |
| | 1461 | | string copyId, |
| | 1462 | | ShareFileRequestConditions conditions, |
| | 1463 | | bool async, |
| | 1464 | | CancellationToken cancellationToken) |
| | 1465 | | { |
| 8 | 1466 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 1467 | | { |
| | 1468 | | Pipeline.LogMethodEnter( |
| | 1469 | | nameof(ShareFileClient), |
| | 1470 | | message: |
| | 1471 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1472 | | $"{nameof(copyId)}: {copyId}"); |
| | 1473 | | try |
| | 1474 | | { |
| 8 | 1475 | | return await FileRestClient.File.AbortCopyAsync( |
| 8 | 1476 | | ClientDiagnostics, |
| 8 | 1477 | | Pipeline, |
| 8 | 1478 | | Uri, |
| 8 | 1479 | | copyId: copyId, |
| 8 | 1480 | | leaseId: conditions?.LeaseId, |
| 8 | 1481 | | version: Version.ToVersionString(), |
| 8 | 1482 | | async: async, |
| 8 | 1483 | | cancellationToken: cancellationToken, |
| 8 | 1484 | | operationName: $"{nameof(ShareFileClient)}.{nameof(AbortCopy)}") |
| 8 | 1485 | | .ConfigureAwait(false); |
| | 1486 | | } |
| 8 | 1487 | | catch (Exception ex) |
| | 1488 | | { |
| | 1489 | | Pipeline.LogException(ex); |
| 8 | 1490 | | throw; |
| | 1491 | | } |
| | 1492 | | finally |
| | 1493 | | { |
| | 1494 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 1495 | | } |
| | 1496 | | } |
| 0 | 1497 | | } |
| | 1498 | | #endregion AbortCopy |
| | 1499 | |
|
| | 1500 | | #region Download |
| | 1501 | | /// <summary> |
| | 1502 | | /// The <see cref="Download(HttpRange, bool, ShareFileRequestConditions, CancellationToken)"/> |
| | 1503 | | /// operation reads or downloads a file from the system, including its metadata and properties. |
| | 1504 | | /// |
| | 1505 | | /// For more information, see |
| | 1506 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1507 | | /// Get File</see>. |
| | 1508 | | /// </summary> |
| | 1509 | | /// <param name="range"> |
| | 1510 | | /// Optional. Only download the bytes of the file in the specified |
| | 1511 | | /// range. If not provided, download the entire file. |
| | 1512 | | /// </param> |
| | 1513 | | /// <param name="rangeGetContentHash"> |
| | 1514 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1515 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1516 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1517 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1518 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1519 | | /// is thrown. |
| | 1520 | | /// </param> |
| | 1521 | | /// <param name="conditions"> |
| | 1522 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1523 | | /// on creating the file. |
| | 1524 | | /// </param> |
| | 1525 | | /// <param name="cancellationToken"> |
| | 1526 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1527 | | /// notifications that the operation should be cancelled. |
| | 1528 | | /// </param> |
| | 1529 | | /// <returns> |
| | 1530 | | /// A <see cref="Response{StorageFileDownloadInfo}"/> describing the |
| | 1531 | | /// downloaded file. <see cref="ShareFileDownloadInfo.Content"/> contains |
| | 1532 | | /// the file's data. |
| | 1533 | | /// </returns> |
| | 1534 | | /// <remarks> |
| | 1535 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1536 | | /// a failure occurs. |
| | 1537 | | /// </remarks> |
| | 1538 | | public virtual Response<ShareFileDownloadInfo> Download( |
| | 1539 | | HttpRange range = default, |
| | 1540 | | bool rangeGetContentHash = default, |
| | 1541 | | ShareFileRequestConditions conditions = default, |
| | 1542 | | CancellationToken cancellationToken = default) => |
| 17 | 1543 | | DownloadInternal( |
| 17 | 1544 | | range, |
| 17 | 1545 | | rangeGetContentHash, |
| 17 | 1546 | | conditions, |
| 17 | 1547 | | async: false, |
| 17 | 1548 | | cancellationToken) |
| 17 | 1549 | | .EnsureCompleted(); |
| | 1550 | |
|
| | 1551 | | /// <summary> |
| | 1552 | | /// The <see cref="Download(HttpRange, bool, CancellationToken)"/> operation reads |
| | 1553 | | /// or downloads a file from the system, including its metadata and properties. |
| | 1554 | | /// |
| | 1555 | | /// For more information, see |
| | 1556 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1557 | | /// Get File</see>. |
| | 1558 | | /// </summary> |
| | 1559 | | /// <param name="range"> |
| | 1560 | | /// Optional. Only download the bytes of the file in the specified |
| | 1561 | | /// range. If not provided, download the entire file. |
| | 1562 | | /// </param> |
| | 1563 | | /// <param name="rangeGetContentHash"> |
| | 1564 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1565 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1566 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1567 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1568 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1569 | | /// is thrown. |
| | 1570 | | /// </param> |
| | 1571 | | /// <param name="cancellationToken"> |
| | 1572 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1573 | | /// notifications that the operation should be cancelled. |
| | 1574 | | /// </param> |
| | 1575 | | /// <returns> |
| | 1576 | | /// A <see cref="Response{StorageFileDownloadInfo}"/> describing the |
| | 1577 | | /// downloaded file. <see cref="ShareFileDownloadInfo.Content"/> contains |
| | 1578 | | /// the file's data. |
| | 1579 | | /// </returns> |
| | 1580 | | /// <remarks> |
| | 1581 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1582 | | /// a failure occurs. |
| | 1583 | | /// </remarks> |
| | 1584 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1585 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1586 | | public virtual Response<ShareFileDownloadInfo> Download( |
| | 1587 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1588 | | HttpRange range, |
| | 1589 | | bool rangeGetContentHash, |
| | 1590 | | CancellationToken cancellationToken) => |
| 0 | 1591 | | DownloadInternal( |
| 0 | 1592 | | range, |
| 0 | 1593 | | rangeGetContentHash, |
| 0 | 1594 | | conditions: default, |
| 0 | 1595 | | async: false, |
| 0 | 1596 | | cancellationToken) |
| 0 | 1597 | | .EnsureCompleted(); |
| | 1598 | |
|
| | 1599 | | /// <summary> |
| | 1600 | | /// The <see cref="DownloadAsync(HttpRange, bool, ShareFileRequestConditions, CancellationToken)"/> |
| | 1601 | | /// operation reads or downloads a file from the system, including its metadata and properties. |
| | 1602 | | /// |
| | 1603 | | /// For more information, see |
| | 1604 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1605 | | /// Get File</see>. |
| | 1606 | | /// </summary> |
| | 1607 | | /// <param name="range"> |
| | 1608 | | /// Optional. Only download the bytes of the file in the specified |
| | 1609 | | /// range. If not provided, download the entire file. |
| | 1610 | | /// </param> |
| | 1611 | | /// <param name="rangeGetContentHash"> |
| | 1612 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1613 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1614 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1615 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1616 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1617 | | /// is thrown. |
| | 1618 | | /// </param> |
| | 1619 | | /// <param name="conditions"> |
| | 1620 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1621 | | /// on creating the file. |
| | 1622 | | /// </param> |
| | 1623 | | /// <param name="cancellationToken"> |
| | 1624 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1625 | | /// notifications that the operation should be cancelled. |
| | 1626 | | /// </param> |
| | 1627 | | /// <returns> |
| | 1628 | | /// A <see cref="Response{StorageFileDownloadInfo}"/> describing the |
| | 1629 | | /// downloaded file. <see cref="ShareFileDownloadInfo.Content"/> contains |
| | 1630 | | /// the file's data. |
| | 1631 | | /// </returns> |
| | 1632 | | /// <remarks> |
| | 1633 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1634 | | /// a failure occurs. |
| | 1635 | | /// </remarks> |
| | 1636 | | public virtual async Task<Response<ShareFileDownloadInfo>> DownloadAsync( |
| | 1637 | | HttpRange range = default, |
| | 1638 | | bool rangeGetContentHash = default, |
| | 1639 | | ShareFileRequestConditions conditions = default, |
| | 1640 | | CancellationToken cancellationToken = default) => |
| 17 | 1641 | | await DownloadInternal( |
| 17 | 1642 | | range, |
| 17 | 1643 | | rangeGetContentHash, |
| 17 | 1644 | | conditions, |
| 17 | 1645 | | async: true, |
| 17 | 1646 | | cancellationToken) |
| 17 | 1647 | | .ConfigureAwait(false); |
| | 1648 | |
|
| | 1649 | | /// <summary> |
| | 1650 | | /// The <see cref="DownloadAsync(HttpRange, bool, CancellationToken)"/> operation reads |
| | 1651 | | /// or downloads a file from the system, including its metadata and properties. |
| | 1652 | | /// |
| | 1653 | | /// For more information, see |
| | 1654 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1655 | | /// Get File</see>. |
| | 1656 | | /// </summary> |
| | 1657 | | /// <param name="range"> |
| | 1658 | | /// Optional. Only download the bytes of the file in the specified |
| | 1659 | | /// range. If not provided, download the entire file. |
| | 1660 | | /// </param> |
| | 1661 | | /// <param name="rangeGetContentHash"> |
| | 1662 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1663 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1664 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1665 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1666 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1667 | | /// is thrown. |
| | 1668 | | /// </param> |
| | 1669 | | /// <param name="cancellationToken"> |
| | 1670 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1671 | | /// notifications that the operation should be cancelled. |
| | 1672 | | /// </param> |
| | 1673 | | /// <returns> |
| | 1674 | | /// A <see cref="Response{StorageFileDownloadInfo}"/> describing the |
| | 1675 | | /// downloaded file. <see cref="ShareFileDownloadInfo.Content"/> contains |
| | 1676 | | /// the file's data. |
| | 1677 | | /// </returns> |
| | 1678 | | /// <remarks> |
| | 1679 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1680 | | /// a failure occurs. |
| | 1681 | | /// </remarks> |
| | 1682 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1683 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1684 | | public virtual async Task<Response<ShareFileDownloadInfo>> DownloadAsync( |
| | 1685 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 1686 | | HttpRange range, |
| | 1687 | | bool rangeGetContentHash, |
| | 1688 | | CancellationToken cancellationToken) => |
| 0 | 1689 | | await DownloadInternal( |
| 0 | 1690 | | range, |
| 0 | 1691 | | rangeGetContentHash, |
| 0 | 1692 | | conditions: default, |
| 0 | 1693 | | async: true, |
| 0 | 1694 | | cancellationToken) |
| 0 | 1695 | | .ConfigureAwait(false); |
| | 1696 | |
|
| | 1697 | | /// <summary> |
| | 1698 | | /// The <see cref="DownloadInternal"/> operation reads or downloads a file from the system, including its metada |
| | 1699 | | /// |
| | 1700 | | /// For more information, see |
| | 1701 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1702 | | /// Get File</see>. |
| | 1703 | | /// </summary> |
| | 1704 | | /// <param name="range"> |
| | 1705 | | /// Optional. Only download the bytes of the file in the specified |
| | 1706 | | /// range. If not provided, download the entire file. |
| | 1707 | | /// </param> |
| | 1708 | | /// <param name="rangeGetContentHash"> |
| | 1709 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1710 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1711 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1712 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1713 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1714 | | /// is thrown. |
| | 1715 | | /// </param> |
| | 1716 | | /// <param name="conditions"> |
| | 1717 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1718 | | /// on creating the file. |
| | 1719 | | /// </param> |
| | 1720 | | /// <param name="async"> |
| | 1721 | | /// Whether to invoke the operation asynchronously. |
| | 1722 | | /// </param> |
| | 1723 | | /// <param name="cancellationToken"> |
| | 1724 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1725 | | /// notifications that the operation should be cancelled. |
| | 1726 | | /// </param> |
| | 1727 | | /// <returns> |
| | 1728 | | /// A <see cref="Response{StorageFileDownloadInfo}"/> describing the |
| | 1729 | | /// downloaded file. <see cref="ShareFileDownloadInfo.Content"/> contains |
| | 1730 | | /// the file's data. |
| | 1731 | | /// </returns> |
| | 1732 | | /// <remarks> |
| | 1733 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1734 | | /// a failure occurs. |
| | 1735 | | /// </remarks> |
| | 1736 | | private async Task<Response<ShareFileDownloadInfo>> DownloadInternal( |
| | 1737 | | HttpRange range, |
| | 1738 | | bool rangeGetContentHash, |
| | 1739 | | ShareFileRequestConditions conditions, |
| | 1740 | | bool async, |
| | 1741 | | CancellationToken cancellationToken) |
| | 1742 | | { |
| 66 | 1743 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 1744 | | { |
| | 1745 | | Pipeline.LogMethodEnter( |
| | 1746 | | nameof(ShareFileClient), |
| | 1747 | | message: |
| | 1748 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1749 | | $"{nameof(rangeGetContentHash)}: {rangeGetContentHash}"); |
| | 1750 | | try |
| | 1751 | | { |
| | 1752 | | // Start downloading the file |
| 66 | 1753 | | (Response<FlattenedStorageFileProperties> response, Stream stream) = await StartDownloadAsync( |
| 66 | 1754 | | range, |
| 66 | 1755 | | rangeGetContentHash, |
| 66 | 1756 | | conditions: conditions, |
| 66 | 1757 | | async: async, |
| 66 | 1758 | | cancellationToken: cancellationToken) |
| 66 | 1759 | | .ConfigureAwait(false); |
| | 1760 | |
|
| | 1761 | | // Wrap the response Content in a RetriableStream so we |
| | 1762 | | // can return it before it's finished downloading, but still |
| | 1763 | | // allow retrying if it fails. |
| 60 | 1764 | | response.Value.Content = RetriableStream.Create( |
| 60 | 1765 | | stream, |
| 60 | 1766 | | startOffset => |
| 0 | 1767 | | StartDownloadAsync( |
| 0 | 1768 | | range, |
| 0 | 1769 | | rangeGetContentHash, |
| 0 | 1770 | | startOffset, |
| 0 | 1771 | | conditions, |
| 0 | 1772 | | async, |
| 0 | 1773 | | cancellationToken) |
| 0 | 1774 | | .EnsureCompleted() |
| 0 | 1775 | | .Item2, |
| 60 | 1776 | | async startOffset => |
| 62 | 1777 | | (await StartDownloadAsync( |
| 62 | 1778 | | range, |
| 62 | 1779 | | rangeGetContentHash, |
| 62 | 1780 | | startOffset, |
| 62 | 1781 | | conditions, |
| 62 | 1782 | | async, |
| 62 | 1783 | | cancellationToken) |
| 62 | 1784 | | .ConfigureAwait(false)) |
| 62 | 1785 | | .Item2, |
| 60 | 1786 | | Pipeline.ResponseClassifier, |
| 60 | 1787 | | Constants.MaxReliabilityRetries); |
| | 1788 | |
|
| | 1789 | | // Wrap the FlattenedStorageFileProperties into a StorageFileDownloadInfo |
| | 1790 | | // to make the Content easier to find |
| 60 | 1791 | | return Response.FromValue(new ShareFileDownloadInfo(response.Value), response.GetRawResponse()); |
| | 1792 | | } |
| 6 | 1793 | | catch (Exception ex) |
| | 1794 | | { |
| | 1795 | | Pipeline.LogException(ex); |
| 6 | 1796 | | throw; |
| | 1797 | | } |
| | 1798 | | finally |
| | 1799 | | { |
| | 1800 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 1801 | | } |
| | 1802 | | } |
| 60 | 1803 | | } |
| | 1804 | |
|
| | 1805 | | /// <summary> |
| | 1806 | | /// The <see cref="StartDownloadAsync"/> operation starts to read or downloads a file from the system, including |
| | 1807 | | /// |
| | 1808 | | /// For more information, see |
| | 1809 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file"> |
| | 1810 | | /// Get File</see>. |
| | 1811 | | /// </summary> |
| | 1812 | | /// <param name="range"> |
| | 1813 | | /// Optional. Only download the bytes of the file in the specified |
| | 1814 | | /// range. If not provided, download the entire file. |
| | 1815 | | /// </param> |
| | 1816 | | /// <param name="rangeGetContentHash"> |
| | 1817 | | /// When set to true and specified together with the <paramref name="range"/>, |
| | 1818 | | /// the service returns the MD5 hash for the range, as long as the |
| | 1819 | | /// range is less than or equal to 4 MB in size. If this value is |
| | 1820 | | /// specified without <paramref name="range"/> or set to true when the |
| | 1821 | | /// range exceeds 4 MB in size, a <see cref="RequestFailedException"/> |
| | 1822 | | /// is thrown. |
| | 1823 | | /// </param> |
| | 1824 | | /// <param name="startOffset"> |
| | 1825 | | /// Optional. Starting offset to request - in the event of a retry. |
| | 1826 | | /// </param> |
| | 1827 | | /// <param name="conditions"> |
| | 1828 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 1829 | | /// on creating the file. |
| | 1830 | | /// </param> |
| | 1831 | | /// <param name="async"> |
| | 1832 | | /// Whether to invoke the operation asynchronously. |
| | 1833 | | /// </param> |
| | 1834 | | /// <param name="cancellationToken"> |
| | 1835 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1836 | | /// notifications that the operation should be cancelled. |
| | 1837 | | /// </param> |
| | 1838 | | /// <returns> |
| | 1839 | | /// A <see cref="Response{FlattenedStorageFileProperties}"/> describing the |
| | 1840 | | /// downloaded file. <see cref="FlattenedStorageFileProperties.Content"/> contains |
| | 1841 | | /// the file's data. |
| | 1842 | | /// </returns> |
| | 1843 | | private async Task<(Response<FlattenedStorageFileProperties>, Stream)> StartDownloadAsync( |
| | 1844 | | HttpRange range = default, |
| | 1845 | | bool rangeGetContentHash = default, |
| | 1846 | | long startOffset = 0, |
| | 1847 | | ShareFileRequestConditions conditions = default, |
| | 1848 | | bool async = true, |
| | 1849 | | CancellationToken cancellationToken = default) |
| | 1850 | | { |
| 68 | 1851 | | var pageRange = new HttpRange( |
| 68 | 1852 | | range.Offset + startOffset, |
| 68 | 1853 | | range.Length.HasValue ? |
| 68 | 1854 | | range.Length.Value - startOffset : |
| 68 | 1855 | | (long?)null); |
| | 1856 | | Pipeline.LogTrace($"Download {Uri} with range: {pageRange}"); |
| 68 | 1857 | | (Response<FlattenedStorageFileProperties> response, Stream stream) = |
| 68 | 1858 | | await FileRestClient.File.DownloadAsync( |
| 68 | 1859 | | ClientDiagnostics, |
| 68 | 1860 | | Pipeline, |
| 68 | 1861 | | Uri, |
| 68 | 1862 | | version: Version.ToVersionString(), |
| 68 | 1863 | | range: pageRange.ToString(), |
| 68 | 1864 | | rangeGetContentHash: rangeGetContentHash ? (bool?)true : null, |
| 68 | 1865 | | leaseId: conditions?.LeaseId, |
| 68 | 1866 | | async: async, |
| 68 | 1867 | | cancellationToken: cancellationToken, |
| 68 | 1868 | | operationName: $"{nameof(ShareFileClient)}.{nameof(Download)}") |
| 68 | 1869 | | .ConfigureAwait(false); |
| | 1870 | | Pipeline.LogTrace($"Response: {response.GetRawResponse().Status}, ContentLength: {response.Value.ContentLeng |
| 62 | 1871 | | return (response, stream); |
| 62 | 1872 | | } |
| | 1873 | | #endregion Download |
| | 1874 | |
|
| | 1875 | | #region OpenRead |
| | 1876 | | /// <summary> |
| | 1877 | | /// Opens a stream for reading from the file. The stream will only download |
| | 1878 | | /// the file as the stream is read from. |
| | 1879 | | /// </summary> |
| | 1880 | | /// <param name="position"> |
| | 1881 | | /// The position within the file to begin the stream. |
| | 1882 | | /// Defaults to the beginning of the file. |
| | 1883 | | /// </param> |
| | 1884 | | /// <param name="bufferSize"> |
| | 1885 | | /// The buffer size to use when the stream downloads parts |
| | 1886 | | /// of the file. Defaults to 1 MB. |
| | 1887 | | /// </param> |
| | 1888 | | /// <param name="conditions"> |
| | 1889 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions on |
| | 1890 | | /// the download of this file. |
| | 1891 | | /// </param> |
| | 1892 | | /// <param name="cancellationToken"> |
| | 1893 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1894 | | /// notifications that the operation should be cancelled. |
| | 1895 | | /// </param> |
| | 1896 | | /// <returns> |
| | 1897 | | /// Returns a stream that will download the file as the stream |
| | 1898 | | /// is read from. |
| | 1899 | | /// </returns> |
| | 1900 | | #pragma warning disable AZC0015 // Unexpected client method return type. |
| | 1901 | | public virtual Stream OpenRead( |
| | 1902 | | #pragma warning restore AZC0015 // Unexpected client method return type. |
| | 1903 | | long position = 0, |
| | 1904 | | int? bufferSize = default, |
| | 1905 | | ShareFileRequestConditions conditions = default, |
| | 1906 | | CancellationToken cancellationToken = default) |
| 1 | 1907 | | => OpenReadInteral( |
| 1 | 1908 | | position, |
| 1 | 1909 | | bufferSize, |
| 1 | 1910 | | conditions, |
| 1 | 1911 | | async: false, |
| 1 | 1912 | | cancellationToken).EnsureCompleted(); |
| | 1913 | |
|
| | 1914 | | /// <summary> |
| | 1915 | | /// Opens a stream for reading from the file. The stream will only download |
| | 1916 | | /// the file as the stream is read from. |
| | 1917 | | /// </summary> |
| | 1918 | | /// <param name="allowfileModifications"> |
| | 1919 | | /// If true, you can continue streaming a blob even if it has been modified. |
| | 1920 | | /// </param> |
| | 1921 | | /// <param name="position"> |
| | 1922 | | /// The position within the file to begin the stream. |
| | 1923 | | /// Defaults to the beginning of the file. |
| | 1924 | | /// </param> |
| | 1925 | | /// <param name="bufferSize"> |
| | 1926 | | /// The buffer size to use when the stream downloads parts |
| | 1927 | | /// of the file. Defaults to 1 MB. |
| | 1928 | | /// </param> |
| | 1929 | | /// <param name="cancellationToken"> |
| | 1930 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1931 | | /// notifications that the operation should be cancelled. |
| | 1932 | | /// </param> |
| | 1933 | | /// <returns> |
| | 1934 | | /// Returns a stream that will download the file as the stream |
| | 1935 | | /// is read from. |
| | 1936 | | /// </returns> |
| | 1937 | | #pragma warning disable AZC0015 // Unexpected client method return type. |
| | 1938 | | public virtual Stream OpenRead( |
| | 1939 | | #pragma warning restore AZC0015 // Unexpected client method return type. |
| | 1940 | | bool allowfileModifications, |
| | 1941 | | long position = 0, |
| | 1942 | | int? bufferSize = default, |
| | 1943 | | CancellationToken cancellationToken = default) |
| 0 | 1944 | | => OpenRead( |
| 0 | 1945 | | position, |
| 0 | 1946 | | bufferSize, |
| 0 | 1947 | | allowfileModifications ? new ShareFileRequestConditions() : null, |
| 0 | 1948 | | cancellationToken); |
| | 1949 | |
|
| | 1950 | | /// <summary> |
| | 1951 | | /// Opens a stream for reading from the file. The stream will only download |
| | 1952 | | /// the file as the stream is read from. |
| | 1953 | | /// </summary> |
| | 1954 | | /// <param name="position"> |
| | 1955 | | /// The position within the file to begin the stream. |
| | 1956 | | /// Defaults to the beginning of the file. |
| | 1957 | | /// </param> |
| | 1958 | | /// <param name="bufferSize"> |
| | 1959 | | /// The buffer size to use when the stream downloads parts |
| | 1960 | | /// of the file. Defaults to 1 MB. |
| | 1961 | | /// </param> |
| | 1962 | | /// <param name="conditions"> |
| | 1963 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions on |
| | 1964 | | /// the download of the file. |
| | 1965 | | /// </param> |
| | 1966 | | /// <param name="cancellationToken"> |
| | 1967 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1968 | | /// notifications that the operation should be cancelled. |
| | 1969 | | /// </param> |
| | 1970 | | /// <returns> |
| | 1971 | | /// Returns a stream that will download the file as the stream |
| | 1972 | | /// is read from. |
| | 1973 | | /// </returns> |
| | 1974 | | #pragma warning disable AZC0015 // Unexpected client method return type. |
| | 1975 | | public virtual async Task<Stream> OpenReadAsync( |
| | 1976 | | #pragma warning restore AZC0015 // Unexpected client method return type. |
| | 1977 | | long position = 0, |
| | 1978 | | int? bufferSize = default, |
| | 1979 | | ShareFileRequestConditions conditions = default, |
| | 1980 | | CancellationToken cancellationToken = default) |
| 13 | 1981 | | => await OpenReadInteral( |
| 13 | 1982 | | position, |
| 13 | 1983 | | bufferSize, |
| 13 | 1984 | | conditions, |
| 13 | 1985 | | async: true, |
| 13 | 1986 | | cancellationToken).ConfigureAwait(false); |
| | 1987 | |
|
| | 1988 | | /// <summary> |
| | 1989 | | /// Opens a stream for reading from the file. The stream will only download |
| | 1990 | | /// the file as the stream is read from. |
| | 1991 | | /// </summary> |
| | 1992 | | /// <param name="allowfileModifications"> |
| | 1993 | | /// If true, you can continue streaming a blob even if it has been modified. |
| | 1994 | | /// </param> |
| | 1995 | | /// <param name="position"> |
| | 1996 | | /// The position within the file to begin the stream. |
| | 1997 | | /// Defaults to the beginning of the file. |
| | 1998 | | /// </param> |
| | 1999 | | /// <param name="bufferSize"> |
| | 2000 | | /// The buffer size to use when the stream downloads parts |
| | 2001 | | /// of the file. Defaults to 1 MB. |
| | 2002 | | /// </param> |
| | 2003 | | /// <param name="cancellationToken"> |
| | 2004 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2005 | | /// notifications that the operation should be cancelled. |
| | 2006 | | /// </param> |
| | 2007 | | /// <returns> |
| | 2008 | | /// Returns a stream that will download the file as the stream |
| | 2009 | | /// is read from. |
| | 2010 | | /// </returns> |
| | 2011 | | #pragma warning disable AZC0015 // Unexpected client method return type. |
| | 2012 | | public virtual async Task<Stream> OpenReadAsync( |
| | 2013 | | #pragma warning restore AZC0015 // Unexpected client method return type. |
| | 2014 | | bool allowfileModifications, |
| | 2015 | | long position = 0, |
| | 2016 | | int? bufferSize = default, |
| | 2017 | | CancellationToken cancellationToken = default) |
| 0 | 2018 | | => await OpenReadAsync( |
| 0 | 2019 | | position, |
| 0 | 2020 | | bufferSize, |
| 0 | 2021 | | allowfileModifications ? new ShareFileRequestConditions() : null, |
| 0 | 2022 | | cancellationToken).ConfigureAwait(false); |
| | 2023 | |
|
| | 2024 | | /// <summary> |
| | 2025 | | /// Opens a stream for reading from the file. The stream will only download |
| | 2026 | | /// the file as the stream is read from. |
| | 2027 | | /// </summary> |
| | 2028 | | /// <param name="position"> |
| | 2029 | | /// The position within the file to begin the stream. |
| | 2030 | | /// Defaults to the beginning of the file. |
| | 2031 | | /// </param> |
| | 2032 | | /// <param name="bufferSize"> |
| | 2033 | | /// The buffer size to use when the stream downloads parts |
| | 2034 | | /// of the file. Defaults to 1 MB. |
| | 2035 | | /// </param> |
| | 2036 | | /// <param name="conditions"> |
| | 2037 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions on |
| | 2038 | | /// the download of the file. |
| | 2039 | | /// </param> |
| | 2040 | | /// <param name="async"> |
| | 2041 | | /// Whether to invoke the operation asynchronously. |
| | 2042 | | /// </param> |
| | 2043 | | /// <param name="cancellationToken"> |
| | 2044 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2045 | | /// notifications that the operation should be cancelled. |
| | 2046 | | /// </param> |
| | 2047 | | /// <returns> |
| | 2048 | | /// Returns a stream that will download the file as the stream |
| | 2049 | | /// is read from. |
| | 2050 | | /// </returns> |
| | 2051 | | #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously |
| | 2052 | | internal async Task<Stream> OpenReadInteral( |
| | 2053 | | #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously |
| | 2054 | | long position, |
| | 2055 | | int? bufferSize, |
| | 2056 | | ShareFileRequestConditions conditions, |
| | 2057 | | #pragma warning disable CA1801 |
| | 2058 | | bool async, |
| | 2059 | | CancellationToken cancellationToken) |
| | 2060 | | #pragma warning restore CA1801 |
| | 2061 | | { |
| 14 | 2062 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(ShareFileClient)}.{nameof(OpenRead)}"); |
| | 2063 | | try |
| | 2064 | | { |
| 14 | 2065 | | scope.Start(); |
| | 2066 | |
|
| 14 | 2067 | | return new LazyLoadingReadOnlyStream<ShareFileRequestConditions, ShareFileProperties>( |
| 14 | 2068 | | async (HttpRange range, |
| 14 | 2069 | | ShareFileRequestConditions conditions, |
| 14 | 2070 | | bool rangeGetContentHash, |
| 14 | 2071 | | bool async, |
| 14 | 2072 | | CancellationToken cancellationToken) => |
| 14 | 2073 | | { |
| 46 | 2074 | | Response<ShareFileDownloadInfo> response = await DownloadInternal( |
| 46 | 2075 | | range, |
| 46 | 2076 | | rangeGetContentHash, |
| 46 | 2077 | | conditions, |
| 46 | 2078 | | async, |
| 46 | 2079 | | cancellationToken).ConfigureAwait(false); |
| 14 | 2080 | |
|
| 42 | 2081 | | return Response.FromValue( |
| 42 | 2082 | | (IDownloadedContent)response.Value, |
| 42 | 2083 | | response.GetRawResponse()); |
| 42 | 2084 | | }, |
| 14 | 2085 | | createRequestConditionsFunc: null, |
| 14 | 2086 | | async (bool async, CancellationToken cancellationToken) |
| 0 | 2087 | | => await GetPropertiesInternal(conditions: default, async, cancellationToken).ConfigureAwait(fal |
| 14 | 2088 | | position, |
| 14 | 2089 | | bufferSize, |
| 14 | 2090 | | conditions); |
| | 2091 | | } |
| 0 | 2092 | | catch (Exception ex) |
| | 2093 | | { |
| 0 | 2094 | | scope.Failed(ex); |
| 0 | 2095 | | throw; |
| | 2096 | | } |
| | 2097 | | finally |
| | 2098 | | { |
| 14 | 2099 | | scope.Dispose(); |
| | 2100 | | } |
| 14 | 2101 | | } |
| | 2102 | | #endregion OpenRead |
| | 2103 | |
|
| | 2104 | | #region Delete |
| | 2105 | | /// <summary> |
| | 2106 | | /// The <see cref="Delete(ShareFileRequestConditions, CancellationToken)"/> |
| | 2107 | | /// operation immediately removes the file from the storage account. |
| | 2108 | | /// |
| | 2109 | | /// For more information, see |
| | 2110 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 2111 | | /// Delete File</see>. |
| | 2112 | | /// </summary> |
| | 2113 | | /// <param name="conditions"> |
| | 2114 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2115 | | /// on creating the file. |
| | 2116 | | /// </param> |
| | 2117 | | /// <param name="cancellationToken"> |
| | 2118 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2119 | | /// notifications that the operation should be cancelled. |
| | 2120 | | /// </param> |
| | 2121 | | /// <returns> |
| | 2122 | | /// A <see cref="Response"/> on successfully deleting. |
| | 2123 | | /// </returns> |
| | 2124 | | /// <remarks> |
| | 2125 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2126 | | /// a failure occurs. |
| | 2127 | | /// </remarks> |
| | 2128 | | public virtual Response Delete( |
| | 2129 | | ShareFileRequestConditions conditions = default, |
| | 2130 | | CancellationToken cancellationToken = default) => |
| 5 | 2131 | | DeleteInternal( |
| 5 | 2132 | | conditions, |
| 5 | 2133 | | async: false, |
| 5 | 2134 | | cancellationToken) |
| 5 | 2135 | | .EnsureCompleted(); |
| | 2136 | |
|
| | 2137 | | /// <summary> |
| | 2138 | | /// The <see cref="Delete(CancellationToken)"/> operation immediately |
| | 2139 | | /// removes the file from the storage account. |
| | 2140 | | /// |
| | 2141 | | /// For more information, see |
| | 2142 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 2143 | | /// Delete File</see>. |
| | 2144 | | /// </summary> |
| | 2145 | | /// <param name="cancellationToken"> |
| | 2146 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2147 | | /// notifications that the operation should be cancelled. |
| | 2148 | | /// </param> |
| | 2149 | | /// <returns> |
| | 2150 | | /// A <see cref="Response"/> on successfully deleting. |
| | 2151 | | /// </returns> |
| | 2152 | | /// <remarks> |
| | 2153 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2154 | | /// a failure occurs. |
| | 2155 | | /// </remarks> |
| | 2156 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2157 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2158 | | public virtual Response Delete( |
| | 2159 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2160 | | CancellationToken cancellationToken) => |
| 0 | 2161 | | DeleteInternal( |
| 0 | 2162 | | conditions: default, |
| 0 | 2163 | | async: false, |
| 0 | 2164 | | cancellationToken) |
| 0 | 2165 | | .EnsureCompleted(); |
| | 2166 | |
|
| | 2167 | | /// <summary> |
| | 2168 | | /// The <see cref="DeleteAsync(ShareFileRequestConditions, CancellationToken)"/> operation |
| | 2169 | | /// immediately removes the file from the storage account. |
| | 2170 | | /// |
| | 2171 | | /// For more information, see |
| | 2172 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 2173 | | /// Delete File</see>. |
| | 2174 | | /// </summary> |
| | 2175 | | /// <param name="conditions"> |
| | 2176 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2177 | | /// on creating the file. |
| | 2178 | | /// </param> |
| | 2179 | | /// <param name="cancellationToken"> |
| | 2180 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2181 | | /// notifications that the operation should be cancelled. |
| | 2182 | | /// </param> |
| | 2183 | | /// <returns> |
| | 2184 | | /// A <see cref="Response"/> on successfully deleting. |
| | 2185 | | /// </returns> |
| | 2186 | | /// <remarks> |
| | 2187 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2188 | | /// a failure occurs. |
| | 2189 | | /// </remarks> |
| | 2190 | | public virtual async Task<Response> DeleteAsync( |
| | 2191 | | ShareFileRequestConditions conditions = default, |
| | 2192 | | CancellationToken cancellationToken = default) => |
| 5 | 2193 | | await DeleteInternal( |
| 5 | 2194 | | conditions, |
| 5 | 2195 | | async: true, |
| 5 | 2196 | | cancellationToken) |
| 5 | 2197 | | .ConfigureAwait(false); |
| | 2198 | |
|
| | 2199 | | /// <summary> |
| | 2200 | | /// The <see cref="DeleteAsync(CancellationToken)"/> operation |
| | 2201 | | /// immediately removes the file from the storage account. |
| | 2202 | | /// |
| | 2203 | | /// For more information, see |
| | 2204 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 2205 | | /// Delete File</see>. |
| | 2206 | | /// </summary> |
| | 2207 | | /// <param name="cancellationToken"> |
| | 2208 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2209 | | /// notifications that the operation should be cancelled. |
| | 2210 | | /// </param> |
| | 2211 | | /// <returns> |
| | 2212 | | /// A <see cref="Response"/> on successfully deleting. |
| | 2213 | | /// </returns> |
| | 2214 | | /// <remarks> |
| | 2215 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2216 | | /// a failure occurs. |
| | 2217 | | /// </remarks> |
| | 2218 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2219 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2220 | | public virtual async Task<Response> DeleteAsync( |
| | 2221 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2222 | | CancellationToken cancellationToken) => |
| 0 | 2223 | | await DeleteInternal( |
| 0 | 2224 | | conditions: default, |
| 0 | 2225 | | async: true, |
| 0 | 2226 | | cancellationToken) |
| 0 | 2227 | | .ConfigureAwait(false); |
| | 2228 | |
|
| | 2229 | | /// <summary> |
| | 2230 | | /// The <see cref="DeleteInternal"/> operation immediately removes the file from the storage account. |
| | 2231 | | /// |
| | 2232 | | /// For more information, see |
| | 2233 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-file2"> |
| | 2234 | | /// Delete File</see>. |
| | 2235 | | /// </summary> |
| | 2236 | | /// <param name="conditions"> |
| | 2237 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2238 | | /// on creating the file. |
| | 2239 | | /// </param> |
| | 2240 | | /// <param name="async"> |
| | 2241 | | /// Whether to invoke the operation asynchronously. |
| | 2242 | | /// </param> |
| | 2243 | | /// <param name="cancellationToken"> |
| | 2244 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2245 | | /// notifications that the operation should be cancelled. |
| | 2246 | | /// </param> |
| | 2247 | | /// <param name="operationName"> |
| | 2248 | | /// Optional. To indicate if the name of the operation. |
| | 2249 | | /// </param> |
| | 2250 | | /// <returns> |
| | 2251 | | /// A <see cref="Response"/> on successfully deleting. |
| | 2252 | | /// </returns> |
| | 2253 | | /// <remarks> |
| | 2254 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2255 | | /// a failure occurs. |
| | 2256 | | /// </remarks> |
| | 2257 | | private async Task<Response> DeleteInternal( |
| | 2258 | | ShareFileRequestConditions conditions, |
| | 2259 | | bool async, |
| | 2260 | | CancellationToken cancellationToken, |
| | 2261 | | string operationName = default) |
| | 2262 | | { |
| 18 | 2263 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 2264 | | { |
| | 2265 | | Pipeline.LogMethodEnter( |
| | 2266 | | nameof(ShareFileClient), |
| | 2267 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 2268 | | try |
| | 2269 | | { |
| 18 | 2270 | | return await FileRestClient.File.DeleteAsync( |
| 18 | 2271 | | clientDiagnostics: ClientDiagnostics, |
| 18 | 2272 | | pipeline: Pipeline, |
| 18 | 2273 | | resourceUri: Uri, |
| 18 | 2274 | | leaseId: conditions?.LeaseId, |
| 18 | 2275 | | version: Version.ToVersionString(), |
| 18 | 2276 | | async: async, |
| 18 | 2277 | | cancellationToken: cancellationToken, |
| 18 | 2278 | | operationName: operationName ?? $"{nameof(ShareFileClient)}.{nameof(Delete)}") |
| 18 | 2279 | | .ConfigureAwait(false); |
| | 2280 | | } |
| 10 | 2281 | | catch (Exception ex) |
| | 2282 | | { |
| | 2283 | | Pipeline.LogException(ex); |
| 10 | 2284 | | throw; |
| | 2285 | | } |
| | 2286 | | finally |
| | 2287 | | { |
| | 2288 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 2289 | | } |
| | 2290 | | } |
| 8 | 2291 | | } |
| | 2292 | | #endregion Delete |
| | 2293 | |
|
| | 2294 | | #region GetProperties |
| | 2295 | | /// <summary> |
| | 2296 | | /// The <see cref="GetProperties(ShareFileRequestConditions, CancellationToken)"/> |
| | 2297 | | /// operation returns all user-defined metadata, standard HTTP properties, |
| | 2298 | | /// and system properties for the file. It does not return the content of the |
| | 2299 | | /// file. |
| | 2300 | | /// |
| | 2301 | | /// For more information, see |
| | 2302 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file-properties"> |
| | 2303 | | /// Get File Properties</see>. |
| | 2304 | | /// </summary> |
| | 2305 | | /// <param name="conditions"> |
| | 2306 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2307 | | /// on creating the file. |
| | 2308 | | /// </param> |
| | 2309 | | /// <param name="cancellationToken"> |
| | 2310 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2311 | | /// notifications that the operation should be cancelled. |
| | 2312 | | /// </param> |
| | 2313 | | /// <returns> |
| | 2314 | | /// A <see cref="Response{StorageFileProperties}"/> describing the |
| | 2315 | | /// file's properties. |
| | 2316 | | /// </returns> |
| | 2317 | | /// <remarks> |
| | 2318 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2319 | | /// a failure occurs. |
| | 2320 | | /// </remarks> |
| | 2321 | | public virtual Response<ShareFileProperties> GetProperties( |
| | 2322 | | ShareFileRequestConditions conditions = default, |
| | 2323 | | CancellationToken cancellationToken = default) => |
| 29 | 2324 | | GetPropertiesInternal( |
| 29 | 2325 | | conditions, |
| 29 | 2326 | | async: false, |
| 29 | 2327 | | cancellationToken) |
| 29 | 2328 | | .EnsureCompleted(); |
| | 2329 | |
|
| | 2330 | | /// <summary> |
| | 2331 | | /// The <see cref="GetProperties(CancellationToken)"/> operation |
| | 2332 | | /// returns all user-defined metadata, standard HTTP properties, |
| | 2333 | | /// and system properties for the file. It does not return the |
| | 2334 | | /// content of the file. |
| | 2335 | | /// |
| | 2336 | | /// For more information, see |
| | 2337 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file-properties"> |
| | 2338 | | /// Get File Properties</see>. |
| | 2339 | | /// </summary> |
| | 2340 | | /// <param name="cancellationToken"> |
| | 2341 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2342 | | /// notifications that the operation should be cancelled. |
| | 2343 | | /// </param> |
| | 2344 | | /// <returns> |
| | 2345 | | /// A <see cref="Response{StorageFileProperties}"/> describing the |
| | 2346 | | /// file's properties. |
| | 2347 | | /// </returns> |
| | 2348 | | /// <remarks> |
| | 2349 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2350 | | /// a failure occurs. |
| | 2351 | | /// </remarks> |
| | 2352 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2353 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2354 | | public virtual Response<ShareFileProperties> GetProperties( |
| | 2355 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2356 | | CancellationToken cancellationToken) => |
| 0 | 2357 | | GetPropertiesInternal( |
| 0 | 2358 | | conditions: default, |
| 0 | 2359 | | async: false, |
| 0 | 2360 | | cancellationToken) |
| 0 | 2361 | | .EnsureCompleted(); |
| | 2362 | |
|
| | 2363 | | /// <summary> |
| | 2364 | | /// The <see cref="GetPropertiesAsync(ShareFileRequestConditions, CancellationToken)"/> |
| | 2365 | | /// operation returns all user-defined metadata, standard HTTP properties, and system |
| | 2366 | | /// properties for the file. It does not return the content of the file. |
| | 2367 | | /// |
| | 2368 | | /// For more information, see |
| | 2369 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file-properties"> |
| | 2370 | | /// Get File Properties</see>. |
| | 2371 | | /// </summary> |
| | 2372 | | /// <param name="conditions"> |
| | 2373 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2374 | | /// on creating the file. |
| | 2375 | | /// </param> |
| | 2376 | | /// <param name="cancellationToken"> |
| | 2377 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2378 | | /// notifications that the operation should be cancelled. |
| | 2379 | | /// </param> |
| | 2380 | | /// <returns> |
| | 2381 | | /// A <see cref="Response{StorageFileProperties}"/> describing the |
| | 2382 | | /// file's properties. |
| | 2383 | | /// </returns> |
| | 2384 | | /// <remarks> |
| | 2385 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2386 | | /// a failure occurs. |
| | 2387 | | /// </remarks> |
| | 2388 | | public virtual async Task<Response<ShareFileProperties>> GetPropertiesAsync( |
| | 2389 | | ShareFileRequestConditions conditions = default, |
| | 2390 | | CancellationToken cancellationToken = default) => |
| 51 | 2391 | | await GetPropertiesInternal( |
| 51 | 2392 | | conditions, |
| 51 | 2393 | | true, // async |
| 51 | 2394 | | cancellationToken) |
| 51 | 2395 | | .ConfigureAwait(false); |
| | 2396 | |
|
| | 2397 | | /// <summary> |
| | 2398 | | /// The <see cref="GetPropertiesAsync(CancellationToken)"/> operation returns all |
| | 2399 | | /// user-defined metadata, standard HTTP properties, and system |
| | 2400 | | /// properties for the file. It does not return the content of the |
| | 2401 | | /// file. |
| | 2402 | | /// |
| | 2403 | | /// For more information, see |
| | 2404 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file-properties"> |
| | 2405 | | /// Get File Properties</see>. |
| | 2406 | | /// </summary> |
| | 2407 | | /// <param name="cancellationToken"> |
| | 2408 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2409 | | /// notifications that the operation should be cancelled. |
| | 2410 | | /// </param> |
| | 2411 | | /// <returns> |
| | 2412 | | /// A <see cref="Response{StorageFileProperties}"/> describing the |
| | 2413 | | /// file's properties. |
| | 2414 | | /// </returns> |
| | 2415 | | /// <remarks> |
| | 2416 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2417 | | /// a failure occurs. |
| | 2418 | | /// </remarks> |
| | 2419 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2420 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2421 | | public virtual async Task<Response<ShareFileProperties>> GetPropertiesAsync( |
| | 2422 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2423 | | CancellationToken cancellationToken) => |
| 0 | 2424 | | await GetPropertiesInternal( |
| 0 | 2425 | | conditions: default, |
| 0 | 2426 | | async: true, |
| 0 | 2427 | | cancellationToken) |
| 0 | 2428 | | .ConfigureAwait(false); |
| | 2429 | |
|
| | 2430 | | /// <summary> |
| | 2431 | | /// The <see cref="GetPropertiesInternal"/> operation returns all |
| | 2432 | | /// user-defined metadata, standard HTTP properties, and system |
| | 2433 | | /// properties for the file. It does not return the content of the |
| | 2434 | | /// file. |
| | 2435 | | /// |
| | 2436 | | /// For more information, see |
| | 2437 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-file-properties"> |
| | 2438 | | /// Get File Properties</see>. |
| | 2439 | | /// </summary> |
| | 2440 | | /// <param name="conditions"> |
| | 2441 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2442 | | /// on creating the file. |
| | 2443 | | /// </param> |
| | 2444 | | /// <param name="async"> |
| | 2445 | | /// Whether to invoke the operation asynchronously. |
| | 2446 | | /// </param> |
| | 2447 | | /// <param name="cancellationToken"> |
| | 2448 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2449 | | /// notifications that the operation should be cancelled. |
| | 2450 | | /// </param> |
| | 2451 | | /// <param name="operationName"> |
| | 2452 | | /// Optional. To indicate if the name of the operation. |
| | 2453 | | /// </param> |
| | 2454 | | /// <returns> |
| | 2455 | | /// A <see cref="Response{StorageFileProperties}"/> describing the |
| | 2456 | | /// file's properties. |
| | 2457 | | /// </returns> |
| | 2458 | | /// <remarks> |
| | 2459 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2460 | | /// a failure occurs. |
| | 2461 | | /// </remarks> |
| | 2462 | | private async Task<Response<ShareFileProperties>> GetPropertiesInternal( |
| | 2463 | | ShareFileRequestConditions conditions, |
| | 2464 | | bool async, |
| | 2465 | | CancellationToken cancellationToken, |
| | 2466 | | string operationName = default) |
| | 2467 | | { |
| 88 | 2468 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 2469 | | { |
| | 2470 | | Pipeline.LogMethodEnter( |
| | 2471 | | nameof(ShareFileClient), |
| | 2472 | | message: |
| | 2473 | | $"{nameof(Uri)}: {Uri}"); |
| | 2474 | | try |
| | 2475 | | { |
| 88 | 2476 | | Response<RawStorageFileProperties> response = await FileRestClient.File.GetPropertiesAsync( |
| 88 | 2477 | | ClientDiagnostics, |
| 88 | 2478 | | Pipeline, |
| 88 | 2479 | | Uri, |
| 88 | 2480 | | leaseId: conditions?.LeaseId, |
| 88 | 2481 | | version: Version.ToVersionString(), |
| 88 | 2482 | | async: async, |
| 88 | 2483 | | cancellationToken: cancellationToken, |
| 88 | 2484 | | operationName: operationName ?? $"{nameof(ShareFileClient)}.{nameof(GetProperties)}") |
| 88 | 2485 | | .ConfigureAwait(false); |
| | 2486 | |
|
| | 2487 | | // Return an exploding Response on 304 |
| 74 | 2488 | | return response.IsUnavailable() ? |
| 74 | 2489 | | response.GetRawResponse().AsNoBodyResponse<ShareFileProperties>() : |
| 74 | 2490 | | Response.FromValue(new ShareFileProperties(response.Value), response.GetRawResponse()); |
| | 2491 | | } |
| 14 | 2492 | | catch (Exception ex) |
| | 2493 | | { |
| | 2494 | | Pipeline.LogException(ex); |
| 14 | 2495 | | throw; |
| | 2496 | | } |
| | 2497 | | finally |
| | 2498 | | { |
| | 2499 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 2500 | | } |
| | 2501 | | } |
| 74 | 2502 | | } |
| | 2503 | | #endregion GetProperties |
| | 2504 | |
|
| | 2505 | | #region SetHttpHeaders |
| | 2506 | | /// <summary> |
| | 2507 | | /// The <see cref="SetHttpHeaders(long?, ShareFileHttpHeaders, FileSmbProperties, string, ShareFileRequestCondit |
| | 2508 | | /// operation sets system properties on the file. |
| | 2509 | | /// |
| | 2510 | | /// For more information, see |
| | 2511 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-properties"> |
| | 2512 | | /// Set File Properties</see>. |
| | 2513 | | /// </summary> |
| | 2514 | | /// <param name="newSize"> |
| | 2515 | | /// Optional. Resizes a file to the specified size. |
| | 2516 | | /// If the specified byte value is less than the current size |
| | 2517 | | /// of the file, then all ranges above the specified byte value |
| | 2518 | | /// are cleared. |
| | 2519 | | /// </param> |
| | 2520 | | /// <param name="httpHeaders"> |
| | 2521 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2522 | | /// </param> |
| | 2523 | | /// <param name="smbProperties"> |
| | 2524 | | /// Optional SMB properties to set for the file. |
| | 2525 | | /// </param> |
| | 2526 | | /// <param name="filePermission"> |
| | 2527 | | /// Optional file permission to set for the file. |
| | 2528 | | /// </param> |
| | 2529 | | /// <param name="conditions"> |
| | 2530 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2531 | | /// on creating the file. |
| | 2532 | | /// </param> |
| | 2533 | | /// <param name="cancellationToken"> |
| | 2534 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2535 | | /// notifications that the operation should be cancelled. |
| | 2536 | | /// </param> |
| | 2537 | | /// <returns> |
| | 2538 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 2539 | | /// state of the file. |
| | 2540 | | /// </returns> |
| | 2541 | | /// <remarks> |
| | 2542 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2543 | | /// a failure occurs. |
| | 2544 | | /// </remarks> |
| | 2545 | | public virtual Response<ShareFileInfo> SetHttpHeaders( |
| | 2546 | | long? newSize = default, |
| | 2547 | | ShareFileHttpHeaders httpHeaders = default, |
| | 2548 | | FileSmbProperties smbProperties = default, |
| | 2549 | | string filePermission = default, |
| | 2550 | | ShareFileRequestConditions conditions = default, |
| | 2551 | | CancellationToken cancellationToken = default) => |
| 8 | 2552 | | SetHttpHeadersInternal( |
| 8 | 2553 | | newSize, |
| 8 | 2554 | | httpHeaders, |
| 8 | 2555 | | smbProperties, |
| 8 | 2556 | | filePermission, |
| 8 | 2557 | | conditions, |
| 8 | 2558 | | async: false, |
| 8 | 2559 | | cancellationToken) |
| 8 | 2560 | | .EnsureCompleted(); |
| | 2561 | |
|
| | 2562 | | /// <summary> |
| | 2563 | | /// The <see cref="SetHttpHeaders(long?, ShareFileHttpHeaders, FileSmbProperties, string, CancellationToken)"/> |
| | 2564 | | /// operation sets system |
| | 2565 | | /// properties on the file. |
| | 2566 | | /// |
| | 2567 | | /// For more information, see |
| | 2568 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-properties"> |
| | 2569 | | /// Set File Properties</see>. |
| | 2570 | | /// </summary> |
| | 2571 | | /// <param name="newSize"> |
| | 2572 | | /// Optional. Resizes a file to the specified size. |
| | 2573 | | /// If the specified byte value is less than the current size |
| | 2574 | | /// of the file, then all ranges above the specified byte value |
| | 2575 | | /// are cleared. |
| | 2576 | | /// </param> |
| | 2577 | | /// <param name="httpHeaders"> |
| | 2578 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2579 | | /// </param> |
| | 2580 | | /// <param name="smbProperties"> |
| | 2581 | | /// Optional SMB properties to set for the file. |
| | 2582 | | /// </param> |
| | 2583 | | /// <param name="filePermission"> |
| | 2584 | | /// Optional file permission to set for the file. |
| | 2585 | | /// </param> |
| | 2586 | | /// <param name="cancellationToken"> |
| | 2587 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2588 | | /// notifications that the operation should be cancelled. |
| | 2589 | | /// </param> |
| | 2590 | | /// <returns> |
| | 2591 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 2592 | | /// state of the file. |
| | 2593 | | /// </returns> |
| | 2594 | | /// <remarks>s |
| | 2595 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2596 | | /// a failure occurs. |
| | 2597 | | /// </remarks> |
| | 2598 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2599 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2600 | | public virtual Response<ShareFileInfo> SetHttpHeaders( |
| | 2601 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2602 | | long? newSize, |
| | 2603 | | ShareFileHttpHeaders httpHeaders, |
| | 2604 | | FileSmbProperties smbProperties, |
| | 2605 | | string filePermission, |
| | 2606 | | CancellationToken cancellationToken) => |
| 0 | 2607 | | SetHttpHeadersInternal( |
| 0 | 2608 | | newSize, |
| 0 | 2609 | | httpHeaders, |
| 0 | 2610 | | smbProperties, |
| 0 | 2611 | | filePermission, |
| 0 | 2612 | | conditions: default, |
| 0 | 2613 | | async: false, |
| 0 | 2614 | | cancellationToken) |
| 0 | 2615 | | .EnsureCompleted(); |
| | 2616 | |
|
| | 2617 | | /// <summary> |
| | 2618 | | /// The <see cref="SetHttpHeadersAsync(long?, ShareFileHttpHeaders, FileSmbProperties, string, ShareFileRequestC |
| | 2619 | | /// operation sets system properties on the file. |
| | 2620 | | /// |
| | 2621 | | /// For more information, see |
| | 2622 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-properties"> |
| | 2623 | | /// Set File Properties</see>. |
| | 2624 | | /// </summary> |
| | 2625 | | /// <param name="newSize"> |
| | 2626 | | /// Optional. Resizes a file to the specified size. |
| | 2627 | | /// If the specified byte value is less than the current size |
| | 2628 | | /// of the file, then all ranges above the specified byte value |
| | 2629 | | /// are cleared. |
| | 2630 | | /// </param> |
| | 2631 | | /// <param name="httpHeaders"> |
| | 2632 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2633 | | /// </param> |
| | 2634 | | /// <param name="smbProperties"> |
| | 2635 | | /// Optional SMB properties to set for the file. |
| | 2636 | | /// </param> |
| | 2637 | | /// <param name="filePermission"> |
| | 2638 | | /// Optional file permission to set for the file. |
| | 2639 | | /// </param> |
| | 2640 | | /// <param name="conditions"> |
| | 2641 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2642 | | /// on creating the file. |
| | 2643 | | /// </param> |
| | 2644 | | /// <param name="cancellationToken"> |
| | 2645 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2646 | | /// notifications that the operation should be cancelled. |
| | 2647 | | /// </param> |
| | 2648 | | /// <returns> |
| | 2649 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 2650 | | /// state of the file. |
| | 2651 | | /// </returns> |
| | 2652 | | /// <remarks> |
| | 2653 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2654 | | /// a failure occurs. |
| | 2655 | | /// </remarks> |
| | 2656 | | public virtual async Task<Response<ShareFileInfo>> SetHttpHeadersAsync( |
| | 2657 | | long? newSize = default, |
| | 2658 | | ShareFileHttpHeaders httpHeaders = default, |
| | 2659 | | FileSmbProperties smbProperties = default, |
| | 2660 | | string filePermission = default, |
| | 2661 | | ShareFileRequestConditions conditions = default, |
| | 2662 | | CancellationToken cancellationToken = default) => |
| 8 | 2663 | | await SetHttpHeadersInternal( |
| 8 | 2664 | | newSize, |
| 8 | 2665 | | httpHeaders, |
| 8 | 2666 | | smbProperties, |
| 8 | 2667 | | filePermission, |
| 8 | 2668 | | conditions, |
| 8 | 2669 | | async: true, |
| 8 | 2670 | | cancellationToken) |
| 8 | 2671 | | .ConfigureAwait(false); |
| | 2672 | |
|
| | 2673 | | /// <summary> |
| | 2674 | | /// The <see cref="SetHttpHeadersAsync(long?, ShareFileHttpHeaders, FileSmbProperties, string, CancellationToken |
| | 2675 | | /// operation sets system properties on the file. |
| | 2676 | | /// |
| | 2677 | | /// For more information, see |
| | 2678 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-properties"> |
| | 2679 | | /// Set File Properties</see>. |
| | 2680 | | /// </summary> |
| | 2681 | | /// <param name="newSize"> |
| | 2682 | | /// Optional. Resizes a file to the specified size. |
| | 2683 | | /// If the specified byte value is less than the current size |
| | 2684 | | /// of the file, then all ranges above the specified byte value |
| | 2685 | | /// are cleared. |
| | 2686 | | /// </param> |
| | 2687 | | /// <param name="httpHeaders"> |
| | 2688 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2689 | | /// </param> |
| | 2690 | | /// <param name="smbProperties"> |
| | 2691 | | /// Optional SMB properties to set for the file. |
| | 2692 | | /// </param> |
| | 2693 | | /// <param name="filePermission"> |
| | 2694 | | /// Optional file permission to set for the file. |
| | 2695 | | /// </param> |
| | 2696 | | /// <param name="cancellationToken"> |
| | 2697 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2698 | | /// notifications that the operation should be cancelled. |
| | 2699 | | /// </param> |
| | 2700 | | /// <returns> |
| | 2701 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 2702 | | /// state of the file. |
| | 2703 | | /// </returns> |
| | 2704 | | /// <remarks> |
| | 2705 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2706 | | /// a failure occurs. |
| | 2707 | | /// </remarks> |
| | 2708 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2709 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2710 | | public virtual async Task<Response<ShareFileInfo>> SetHttpHeadersAsync( |
| | 2711 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2712 | | long? newSize, |
| | 2713 | | ShareFileHttpHeaders httpHeaders, |
| | 2714 | | FileSmbProperties smbProperties, |
| | 2715 | | string filePermission, |
| | 2716 | | CancellationToken cancellationToken) => |
| 0 | 2717 | | await SetHttpHeadersInternal( |
| 0 | 2718 | | newSize, |
| 0 | 2719 | | httpHeaders, |
| 0 | 2720 | | smbProperties, |
| 0 | 2721 | | filePermission, |
| 0 | 2722 | | conditions: default, |
| 0 | 2723 | | async: true, |
| 0 | 2724 | | cancellationToken) |
| 0 | 2725 | | .ConfigureAwait(false); |
| | 2726 | |
|
| | 2727 | | /// <summary> |
| | 2728 | | /// The <see cref="SetHttpHeadersInternal"/> operation sets system |
| | 2729 | | /// properties on the file. |
| | 2730 | | /// |
| | 2731 | | /// For more information, see |
| | 2732 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-properties"> |
| | 2733 | | /// Set File Properties</see>. |
| | 2734 | | /// </summary> |
| | 2735 | | /// <param name="newSize"> |
| | 2736 | | /// Optional. Resizes a file to the specified size. |
| | 2737 | | /// If the specified byte value is less than the current size |
| | 2738 | | /// of the file, then all ranges above the specified byte value |
| | 2739 | | /// are cleared. |
| | 2740 | | /// </param> |
| | 2741 | | /// <param name="httpHeaders"> |
| | 2742 | | /// Optional. The standard HTTP header system properties to set. If not specified, existing values will be clea |
| | 2743 | | /// </param> |
| | 2744 | | /// <param name="smbProperties"> |
| | 2745 | | /// Optional SMB properties to set for the file. |
| | 2746 | | /// </param> |
| | 2747 | | /// <param name="filePermission"> |
| | 2748 | | /// Optional file permission to set ofr the file. |
| | 2749 | | /// </param> |
| | 2750 | | /// <param name="conditions"> |
| | 2751 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2752 | | /// on creating the file. |
| | 2753 | | /// </param> |
| | 2754 | | /// <param name="async"> |
| | 2755 | | /// Whether to invoke the operation asynchronously. |
| | 2756 | | /// </param> |
| | 2757 | | /// <param name="cancellationToken"> |
| | 2758 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2759 | | /// notifications that the operation should be cancelled. |
| | 2760 | | /// </param> |
| | 2761 | | /// <returns> |
| | 2762 | | /// A <see cref="Response{StorageFileInfo}"/> describing the |
| | 2763 | | /// state of the file. |
| | 2764 | | /// </returns> |
| | 2765 | | /// <remarks> |
| | 2766 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2767 | | /// a failure occurs. |
| | 2768 | | /// </remarks> |
| | 2769 | | private async Task<Response<ShareFileInfo>> SetHttpHeadersInternal( |
| | 2770 | | long? newSize, |
| | 2771 | | ShareFileHttpHeaders httpHeaders, |
| | 2772 | | FileSmbProperties smbProperties, |
| | 2773 | | string filePermission, |
| | 2774 | | ShareFileRequestConditions conditions, |
| | 2775 | | bool async, |
| | 2776 | | CancellationToken cancellationToken) |
| | 2777 | | { |
| 16 | 2778 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 2779 | | { |
| | 2780 | | Pipeline.LogMethodEnter( |
| | 2781 | | nameof(ShareFileClient), |
| | 2782 | | message: |
| | 2783 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 2784 | | $"{nameof(newSize)}: {newSize}\n" + |
| | 2785 | | $"{nameof(httpHeaders)}: {httpHeaders}"); |
| | 2786 | | try |
| | 2787 | | { |
| 16 | 2788 | | FileSmbProperties smbProps = smbProperties ?? new FileSmbProperties(); |
| | 2789 | |
|
| 16 | 2790 | | ShareExtensions.AssertValidFilePermissionAndKey(filePermission, smbProps.FilePermissionKey); |
| 12 | 2791 | | if (filePermission == null && smbProps.FilePermissionKey == null) |
| | 2792 | | { |
| 8 | 2793 | | filePermission = Constants.File.Preserve; |
| | 2794 | | } |
| | 2795 | |
|
| 12 | 2796 | | Response<RawStorageFileInfo> response = await FileRestClient.File.SetPropertiesAsync( |
| 12 | 2797 | | ClientDiagnostics, |
| 12 | 2798 | | Pipeline, |
| 12 | 2799 | | Uri, |
| 12 | 2800 | | version: Version.ToVersionString(), |
| 12 | 2801 | | fileContentLength: newSize, |
| 12 | 2802 | | fileContentType: httpHeaders?.ContentType, |
| 12 | 2803 | | fileContentEncoding: httpHeaders?.ContentEncoding, |
| 12 | 2804 | | fileContentLanguage: httpHeaders?.ContentLanguage, |
| 12 | 2805 | | fileCacheControl: httpHeaders?.CacheControl, |
| 12 | 2806 | | fileContentHash: httpHeaders?.ContentHash, |
| 12 | 2807 | | fileContentDisposition: httpHeaders?.ContentDisposition, |
| 12 | 2808 | | fileAttributes: smbProps.FileAttributes?.ToAttributesString() ?? Constants.File.Preserve, |
| 12 | 2809 | | filePermission: filePermission, |
| 12 | 2810 | | fileCreationTime: smbProps.FileCreatedOn.ToFileDateTimeString() ?? Constants.File.Preserve, |
| 12 | 2811 | | fileLastWriteTime: smbProps.FileLastWrittenOn.ToFileDateTimeString() ?? Constants.File.Preserve, |
| 12 | 2812 | | filePermissionKey: smbProps.FilePermissionKey, |
| 12 | 2813 | | leaseId: conditions?.LeaseId, |
| 12 | 2814 | | async: async, |
| 12 | 2815 | | operationName: $"{nameof(ShareFileClient)}.{nameof(SetHttpHeaders)}", |
| 12 | 2816 | | cancellationToken: cancellationToken) |
| 12 | 2817 | | .ConfigureAwait(false); |
| | 2818 | |
|
| 8 | 2819 | | return Response.FromValue(new ShareFileInfo(response.Value), response.GetRawResponse()); |
| | 2820 | | } |
| 8 | 2821 | | catch (Exception ex) |
| | 2822 | | { |
| | 2823 | | Pipeline.LogException(ex); |
| 8 | 2824 | | throw; |
| | 2825 | | } |
| | 2826 | | finally |
| | 2827 | | { |
| | 2828 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 2829 | | } |
| | 2830 | | } |
| 8 | 2831 | | } |
| | 2832 | | #endregion SetHttpHeaders |
| | 2833 | |
|
| | 2834 | | #region SetMetadata |
| | 2835 | | /// <summary> |
| | 2836 | | /// The <see cref="SetMetadata(Metadata, ShareFileRequestConditions, CancellationToken)"/> operation sets user-d |
| | 2837 | | /// metadata for the specified file as one or more name-value pairs. |
| | 2838 | | /// |
| | 2839 | | /// For more information, see |
| | 2840 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-metadata"> |
| | 2841 | | /// Set File Metadata</see>. |
| | 2842 | | /// </summary> |
| | 2843 | | /// <param name="metadata"> |
| | 2844 | | /// Custom metadata to set for this file. |
| | 2845 | | /// </param> |
| | 2846 | | /// <param name="conditions"> |
| | 2847 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2848 | | /// on creating the file. |
| | 2849 | | /// </param> |
| | 2850 | | /// <param name="cancellationToken"> |
| | 2851 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2852 | | /// notifications that the operation should be cancelled. |
| | 2853 | | /// </param> |
| | 2854 | | /// <returns> |
| | 2855 | | /// A <see cref="Response{StorageFileInfo}"/> describing the updated |
| | 2856 | | /// file. |
| | 2857 | | /// </returns> |
| | 2858 | | /// <remarks> |
| | 2859 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2860 | | /// a failure occurs. |
| | 2861 | | /// </remarks> |
| | 2862 | | public virtual Response<ShareFileInfo> SetMetadata( |
| | 2863 | | Metadata metadata, |
| | 2864 | | ShareFileRequestConditions conditions = default, |
| | 2865 | | CancellationToken cancellationToken = default) => |
| 4 | 2866 | | SetMetadataInternal( |
| 4 | 2867 | | metadata, |
| 4 | 2868 | | conditions, |
| 4 | 2869 | | async: false, |
| 4 | 2870 | | cancellationToken) |
| 4 | 2871 | | .EnsureCompleted(); |
| | 2872 | |
|
| | 2873 | | /// <summary> |
| | 2874 | | /// The <see cref="SetMetadata(Metadata, CancellationToken)"/> operation sets user-defined |
| | 2875 | | /// metadata for the specified file as one or more name-value pairs. |
| | 2876 | | /// |
| | 2877 | | /// For more information, see |
| | 2878 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-metadata"> |
| | 2879 | | /// Set File Metadata</see>. |
| | 2880 | | /// </summary> |
| | 2881 | | /// <param name="metadata"> |
| | 2882 | | /// Custom metadata to set for this file. |
| | 2883 | | /// </param> |
| | 2884 | | /// <param name="cancellationToken"> |
| | 2885 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2886 | | /// notifications that the operation should be cancelled. |
| | 2887 | | /// </param> |
| | 2888 | | /// <returns> |
| | 2889 | | /// A <see cref="Response{StorageFileInfo}"/> describing the updated |
| | 2890 | | /// file. |
| | 2891 | | /// </returns> |
| | 2892 | | /// <remarks> |
| | 2893 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2894 | | /// a failure occurs. |
| | 2895 | | /// </remarks> |
| | 2896 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2897 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2898 | | public virtual Response<ShareFileInfo> SetMetadata( |
| | 2899 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2900 | | Metadata metadata, |
| | 2901 | | CancellationToken cancellationToken) => |
| 0 | 2902 | | SetMetadataInternal( |
| 0 | 2903 | | metadata, |
| 0 | 2904 | | conditions: default, |
| 0 | 2905 | | async: false, |
| 0 | 2906 | | cancellationToken) |
| 0 | 2907 | | .EnsureCompleted(); |
| | 2908 | |
|
| | 2909 | | /// <summary> |
| | 2910 | | /// The <see cref="SetMetadataAsync(Metadata, ShareFileRequestConditions, CancellationToken)"/> operation sets u |
| | 2911 | | /// metadata for the specified file as one or more name-value pairs. |
| | 2912 | | /// |
| | 2913 | | /// For more information, see |
| | 2914 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-metadata"> |
| | 2915 | | /// Set File Metadata</see>. |
| | 2916 | | /// </summary> |
| | 2917 | | /// <param name="metadata"> |
| | 2918 | | /// Custom metadata to set for this file. |
| | 2919 | | /// </param> |
| | 2920 | | /// <param name="conditions"> |
| | 2921 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2922 | | /// on creating the file. |
| | 2923 | | /// </param> |
| | 2924 | | /// <param name="cancellationToken"> |
| | 2925 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2926 | | /// notifications that the operation should be cancelled. |
| | 2927 | | /// </param> |
| | 2928 | | /// <returns> |
| | 2929 | | /// A <see cref="Response{StorageFileInfo}"/> describing the updated |
| | 2930 | | /// file. |
| | 2931 | | /// </returns> |
| | 2932 | | /// <remarks> |
| | 2933 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2934 | | /// a failure occurs. |
| | 2935 | | /// </remarks> |
| | 2936 | | public virtual async Task<Response<ShareFileInfo>> SetMetadataAsync( |
| | 2937 | | Metadata metadata, |
| | 2938 | | ShareFileRequestConditions conditions = default, |
| | 2939 | | CancellationToken cancellationToken = default) => |
| 4 | 2940 | | await SetMetadataInternal( |
| 4 | 2941 | | metadata, |
| 4 | 2942 | | conditions, |
| 4 | 2943 | | async: true, |
| 4 | 2944 | | cancellationToken) |
| 4 | 2945 | | .ConfigureAwait(false); |
| | 2946 | |
|
| | 2947 | | /// <summary> |
| | 2948 | | /// The <see cref="SetMetadata(Metadata, CancellationToken)"/> operation sets user-defined |
| | 2949 | | /// metadata for the specified file as one or more name-value pairs. |
| | 2950 | | /// |
| | 2951 | | /// For more information, see |
| | 2952 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-metadata"> |
| | 2953 | | /// Set File Metadata</see>. |
| | 2954 | | /// </summary> |
| | 2955 | | /// <param name="metadata"> |
| | 2956 | | /// Custom metadata to set for this file. |
| | 2957 | | /// </param> |
| | 2958 | | /// <param name="cancellationToken"> |
| | 2959 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2960 | | /// notifications that the operation should be cancelled. |
| | 2961 | | /// </param> |
| | 2962 | | /// <returns> |
| | 2963 | | /// A <see cref="Response{StorageFileInfo}"/> describing the updated |
| | 2964 | | /// file. |
| | 2965 | | /// </returns> |
| | 2966 | | /// <remarks> |
| | 2967 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2968 | | /// a failure occurs. |
| | 2969 | | /// </remarks> |
| | 2970 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2971 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2972 | | public virtual async Task<Response<ShareFileInfo>> SetMetadataAsync( |
| | 2973 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 2974 | | Metadata metadata, |
| | 2975 | | CancellationToken cancellationToken) => |
| 0 | 2976 | | await SetMetadataInternal( |
| 0 | 2977 | | metadata, |
| 0 | 2978 | | conditions: default, |
| 0 | 2979 | | async: true, |
| 0 | 2980 | | cancellationToken) |
| 0 | 2981 | | .ConfigureAwait(false); |
| | 2982 | |
|
| | 2983 | | /// <summary> |
| | 2984 | | /// The <see cref="SetMetadataInternal"/> operation sets user-defined |
| | 2985 | | /// metadata for the specified file as one or more name-value pairs. |
| | 2986 | | /// |
| | 2987 | | /// For more information, see |
| | 2988 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-file-metadata"> |
| | 2989 | | /// Set File Metadata</see>. |
| | 2990 | | /// </summary> |
| | 2991 | | /// <param name="metadata"> |
| | 2992 | | /// Custom metadata to set for this file. |
| | 2993 | | /// </param> |
| | 2994 | | /// <param name="conditions"> |
| | 2995 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 2996 | | /// on creating the file. |
| | 2997 | | /// </param> |
| | 2998 | | /// <param name="async"> |
| | 2999 | | /// Whether to invoke the operation asynchronously. |
| | 3000 | | /// </param> |
| | 3001 | | /// <param name="cancellationToken"> |
| | 3002 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3003 | | /// notifications that the operation should be cancelled. |
| | 3004 | | /// </param> |
| | 3005 | | /// <returns> |
| | 3006 | | /// A <see cref="Response{StorageFileInfo}"/> describing the updated |
| | 3007 | | /// file. |
| | 3008 | | /// </returns> |
| | 3009 | | /// <remarks> |
| | 3010 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3011 | | /// a failure occurs. |
| | 3012 | | /// </remarks> |
| | 3013 | | private async Task<Response<ShareFileInfo>> SetMetadataInternal( |
| | 3014 | | Metadata metadata, |
| | 3015 | | ShareFileRequestConditions conditions, |
| | 3016 | | bool async, |
| | 3017 | | CancellationToken cancellationToken) |
| | 3018 | | { |
| 8 | 3019 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 3020 | | { |
| | 3021 | | Pipeline.LogMethodEnter( |
| | 3022 | | nameof(ShareFileClient), |
| | 3023 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 3024 | | try |
| | 3025 | | { |
| 8 | 3026 | | Response<RawStorageFileInfo> response = await FileRestClient.File.SetMetadataAsync( |
| 8 | 3027 | | ClientDiagnostics, |
| 8 | 3028 | | Pipeline, |
| 8 | 3029 | | Uri, |
| 8 | 3030 | | version: Version.ToVersionString(), |
| 8 | 3031 | | metadata: metadata, |
| 8 | 3032 | | leaseId: conditions?.LeaseId, |
| 8 | 3033 | | async: async, |
| 8 | 3034 | | cancellationToken: cancellationToken, |
| 8 | 3035 | | operationName: $"{nameof(ShareFileClient)}.{nameof(SetMetadata)}") |
| 8 | 3036 | | .ConfigureAwait(false); |
| | 3037 | |
|
| 4 | 3038 | | return Response.FromValue(new ShareFileInfo(response.Value), response.GetRawResponse()); |
| | 3039 | | } |
| 4 | 3040 | | catch (Exception ex) |
| | 3041 | | { |
| | 3042 | | Pipeline.LogException(ex); |
| 4 | 3043 | | throw; |
| | 3044 | | } |
| | 3045 | | finally |
| | 3046 | | { |
| | 3047 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 3048 | | } |
| | 3049 | | } |
| 4 | 3050 | | } |
| | 3051 | | #endregion SetMetadata |
| | 3052 | |
|
| | 3053 | | #region ClearRange |
| | 3054 | | /// <summary> |
| | 3055 | | /// The <see cref="ClearRange"/> |
| | 3056 | | /// operation clears the <paramref name="range"/> of a file. |
| | 3057 | | /// |
| | 3058 | | /// For more information, see |
| | 3059 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3060 | | /// Put Range</see>. |
| | 3061 | | /// </summary> |
| | 3062 | | /// <param name="range"> |
| | 3063 | | /// Specifies the range of bytes to be cleared. Both the start and end of the range must be specified. |
| | 3064 | | /// </param> |
| | 3065 | | /// <param name="conditions"> |
| | 3066 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3067 | | /// on creating the file. |
| | 3068 | | /// </param> |
| | 3069 | | /// <param name="cancellationToken"> |
| | 3070 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3071 | | /// notifications that the operation should be cancelled. |
| | 3072 | | /// </param> |
| | 3073 | | /// <returns> |
| | 3074 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3075 | | /// state of the file. |
| | 3076 | | /// </returns> |
| | 3077 | | /// <remarks> |
| | 3078 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3079 | | /// a failure occurs. |
| | 3080 | | /// </remarks> |
| | 3081 | | public virtual Response<ShareFileUploadInfo> ClearRange( |
| | 3082 | | HttpRange range, |
| | 3083 | | ShareFileRequestConditions conditions = default, |
| | 3084 | | CancellationToken cancellationToken = default) => |
| 2 | 3085 | | ClearRangeInternal( |
| 2 | 3086 | | range: range, |
| 2 | 3087 | | conditions: conditions, |
| 2 | 3088 | | async: false, |
| 2 | 3089 | | cancellationToken: cancellationToken) |
| 2 | 3090 | | .EnsureCompleted(); |
| | 3091 | |
|
| | 3092 | |
|
| | 3093 | | /// <summary> |
| | 3094 | | /// The <see cref="ClearRangeAsync"/> |
| | 3095 | | /// operation clears the <paramref name="range"/> of a file. |
| | 3096 | | /// |
| | 3097 | | /// For more information, see |
| | 3098 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3099 | | /// Put Range</see>. |
| | 3100 | | /// </summary> |
| | 3101 | | /// <param name="range"> |
| | 3102 | | /// Specifies the range of bytes to be cleared. Both the start and end of the range must be specified. |
| | 3103 | | /// </param> |
| | 3104 | | /// <param name="conditions"> |
| | 3105 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3106 | | /// on creating the file. |
| | 3107 | | /// </param> |
| | 3108 | | /// <param name="cancellationToken"> |
| | 3109 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3110 | | /// notifications that the operation should be cancelled. |
| | 3111 | | /// </param> |
| | 3112 | | /// <returns> |
| | 3113 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3114 | | /// state of the file. |
| | 3115 | | /// </returns> |
| | 3116 | | /// <remarks> |
| | 3117 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3118 | | /// a failure occurs. |
| | 3119 | | /// </remarks> |
| | 3120 | | public virtual async Task<Response<ShareFileUploadInfo>> ClearRangeAsync( |
| | 3121 | | HttpRange range, |
| | 3122 | | ShareFileRequestConditions conditions = default, |
| | 3123 | | CancellationToken cancellationToken = default) => |
| 2 | 3124 | | await ClearRangeInternal( |
| 2 | 3125 | | range: range, |
| 2 | 3126 | | conditions: conditions, |
| 2 | 3127 | | async: true, |
| 2 | 3128 | | cancellationToken: cancellationToken) |
| 2 | 3129 | | .ConfigureAwait(false); |
| | 3130 | |
|
| | 3131 | | /// <summary> |
| | 3132 | | /// The <see cref="UploadRangeInternal"/> operation clears the |
| | 3133 | | /// <paramref name="range"/> of a file. |
| | 3134 | | /// |
| | 3135 | | /// For more information, see |
| | 3136 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3137 | | /// Put Range</see>. |
| | 3138 | | /// </summary> |
| | 3139 | | /// <param name="range"> |
| | 3140 | | /// Specifies the range of bytes to be cleated. Both the start and end of the range must be specified. |
| | 3141 | | /// </param> |
| | 3142 | | /// <param name="conditions"> |
| | 3143 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3144 | | /// on creating the file. |
| | 3145 | | /// </param> |
| | 3146 | | /// <param name="async"> |
| | 3147 | | /// Whether to invoke the operation asynchronously. |
| | 3148 | | /// </param> |
| | 3149 | | /// <param name="cancellationToken"> |
| | 3150 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3151 | | /// notifications that the operation should be cancelled. |
| | 3152 | | /// </param> |
| | 3153 | | /// <returns> |
| | 3154 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3155 | | /// state of the file. |
| | 3156 | | /// </returns> |
| | 3157 | | /// <remarks> |
| | 3158 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3159 | | /// a failure occurs. |
| | 3160 | | /// </remarks> |
| | 3161 | | private async Task<Response<ShareFileUploadInfo>> ClearRangeInternal( |
| | 3162 | | HttpRange range, |
| | 3163 | | ShareFileRequestConditions conditions, |
| | 3164 | | bool async, |
| | 3165 | | CancellationToken cancellationToken) |
| | 3166 | | { |
| 4 | 3167 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 3168 | | { |
| 4 | 3169 | | DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(ShareFileClient)}.{nameof(ClearRange)}") |
| | 3170 | |
|
| | 3171 | | Pipeline.LogMethodEnter( |
| | 3172 | | nameof(ShareFileClient), |
| | 3173 | | message: |
| | 3174 | | $"{nameof(Uri)}: {Uri}"); |
| | 3175 | | try |
| | 3176 | | { |
| 4 | 3177 | | scope.Start(); |
| 4 | 3178 | | return await FileRestClient.File.UploadRangeAsync( |
| 4 | 3179 | | ClientDiagnostics, |
| 4 | 3180 | | Pipeline, |
| 4 | 3181 | | Uri, |
| 4 | 3182 | | version: Version.ToVersionString(), |
| 4 | 3183 | | range: range.ToString(), |
| 4 | 3184 | | fileRangeWrite: ShareFileRangeWriteType.Clear, |
| 4 | 3185 | | contentLength: 0, |
| 4 | 3186 | | leaseId: conditions?.LeaseId, |
| 4 | 3187 | | async: async, |
| 4 | 3188 | | cancellationToken: cancellationToken, |
| 4 | 3189 | | operationName: $"{nameof(ShareFileClient)}.{nameof(UploadRange)}").ConfigureAwait(false); |
| | 3190 | | } |
| 2 | 3191 | | catch (Exception ex) |
| | 3192 | | { |
| 2 | 3193 | | scope.Failed(ex); |
| | 3194 | | Pipeline.LogException(ex); |
| 2 | 3195 | | throw; |
| | 3196 | | } |
| | 3197 | | finally |
| | 3198 | | { |
| 4 | 3199 | | scope.Dispose(); |
| | 3200 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 3201 | | } |
| | 3202 | | } |
| 2 | 3203 | | } |
| | 3204 | | #endregion ClearRange |
| | 3205 | |
|
| | 3206 | | #region UploadRange |
| | 3207 | | /// <summary> |
| | 3208 | | /// The <see cref="UploadRange(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, Cancellat |
| | 3209 | | /// operation writes <paramref name="content"/> to a <paramref name="range"/> of a file. |
| | 3210 | | /// |
| | 3211 | | /// For more information, see |
| | 3212 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3213 | | /// Put Range</see>. |
| | 3214 | | /// </summary> |
| | 3215 | | /// <param name="range"> |
| | 3216 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3217 | | /// </param> |
| | 3218 | | /// <param name="content"> |
| | 3219 | | /// A <see cref="Stream"/> containing the content of the range to upload. |
| | 3220 | | /// </param> |
| | 3221 | | /// <param name="transactionalContentHash"> |
| | 3222 | | /// Optional MD5 hash of the range content. |
| | 3223 | | /// |
| | 3224 | | /// This hash is used to verify the integrity of the range during transport. When this hash |
| | 3225 | | /// is specified, the storage service compares the hash of the content |
| | 3226 | | /// that has arrived with this value. Note that this MD5 hash is not |
| | 3227 | | /// stored with the file. If the two hashes do not match, the |
| | 3228 | | /// operation will fail with a <see cref="RequestFailedException"/>. |
| | 3229 | | /// </param> |
| | 3230 | | /// <param name="progressHandler"> |
| | 3231 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3232 | | /// progress updates about data transfers. |
| | 3233 | | /// </param> |
| | 3234 | | /// <param name="conditions"> |
| | 3235 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3236 | | /// on creating the file. |
| | 3237 | | /// </param> |
| | 3238 | | /// <param name="cancellationToken"> |
| | 3239 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3240 | | /// notifications that the operation should be cancelled. |
| | 3241 | | /// </param> |
| | 3242 | | /// <returns> |
| | 3243 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3244 | | /// state of the file. |
| | 3245 | | /// </returns> |
| | 3246 | | /// <remarks> |
| | 3247 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3248 | | /// a failure occurs. |
| | 3249 | | /// </remarks> |
| | 3250 | | public virtual Response<ShareFileUploadInfo> UploadRange( |
| | 3251 | | HttpRange range, |
| | 3252 | | Stream content, |
| | 3253 | | byte[] transactionalContentHash = null, |
| | 3254 | | IProgress<long> progressHandler = default, |
| | 3255 | | ShareFileRequestConditions conditions = default, |
| | 3256 | | CancellationToken cancellationToken = default) => |
| 10 | 3257 | | UploadRangeInternal( |
| 10 | 3258 | | range, |
| 10 | 3259 | | content, |
| 10 | 3260 | | transactionalContentHash, |
| 10 | 3261 | | progressHandler, |
| 10 | 3262 | | conditions: conditions, |
| 10 | 3263 | | false, // async |
| 10 | 3264 | | cancellationToken) |
| 10 | 3265 | | .EnsureCompleted(); |
| | 3266 | |
|
| | 3267 | | /// <summary> |
| | 3268 | | /// The <see cref="UploadRangeAsync(HttpRange, Stream, byte[], IProgress{long}, ShareFileRequestConditions, Canc |
| | 3269 | | /// operation writes <paramref name="content"/> to a <paramref name="range"/> of a file. |
| | 3270 | | /// |
| | 3271 | | /// For more information, see |
| | 3272 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3273 | | /// Put Range</see>. |
| | 3274 | | /// </summary> |
| | 3275 | | /// <param name="range"> |
| | 3276 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3277 | | /// </param> |
| | 3278 | | /// <param name="content"> |
| | 3279 | | /// A <see cref="Stream"/> containing the content of the range to upload. |
| | 3280 | | /// </param> |
| | 3281 | | /// <param name="transactionalContentHash"> |
| | 3282 | | /// Optional MD5 hash of the range content. |
| | 3283 | | /// |
| | 3284 | | /// This hash is used to verify the integrity of the range during transport. When this hash |
| | 3285 | | /// is specified, the storage service compares the hash of the content |
| | 3286 | | /// that has arrived with this value. Note that this MD5 hash is not |
| | 3287 | | /// stored with the file. If the two hashes do not match, the |
| | 3288 | | /// operation will fail with a <see cref="RequestFailedException"/>. |
| | 3289 | | /// </param> |
| | 3290 | | /// <param name="progressHandler"> |
| | 3291 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3292 | | /// progress updates about data transfers. |
| | 3293 | | /// </param> |
| | 3294 | | /// <param name="conditions"> |
| | 3295 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3296 | | /// on creating the file. |
| | 3297 | | /// </param> |
| | 3298 | | /// <param name="cancellationToken"> |
| | 3299 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3300 | | /// notifications that the operation should be cancelled. |
| | 3301 | | /// </param> |
| | 3302 | | /// <returns> |
| | 3303 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3304 | | /// state of the file. |
| | 3305 | | /// </returns> |
| | 3306 | | /// <remarks> |
| | 3307 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3308 | | /// a failure occurs. |
| | 3309 | | /// </remarks> |
| | 3310 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadRangeAsync( |
| | 3311 | | HttpRange range, |
| | 3312 | | Stream content, |
| | 3313 | | byte[] transactionalContentHash = default, |
| | 3314 | | IProgress<long> progressHandler = default, |
| | 3315 | | ShareFileRequestConditions conditions = default, |
| | 3316 | | CancellationToken cancellationToken = default) => |
| 10 | 3317 | | await UploadRangeInternal( |
| 10 | 3318 | | range, |
| 10 | 3319 | | content, |
| 10 | 3320 | | transactionalContentHash, |
| 10 | 3321 | | progressHandler, |
| 10 | 3322 | | conditions: conditions, |
| 10 | 3323 | | true, // async |
| 10 | 3324 | | cancellationToken) |
| 10 | 3325 | | .ConfigureAwait(false); |
| | 3326 | |
|
| | 3327 | | /// <summary> |
| | 3328 | | /// The <see cref="UploadRange(ShareFileRangeWriteType, HttpRange, Stream, byte[], IProgress{long}, Cancellation |
| | 3329 | | /// operation writes <paramref name="content"/> to a <paramref name="range"/> of a file. |
| | 3330 | | /// |
| | 3331 | | /// For more information, see |
| | 3332 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3333 | | /// Put Range</see>. |
| | 3334 | | /// </summary> |
| | 3335 | | /// <param name="writeType">Required. Specifies whether to update or clear the range. |
| | 3336 | | /// </param> |
| | 3337 | | /// <param name="range"> |
| | 3338 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3339 | | /// </param> |
| | 3340 | | /// <param name="content"> |
| | 3341 | | /// A <see cref="Stream"/> containing the content of the range to upload. |
| | 3342 | | /// </param> |
| | 3343 | | /// <param name="transactionalContentHash"> |
| | 3344 | | /// Optional MD5 hash of the range content. Must not be used when <paramref name="writeType"/> is set to <see c |
| | 3345 | | /// |
| | 3346 | | /// This hash is used to verify the integrity of the range during transport. When this hash |
| | 3347 | | /// is specified, the storage service compares the hash of the content |
| | 3348 | | /// that has arrived with this value. Note that this MD5 hash is not |
| | 3349 | | /// stored with the file. If the two hashes do not match, the |
| | 3350 | | /// operation will fail with a <see cref="RequestFailedException"/>. |
| | 3351 | | /// </param> |
| | 3352 | | /// <param name="progressHandler"> |
| | 3353 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3354 | | /// progress updates about data transfers. |
| | 3355 | | /// </param> |
| | 3356 | | /// <param name="cancellationToken"> |
| | 3357 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3358 | | /// notifications that the operation should be cancelled. |
| | 3359 | | /// </param> |
| | 3360 | | /// <returns> |
| | 3361 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3362 | | /// state of the file. |
| | 3363 | | /// </returns> |
| | 3364 | | /// <remarks> |
| | 3365 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3366 | | /// a failure occurs. |
| | 3367 | | /// </remarks> |
| | 3368 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3369 | | public virtual Response<ShareFileUploadInfo> UploadRange( |
| | 3370 | | ShareFileRangeWriteType writeType, |
| | 3371 | | HttpRange range, |
| | 3372 | | Stream content, |
| | 3373 | | byte[] transactionalContentHash = default, |
| | 3374 | | IProgress<long> progressHandler = default, |
| | 3375 | | CancellationToken cancellationToken = default) => |
| 11 | 3376 | | UploadRangeInternal( |
| 11 | 3377 | | range, |
| 11 | 3378 | | content, |
| 11 | 3379 | | transactionalContentHash, |
| 11 | 3380 | | progressHandler, |
| 11 | 3381 | | conditions: default, |
| 11 | 3382 | | false, // async |
| 11 | 3383 | | cancellationToken) |
| 11 | 3384 | | .EnsureCompleted(); |
| | 3385 | |
|
| | 3386 | | /// <summary> |
| | 3387 | | /// The <see cref="UploadRange(ShareFileRangeWriteType, HttpRange, Stream, byte[], IProgress{long}, Cancellation |
| | 3388 | | /// operation writes <paramref name="content"/> to a <paramref name="range"/> of a file. |
| | 3389 | | /// |
| | 3390 | | /// For more information, see |
| | 3391 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3392 | | /// Put Range</see>. |
| | 3393 | | /// </summary> |
| | 3394 | | /// <param name="writeType">Required. Specifies whether to update or clear the range. |
| | 3395 | | /// </param> |
| | 3396 | | /// <param name="range"> |
| | 3397 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3398 | | /// </param> |
| | 3399 | | /// <param name="content"> |
| | 3400 | | /// A <see cref="Stream"/> containing the content of the range to upload. |
| | 3401 | | /// </param> |
| | 3402 | | /// <param name="transactionalContentHash"> |
| | 3403 | | /// Optional MD5 hash of the range content. Must not be used when <paramref name="writeType"/> is set to <see c |
| | 3404 | | /// |
| | 3405 | | /// This hash is used to verify the integrity of the range during transport. When this hash |
| | 3406 | | /// is specified, the storage service compares the hash of the content |
| | 3407 | | /// that has arrived with this value. Note that this MD5 hash is not |
| | 3408 | | /// stored with the file. If the two hashes do not match, the |
| | 3409 | | /// operation will fail with a <see cref="RequestFailedException"/>. |
| | 3410 | | /// </param> |
| | 3411 | | /// <param name="progressHandler"> |
| | 3412 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3413 | | /// progress updates about data transfers. |
| | 3414 | | /// </param> |
| | 3415 | | /// <param name="cancellationToken"> |
| | 3416 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3417 | | /// notifications that the operation should be cancelled. |
| | 3418 | | /// </param> |
| | 3419 | | /// <returns> |
| | 3420 | | /// A <see cref="Response{ShareFileUploadInfo}"/> describing the |
| | 3421 | | /// state of the file. |
| | 3422 | | /// </returns> |
| | 3423 | | /// <remarks> |
| | 3424 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3425 | | /// a failure occurs. |
| | 3426 | | /// </remarks> |
| | 3427 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3428 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadRangeAsync( |
| | 3429 | | ShareFileRangeWriteType writeType, |
| | 3430 | | HttpRange range, |
| | 3431 | | Stream content, |
| | 3432 | | byte[] transactionalContentHash = default, |
| | 3433 | | IProgress<long> progressHandler = default, |
| | 3434 | | CancellationToken cancellationToken = default) => |
| 11 | 3435 | | await UploadRangeInternal( |
| 11 | 3436 | | range, |
| 11 | 3437 | | content, |
| 11 | 3438 | | transactionalContentHash, |
| 11 | 3439 | | progressHandler, |
| 11 | 3440 | | conditions: default, |
| 11 | 3441 | | true, // async |
| 11 | 3442 | | cancellationToken) |
| 11 | 3443 | | .ConfigureAwait(false); |
| | 3444 | |
|
| | 3445 | | /// <summary> |
| | 3446 | | /// The <see cref="UploadRangeInternal"/> operation writes |
| | 3447 | | /// <paramref name="content"/> to a <paramref name="range"/> of a file. |
| | 3448 | | /// |
| | 3449 | | /// For more information, see |
| | 3450 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3451 | | /// Put Range</see>. |
| | 3452 | | /// </summary> |
| | 3453 | | /// <param name="range"> |
| | 3454 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3455 | | /// </param> |
| | 3456 | | /// <param name="content"> |
| | 3457 | | /// A <see cref="Stream"/> containing the content of the range to upload. |
| | 3458 | | /// </param> |
| | 3459 | | /// <param name="transactionalContentHash"> |
| | 3460 | | /// Optional MD5 hash of the range content. |
| | 3461 | | /// |
| | 3462 | | /// This hash is used to verify the integrity of the range during transport. When this hash |
| | 3463 | | /// is specified, the storage service compares the hash of the content |
| | 3464 | | /// that has arrived with this value. Note that this MD5 hash is not |
| | 3465 | | /// stored with the file. If the two hashes do not match, the |
| | 3466 | | /// operation will fail with a <see cref="RequestFailedException"/>. |
| | 3467 | | /// </param> |
| | 3468 | | /// <param name="progressHandler"> |
| | 3469 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3470 | | /// progress updates about data transfers. |
| | 3471 | | /// </param> |
| | 3472 | | /// <param name="conditions"> |
| | 3473 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3474 | | /// on creating the file. |
| | 3475 | | /// </param> |
| | 3476 | | /// <param name="async"> |
| | 3477 | | /// Whether to invoke the operation asynchronously. |
| | 3478 | | /// </param> |
| | 3479 | | /// <param name="cancellationToken"> |
| | 3480 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3481 | | /// notifications that the operation should be cancelled. |
| | 3482 | | /// </param> |
| | 3483 | | /// <returns> |
| | 3484 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3485 | | /// state of the file. |
| | 3486 | | /// </returns> |
| | 3487 | | /// <remarks> |
| | 3488 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3489 | | /// a failure occurs. |
| | 3490 | | /// </remarks> |
| | 3491 | | private async Task<Response<ShareFileUploadInfo>> UploadRangeInternal( |
| | 3492 | | HttpRange range, |
| | 3493 | | Stream content, |
| | 3494 | | byte[] transactionalContentHash, |
| | 3495 | | IProgress<long> progressHandler, |
| | 3496 | | ShareFileRequestConditions conditions, |
| | 3497 | | bool async, |
| | 3498 | | CancellationToken cancellationToken) |
| | 3499 | | { |
| 1300 | 3500 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 3501 | | { |
| | 3502 | | Pipeline.LogMethodEnter( |
| | 3503 | | nameof(ShareFileClient), |
| | 3504 | | message: |
| | 3505 | | $"{nameof(Uri)}: {Uri}"); |
| | 3506 | | try |
| | 3507 | | { |
| 1300 | 3508 | | content = content.WithNoDispose().WithProgress(progressHandler); |
| 1300 | 3509 | | return await FileRestClient.File.UploadRangeAsync( |
| 1300 | 3510 | | ClientDiagnostics, |
| 1300 | 3511 | | Pipeline, |
| 1300 | 3512 | | Uri, |
| 1300 | 3513 | | version: Version.ToVersionString(), |
| 1300 | 3514 | | optionalbody: content, |
| 1300 | 3515 | | contentLength: content.Length, |
| 1300 | 3516 | | range: range.ToString(), |
| 1300 | 3517 | | fileRangeWrite: ShareFileRangeWriteType.Update, |
| 1300 | 3518 | | contentHash: transactionalContentHash, |
| 1300 | 3519 | | leaseId: conditions?.LeaseId, |
| 1300 | 3520 | | async: async, |
| 1300 | 3521 | | cancellationToken: cancellationToken, |
| 1300 | 3522 | | operationName: $"{nameof(ShareFileClient)}.{nameof(UploadRange)}").ConfigureAwait(false); |
| | 3523 | | } |
| 8 | 3524 | | catch (Exception ex) |
| | 3525 | | { |
| | 3526 | | Pipeline.LogException(ex); |
| 8 | 3527 | | throw; |
| | 3528 | | } |
| | 3529 | | finally |
| | 3530 | | { |
| | 3531 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 3532 | | } |
| | 3533 | | } |
| 1292 | 3534 | | } |
| | 3535 | | #endregion UploadRange |
| | 3536 | |
|
| | 3537 | | #region UploadRangeFromUrl |
| | 3538 | | /// <summary> |
| | 3539 | | /// The <see cref="UploadRangeFromUri(Uri, HttpRange, HttpRange, ShareFileRequestConditions, CancellationToken)" |
| | 3540 | | /// operation writes a range from an Azure File to another Azure file. This API is supported only for version 20 |
| | 3541 | | /// </summary> |
| | 3542 | | /// <param name="sourceUri"> |
| | 3543 | | /// Required. Specifies the URL of the source file, up to 2 KB in length. |
| | 3544 | | /// If source is an Azure blob or Azure file, it must either be public or must be authenticated via a |
| | 3545 | | /// shared access signature. If the source is public, no authentication is required to perform the operation. |
| | 3546 | | /// </param> |
| | 3547 | | /// <param name="range"> |
| | 3548 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3549 | | /// </param> |
| | 3550 | | /// <param name="sourceRange"> |
| | 3551 | | /// Specifies the range of bytes to be written from. Both the start and end of the range must be specified. |
| | 3552 | | /// </param> |
| | 3553 | | /// <param name="conditions"> |
| | 3554 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3555 | | /// on creating the file. |
| | 3556 | | /// </param> |
| | 3557 | | /// <param name="cancellationToken"> |
| | 3558 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3559 | | /// notifications that the operation should be cancelled. |
| | 3560 | | /// </param> |
| | 3561 | | /// <returns> |
| | 3562 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3563 | | /// state of the file. |
| | 3564 | | /// </returns> |
| | 3565 | | /// <remarks> |
| | 3566 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3567 | | /// a failure occurs. |
| | 3568 | | /// </remarks> |
| | 3569 | | public virtual Response<ShareFileUploadInfo> UploadRangeFromUri( |
| | 3570 | | Uri sourceUri, |
| | 3571 | | HttpRange range, |
| | 3572 | | HttpRange sourceRange, |
| | 3573 | | ShareFileRequestConditions conditions = default, |
| | 3574 | | CancellationToken cancellationToken = default) => |
| 1 | 3575 | | this.UploadRangeFromUriInternal( |
| 1 | 3576 | | sourceUri, |
| 1 | 3577 | | range, |
| 1 | 3578 | | sourceRange, |
| 1 | 3579 | | conditions, |
| 1 | 3580 | | async: false, |
| 1 | 3581 | | cancellationToken) |
| 1 | 3582 | | .EnsureCompleted(); |
| | 3583 | |
|
| | 3584 | | /// <summary> |
| | 3585 | | /// The <see cref="UploadRangeFromUri(Uri, HttpRange, HttpRange, CancellationToken)"/> |
| | 3586 | | /// operation writes a range from an Azure File to another Azure file. This API is supported only for version 20 |
| | 3587 | | /// </summary> |
| | 3588 | | /// <param name="sourceUri"> |
| | 3589 | | /// Required. Specifies the URL of the source file, up to 2 KB in length. |
| | 3590 | | /// If source is an Azure blob or Azure file, it must either be public or must be authenticated via a |
| | 3591 | | /// shared access signature. If the source is public, no authentication is required to perform the operation. |
| | 3592 | | /// </param> |
| | 3593 | | /// <param name="range"> |
| | 3594 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3595 | | /// </param> |
| | 3596 | | /// <param name="sourceRange"> |
| | 3597 | | /// Specifies the range of bytes to be written from. Both the start and end of the range must be specified. |
| | 3598 | | /// </param> |
| | 3599 | | /// <param name="cancellationToken"> |
| | 3600 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3601 | | /// notifications that the operation should be cancelled. |
| | 3602 | | /// </param> |
| | 3603 | | /// <returns> |
| | 3604 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3605 | | /// state of the file. |
| | 3606 | | /// </returns> |
| | 3607 | | /// <remarks> |
| | 3608 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3609 | | /// a failure occurs. |
| | 3610 | | /// </remarks> |
| | 3611 | | [ForwardsClientCalls] |
| | 3612 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3613 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3614 | | public virtual Response<ShareFileUploadInfo> UploadRangeFromUri( |
| | 3615 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3616 | | Uri sourceUri, |
| | 3617 | | HttpRange range, |
| | 3618 | | HttpRange sourceRange, |
| | 3619 | | CancellationToken cancellationToken) => |
| 0 | 3620 | | this.UploadRangeFromUriInternal( |
| 0 | 3621 | | sourceUri, |
| 0 | 3622 | | range, |
| 0 | 3623 | | sourceRange, |
| 0 | 3624 | | conditions: default, |
| 0 | 3625 | | async: false, |
| 0 | 3626 | | cancellationToken) |
| 0 | 3627 | | .EnsureCompleted(); |
| | 3628 | |
|
| | 3629 | | /// <summary> |
| | 3630 | | /// The <see cref="UploadRangeFromUriAsync(Uri, HttpRange, HttpRange, ShareFileRequestConditions, CancellationTo |
| | 3631 | | /// operation writes a range from an Azure File to another Azure file. This API is supported only for version 20 |
| | 3632 | | /// </summary> |
| | 3633 | | /// <param name="sourceUri"> |
| | 3634 | | /// Required. Specifies the URL of the source file, up to 2 KB in length. |
| | 3635 | | /// If source is an Azure blob or Azure file, it must either be public or must be authenticated via a |
| | 3636 | | /// shared access signature. If the source is public, no authentication is required to perform the operation. |
| | 3637 | | /// </param> |
| | 3638 | | /// <param name="range"> |
| | 3639 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3640 | | /// </param> |
| | 3641 | | /// <param name="sourceRange"> |
| | 3642 | | /// Specifies the range of bytes to be written from. Both the start and end of the range must be specified. |
| | 3643 | | /// </param> |
| | 3644 | | /// <param name="conditions"> |
| | 3645 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3646 | | /// on creating the file. |
| | 3647 | | /// </param> |
| | 3648 | | /// <param name="cancellationToken"> |
| | 3649 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3650 | | /// notifications that the operation should be cancelled. |
| | 3651 | | /// </param> |
| | 3652 | | /// <returns> |
| | 3653 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3654 | | /// state of the file. |
| | 3655 | | /// </returns> |
| | 3656 | | /// <remarks> |
| | 3657 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3658 | | /// a failure occurs. |
| | 3659 | | /// </remarks> |
| | 3660 | | [ForwardsClientCalls] |
| | 3661 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadRangeFromUriAsync( |
| | 3662 | | Uri sourceUri, |
| | 3663 | | HttpRange range, |
| | 3664 | | HttpRange sourceRange, |
| | 3665 | | ShareFileRequestConditions conditions = default, |
| | 3666 | | CancellationToken cancellationToken = default) => |
| 1 | 3667 | | await this.UploadRangeFromUriInternal( |
| 1 | 3668 | | sourceUri, |
| 1 | 3669 | | range, |
| 1 | 3670 | | sourceRange, |
| 1 | 3671 | | conditions, |
| 1 | 3672 | | async: true, |
| 1 | 3673 | | cancellationToken) |
| 1 | 3674 | | .ConfigureAwait(false); |
| | 3675 | |
|
| | 3676 | |
|
| | 3677 | |
|
| | 3678 | | /// <summary> |
| | 3679 | | /// The <see cref="UploadRangeFromUriAsync(Uri, HttpRange, HttpRange, CancellationToken)"/> |
| | 3680 | | /// operation writes a range from an Azure File to another Azure file. This API is supported only for version 20 |
| | 3681 | | /// </summary> |
| | 3682 | | /// <param name="sourceUri"> |
| | 3683 | | /// Required. Specifies the URL of the source file, up to 2 KB in length. |
| | 3684 | | /// If source is an Azure blob or Azure file, it must either be public or must be authenticated via a |
| | 3685 | | /// shared access signature. If the source is public, no authentication is required to perform the operation. |
| | 3686 | | /// </param> |
| | 3687 | | /// <param name="range"> |
| | 3688 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3689 | | /// </param> |
| | 3690 | | /// <param name="sourceRange"> |
| | 3691 | | /// Specifies the range of bytes to be written from. Both the start and end of the range must be specified. |
| | 3692 | | /// </param> |
| | 3693 | | /// <param name="cancellationToken"> |
| | 3694 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3695 | | /// notifications that the operation should be cancelled. |
| | 3696 | | /// </param> |
| | 3697 | | /// <returns> |
| | 3698 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3699 | | /// state of the file. |
| | 3700 | | /// </returns> |
| | 3701 | | /// <remarks> |
| | 3702 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3703 | | /// a failure occurs. |
| | 3704 | | /// </remarks> |
| | 3705 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3706 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3707 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadRangeFromUriAsync( |
| | 3708 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3709 | | Uri sourceUri, |
| | 3710 | | HttpRange range, |
| | 3711 | | HttpRange sourceRange, |
| | 3712 | | CancellationToken cancellationToken) => |
| 0 | 3713 | | await this.UploadRangeFromUriInternal( |
| 0 | 3714 | | sourceUri, |
| 0 | 3715 | | range, |
| 0 | 3716 | | sourceRange, |
| 0 | 3717 | | conditions: default, |
| 0 | 3718 | | async: true, |
| 0 | 3719 | | cancellationToken) |
| 0 | 3720 | | .ConfigureAwait(false); |
| | 3721 | |
|
| | 3722 | | /// <summary> |
| | 3723 | | /// The <see cref="UploadRangeInternal"/> operation writes a range from an Azure File to another Azure file. |
| | 3724 | | /// This API is supported only for version 2019-02-02 and higher. |
| | 3725 | | /// </summary> |
| | 3726 | | /// <param name="sourceUri"> |
| | 3727 | | /// Required. Specifies the URL of the source file, up to 2 KB in length. |
| | 3728 | | /// If source is an Azure blob or Azure file, it must either be public or must be authenticated via a |
| | 3729 | | /// shared access signature. If the source is public, no authentication is required to perform the operation. |
| | 3730 | | /// </param> |
| | 3731 | | /// <param name="range"> |
| | 3732 | | /// Specifies the range of bytes to be written. Both the start and end of the range must be specified. |
| | 3733 | | /// </param> |
| | 3734 | | /// <param name="sourceRange"> |
| | 3735 | | /// Specifies the range of bytes to be written from. Both the start and end of the range must be specified. |
| | 3736 | | /// </param> |
| | 3737 | | /// <param name="conditions"> |
| | 3738 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3739 | | /// on creating the file. |
| | 3740 | | /// </param> |
| | 3741 | | /// <param name="async"> |
| | 3742 | | /// Whether to invoke the operation asynchronously. |
| | 3743 | | /// </param> |
| | 3744 | | /// <param name="cancellationToken"> |
| | 3745 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 3746 | | /// notifications that the operation should be cancelled. |
| | 3747 | | /// </param> |
| | 3748 | | /// <returns> |
| | 3749 | | /// A <see cref="Response{FileInfo}"/> describing the |
| | 3750 | | /// state of the file. |
| | 3751 | | /// </returns> |
| | 3752 | | /// <remarks> |
| | 3753 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3754 | | /// a failure occurs. |
| | 3755 | | /// </remarks> |
| | 3756 | | private async Task<Response<ShareFileUploadInfo>> UploadRangeFromUriInternal( |
| | 3757 | | Uri sourceUri, |
| | 3758 | | HttpRange range, |
| | 3759 | | HttpRange sourceRange, |
| | 3760 | | ShareFileRequestConditions conditions, |
| | 3761 | | bool async, |
| | 3762 | | CancellationToken cancellationToken) |
| | 3763 | | { |
| 2 | 3764 | | using (this.Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 3765 | | { |
| | 3766 | | this.Pipeline.LogMethodEnter( |
| | 3767 | | nameof(ShareFileClient), |
| | 3768 | | message: |
| | 3769 | | $"{nameof(this.Uri)}: {this.Uri}\n" + |
| | 3770 | | $"{nameof(sourceUri)}: {sourceUri}"); |
| | 3771 | | try |
| | 3772 | | { |
| 2 | 3773 | | var response = await FileRestClient.File.UploadRangeFromURLAsync( |
| 2 | 3774 | | clientDiagnostics: ClientDiagnostics, |
| 2 | 3775 | | pipeline: Pipeline, |
| 2 | 3776 | | resourceUri: Uri, |
| 2 | 3777 | | range: range.ToString(), |
| 2 | 3778 | | copySource: sourceUri, |
| 2 | 3779 | | contentLength: default, |
| 2 | 3780 | | version: Version.ToVersionString(), |
| 2 | 3781 | | sourceRange: sourceRange.ToString(), |
| 2 | 3782 | | leaseId: conditions?.LeaseId, |
| 2 | 3783 | | async: async, |
| 2 | 3784 | | cancellationToken: cancellationToken) |
| 2 | 3785 | | .ConfigureAwait(false); |
| | 3786 | |
|
| 0 | 3787 | | return Response.FromValue( |
| 0 | 3788 | | new ShareFileUploadInfo |
| 0 | 3789 | | { |
| 0 | 3790 | | ETag = response.Value.ETag, |
| 0 | 3791 | | LastModified = response.Value.LastModified, |
| 0 | 3792 | | ContentHash = response.Value.XMSContentCrc64, |
| 0 | 3793 | | IsServerEncrypted = response.Value.IsServerEncrypted |
| 0 | 3794 | | }, response.GetRawResponse()); |
| | 3795 | | } |
| 2 | 3796 | | catch (Exception ex) |
| | 3797 | | { |
| | 3798 | | this.Pipeline.LogException(ex); |
| 2 | 3799 | | throw; |
| | 3800 | | } |
| | 3801 | | finally |
| | 3802 | | { |
| | 3803 | | this.Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 3804 | | } |
| | 3805 | | } |
| 0 | 3806 | | } |
| | 3807 | | #endregion UploadRangeFromUrl |
| | 3808 | |
|
| | 3809 | | #region Upload |
| | 3810 | | /// <summary> |
| | 3811 | | /// The <see cref="Upload(Stream, IProgress{long}, ShareFileRequestConditions, CancellationToken)"/> |
| | 3812 | | /// operation writes <paramref name="content"/> to a file. |
| | 3813 | | /// |
| | 3814 | | /// For more information, see |
| | 3815 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3816 | | /// Put Range</see>. |
| | 3817 | | /// </summary> |
| | 3818 | | /// <param name="content"> |
| | 3819 | | /// A <see cref="Stream"/> containing the content of the file to upload. |
| | 3820 | | /// </param> |
| | 3821 | | /// <param name="progressHandler"> |
| | 3822 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3823 | | /// progress updates about data transfers. |
| | 3824 | | /// </param> |
| | 3825 | | /// <param name="conditions"> |
| | 3826 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3827 | | /// on creating the file. |
| | 3828 | | /// </param> |
| | 3829 | | /// <param name="cancellationToken"> |
| | 3830 | | /// Optional <see cref="CancellationToken"/> to propagate notifications |
| | 3831 | | /// that the operation should be cancelled. |
| | 3832 | | /// </param> |
| | 3833 | | /// <returns> |
| | 3834 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3835 | | /// state of the file. |
| | 3836 | | /// </returns> |
| | 3837 | | /// <remarks> |
| | 3838 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3839 | | /// a failure occurs. |
| | 3840 | | /// </remarks> |
| | 3841 | | [ForwardsClientCalls] |
| | 3842 | | public virtual Response<ShareFileUploadInfo> Upload( |
| | 3843 | | Stream content, |
| | 3844 | | IProgress<long> progressHandler = default, |
| | 3845 | | ShareFileRequestConditions conditions = default, |
| | 3846 | | CancellationToken cancellationToken = default) => |
| 6 | 3847 | | UploadInternal( |
| 6 | 3848 | | content, |
| 6 | 3849 | | progressHandler, |
| 6 | 3850 | | conditions, |
| 6 | 3851 | | Constants.File.MaxFileUpdateRange, |
| 6 | 3852 | | async: false, |
| 6 | 3853 | | cancellationToken) |
| 6 | 3854 | | .EnsureCompleted(); |
| | 3855 | |
|
| | 3856 | | /// <summary> |
| | 3857 | | /// The <see cref="Upload(Stream, IProgress{long}, ShareFileRequestConditions, CancellationToken)"/> |
| | 3858 | | /// operation writes <paramref name="content"/> to a file. |
| | 3859 | | /// |
| | 3860 | | /// For more information, see |
| | 3861 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3862 | | /// Put Range</see>. |
| | 3863 | | /// </summary> |
| | 3864 | | /// <param name="content"> |
| | 3865 | | /// A <see cref="Stream"/> containing the content of the file to upload. |
| | 3866 | | /// </param> |
| | 3867 | | /// <param name="progressHandler"> |
| | 3868 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3869 | | /// progress updates about data transfers. |
| | 3870 | | /// </param> |
| | 3871 | | /// <param name="cancellationToken"> |
| | 3872 | | /// Optional <see cref="CancellationToken"/> to propagate notifications |
| | 3873 | | /// that the operation should be cancelled. |
| | 3874 | | /// </param> |
| | 3875 | | /// <returns> |
| | 3876 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3877 | | /// state of the file. |
| | 3878 | | /// </returns> |
| | 3879 | | /// <remarks> |
| | 3880 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3881 | | /// a failure occurs. |
| | 3882 | | /// </remarks> |
| | 3883 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3884 | | [ForwardsClientCalls] |
| | 3885 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3886 | | public virtual Response<ShareFileUploadInfo> Upload( |
| | 3887 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3888 | | Stream content, |
| | 3889 | | IProgress<long> progressHandler, |
| | 3890 | | CancellationToken cancellationToken) => |
| 0 | 3891 | | UploadInternal( |
| 0 | 3892 | | content, |
| 0 | 3893 | | progressHandler, |
| 0 | 3894 | | conditions: default, |
| 0 | 3895 | | Constants.File.MaxFileUpdateRange, |
| 0 | 3896 | | async: false, |
| 0 | 3897 | | cancellationToken) |
| 0 | 3898 | | .EnsureCompleted(); |
| | 3899 | |
|
| | 3900 | | /// <summary> |
| | 3901 | | /// The <see cref="UploadAsync(Stream, IProgress{long}, ShareFileRequestConditions, CancellationToken)"/> operat |
| | 3902 | | /// <paramref name="content"/> to a file. |
| | 3903 | | /// |
| | 3904 | | /// For more information, see |
| | 3905 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3906 | | /// Put Range</see>. |
| | 3907 | | /// </summary> |
| | 3908 | | /// <param name="content"> |
| | 3909 | | /// A <see cref="Stream"/> containing the content of the file to upload. |
| | 3910 | | /// </param> |
| | 3911 | | /// <param name="progressHandler"> |
| | 3912 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3913 | | /// progress updates about data transfers. |
| | 3914 | | /// </param> |
| | 3915 | | /// <param name="conditions"> |
| | 3916 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 3917 | | /// on creating the file. |
| | 3918 | | /// </param> |
| | 3919 | | /// <param name="cancellationToken"> |
| | 3920 | | /// Optional <see cref="CancellationToken"/> to propagate notifications |
| | 3921 | | /// that the operation should be cancelled. |
| | 3922 | | /// </param> |
| | 3923 | | /// <returns> |
| | 3924 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3925 | | /// state of the file. |
| | 3926 | | /// </returns> |
| | 3927 | | /// <remarks> |
| | 3928 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3929 | | /// a failure occurs. |
| | 3930 | | /// </remarks> |
| | 3931 | | [ForwardsClientCalls] |
| | 3932 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadAsync( |
| | 3933 | | Stream content, |
| | 3934 | | IProgress<long> progressHandler = default, |
| | 3935 | | ShareFileRequestConditions conditions = default, |
| | 3936 | | CancellationToken cancellationToken = default) => |
| 14 | 3937 | | await UploadInternal( |
| 14 | 3938 | | content, |
| 14 | 3939 | | progressHandler, |
| 14 | 3940 | | conditions, |
| 14 | 3941 | | Constants.File.MaxFileUpdateRange, |
| 14 | 3942 | | async: true, |
| 14 | 3943 | | cancellationToken) |
| 14 | 3944 | | .ConfigureAwait(false); |
| | 3945 | |
|
| | 3946 | | /// <summary> |
| | 3947 | | /// The <see cref="UploadAsync(Stream, IProgress{long}, CancellationToken)"/> operation writes |
| | 3948 | | /// <paramref name="content"/> to a file. |
| | 3949 | | /// |
| | 3950 | | /// For more information, see |
| | 3951 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3952 | | /// Put Range</see>. |
| | 3953 | | /// </summary> |
| | 3954 | | /// <param name="content"> |
| | 3955 | | /// A <see cref="Stream"/> containing the content of the file to upload. |
| | 3956 | | /// </param> |
| | 3957 | | /// <param name="progressHandler"> |
| | 3958 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 3959 | | /// progress updates about data transfers. |
| | 3960 | | /// </param> |
| | 3961 | | /// <param name="cancellationToken"> |
| | 3962 | | /// Optional <see cref="CancellationToken"/> to propagate notifications |
| | 3963 | | /// that the operation should be cancelled. |
| | 3964 | | /// </param> |
| | 3965 | | /// <returns> |
| | 3966 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 3967 | | /// state of the file. |
| | 3968 | | /// </returns> |
| | 3969 | | /// <remarks> |
| | 3970 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 3971 | | /// a failure occurs. |
| | 3972 | | /// </remarks> |
| | 3973 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3974 | | [ForwardsClientCalls] |
| | 3975 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 3976 | | public virtual async Task<Response<ShareFileUploadInfo>> UploadAsync( |
| | 3977 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 3978 | | Stream content, |
| | 3979 | | IProgress<long> progressHandler, |
| | 3980 | | CancellationToken cancellationToken) => |
| 0 | 3981 | | await UploadInternal( |
| 0 | 3982 | | content, |
| 0 | 3983 | | progressHandler, |
| 0 | 3984 | | conditions: default, |
| 0 | 3985 | | Constants.File.MaxFileUpdateRange, |
| 0 | 3986 | | async: true, |
| 0 | 3987 | | cancellationToken) |
| 0 | 3988 | | .ConfigureAwait(false); |
| | 3989 | |
|
| | 3990 | | /// <summary> |
| | 3991 | | /// The <see cref="UploadInternal"/> operation writes |
| | 3992 | | /// <paramref name="content"/> to a file. |
| | 3993 | | /// |
| | 3994 | | /// For more information, see |
| | 3995 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-range"> |
| | 3996 | | /// Put Range</see>. |
| | 3997 | | /// </summary> |
| | 3998 | | /// <param name="content"> |
| | 3999 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 4000 | | /// </param> |
| | 4001 | | /// <param name="progressHandler"> |
| | 4002 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 4003 | | /// progress updates about data transfers. |
| | 4004 | | /// </param> |
| | 4005 | | /// <param name="conditions"> |
| | 4006 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 4007 | | /// on creating the file. |
| | 4008 | | /// </param> |
| | 4009 | | /// <param name="singleRangeThreshold"> |
| | 4010 | | /// The maximum size stream that we'll upload as a single range. The |
| | 4011 | | /// default value is 4MB. |
| | 4012 | | /// </param> |
| | 4013 | | /// <param name="async"> |
| | 4014 | | /// Whether to invoke the operation asynchronously. |
| | 4015 | | /// </param> |
| | 4016 | | /// <param name="cancellationToken"> |
| | 4017 | | /// Optional <see cref="CancellationToken"/> to propagate notifications |
| | 4018 | | /// that the operation should be cancelled. |
| | 4019 | | /// </param> |
| | 4020 | | /// <returns> |
| | 4021 | | /// A <see cref="Response{StorageFileUploadInfo}"/> describing the |
| | 4022 | | /// state of the file. |
| | 4023 | | /// </returns> |
| | 4024 | | /// <remarks> |
| | 4025 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4026 | | /// a failure occurs. |
| | 4027 | | /// </remarks> |
| | 4028 | | internal async Task<Response<ShareFileUploadInfo>> UploadInternal( |
| | 4029 | | Stream content, |
| | 4030 | | IProgress<long> progressHandler, |
| | 4031 | | ShareFileRequestConditions conditions, |
| | 4032 | | int singleRangeThreshold, |
| | 4033 | | bool async, |
| | 4034 | | CancellationToken cancellationToken) |
| | 4035 | | { |
| | 4036 | | // Try to upload the file as a single range |
| | 4037 | | Debug.Assert(singleRangeThreshold <= Constants.File.MaxFileUpdateRange); |
| 38 | 4038 | | var length = content.Length; |
| 38 | 4039 | | if (length <= singleRangeThreshold) |
| | 4040 | | { |
| 24 | 4041 | | return await UploadRangeInternal( |
| 24 | 4042 | | new HttpRange(0, length), |
| 24 | 4043 | | content, |
| 24 | 4044 | | null, |
| 24 | 4045 | | progressHandler, |
| 24 | 4046 | | conditions, |
| 24 | 4047 | | async, |
| 24 | 4048 | | cancellationToken) |
| 24 | 4049 | | .ConfigureAwait(false); |
| | 4050 | | } |
| | 4051 | |
|
| | 4052 | | // Otherwise naively split the file into ranges and upload them individually |
| 14 | 4053 | | var response = default(Response<ShareFileUploadInfo>); |
| 14 | 4054 | | var pool = default(MemoryPool<byte>); |
| | 4055 | | try |
| | 4056 | | { |
| 14 | 4057 | | pool = (singleRangeThreshold < MemoryPool<byte>.Shared.MaxBufferSize) ? |
| 14 | 4058 | | MemoryPool<byte>.Shared : |
| 14 | 4059 | | new StorageMemoryPool(singleRangeThreshold, 1); |
| | 4060 | | for (; ; ) |
| | 4061 | | { |
| | 4062 | | // Get the next chunk of content |
| 1248 | 4063 | | var parentPosition = content.Position; |
| 1248 | 4064 | | IMemoryOwner<byte> buffer = pool.Rent(singleRangeThreshold); |
| 1248 | 4065 | | if (!MemoryMarshal.TryGetArray<byte>(buffer.Memory, out ArraySegment<byte> segment)) |
| | 4066 | | { |
| 0 | 4067 | | throw Errors.UnableAccessArray(); |
| | 4068 | | } |
| 1248 | 4069 | | var count = async ? |
| 1248 | 4070 | | await content.ReadAsync(segment.Array, 0, singleRangeThreshold, cancellationToken).ConfigureAwai |
| 1248 | 4071 | | content.Read(segment.Array, 0, singleRangeThreshold); |
| | 4072 | |
|
| | 4073 | | // Stop when we've exhausted the content |
| 1248 | 4074 | | if (count <= 0) { break; } |
| | 4075 | |
|
| | 4076 | | // Upload the chunk |
| 1234 | 4077 | | var partition = new StreamPartition( |
| 1234 | 4078 | | buffer.Memory, |
| 1234 | 4079 | | parentPosition, |
| 1234 | 4080 | | count, |
| 0 | 4081 | | () => buffer.Dispose(), |
| 1234 | 4082 | | cancellationToken); |
| 1234 | 4083 | | response = await UploadRangeInternal( |
| 1234 | 4084 | | new HttpRange(partition.ParentPosition, partition.Length), |
| 1234 | 4085 | | partition, |
| 1234 | 4086 | | null, |
| 1234 | 4087 | | progressHandler, |
| 1234 | 4088 | | conditions, |
| 1234 | 4089 | | async, |
| 1234 | 4090 | | cancellationToken) |
| 1234 | 4091 | | .ConfigureAwait(false); |
| | 4092 | |
|
| 1234 | 4093 | | } |
| 14 | 4094 | | } |
| | 4095 | | finally |
| | 4096 | | { |
| 14 | 4097 | | if (pool is StorageMemoryPool) |
| | 4098 | | { |
| 0 | 4099 | | pool.Dispose(); |
| | 4100 | | } |
| | 4101 | | } |
| 14 | 4102 | | return response; |
| 34 | 4103 | | } |
| | 4104 | | #endregion Upload |
| | 4105 | |
|
| | 4106 | | #region GetRangeList |
| | 4107 | | /// <summary> |
| | 4108 | | /// Returns the list of valid ranges for a file. |
| | 4109 | | /// |
| | 4110 | | /// For more information, see |
| | 4111 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-ranges"> |
| | 4112 | | /// List Ranges</see>. |
| | 4113 | | /// </summary> |
| | 4114 | | /// <param name="range"> |
| | 4115 | | /// Optional. Specifies the range of bytes over which to list ranges, inclusively. |
| | 4116 | | /// If omitted, then all ranges for the file are returned. |
| | 4117 | | /// </param> |
| | 4118 | | /// <param name="conditions"> |
| | 4119 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 4120 | | /// on creating the file. |
| | 4121 | | /// </param> |
| | 4122 | | /// <param name="cancellationToken"> |
| | 4123 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4124 | | /// notifications that the operation should be cancelled. |
| | 4125 | | /// </param> |
| | 4126 | | /// <returns> |
| | 4127 | | /// A <see cref="Response{StorageFileRangeInfo}"/> describing the |
| | 4128 | | /// valid ranges for this file. |
| | 4129 | | /// </returns> |
| | 4130 | | /// <remarks> |
| | 4131 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4132 | | /// a failure occurs. |
| | 4133 | | /// </remarks> |
| | 4134 | | public virtual Response<ShareFileRangeInfo> GetRangeList( |
| | 4135 | | HttpRange range, |
| | 4136 | | ShareFileRequestConditions conditions = default, |
| | 4137 | | CancellationToken cancellationToken = default) => |
| 5 | 4138 | | GetRangeListInternal( |
| 5 | 4139 | | range, |
| 5 | 4140 | | conditions, |
| 5 | 4141 | | async: false, |
| 5 | 4142 | | cancellationToken) |
| 5 | 4143 | | .EnsureCompleted(); |
| | 4144 | |
|
| | 4145 | | /// <summary> |
| | 4146 | | /// Returns the list of valid ranges for a file. |
| | 4147 | | /// |
| | 4148 | | /// For more information, see |
| | 4149 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-ranges"> |
| | 4150 | | /// List Ranges</see>. |
| | 4151 | | /// </summary> |
| | 4152 | | /// <param name="range"> |
| | 4153 | | /// Optional. Specifies the range of bytes over which to list ranges, inclusively. |
| | 4154 | | /// If omitted, then all ranges for the file are returned. |
| | 4155 | | /// </param> |
| | 4156 | | /// <param name="cancellationToken"> |
| | 4157 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4158 | | /// notifications that the operation should be cancelled. |
| | 4159 | | /// </param> |
| | 4160 | | /// <returns> |
| | 4161 | | /// A <see cref="Response{StorageFileRangeInfo}"/> describing the |
| | 4162 | | /// valid ranges for this file. |
| | 4163 | | /// </returns> |
| | 4164 | | /// <remarks> |
| | 4165 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4166 | | /// a failure occurs. |
| | 4167 | | /// </remarks> |
| | 4168 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 4169 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 4170 | | public virtual Response<ShareFileRangeInfo> GetRangeList( |
| | 4171 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 4172 | | HttpRange range, |
| | 4173 | | CancellationToken cancellationToken) => |
| 0 | 4174 | | GetRangeListInternal( |
| 0 | 4175 | | range, |
| 0 | 4176 | | conditions: default, |
| 0 | 4177 | | async: false, |
| 0 | 4178 | | cancellationToken) |
| 0 | 4179 | | .EnsureCompleted(); |
| | 4180 | |
|
| | 4181 | | /// <summary> |
| | 4182 | | /// Returns the list of valid ranges for a file. |
| | 4183 | | /// |
| | 4184 | | /// For more information, see |
| | 4185 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-ranges"> |
| | 4186 | | /// List Ranges</see>. |
| | 4187 | | /// </summary> |
| | 4188 | | /// <param name="range"> |
| | 4189 | | /// Optional. Specifies the range of bytes over which to list ranges, inclusively. |
| | 4190 | | /// If omitted, then all ranges for the file are returned. |
| | 4191 | | /// </param> |
| | 4192 | | /// <param name="conditions"> |
| | 4193 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 4194 | | /// on creating the file. |
| | 4195 | | /// </param> |
| | 4196 | | /// <param name="cancellationToken"> |
| | 4197 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4198 | | /// notifications that the operation should be cancelled. |
| | 4199 | | /// </param> |
| | 4200 | | /// <returns> |
| | 4201 | | /// A <see cref="Response{StorageFileRangeInfo}"/> describing the |
| | 4202 | | /// valid ranges for this file. |
| | 4203 | | /// </returns> |
| | 4204 | | /// <remarks> |
| | 4205 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4206 | | /// a failure occurs. |
| | 4207 | | /// </remarks> |
| | 4208 | | public virtual async Task<Response<ShareFileRangeInfo>> GetRangeListAsync( |
| | 4209 | | HttpRange range, |
| | 4210 | | ShareFileRequestConditions conditions = default, |
| | 4211 | | CancellationToken cancellationToken = default) => |
| 5 | 4212 | | await GetRangeListInternal( |
| 5 | 4213 | | range, |
| 5 | 4214 | | conditions, |
| 5 | 4215 | | async: true, |
| 5 | 4216 | | cancellationToken) |
| 5 | 4217 | | .ConfigureAwait(false); |
| | 4218 | |
|
| | 4219 | | /// <summary> |
| | 4220 | | /// Returns the list of valid ranges for a file. |
| | 4221 | | /// |
| | 4222 | | /// For more information, see |
| | 4223 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-ranges"> |
| | 4224 | | /// List Ranges</see>. |
| | 4225 | | /// </summary> |
| | 4226 | | /// <param name="range"> |
| | 4227 | | /// Optional. Specifies the range of bytes over which to list ranges, inclusively. |
| | 4228 | | /// If omitted, then all ranges for the file are returned. |
| | 4229 | | /// </param> |
| | 4230 | | /// <param name="cancellationToken"> |
| | 4231 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4232 | | /// notifications that the operation should be cancelled. |
| | 4233 | | /// </param> |
| | 4234 | | /// <returns> |
| | 4235 | | /// A <see cref="Response{StorageFileRangeInfo}"/> describing the |
| | 4236 | | /// valid ranges for this file. |
| | 4237 | | /// </returns> |
| | 4238 | | /// <remarks> |
| | 4239 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4240 | | /// a failure occurs. |
| | 4241 | | /// </remarks> |
| | 4242 | | #pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 4243 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 4244 | | public virtual async Task<Response<ShareFileRangeInfo>> GetRangeListAsync( |
| | 4245 | | #pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional Ca |
| | 4246 | | HttpRange range, |
| | 4247 | | CancellationToken cancellationToken) => |
| 0 | 4248 | | await GetRangeListInternal( |
| 0 | 4249 | | range, |
| 0 | 4250 | | conditions: default, |
| 0 | 4251 | | async: true, |
| 0 | 4252 | | cancellationToken) |
| 0 | 4253 | | .ConfigureAwait(false); |
| | 4254 | |
|
| | 4255 | | /// <summary> |
| | 4256 | | /// Returns the list of valid ranges for a file. |
| | 4257 | | /// |
| | 4258 | | /// For more information, see |
| | 4259 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-ranges"> |
| | 4260 | | /// List Ranges</see>. |
| | 4261 | | /// </summary> |
| | 4262 | | /// <param name="range"> |
| | 4263 | | /// Optional. Specifies the range of bytes over which to list ranges, inclusively. |
| | 4264 | | /// If omitted, then all ranges for the file are returned. |
| | 4265 | | /// </param> |
| | 4266 | | /// <param name="conditions"> |
| | 4267 | | /// Optional <see cref="ShareFileRequestConditions"/> to add conditions |
| | 4268 | | /// on creating the file. |
| | 4269 | | /// </param> |
| | 4270 | | /// <param name="async"> |
| | 4271 | | /// Whether to invoke the operation asynchronously. |
| | 4272 | | /// </param> |
| | 4273 | | /// <param name="cancellationToken"> |
| | 4274 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4275 | | /// notifications that the operation should be cancelled. |
| | 4276 | | /// </param> |
| | 4277 | | /// <returns> |
| | 4278 | | /// A <see cref="Response{StorageFileRangeInfo}"/> describing the |
| | 4279 | | /// valid ranges for this file. |
| | 4280 | | /// </returns> |
| | 4281 | | /// <remarks> |
| | 4282 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4283 | | /// a failure occurs. |
| | 4284 | | /// </remarks> |
| | 4285 | | private async Task<Response<ShareFileRangeInfo>> GetRangeListInternal( |
| | 4286 | | HttpRange range, |
| | 4287 | | ShareFileRequestConditions conditions, |
| | 4288 | | bool async, |
| | 4289 | | CancellationToken cancellationToken) |
| | 4290 | | { |
| 10 | 4291 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 4292 | | { |
| | 4293 | | Pipeline.LogMethodEnter( |
| | 4294 | | nameof(ShareFileClient), |
| | 4295 | | message: |
| | 4296 | | $"{nameof(Uri)}: {Uri}"); |
| | 4297 | | try |
| | 4298 | | { |
| 10 | 4299 | | Response<ShareFileRangeInfoInternal> response = await FileRestClient.File.GetRangeListAsync( |
| 10 | 4300 | | ClientDiagnostics, |
| 10 | 4301 | | Pipeline, |
| 10 | 4302 | | Uri, |
| 10 | 4303 | | version: Version.ToVersionString(), |
| 10 | 4304 | | range: range.ToString(), |
| 10 | 4305 | | leaseId: conditions?.LeaseId, |
| 10 | 4306 | | async: async, |
| 10 | 4307 | | cancellationToken: cancellationToken, |
| 10 | 4308 | | operationName: $"{nameof(ShareFileClient)}.{nameof(GetRangeList)}") |
| 10 | 4309 | | .ConfigureAwait(false); |
| 6 | 4310 | | return Response.FromValue(new ShareFileRangeInfo(response.Value), response.GetRawResponse()); |
| | 4311 | | } |
| 4 | 4312 | | catch (Exception ex) |
| | 4313 | | { |
| | 4314 | | Pipeline.LogException(ex); |
| 4 | 4315 | | throw; |
| | 4316 | | } |
| | 4317 | | finally |
| | 4318 | | { |
| | 4319 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 4320 | | } |
| | 4321 | | } |
| 6 | 4322 | | } |
| | 4323 | | #endregion GetRangeList |
| | 4324 | |
|
| | 4325 | | #region GetHandles |
| | 4326 | | /// <summary> |
| | 4327 | | /// The <see cref="GetHandles"/> operation returns an async sequence |
| | 4328 | | /// of the open handles on a directory or a file. Enumerating the |
| | 4329 | | /// handles may make multiple requests to the service while fetching |
| | 4330 | | /// all the values. |
| | 4331 | | /// |
| | 4332 | | /// For more information, see |
| | 4333 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-handles"> |
| | 4334 | | /// List Handles</see>. |
| | 4335 | | /// </summary> |
| | 4336 | | /// <param name="cancellationToken"> |
| | 4337 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4338 | | /// notifications that the operation should be cancelled. |
| | 4339 | | /// </param> |
| | 4340 | | /// <returns> |
| | 4341 | | /// An <see cref="IEnumerable{T}"/> of <see cref="Response{StorageHandle}"/> |
| | 4342 | | /// describing the handles in the directory. |
| | 4343 | | /// </returns> |
| | 4344 | | /// <remarks> |
| | 4345 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4346 | | /// a failure occurs. |
| | 4347 | | /// </remarks> |
| | 4348 | | public virtual Pageable<ShareFileHandle> GetHandles( |
| | 4349 | | CancellationToken cancellationToken = default) => |
| 3 | 4350 | | new GetFileHandlesAsyncCollection(this).ToSyncCollection(cancellationToken); |
| | 4351 | |
|
| | 4352 | | /// <summary> |
| | 4353 | | /// The <see cref="GetHandlesAsync"/> operation returns an async |
| | 4354 | | /// sequence of the open handles on a directory or a file. |
| | 4355 | | /// Enumerating the handles may make multiple requests to the service |
| | 4356 | | /// while fetching all the values. |
| | 4357 | | /// |
| | 4358 | | /// For more information, see |
| | 4359 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-handles"> |
| | 4360 | | /// List Handles</see>. |
| | 4361 | | /// </summary> |
| | 4362 | | /// <param name="cancellationToken"> |
| | 4363 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4364 | | /// notifications that the operation should be cancelled. |
| | 4365 | | /// </param> |
| | 4366 | | /// <returns> |
| | 4367 | | /// A <see cref="AsyncPageable{T}"/> describing the |
| | 4368 | | /// handles on the file. |
| | 4369 | | /// </returns> |
| | 4370 | | /// <remarks> |
| | 4371 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4372 | | /// a failure occurs. |
| | 4373 | | /// </remarks> |
| | 4374 | | public virtual AsyncPageable<ShareFileHandle> GetHandlesAsync( |
| | 4375 | | CancellationToken cancellationToken = default) => |
| 3 | 4376 | | new GetFileHandlesAsyncCollection(this).ToAsyncCollection(cancellationToken); |
| | 4377 | |
|
| | 4378 | | /// <summary> |
| | 4379 | | /// The <see cref="GetHandlesInternal"/> operation returns a list of open |
| | 4380 | | /// handles on the file. |
| | 4381 | | /// |
| | 4382 | | /// For more information, see |
| | 4383 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-handles"> |
| | 4384 | | /// List Handles</see>. |
| | 4385 | | /// </summary> |
| | 4386 | | /// <remarks> |
| | 4387 | | /// </remarks> |
| | 4388 | | /// <param name="marker"> |
| | 4389 | | /// An optional string value that identifies the segment of the list |
| | 4390 | | /// of items to be returned with the next listing operation. The |
| | 4391 | | /// operation returns a non-empty <see cref="StorageHandlesSegment.NextMarker"/> |
| | 4392 | | /// if the listing operation did not return all items remaining to be |
| | 4393 | | /// listed with the current segment. The NextMarker value can |
| | 4394 | | /// be used as the value for the <paramref name="marker"/> parameter |
| | 4395 | | /// in a subsequent call to request the next segment of list items. |
| | 4396 | | /// </param> |
| | 4397 | | /// <param name="maxResults"> |
| | 4398 | | /// Optional. Specifies the maximum number of handles to return. |
| | 4399 | | /// </param> |
| | 4400 | | /// <param name="async"> |
| | 4401 | | /// Whether to invoke the operation asynchronously. |
| | 4402 | | /// </param> |
| | 4403 | | /// <param name="cancellationToken"> |
| | 4404 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4405 | | /// notifications that the operation should be cancelled. |
| | 4406 | | /// </param> |
| | 4407 | | /// <returns> |
| | 4408 | | /// A <see cref="Response{StorageHandlesSegment}"/> describing a |
| | 4409 | | /// segment of the handles on the file. |
| | 4410 | | /// </returns> |
| | 4411 | | /// <remarks> |
| | 4412 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4413 | | /// a failure occurs. |
| | 4414 | | /// </remarks> |
| | 4415 | | internal async Task<Response<StorageHandlesSegment>> GetHandlesInternal( |
| | 4416 | | string marker, |
| | 4417 | | int? maxResults, |
| | 4418 | | bool async, |
| | 4419 | | CancellationToken cancellationToken) |
| | 4420 | | { |
| 6 | 4421 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 4422 | | { |
| | 4423 | | Pipeline.LogMethodEnter( |
| | 4424 | | nameof(ShareFileClient), |
| | 4425 | | message: |
| | 4426 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 4427 | | $"{nameof(marker)}: {marker}\n" + |
| | 4428 | | $"{nameof(maxResults)}: {maxResults}"); |
| | 4429 | | try |
| | 4430 | | { |
| 6 | 4431 | | return await FileRestClient.File.ListHandlesAsync( |
| 6 | 4432 | | ClientDiagnostics, |
| 6 | 4433 | | Pipeline, |
| 6 | 4434 | | Uri, |
| 6 | 4435 | | version: Version.ToVersionString(), |
| 6 | 4436 | | marker: marker, |
| 6 | 4437 | | maxresults: maxResults, |
| 6 | 4438 | | async: async, |
| 6 | 4439 | | cancellationToken: cancellationToken) |
| 6 | 4440 | | .ConfigureAwait(false); |
| | 4441 | | } |
| 2 | 4442 | | catch (Exception ex) |
| | 4443 | | { |
| | 4444 | | Pipeline.LogException(ex); |
| 2 | 4445 | | throw; |
| | 4446 | | } |
| | 4447 | | finally |
| | 4448 | | { |
| | 4449 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 4450 | | } |
| | 4451 | | } |
| 4 | 4452 | | } |
| | 4453 | | #endregion GetHandles |
| | 4454 | |
|
| | 4455 | | #region ForceCloseHandles |
| | 4456 | | /// <summary> |
| | 4457 | | /// The <see cref="ForceCloseHandle"/> operation closes a handle opened on a file |
| | 4458 | | /// at the service. It supports closing a single handle specified by <paramref name="handleId"/>. |
| | 4459 | | /// |
| | 4460 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4461 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4462 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4463 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4464 | | /// or alternative for SMB close. |
| | 4465 | | /// |
| | 4466 | | /// For more information, see |
| | 4467 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4468 | | /// Force Close Handles</see>. |
| | 4469 | | /// </summary> |
| | 4470 | | /// <param name="handleId"> |
| | 4471 | | /// Specifies the handle ID to be closed. |
| | 4472 | | /// </param> |
| | 4473 | | /// <param name="cancellationToken"> |
| | 4474 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4475 | | /// notifications that the operation should be cancelled. |
| | 4476 | | /// </param> |
| | 4477 | | /// <returns> |
| | 4478 | | /// A <see cref="Response{CloseHandlesResult}"/> describing the status of the |
| | 4479 | | /// <see cref="ForceCloseHandle"/> operation. |
| | 4480 | | /// </returns> |
| | 4481 | | /// <remarks> |
| | 4482 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4483 | | /// a failure occurs. |
| | 4484 | | /// </remarks> |
| | 4485 | | public virtual Response<CloseHandlesResult> ForceCloseHandle( |
| | 4486 | | string handleId, |
| | 4487 | | CancellationToken cancellationToken = default) |
| | 4488 | | { |
| 1 | 4489 | | Response<StorageClosedHandlesSegment> response = ForceCloseHandlesInternal( |
| 1 | 4490 | | handleId, |
| 1 | 4491 | | null, |
| 1 | 4492 | | false, // async, |
| 1 | 4493 | | cancellationToken, |
| 1 | 4494 | | $"{nameof(ShareFileClient)}.{nameof(ForceCloseHandle)}") |
| 1 | 4495 | | .EnsureCompleted(); |
| | 4496 | |
|
| 0 | 4497 | | return Response.FromValue( |
| 0 | 4498 | | response.ToCloseHandlesResult(), |
| 0 | 4499 | | response.GetRawResponse()); |
| | 4500 | | } |
| | 4501 | |
|
| | 4502 | | /// <summary> |
| | 4503 | | /// The <see cref="ForceCloseHandleAsync"/> operation closes a handle opened on a file |
| | 4504 | | /// at the service. It supports closing a single handle specified by <paramref name="handleId"/>. |
| | 4505 | | /// |
| | 4506 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4507 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4508 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4509 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4510 | | /// or alternative for SMB close. |
| | 4511 | | /// |
| | 4512 | | /// For more information, see |
| | 4513 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4514 | | /// Force Close Handles</see>. |
| | 4515 | | /// </summary> |
| | 4516 | | /// <param name="handleId"> |
| | 4517 | | /// Specifies the handle ID to be closed. |
| | 4518 | | /// </param> |
| | 4519 | | /// <param name="cancellationToken"> |
| | 4520 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4521 | | /// notifications that the operation should be cancelled. |
| | 4522 | | /// </param> |
| | 4523 | | /// <returns> |
| | 4524 | | /// A <see cref="Response{CloseHandlesResult}"/> describing the status of the |
| | 4525 | | /// <see cref="ForceCloseHandleAsync"/> operation. |
| | 4526 | | /// </returns> |
| | 4527 | | /// <remarks> |
| | 4528 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4529 | | /// a failure occurs. |
| | 4530 | | /// </remarks> |
| | 4531 | | public virtual async Task<Response<CloseHandlesResult>> ForceCloseHandleAsync( |
| | 4532 | | string handleId, |
| | 4533 | | CancellationToken cancellationToken = default) |
| | 4534 | | { |
| 1 | 4535 | | Response<StorageClosedHandlesSegment> response = await ForceCloseHandlesInternal( |
| 1 | 4536 | | handleId, |
| 1 | 4537 | | null, |
| 1 | 4538 | | true, // async, |
| 1 | 4539 | | cancellationToken, |
| 1 | 4540 | | $"{nameof(ShareFileClient)}.{nameof(ForceCloseHandle)}") |
| 1 | 4541 | | .ConfigureAwait(false); |
| | 4542 | |
|
| 0 | 4543 | | return Response.FromValue( |
| 0 | 4544 | | response.ToCloseHandlesResult(), |
| 0 | 4545 | | response.GetRawResponse()); |
| 0 | 4546 | | } |
| | 4547 | |
|
| | 4548 | | /// <summary> |
| | 4549 | | /// The <see cref="ForceCloseAllHandles"/> operation closes all handles opened on a file |
| | 4550 | | /// at the service. |
| | 4551 | | /// |
| | 4552 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4553 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4554 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4555 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4556 | | /// or alternative for SMB close. |
| | 4557 | | /// |
| | 4558 | | /// For more information, see |
| | 4559 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4560 | | /// Force Close Handles</see>. |
| | 4561 | | /// </summary> |
| | 4562 | | /// <param name="cancellationToken"> |
| | 4563 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4564 | | /// notifications that the operation should be cancelled. |
| | 4565 | | /// </param> |
| | 4566 | | /// <returns> |
| | 4567 | | /// A <see cref="CloseHandlesResult"/> describing the status of the |
| | 4568 | | /// <see cref="ForceCloseAllHandles"/> operation. |
| | 4569 | | /// </returns> |
| | 4570 | | /// <remarks> |
| | 4571 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4572 | | /// a failure occurs. |
| | 4573 | | /// </remarks> |
| | 4574 | | public virtual CloseHandlesResult ForceCloseAllHandles( |
| | 4575 | | CancellationToken cancellationToken = default) => |
| 2 | 4576 | | ForceCloseAllHandlesInternal( |
| 2 | 4577 | | false, // async, |
| 2 | 4578 | | cancellationToken) |
| 2 | 4579 | | .EnsureCompleted(); |
| | 4580 | |
|
| | 4581 | | /// <summary> |
| | 4582 | | /// The <see cref="ForceCloseAllHandlesAsync"/> operation closes all handles opened on a file |
| | 4583 | | /// at the service. |
| | 4584 | | /// |
| | 4585 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4586 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4587 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4588 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4589 | | /// or alternative for SMB close. |
| | 4590 | | /// |
| | 4591 | | /// For more information, see |
| | 4592 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4593 | | /// Force Close Handles</see>. |
| | 4594 | | /// </summary> |
| | 4595 | | /// <param name="cancellationToken"> |
| | 4596 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4597 | | /// notifications that the operation should be cancelled. |
| | 4598 | | /// </param> |
| | 4599 | | /// <returns> |
| | 4600 | | /// A <see cref="CloseHandlesResult"/> describing the status of the |
| | 4601 | | /// <see cref="ForceCloseAllHandlesAsync"/> operation. |
| | 4602 | | /// </returns> |
| | 4603 | | /// <remarks> |
| | 4604 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4605 | | /// a failure occurs. |
| | 4606 | | /// </remarks> |
| | 4607 | | public virtual async Task<CloseHandlesResult> ForceCloseAllHandlesAsync( |
| | 4608 | | CancellationToken cancellationToken = default) => |
| 2 | 4609 | | await ForceCloseAllHandlesInternal( |
| 2 | 4610 | | true, // async, |
| 2 | 4611 | | cancellationToken) |
| 2 | 4612 | | .ConfigureAwait(false); |
| | 4613 | |
|
| | 4614 | | /// <summary> |
| | 4615 | | /// The <see cref="ForceCloseAllHandlesInternal"/> operation closes a handle or handles opened on a file |
| | 4616 | | /// at the service. It supports closing all handles opened on that resource. |
| | 4617 | | /// |
| | 4618 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4619 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4620 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4621 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4622 | | /// or alternative for SMB close. |
| | 4623 | | /// |
| | 4624 | | /// For more information, see |
| | 4625 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4626 | | /// Force Close Handles</see>. |
| | 4627 | | /// </summary> |
| | 4628 | | /// <param name="async"> |
| | 4629 | | /// Whether to invoke the operation asynchronously. |
| | 4630 | | /// </param> |
| | 4631 | | /// <param name="cancellationToken"> |
| | 4632 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4633 | | /// notifications that the operation should be cancelled. |
| | 4634 | | /// </param> |
| | 4635 | | /// <returns> |
| | 4636 | | /// A <see cref="Response{ClosedHandlesInfo}"/> describing the status of the |
| | 4637 | | /// <see cref="ForceCloseAllHandlesInternal"/> operation. |
| | 4638 | | /// </returns> |
| | 4639 | | /// <remarks> |
| | 4640 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4641 | | /// a failure occurs. |
| | 4642 | | /// </remarks> |
| | 4643 | | private async Task<CloseHandlesResult> ForceCloseAllHandlesInternal( |
| | 4644 | | bool async, |
| | 4645 | | CancellationToken cancellationToken) |
| | 4646 | | { |
| 4 | 4647 | | int handlesClosed = 0; |
| 4 | 4648 | | int handlesFailed = 0; |
| 4 | 4649 | | string marker = null; |
| | 4650 | | do |
| | 4651 | | { |
| 4 | 4652 | | Response<StorageClosedHandlesSegment> response = |
| 4 | 4653 | | await ForceCloseHandlesInternal(Constants.CloseAllHandles, marker, async, cancellationToken).Configu |
| 2 | 4654 | | marker = response.Value.Marker; |
| 2 | 4655 | | handlesClosed += response.Value.NumberOfHandlesClosed; |
| 2 | 4656 | | handlesFailed += response.Value.NumberOfHandlesFailedToClose; |
| | 4657 | |
|
| 2 | 4658 | | } while (!string.IsNullOrEmpty(marker)); |
| | 4659 | |
|
| 2 | 4660 | | return new CloseHandlesResult() |
| 2 | 4661 | | { |
| 2 | 4662 | | ClosedHandlesCount = handlesClosed, |
| 2 | 4663 | | FailedHandlesCount = handlesFailed |
| 2 | 4664 | | }; |
| 2 | 4665 | | } |
| | 4666 | |
|
| | 4667 | | /// <summary> |
| | 4668 | | /// The <see cref="ForceCloseHandlesInternal"/> operation closes a handle or handles opened on a file |
| | 4669 | | /// at the service. It supports closing a single handle specified by <paramref name="handleId"/> or |
| | 4670 | | /// or closing all handles opened on that resource. |
| | 4671 | | /// |
| | 4672 | | /// This API is intended to be used alongside <see cref="GetHandlesAsync"/> to force close handles that |
| | 4673 | | /// block operations. These handles may have leaked or been lost track of by |
| | 4674 | | /// SMB clients. The API has client-side impact on the handle being closed, including user visible |
| | 4675 | | /// errors due to failed attempts to read or write files. This API is not intended for use as a replacement |
| | 4676 | | /// or alternative for SMB close. |
| | 4677 | | /// |
| | 4678 | | /// For more information, see |
| | 4679 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/force-close-handles"> |
| | 4680 | | /// Force Close Handles</see>. |
| | 4681 | | /// </summary> |
| | 4682 | | /// <param name="handleId"> |
| | 4683 | | /// Optional. Specifies the handle ID to be closed. If not specified, or if equal to "*", will close a |
| | 4684 | | /// </param> |
| | 4685 | | /// <param name="marker"> |
| | 4686 | | /// An optional string value that identifies the segment of the handles |
| | 4687 | | /// to be closed with the next call to <see cref="ForceCloseAllHandlesAsync"/>. The |
| | 4688 | | /// operation returns a non-empty <see cref="StorageClosedHandlesSegment.Marker"/> |
| | 4689 | | /// if the operation did not return all items remaining to be |
| | 4690 | | /// closed with the current segment. The NextMarker value can |
| | 4691 | | /// be used as the value for the <paramref name="marker"/> parameter |
| | 4692 | | /// in a subsequent call to request the closure of the next segment of handles. |
| | 4693 | | /// </param> |
| | 4694 | | /// <param name="async"> |
| | 4695 | | /// Whether to invoke the operation asynchronously. |
| | 4696 | | /// </param> |
| | 4697 | | /// <param name="cancellationToken"> |
| | 4698 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 4699 | | /// notifications that the operation should be cancelled. |
| | 4700 | | /// </param> |
| | 4701 | | /// <param name="operationName"> |
| | 4702 | | /// Optional. Used to indicate the name of the operation. |
| | 4703 | | /// </param> |
| | 4704 | | /// <returns> |
| | 4705 | | /// A <see cref="Response{StorageClosedHandlesSegment}"/> describing a |
| | 4706 | | /// segment of the handles closed. |
| | 4707 | | /// </returns> |
| | 4708 | | /// <remarks> |
| | 4709 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 4710 | | /// a failure occurs. |
| | 4711 | | /// </remarks> |
| | 4712 | | private async Task<Response<StorageClosedHandlesSegment>> ForceCloseHandlesInternal( |
| | 4713 | | string handleId, |
| | 4714 | | string marker, |
| | 4715 | | bool async, |
| | 4716 | | CancellationToken cancellationToken, |
| | 4717 | | string operationName = null) |
| | 4718 | | { |
| 6 | 4719 | | using (Pipeline.BeginLoggingScope(nameof(ShareFileClient))) |
| | 4720 | | { |
| | 4721 | | Pipeline.LogMethodEnter( |
| | 4722 | | nameof(ShareFileClient), |
| | 4723 | | message: |
| | 4724 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 4725 | | $"{nameof(handleId)}: {handleId}\n" + |
| | 4726 | | $"{nameof(marker)}: {marker}"); |
| | 4727 | | try |
| | 4728 | | { |
| 6 | 4729 | | return await FileRestClient.File.ForceCloseHandlesAsync( |
| 6 | 4730 | | ClientDiagnostics, |
| 6 | 4731 | | Pipeline, |
| 6 | 4732 | | Uri, |
| 6 | 4733 | | marker: marker, |
| 6 | 4734 | | handleId: handleId, |
| 6 | 4735 | | version: Version.ToVersionString(), |
| 6 | 4736 | | async: async, |
| 6 | 4737 | | cancellationToken: cancellationToken, |
| 6 | 4738 | | operationName: operationName ?? $"{nameof(ShareFileClient)}.{nameof(ForceCloseAllHandles)}") |
| 6 | 4739 | | .ConfigureAwait(false); |
| | 4740 | | } |
| 4 | 4741 | | catch (Exception ex) |
| | 4742 | | { |
| | 4743 | | Pipeline.LogException(ex); |
| 4 | 4744 | | throw; |
| | 4745 | | } |
| | 4746 | | finally |
| | 4747 | | { |
| | 4748 | | Pipeline.LogMethodExit(nameof(ShareFileClient)); |
| | 4749 | | } |
| | 4750 | | } |
| 2 | 4751 | | } |
| | 4752 | | #endregion ForceCloseHandles |
| | 4753 | | } |
| | 4754 | | } |