| | 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 | | using System.Collections.Generic; |
| | 5 | | using System.IO; |
| | 6 | | using Task = System.Threading.Tasks.Task; |
| | 7 | | using Models = Microsoft.Azure.Batch.Protocol.Models; |
| | 8 | | using System.Threading; |
| | 9 | | using Microsoft.Rest.Azure; |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.Batch |
| | 12 | | { |
| | 13 | | internal class ComputeNodeFile : NodeFile |
| | 14 | | { |
| | 15 | | private readonly PoolOperations _poolOperations; |
| | 16 | | private readonly string _poolId; |
| | 17 | | private readonly string _computeNodeId; |
| | 18 | |
|
| | 19 | | #region // constructors |
| | 20 | |
|
| | 21 | | internal ComputeNodeFile( |
| | 22 | | PoolOperations poolOperations, |
| | 23 | | string poolId, |
| | 24 | | string computeNodeId, |
| | 25 | | Models.NodeFile boundToThis, |
| 4 | 26 | | IEnumerable<BatchClientBehavior> inheritTheseBehaviors) : base(boundToThis, inheritTheseBehaviors) |
| | 27 | | { |
| 4 | 28 | | _poolOperations = poolOperations; |
| 4 | 29 | | _poolId = poolId; |
| 4 | 30 | | _computeNodeId = computeNodeId; |
| 4 | 31 | | } |
| | 32 | | #endregion |
| | 33 | |
|
| | 34 | | #region // NodeFile |
| | 35 | |
|
| | 36 | | public override async System.Threading.Tasks.Task CopyToStreamAsync( |
| | 37 | | Stream stream, |
| | 38 | | GetFileRequestByteRange byteRange = null, |
| | 39 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 40 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 41 | | { |
| | 42 | | // craft the behavior manager for this call |
| 3 | 43 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors); |
| | 44 | |
|
| 3 | 45 | | System.Threading.Tasks.Task<AzureOperationResponse<Models.NodeFile, Models.FileGetFromComputeNodeHeaders>> a |
| 3 | 46 | | this._poolOperations.ParentBatchClient.ProtocolLayer.GetNodeFileByNode( |
| 3 | 47 | | _poolId, |
| 3 | 48 | | _computeNodeId, |
| 3 | 49 | | base.Path, |
| 3 | 50 | | stream, |
| 3 | 51 | | byteRange, |
| 3 | 52 | | bhMgr, |
| 3 | 53 | | cancellationToken); |
| | 54 | |
|
| 3 | 55 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 3 | 56 | | } |
| | 57 | |
|
| | 58 | | public override async System.Threading.Tasks.Task DeleteAsync(bool? recursive = null, IEnumerable<BatchClientBeh |
| | 59 | | { |
| | 60 | | // craft the behavior manager for this call |
| 0 | 61 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors); |
| | 62 | |
|
| 0 | 63 | | var asyncTask = _poolOperations.ParentBatchClient.ProtocolLayer.DeleteNodeFileByNode( |
| 0 | 64 | | _poolId, |
| 0 | 65 | | _computeNodeId, |
| 0 | 66 | | base.Path, |
| 0 | 67 | | recursive, |
| 0 | 68 | | bhMgr, |
| 0 | 69 | | cancellationToken); |
| | 70 | |
|
| 0 | 71 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | #endregion |
| | 75 | |
|
| | 76 | | #region IRefreshable |
| | 77 | |
|
| | 78 | | public override async System.Threading.Tasks.Task RefreshAsync( |
| | 79 | | DetailLevel detailLevel = null, |
| | 80 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 81 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 82 | | { |
| | 83 | | // create the behavior managaer |
| 0 | 84 | | BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors, detailLevel); |
| | 85 | |
|
| 0 | 86 | | System.Threading.Tasks.Task<AzureOperationResponse<Models.NodeFile, Models.FileGetPropertiesFromComputeNodeH |
| 0 | 87 | | this._poolOperations.ParentBatchClient.ProtocolLayer.GetNodeFilePropertiesByNode( |
| 0 | 88 | | _poolId, |
| 0 | 89 | | _computeNodeId, |
| 0 | 90 | | base.Path, |
| 0 | 91 | | bhMgr, |
| 0 | 92 | | cancellationToken); |
| | 93 | |
|
| 0 | 94 | | AzureOperationResponse<Models.NodeFile, Models.FileGetPropertiesFromComputeNodeHeaders> response = await asy |
| | 95 | |
|
| | 96 | | // immediately available to all threads |
| 0 | 97 | | System.Threading.Interlocked.Exchange(ref base.fileItemBox, new FileItemBox(response.Body)); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | public override void Refresh(DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehavior |
| | 101 | | { |
| 0 | 102 | | Task asyncTask = RefreshAsync(detailLevel, additionalBehaviors); |
| 0 | 103 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | #endregion |
| | 107 | |
|
| | 108 | | } |
| | 109 | | } |