ChannelContext.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Taobao.Top.Link.Channel
  5. {
  6. /// <summary>context used with channel event
  7. /// </summary>
  8. public class ChannelContext : EventArgs
  9. {
  10. /// <summary>error from channel
  11. /// </summary>
  12. public Exception Error { get; private set; }
  13. /// <summary>the channel used to sending message
  14. /// </summary>
  15. public IChannelSender Sender { get; private set; }
  16. /// <summary>received message
  17. /// </summary>
  18. public object Message { get; private set; }
  19. public ChannelContext(Exception error)
  20. {
  21. this.Error = error;
  22. }
  23. public ChannelContext(object message, IChannelSender sender)
  24. {
  25. this.Message = message;
  26. this.Sender = sender;
  27. }
  28. /// <summary>
  29. /// send data to channel where the message come from
  30. /// </summary>
  31. /// <param name="data"></param>
  32. public void Reply(byte[] data)
  33. {
  34. if (this.Sender == null)
  35. throw new LinkException("can not send");
  36. this.Sender.Send(data);
  37. }
  38. }
  39. }