| | | 1 | | using System; |
| | | 2 | | using System.Text.RegularExpressions; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Specifies behavior for expected expression. |
| | | 8 | | /// </summary> |
| | | 9 | | public class ExpectAction |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets the expected regular expression. |
| | | 13 | | /// </summary> |
| | 15 | 14 | | public Regex Expect { get; private set; } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the action to perform when expected expression is found. |
| | | 18 | | /// </summary> |
| | 12 | 19 | | public Action<string> Action { get; private set; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="ExpectAction"/> class. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="expect">The expect regular expression.</param> |
| | | 25 | | /// <param name="action">The action to perform.</param> |
| | | 26 | | /// <exception cref="ArgumentNullException"><paramref name="expect"/> or <paramref name="action"/> is <see langw |
| | 3 | 27 | | public ExpectAction(Regex expect, Action<string> action) |
| | 3 | 28 | | { |
| | 3 | 29 | | if (expect is null) |
| | 0 | 30 | | { |
| | 0 | 31 | | throw new ArgumentNullException(nameof(expect)); |
| | | 32 | | } |
| | | 33 | | |
| | 3 | 34 | | if (action is null) |
| | 0 | 35 | | { |
| | 0 | 36 | | throw new ArgumentNullException(nameof(action)); |
| | | 37 | | } |
| | | 38 | | |
| | 3 | 39 | | Expect = expect; |
| | 3 | 40 | | Action = action; |
| | 3 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Initializes a new instance of the <see cref="ExpectAction"/> class. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="expect">The expect expression.</param> |
| | | 47 | | /// <param name="action">The action to perform.</param> |
| | | 48 | | /// <exception cref="ArgumentNullException"><paramref name="expect"/> or <paramref name="action"/> is <see langw |
| | 3 | 49 | | public ExpectAction(string expect, Action<string> action) |
| | 3 | 50 | | { |
| | 3 | 51 | | if (expect is null) |
| | 0 | 52 | | { |
| | 0 | 53 | | throw new ArgumentNullException(nameof(expect)); |
| | | 54 | | } |
| | | 55 | | |
| | 3 | 56 | | if (action is null) |
| | 0 | 57 | | { |
| | 0 | 58 | | throw new ArgumentNullException(nameof(action)); |
| | | 59 | | } |
| | | 60 | | |
| | 3 | 61 | | Expect = new Regex(Regex.Escape(expect)); |
| | 3 | 62 | | Action = action; |
| | 3 | 63 | | } |
| | | 64 | | } |
| | | 65 | | } |