| | 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; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Collections.ObjectModel; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | |
|
| | 12 | | using Microsoft.Azure.Batch.Protocol.Models; |
| | 13 | |
|
| | 14 | | namespace Microsoft.Azure.Batch |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Performs application-related operations on an Azure Batch account. |
| | 18 | | /// </summary> |
| | 19 | | public class ApplicationOperations : IInheritedBehaviors |
| | 20 | | { |
| | 21 | | private readonly BatchClient _parentBatchClient; |
| | 22 | |
|
| | 23 | | #region // constructors |
| | 24 | |
|
| 0 | 25 | | private ApplicationOperations() |
| | 26 | | { |
| 0 | 27 | | } |
| | 28 | |
|
| 5 | 29 | | internal ApplicationOperations(BatchClient parentBatchClient, IEnumerable<BatchClientBehavior> inheritedBehavior |
| | 30 | | { |
| 5 | 31 | | _parentBatchClient = parentBatchClient; |
| | 32 | |
|
| | 33 | | // set up the behavior inheritance |
| 5 | 34 | | InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors); |
| 5 | 35 | | } |
| | 36 | |
|
| | 37 | | #endregion |
| | 38 | |
|
| | 39 | | #region // internal/private |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// allows child objects to access the protocol wrapper and secrets to make verb calls |
| | 43 | | /// </summary> |
| | 44 | | internal BatchClient ParentBatchClient |
| | 45 | | { |
| 8 | 46 | | get { return _parentBatchClient; } |
| | 47 | | } |
| | 48 | |
|
| | 49 | | #endregion // internal/private |
| | 50 | |
|
| | 51 | |
|
| | 52 | | #region IInheritedBehaviors |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets or sets a list of behaviors that modify or customize requests to the Batch service |
| | 56 | | /// made via this <see cref="ApplicationOperations"/>. |
| | 57 | | /// </summary> |
| | 58 | | /// <remarks> |
| | 59 | | /// <para>These behaviors are inherited by child objects.</para> |
| | 60 | | /// <para>Modifications are applied in the order of the collection. The last write wins.</para> |
| | 61 | | /// </remarks> |
| 11 | 62 | | public IList<BatchClientBehavior> CustomBehaviors { get; set; } |
| | 63 | |
|
| | 64 | | #endregion IInheritedBehaviors |
| | 65 | |
|
| | 66 | | #region // ApplicationOperations |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// Enumerates the <see cref="ApplicationSummary">applications</see> in the Batch account. |
| | 70 | | /// </summary> |
| | 71 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which |
| | 72 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 73 | | /// <returns>An <see cref="IPagedEnumerable{ApplicationSummary}"/> that can be used to enumerate applications as |
| | 74 | | /// <remarks>This method returns immediately; the applications are retrieved from the Batch service only when th |
| | 75 | | /// Retrieval is non-atomic; applications are retrieved in pages during enumeration of the collection.</remarks> |
| | 76 | | public IPagedEnumerable<ApplicationSummary> ListApplicationSummaries(DetailLevel detailLevel = null, IEnumerable |
| | 77 | | { |
| | 78 | | // craft the behavior manager for this call |
| 3 | 79 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 80 | |
|
| 3 | 81 | | PagedEnumerable<ApplicationSummary> enumerable = new PagedEnumerable<ApplicationSummary>( |
| 3 | 82 | | // the lambda will be the enumerator factory |
| 3 | 83 | | () => |
| 3 | 84 | | { |
| 3 | 85 | | // here is the actual strongly typed enumerator |
| 7 | 86 | | AsyncApplicationSummariesEnumerator typedEnumerator = new AsyncApplicationSummariesEnumerator(th |
| 3 | 87 | |
|
| 3 | 88 | | // here is the base |
| 3 | 89 | | PagedEnumeratorBase<ApplicationSummary> enumeratorBase = typedEnumerator; |
| 3 | 90 | |
|
| 7 | 91 | | return enumeratorBase; |
| 3 | 92 | | }); |
| | 93 | |
|
| 3 | 94 | | return enumerable; |
| | 95 | | } |
| | 96 | |
|
| | 97 | | /// <summary> |
| | 98 | | /// Gets information about the specified application. |
| | 99 | | /// </summary> |
| | 100 | | /// <param name="applicationId">The id of the application to get.</param> |
| | 101 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved fr |
| | 102 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 103 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 104 | | /// <returns>An <see cref="ApplicationSummary"/> containing information about the specified application.</return |
| | 105 | | /// <remarks>The get application operation runs asynchronously.</remarks> |
| | 106 | | public async System.Threading.Tasks.Task<ApplicationSummary> GetApplicationSummaryAsync(string applicationId, De |
| | 107 | | { |
| | 108 | | // create the behavior manager |
| 2 | 109 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); |
| | 110 | |
|
| | 111 | | // start call to server |
| 2 | 112 | | var asyncTask = this.ParentBatchClient.ProtocolLayer.GetApplicationSummary(applicationId, bhMgr, cancellatio |
| | 113 | |
|
| 2 | 114 | | var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| | 115 | |
|
| | 116 | | // construct object model ApplicationSummary |
| 2 | 117 | | ApplicationSummary applicationSummary = new ApplicationSummary(response.Body); |
| | 118 | |
|
| 2 | 119 | | return applicationSummary; |
| 2 | 120 | | } |
| | 121 | |
|
| | 122 | | /// <summary> |
| | 123 | | /// Gets information about the specified application. |
| | 124 | | /// </summary> |
| | 125 | | /// <param name="applicationId">The id of the application to get.</param> |
| | 126 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved fr |
| | 127 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 128 | | /// <returns>An <see cref="ApplicationSummary"/> containing information about the specified application.</return |
| | 129 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetApplicationSummaryAs |
| | 130 | | public ApplicationSummary GetApplicationSummary(string applicationId, DetailLevel detailLevel = null, IEnumerabl |
| | 131 | | { |
| 1 | 132 | | Task<ApplicationSummary> asyncTask = GetApplicationSummaryAsync(applicationId, detailLevel, additionalBehavi |
| 1 | 133 | | ApplicationSummary applicationSummary = asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, addition |
| | 134 | |
|
| 1 | 135 | | return applicationSummary; |
| | 136 | | } |
| | 137 | |
|
| | 138 | | #endregion |
| | 139 | |
|
| | 140 | |
|
| | 141 | | } |
| | 142 | | } |