| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.Batch |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Text; |
| | 9 | | using System.IO; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using System.Threading; |
| | 12 | | using Models = Microsoft.Azure.Batch.Protocol.Models; |
| | 13 | | using Microsoft.Rest.Azure; |
| | 14 | |
|
| | 15 | | internal class TaskFile : NodeFile |
| | 16 | | { |
| | 17 | | private readonly JobOperations _jobOperations; |
| | 18 | | private readonly string _jobId; |
| | 19 | | private readonly string _taskId; |
| | 20 | |
|
| | 21 | | #region // constructors |
| | 22 | |
|
| | 23 | | internal TaskFile( |
| | 24 | | JobOperations jobOperations, |
| | 25 | | string jobId, |
| | 26 | | string taskId, |
| | 27 | | Models.NodeFile boundToThis, |
| 4 | 28 | | IEnumerable<BatchClientBehavior> inheritTheseBehaviors) : base(boundToThis, inheritTheseBehaviors) |
| | 29 | | { |
| 4 | 30 | | _jobOperations = jobOperations; |
| 4 | 31 | | _jobId = jobId; |
| 4 | 32 | | _taskId = taskId; |
| 4 | 33 | | } |
| | 34 | |
|
| | 35 | | #endregion |
| | 36 | |
|
| | 37 | | #region // NodeFile |
| | 38 | |
|
| | 39 | | public override async System.Threading.Tasks.Task CopyToStreamAsync( |
| | 40 | | Stream stream, |
| | 41 | | GetFileRequestByteRange byteRange = null, |
| | 42 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 43 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 44 | | { |
| | 45 | | // craft the behavior manager for this call |
| 3 | 46 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors); |
| | 47 | |
|
| 3 | 48 | | System.Threading.Tasks.Task<AzureOperationResponse<Models.NodeFile, Models.FileGetFromTaskHeaders>> asyncTas |
| 3 | 49 | | this._jobOperations.ParentBatchClient.ProtocolLayer.GetNodeFileByTask( |
| 3 | 50 | | _jobId, |
| 3 | 51 | | _taskId, |
| 3 | 52 | | base.Path, |
| 3 | 53 | | stream, |
| 3 | 54 | | byteRange, |
| 3 | 55 | | bhMgr, |
| 3 | 56 | | cancellationToken); |
| | 57 | |
|
| 3 | 58 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 3 | 59 | | } |
| | 60 | |
|
| | 61 | | public override async System.Threading.Tasks.Task DeleteAsync(bool? recursive = null, IEnumerable<BatchClientBeh |
| | 62 | | { |
| | 63 | | // craft the behavior manager for this call |
| 0 | 64 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors); |
| | 65 | |
|
| 0 | 66 | | var asyncTask = this._jobOperations.ParentBatchClient.ProtocolLayer.DeleteNodeFileByTask(_jobId, _taskId, ba |
| | 67 | |
|
| 0 | 68 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | #endregion // NodeFile |
| | 72 | |
|
| | 73 | | #region IRefreshable |
| | 74 | |
|
| | 75 | | public override async System.Threading.Tasks.Task RefreshAsync(DetailLevel detailLevel = null, IEnumerable<Batch |
| | 76 | | { |
| | 77 | | // create the behavior managaer |
| 0 | 78 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors, detailLevel); |
| | 79 | |
|
| 0 | 80 | | System.Threading.Tasks.Task<AzureOperationResponse<Models.NodeFile, Models.FileGetPropertiesFromTaskHeaders> |
| 0 | 81 | | this._jobOperations.ParentBatchClient.ProtocolLayer.GetNodeFilePropertiesByTask( |
| 0 | 82 | | _jobId, |
| 0 | 83 | | _taskId, |
| 0 | 84 | | this.Path, |
| 0 | 85 | | bhMgr, |
| 0 | 86 | | cancellationToken); |
| | 87 | |
|
| 0 | 88 | | AzureOperationResponse<Models.NodeFile, Models.FileGetPropertiesFromTaskHeaders> response = await asyncTask. |
| | 89 | |
|
| | 90 | | // immediately available to all threads |
| 0 | 91 | | System.Threading.Interlocked.Exchange(ref base.fileItemBox, new FileItemBox(response.Body)); |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | public override void Refresh(DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehavior |
| | 95 | | { |
| 0 | 96 | | Task asyncTask = RefreshAsync(detailLevel, additionalBehaviors); |
| 0 | 97 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | #endregion IRefreshable |
| | 101 | |
|
| | 102 | | } |
| | 103 | | } |
| | 104 | |
|
| | 105 | |
|