ChannelAsyncResult.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Threading;
  3. namespace Renci.SshClient
  4. {
  5. /// <summary>
  6. /// Provides additional information for asynchronous command execution
  7. /// </summary>
  8. public class CommandAsyncResult : IAsyncResult
  9. {
  10. /// <summary>
  11. /// Gets or sets the command that async result was created for.
  12. /// </summary>
  13. /// <value>The channel.</value>
  14. private SshCommand _command;
  15. /// <summary>
  16. /// Gets or sets the bytes received. If SFTP only file bytes are counted.
  17. /// </summary>
  18. /// <value>Total bytes received.</value>
  19. public int BytesReceived { get; set; }
  20. /// <summary>
  21. /// Gets or sets the bytes sent by SFTP.
  22. /// </summary>
  23. /// <value>Total bytes sent.</value>
  24. public int BytesSent { get; set; }
  25. #region IAsyncResult Members
  26. /// <summary>
  27. /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
  28. /// </summary>
  29. /// <returns>A user-defined object that qualifies or contains information about an asynchronous operation.</returns>
  30. public object AsyncState { get; internal set; }
  31. /// <summary>
  32. /// Gets a <see cref="T:System.Threading.WaitHandle"/> that is used to wait for an asynchronous operation to complete.
  33. /// </summary>
  34. /// <returns>A <see cref="T:System.Threading.WaitHandle"/> that is used to wait for an asynchronous operation to complete.</returns>
  35. public WaitHandle AsyncWaitHandle { get; internal set; }
  36. /// <summary>
  37. /// Gets a value that indicates whether the asynchronous operation completed synchronously.
  38. /// </summary>
  39. /// <returns>true if the asynchronous operation completed synchronously; otherwise, false.</returns>
  40. public bool CompletedSynchronously { get; internal set; }
  41. /// <summary>
  42. /// Gets a value that indicates whether the asynchronous operation has completed.
  43. /// </summary>
  44. /// <returns>true if the operation is complete; otherwise, false.</returns>
  45. public bool IsCompleted { get; internal set; }
  46. #endregion
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref="CommandAsyncResult"/> class.
  49. /// </summary>
  50. /// <param name="command">The command.</param>
  51. internal CommandAsyncResult(SshCommand command)
  52. {
  53. this._command = command;
  54. }
  55. /// <summary>
  56. /// Validates that command object is valid to be used with this instance.
  57. /// </summary>
  58. /// <param name="command">The command.</param>
  59. public void ValidateCommand(SshCommand command)
  60. {
  61. if (this._command != command)
  62. {
  63. throw new InvalidOperationException("Invalid IAsyncResult parameter");
  64. }
  65. }
  66. }
  67. }