| | | 1 | | // Copyright (c) Microsoft and contributors. All rights reserved. |
| | | 2 | | // |
| | | 3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
| | | 4 | | // you may not use this file except in compliance with the License. |
| | | 5 | | // You may obtain a copy of the License at |
| | | 6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
| | | 7 | | // |
| | | 8 | | // Unless required by applicable law or agreed to in writing, software |
| | | 9 | | // distributed under the License is distributed on an "AS IS" BASIS, |
| | | 10 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | 11 | | // |
| | | 12 | | // See the License for the specific language governing permissions and |
| | | 13 | | // limitations under the License. |
| | | 14 | | |
| | | 15 | | using Microsoft.Azure.Batch.Conventions.Files.Utilities; |
| | | 16 | | using System; |
| | | 17 | | using System.Collections.Generic; |
| | | 18 | | using System.Diagnostics; |
| | | 19 | | using System.Linq; |
| | | 20 | | using System.Text; |
| | | 21 | | using System.Threading.Tasks; |
| | | 22 | | |
| | | 23 | | namespace Microsoft.Azure.Batch.Conventions.Files |
| | | 24 | | { |
| | | 25 | | /// <summary> |
| | | 26 | | /// Represents a category of job outputs, such as the main task output, or a preview of the |
| | | 27 | | /// task output, or a log of the task processing. |
| | | 28 | | /// </summary> |
| | | 29 | | public sealed class TaskOutputKind : IEquatable<TaskOutputKind>, IOutputKind |
| | | 30 | | { |
| | | 31 | | /// <summary> |
| | | 32 | | /// A <see cref="TaskOutputKind"/> representing the main output of a task. |
| | | 33 | | /// </summary> |
| | 1 | 34 | | public static readonly TaskOutputKind TaskOutput = new TaskOutputKind("TaskOutput"); |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// A <see cref="TaskOutputKind"/> representing a preview of the task output. |
| | | 38 | | /// </summary> |
| | 1 | 39 | | public static readonly TaskOutputKind TaskPreview = new TaskOutputKind("TaskPreview"); |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// A <see cref="TaskOutputKind"/> representing a log of the task processing. |
| | | 43 | | /// </summary> |
| | 1 | 44 | | public static readonly TaskOutputKind TaskLog = new TaskOutputKind("TaskLog"); |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// A <see cref="TaskOutputKind"/> representing an intermediate file, for example being |
| | | 48 | | /// persisted for diagnostic or checkpointing purposes. |
| | | 49 | | /// </summary> |
| | 1 | 50 | | public static readonly TaskOutputKind TaskIntermediate = new TaskOutputKind("TaskIntermediate"); |
| | | 51 | | |
| | 1 | 52 | | private static readonly StringComparer TextComparer = StringComparer.Ordinal; // case sensitive, since we prese |
| | | 53 | | |
| | | 54 | | private readonly string _text; |
| | | 55 | | |
| | 33 | 56 | | private TaskOutputKind(string text) |
| | | 57 | | { |
| | 33 | 58 | | Validate.IsNotNullOrEmpty(text, nameof(text)); |
| | | 59 | | |
| | 31 | 60 | | _text = text; |
| | 31 | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Gets a <see cref="TaskOutputKind"/> representing a custom category of task outputs. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <param name="text">A text identifier for the custom TaskOutputKind.</param> |
| | | 67 | | /// <returns>A TaskOutputKind with the specified text.</returns> |
| | | 68 | | /// <exception cref="ArgumentNullException"><paramref name="text"/> is null.</exception> |
| | | 69 | | /// <exception cref="ArgumentException"><paramref name="text"/> is empty.</exception> |
| | | 70 | | public static TaskOutputKind Custom(string text) |
| | | 71 | | { |
| | 29 | 72 | | return new TaskOutputKind(text); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Returns a string that represents the current object. |
| | | 77 | | /// </summary> |
| | | 78 | | /// <returns>A textual representation of the <see cref="TaskOutputKind"/>.</returns> |
| | | 79 | | public override string ToString() |
| | | 80 | | { |
| | 13 | 81 | | return _text; |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Determinates whether this instance and another specified <see cref="TaskOutputKind"/> |
| | | 86 | | /// have the same value. |
| | | 87 | | /// </summary> |
| | | 88 | | /// <param name="other">The TaskOutputKind to compare to this instance.</param> |
| | | 89 | | /// <returns>true if the value of the <paramref name="other"/> parameter is the same as |
| | | 90 | | /// the value of this instance; otherwise, false.</returns> |
| | | 91 | | public bool Equals(TaskOutputKind other) |
| | | 92 | | { |
| | 12 | 93 | | if (ReferenceEquals(other, null)) |
| | | 94 | | { |
| | 4 | 95 | | return false; |
| | | 96 | | } |
| | 8 | 97 | | return TextComparer.Equals(other._text, _text); |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Determines whether the specified object is equal to the current object. |
| | | 102 | | /// </summary> |
| | | 103 | | /// <param name="obj">The object to compare with the current object.</param> |
| | | 104 | | /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> |
| | | 105 | | public override bool Equals(object obj) |
| | | 106 | | { |
| | 3 | 107 | | return Equals(obj as TaskOutputKind); |
| | | 108 | | } |
| | | 109 | | |
| | | 110 | | /// <summary> |
| | | 111 | | /// Returns the hash code for this <see cref="TaskOutputKind"/>. |
| | | 112 | | /// </summary> |
| | | 113 | | /// <returns>A 32-bit signed integer hash code.</returns> |
| | | 114 | | public override int GetHashCode() |
| | | 115 | | { |
| | | 116 | | Debug.Assert(_text != null); |
| | | 117 | | |
| | 0 | 118 | | return TextComparer.GetHashCode(_text); |
| | | 119 | | } |
| | | 120 | | |
| | | 121 | | /// <summary> |
| | | 122 | | /// Determines whether two specified <see cref="TaskOutputKind"/> instances have the same value. |
| | | 123 | | /// </summary> |
| | | 124 | | /// <param name="x">The first TaskOutputKind to compare.</param> |
| | | 125 | | /// <param name="y">The second TaskOutputKind to compare.</param> |
| | | 126 | | /// <returns>true if the value of <paramref name="x"/> is the same as the value of <paramref name="y"/>; otherwi |
| | | 127 | | public static bool operator ==(TaskOutputKind x, TaskOutputKind y) |
| | | 128 | | { |
| | 8 | 129 | | if (ReferenceEquals(x, null)) |
| | | 130 | | { |
| | 2 | 131 | | return ReferenceEquals(y, null); |
| | | 132 | | } |
| | 6 | 133 | | return x.Equals(y); |
| | | 134 | | } |
| | | 135 | | |
| | | 136 | | /// <summary> |
| | | 137 | | /// Determines whether two specified <see cref="TaskOutputKind"/> instances have different values. |
| | | 138 | | /// </summary> |
| | | 139 | | /// <param name="x">The first TaskOutputKind to compare.</param> |
| | | 140 | | /// <param name="y">The second TaskOutputKind to compare.</param> |
| | | 141 | | /// <returns>true if the value of <paramref name="x"/> is different from the value of <paramref name="y"/>; othe |
| | | 142 | | public static bool operator !=(TaskOutputKind x, TaskOutputKind y) |
| | | 143 | | { |
| | 4 | 144 | | return !(x == y); |
| | | 145 | | } |
| | | 146 | | |
| | | 147 | | string IOutputKind.Text |
| | | 148 | | { |
| | 8 | 149 | | get { return _text; } |
| | | 150 | | } |
| | | 151 | | } |
| | | 152 | | } |