| | 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.Collections.Generic; |
| | 7 | | using System.Linq; |
| | 8 | |
|
| | 9 | | public partial class TaskDependencies |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Initializes a new instance of the <see cref="TaskDependencies"/> class. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="taskIds">The list of task ids that must complete before this task can be scheduled. null is tre |
| | 15 | | /// <param name="taskIdRanges">The list of task ranges that must complete before this task can be scheduled. nul |
| | 16 | | /// <remarks>This constructor provides the most general way of initializing a TaskDependencies object. |
| | 17 | | /// In practice, most dependencies are on a single task, a list of task ids, or a single range of |
| | 18 | | /// tasks. You can express these dependencies more clearly using <see cref="OnId"/>, <see cref="OnIds(string[])" |
| | 19 | | /// <see cref="OnTasks(CloudTask[])"/>, and <see cref="OnIdRange"/> methods.</remarks> |
| 0 | 20 | | public TaskDependencies(IEnumerable<string> taskIds, IEnumerable<TaskIdRange> taskIdRanges) |
| | 21 | | { |
| 0 | 22 | | if (taskIds == null) |
| | 23 | | { |
| 0 | 24 | | taskIds = Enumerable.Empty<string>(); |
| | 25 | | } |
| | 26 | |
|
| 0 | 27 | | if (taskIdRanges == null) |
| | 28 | | { |
| 0 | 29 | | taskIdRanges = Enumerable.Empty<TaskIdRange>(); |
| | 30 | | } |
| | 31 | |
|
| 0 | 32 | | this.TaskIds = new List<string>(taskIds).AsReadOnly(); |
| 0 | 33 | | this.TaskIdRanges = new List<TaskIdRange>(taskIdRanges).AsReadOnly(); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a single task. |
| | 38 | | /// </summary> |
| | 39 | | /// <param name="id">The task to depend on.</param> |
| | 40 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on a single task.</returns> |
| | 41 | | public static TaskDependencies OnId(string id) |
| | 42 | | { |
| 0 | 43 | | return new TaskDependencies(new[] { id }, null); |
| | 44 | | } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a list of task ids. |
| | 48 | | /// </summary> |
| | 49 | | /// <param name="ids">The tasks to depend on.</param> |
| | 50 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on the specified tasks.</returns> |
| | 51 | | public static TaskDependencies OnIds(IEnumerable<string> ids) |
| | 52 | | { |
| 0 | 53 | | return new TaskDependencies(ids, null); |
| | 54 | | } |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a list of task ids. |
| | 58 | | /// </summary> |
| | 59 | | /// <param name="ids">The tasks to depend on.</param> |
| | 60 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on the specified tasks.</returns> |
| | 61 | | public static TaskDependencies OnIds(params string[] ids) |
| | 62 | | { |
| 0 | 63 | | return new TaskDependencies(ids, null); |
| | 64 | | } |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a list of tasks. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name="tasks">The tasks to depend on.</param> |
| | 70 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on the specified tasks.</returns> |
| | 71 | | public static TaskDependencies OnTasks(IEnumerable<CloudTask> tasks) |
| | 72 | | { |
| 0 | 73 | | return new TaskDependencies(tasks.Select(t => t.Id), null); |
| | 74 | | } |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a list of tasks. |
| | 78 | | /// </summary> |
| | 79 | | /// <param name="tasks">The tasks to depend on.</param> |
| | 80 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on the specified tasks.</returns> |
| | 81 | | public static TaskDependencies OnTasks(params CloudTask[] tasks) |
| | 82 | | { |
| 0 | 83 | | return new TaskDependencies(tasks.Select(t => t.Id), null); |
| | 84 | | } |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Gets a <see cref="TaskDependencies"/> representing dependency on a range of task ids. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name="start">The first task id in the range to depend on.</param> |
| | 90 | | /// <param name="end">The last task id in the range to depend on.</param> |
| | 91 | | /// <returns>A <see cref="TaskDependencies"/> representing dependency on the specified range of tasks.</returns> |
| | 92 | | public static TaskDependencies OnIdRange(int start, int end) |
| | 93 | | { |
| 0 | 94 | | return new TaskDependencies(null, new[] { new TaskIdRange(start, end) }); |
| | 95 | | } |
| | 96 | | } |
| | 97 | | } |