| | 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 job output, or a preview of the |
| | 27 | | /// job output. |
| | 28 | | /// </summary> |
| | 29 | | public sealed class JobOutputKind : IEquatable<JobOutputKind>, IOutputKind |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// A <see cref="JobOutputKind"/> representing the main output of a job. |
| | 33 | | /// </summary> |
| 1 | 34 | | public static readonly JobOutputKind JobOutput = new JobOutputKind("JobOutput"); |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// A <see cref="JobOutputKind"/> representing a preview of the job output. |
| | 38 | | /// </summary> |
| 1 | 39 | | public static readonly JobOutputKind JobPreview = new JobOutputKind("JobPreview"); |
| | 40 | |
|
| 1 | 41 | | private static readonly StringComparer TextComparer = StringComparer.Ordinal; // case sensitive, since we prese |
| | 42 | |
|
| | 43 | | private readonly string _text; |
| | 44 | |
|
| 31 | 45 | | private JobOutputKind(string text) |
| | 46 | | { |
| 31 | 47 | | Validate.IsNotNullOrEmpty(text, nameof(text)); |
| | 48 | |
|
| 29 | 49 | | _text = text; |
| 29 | 50 | | } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Gets a <see cref="JobOutputKind"/> representing a custom category of job outputs. |
| | 54 | | /// </summary> |
| | 55 | | /// <param name="text">A text identifier for the custom JobOutputKind.</param> |
| | 56 | | /// <returns>A JobOutputKind with the specified text.</returns> |
| | 57 | | /// <exception cref="ArgumentNullException"><paramref name="text"/> is null.</exception> |
| | 58 | | /// <exception cref="ArgumentException"><paramref name="text"/> is empty.</exception> |
| | 59 | | public static JobOutputKind Custom(string text) |
| | 60 | | { |
| 29 | 61 | | return new JobOutputKind(text); |
| | 62 | | } |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// Returns a string that represents the current object. |
| | 66 | | /// </summary> |
| | 67 | | /// <returns>A textual representation of the <see cref="JobOutputKind"/>.</returns> |
| | 68 | | public override string ToString() |
| | 69 | | { |
| 9 | 70 | | return _text; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Determinates whether this instance and another specified <see cref="JobOutputKind"/> |
| | 75 | | /// have the same value. |
| | 76 | | /// </summary> |
| | 77 | | /// <param name="other">The JobOutputKind to compare to this instance.</param> |
| | 78 | | /// <returns>true if the value of the <paramref name="other"/> parameter is the same as |
| | 79 | | /// the value of this instance; otherwise, false.</returns> |
| | 80 | | public bool Equals(JobOutputKind other) |
| | 81 | | { |
| 12 | 82 | | if (ReferenceEquals(other, null)) |
| | 83 | | { |
| 4 | 84 | | return false; |
| | 85 | | } |
| 8 | 86 | | return TextComparer.Equals(other._text, _text); |
| | 87 | | } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Determines whether the specified object is equal to the current object. |
| | 91 | | /// </summary> |
| | 92 | | /// <param name="obj">The object to compare with the current object.</param> |
| | 93 | | /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> |
| | 94 | | public override bool Equals(object obj) |
| | 95 | | { |
| 3 | 96 | | return Equals(obj as JobOutputKind); |
| | 97 | | } |
| | 98 | |
|
| | 99 | | /// <summary> |
| | 100 | | /// Returns the hash code for this <see cref="JobOutputKind"/>. |
| | 101 | | /// </summary> |
| | 102 | | /// <returns>A 32-bit signed integer hash code.</returns> |
| | 103 | | public override int GetHashCode() |
| | 104 | | { |
| | 105 | | Debug.Assert(_text != null); |
| | 106 | |
|
| 0 | 107 | | return TextComparer.GetHashCode(_text); |
| | 108 | | } |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Determines whether two specified <see cref="JobOutputKind"/> instances have the same value. |
| | 112 | | /// </summary> |
| | 113 | | /// <param name="x">The first JobOutputKind to compare.</param> |
| | 114 | | /// <param name="y">The second JobOutputKind to compare.</param> |
| | 115 | | /// <returns>true if the value of <paramref name="x"/> is the same as the value of <paramref name="y"/>; otherwi |
| | 116 | | public static bool operator ==(JobOutputKind x, JobOutputKind y) |
| | 117 | | { |
| 8 | 118 | | if (ReferenceEquals(x, null)) |
| | 119 | | { |
| 2 | 120 | | return ReferenceEquals(y, null); |
| | 121 | | } |
| 6 | 122 | | return x.Equals(y); |
| | 123 | | } |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Determines whether two specified <see cref="JobOutputKind"/> instances have different values. |
| | 127 | | /// </summary> |
| | 128 | | /// <param name="x">The first JobOutputKind to compare.</param> |
| | 129 | | /// <param name="y">The second JobOutputKind to compare.</param> |
| | 130 | | /// <returns>true if the value of <paramref name="x"/> is different from the value of <paramref name="y"/>; othe |
| | 131 | | public static bool operator !=(JobOutputKind x, JobOutputKind y) |
| | 132 | | { |
| 4 | 133 | | return !(x == y); |
| | 134 | | } |
| | 135 | |
|
| | 136 | | string IOutputKind.Text |
| | 137 | | { |
| 6 | 138 | | get { return _text; } |
| | 139 | | } |
| | 140 | | } |
| | 141 | | } |