ExpectAction.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. namespace Renci.SshNet
  7. {
  8. /// <summary>
  9. /// Specifies behavior for expected expression
  10. /// </summary>
  11. public class ExpectAction
  12. {
  13. /// <summary>
  14. /// Gets the expected regular expression.
  15. /// </summary>
  16. public Regex Expect { get; private set; }
  17. /// <summary>
  18. /// Gets the action to perform when expected expression is found.
  19. /// </summary>
  20. public Action<string> Action { get; private set; }
  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 null.</exception>
  27. public ExpectAction(Regex expect, Action<string> action)
  28. {
  29. if (expect == null)
  30. throw new ArgumentNullException("expect");
  31. if (action == null)
  32. throw new ArgumentNullException("action");
  33. this.Expect = expect;
  34. this.Action = action;
  35. }
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="ExpectAction"/> class.
  38. /// </summary>
  39. /// <param name="expect">The expect expression.</param>
  40. /// <param name="action">The action to perform.</param>
  41. /// <exception cref="ArgumentNullException"><paramref name="expect"/> or <paramref name="action"/> is null.</exception>
  42. public ExpectAction(string expect, Action<string> action)
  43. {
  44. if (expect == null)
  45. throw new ArgumentNullException("expect");
  46. if (action == null)
  47. throw new ArgumentNullException("action");
  48. this.Expect = new Regex(Regex.Escape(expect));
  49. this.Action = action;
  50. }
  51. }
  52. }