ExpectAction.cs 2.0 KB

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