PageRenderTime 103ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/CBR/CBR.Core/Helpers/MVVM/Events/IMessenger.cs

#
C# | 232 lines | 32 code | 14 blank | 186 comment | 0 complexity | 1f7d65d21637d95115a100ec889dfeed MD5 | raw file
  1. // **************************************************************************
  2. // <copyright file="IMessenger.cs" company="GalaSoft Laurent Bugnion">
  3. // Copyright © GalaSoft Laurent Bugnion 2009-2011
  4. // </copyright>
  5. // ****************************************************************************
  6. // <author>Laurent Bugnion</author>
  7. // <email>laurent@galasoft.ch</email>
  8. // <date>23.9.2009</date>
  9. // <project>GalaSoft.MvvmLight.Messaging</project>
  10. // <web>http://www.galasoft.ch</web>
  11. // <license>
  12. // See license.txt in this project or http://www.galasoft.ch/license_MIT.txt
  13. // </license>
  14. // ****************************************************************************
  15. using System;
  16. using System.Diagnostics.CodeAnalysis;
  17. ////using GalaSoft.Utilities.Attributes;
  18. namespace CBR.Core.Helpers
  19. {
  20. /// <summary>
  21. /// The Messenger is a class allowing objects to exchange messages.
  22. /// </summary>
  23. ////[ClassInfo(typeof(Messenger))]
  24. public interface IMessenger
  25. {
  26. /// <summary>
  27. /// Registers a recipient for a type of message TMessage. The action
  28. /// parameter will be executed when a corresponding message is sent.
  29. /// <para>Registering a recipient does not create a hard reference to it,
  30. /// so if this recipient is deleted, no memory leak is caused.</para>
  31. /// </summary>
  32. /// <typeparam name="TMessage">The type of message that the recipient registers
  33. /// for.</typeparam>
  34. /// <param name="recipient">The recipient that will receive the messages.</param>
  35. /// <param name="action">The action that will be executed when a message
  36. /// of type TMessage is sent.</param>
  37. void Register<TMessage>(object recipient, Action<TMessage> action);
  38. /// <summary>
  39. /// Registers a recipient for a type of message TMessage.
  40. /// The action parameter will be executed when a corresponding
  41. /// message is sent. See the receiveDerivedMessagesToo parameter
  42. /// for details on how messages deriving from TMessage (or, if TMessage is an interface,
  43. /// messages implementing TMessage) can be received too.
  44. /// <para>Registering a recipient does not create a hard reference to it,
  45. /// so if this recipient is deleted, no memory leak is caused.</para>
  46. /// </summary>
  47. /// <typeparam name="TMessage">The type of message that the recipient registers
  48. /// for.</typeparam>
  49. /// <param name="recipient">The recipient that will receive the messages.</param>
  50. /// <param name="token">A token for a messaging channel. If a recipient registers
  51. /// using a token, and a sender sends a message using the same token, then this
  52. /// message will be delivered to the recipient. Other recipients who did not
  53. /// use a token when registering (or who used a different token) will not
  54. /// get the message. Similarly, messages sent without any token, or with a different
  55. /// token, will not be delivered to that recipient.</param>
  56. /// <param name="action">The action that will be executed when a message
  57. /// of type TMessage is sent.</param>
  58. void Register<TMessage>(object recipient, object token, Action<TMessage> action);
  59. /// <summary>
  60. /// Registers a recipient for a type of message TMessage.
  61. /// The action parameter will be executed when a corresponding
  62. /// message is sent. See the receiveDerivedMessagesToo parameter
  63. /// for details on how messages deriving from TMessage (or, if TMessage is an interface,
  64. /// messages implementing TMessage) can be received too.
  65. /// <para>Registering a recipient does not create a hard reference to it,
  66. /// so if this recipient is deleted, no memory leak is caused.</para>
  67. /// </summary>
  68. /// <typeparam name="TMessage">The type of message that the recipient registers
  69. /// for.</typeparam>
  70. /// <param name="recipient">The recipient that will receive the messages.</param>
  71. /// <param name="token">A token for a messaging channel. If a recipient registers
  72. /// using a token, and a sender sends a message using the same token, then this
  73. /// message will be delivered to the recipient. Other recipients who did not
  74. /// use a token when registering (or who used a different token) will not
  75. /// get the message. Similarly, messages sent without any token, or with a different
  76. /// token, will not be delivered to that recipient.</param>
  77. /// <param name="receiveDerivedMessagesToo">If true, message types deriving from
  78. /// TMessage will also be transmitted to the recipient. For example, if a SendOrderMessage
  79. /// and an ExecuteOrderMessage derive from OrderMessage, registering for OrderMessage
  80. /// and setting receiveDerivedMessagesToo to true will send SendOrderMessage
  81. /// and ExecuteOrderMessage to the recipient that registered.
  82. /// <para>Also, if TMessage is an interface, message types implementing TMessage will also be
  83. /// transmitted to the recipient. For example, if a SendOrderMessage
  84. /// and an ExecuteOrderMessage implement IOrderMessage, registering for IOrderMessage
  85. /// and setting receiveDerivedMessagesToo to true will send SendOrderMessage
  86. /// and ExecuteOrderMessage to the recipient that registered.</para>
  87. /// </param>
  88. /// <param name="action">The action that will be executed when a message
  89. /// of type TMessage is sent.</param>
  90. void Register<TMessage>(object recipient, object token, bool receiveDerivedMessagesToo, Action<TMessage> action);
  91. /// <summary>
  92. /// Registers a recipient for a type of message TMessage.
  93. /// The action parameter will be executed when a corresponding
  94. /// message is sent. See the receiveDerivedMessagesToo parameter
  95. /// for details on how messages deriving from TMessage (or, if TMessage is an interface,
  96. /// messages implementing TMessage) can be received too.
  97. /// <para>Registering a recipient does not create a hard reference to it,
  98. /// so if this recipient is deleted, no memory leak is caused.</para>
  99. /// </summary>
  100. /// <typeparam name="TMessage">The type of message that the recipient registers
  101. /// for.</typeparam>
  102. /// <param name="recipient">The recipient that will receive the messages.</param>
  103. /// <param name="receiveDerivedMessagesToo">If true, message types deriving from
  104. /// TMessage will also be transmitted to the recipient. For example, if a SendOrderMessage
  105. /// and an ExecuteOrderMessage derive from OrderMessage, registering for OrderMessage
  106. /// and setting receiveDerivedMessagesToo to true will send SendOrderMessage
  107. /// and ExecuteOrderMessage to the recipient that registered.
  108. /// <para>Also, if TMessage is an interface, message types implementing TMessage will also be
  109. /// transmitted to the recipient. For example, if a SendOrderMessage
  110. /// and an ExecuteOrderMessage implement IOrderMessage, registering for IOrderMessage
  111. /// and setting receiveDerivedMessagesToo to true will send SendOrderMessage
  112. /// and ExecuteOrderMessage to the recipient that registered.</para>
  113. /// </param>
  114. /// <param name="action">The action that will be executed when a message
  115. /// of type TMessage is sent.</param>
  116. void Register<TMessage>(object recipient, bool receiveDerivedMessagesToo, Action<TMessage> action);
  117. /// <summary>
  118. /// Sends a message to registered recipients. The message will
  119. /// reach all recipients that registered for this message type
  120. /// using one of the Register methods.
  121. /// </summary>
  122. /// <typeparam name="TMessage">The type of message that will be sent.</typeparam>
  123. /// <param name="message">The message to send to registered recipients.</param>
  124. void Send<TMessage>(TMessage message);
  125. /// <summary>
  126. /// Sends a message to registered recipients. The message will
  127. /// reach only recipients that registered for this message type
  128. /// using one of the Register methods, and that are
  129. /// of the targetType.
  130. /// </summary>
  131. /// <typeparam name="TMessage">The type of message that will be sent.</typeparam>
  132. /// <typeparam name="TTarget">The type of recipients that will receive
  133. /// the message. The message won't be sent to recipients of another type.</typeparam>
  134. /// <param name="message">The message to send to registered recipients.</param>
  135. [SuppressMessage(
  136. "Microsoft.Design",
  137. "CA1004:GenericMethodsShouldProvideTypeParameter",
  138. Justification = "This syntax is more convenient than other alternatives.")]
  139. void Send<TMessage, TTarget>(TMessage message);
  140. /// <summary>
  141. /// Sends a message to registered recipients. The message will
  142. /// reach only recipients that registered for this message type
  143. /// using one of the Register methods, and that are
  144. /// of the targetType.
  145. /// </summary>
  146. /// <typeparam name="TMessage">The type of message that will be sent.</typeparam>
  147. /// <param name="message">The message to send to registered recipients.</param>
  148. /// <param name="token">A token for a messaging channel. If a recipient registers
  149. /// using a token, and a sender sends a message using the same token, then this
  150. /// message will be delivered to the recipient. Other recipients who did not
  151. /// use a token when registering (or who used a different token) will not
  152. /// get the message. Similarly, messages sent without any token, or with a different
  153. /// token, will not be delivered to that recipient.</param>
  154. void Send<TMessage>(TMessage message, object token);
  155. /// <summary>
  156. /// Unregisters a messager recipient completely. After this method
  157. /// is executed, the recipient will not receive any messages anymore.
  158. /// </summary>
  159. /// <param name="recipient">The recipient that must be unregistered.</param>
  160. void Unregister(object recipient);
  161. /// <summary>
  162. /// Unregisters a message recipient for a given type of messages only.
  163. /// After this method is executed, the recipient will not receive messages
  164. /// of type TMessage anymore, but will still receive other message types (if it
  165. /// registered for them previously).
  166. /// </summary>
  167. /// <typeparam name="TMessage">The type of messages that the recipient wants
  168. /// to unregister from.</typeparam>
  169. /// <param name="recipient">The recipient that must be unregistered.</param>
  170. [SuppressMessage(
  171. "Microsoft.Design",
  172. "CA1004:GenericMethodsShouldProvideTypeParameter",
  173. Justification = "This syntax is more convenient than other alternatives.")]
  174. void Unregister<TMessage>(object recipient);
  175. /// <summary>
  176. /// Unregisters a message recipient for a given type of messages only and for a given token.
  177. /// After this method is executed, the recipient will not receive messages
  178. /// of type TMessage anymore with the given token, but will still receive other message types
  179. /// or messages with other tokens (if it registered for them previously).
  180. /// </summary>
  181. /// <param name="recipient">The recipient that must be unregistered.</param>
  182. /// <param name="token">The token for which the recipient must be unregistered.</param>
  183. /// <typeparam name="TMessage">The type of messages that the recipient wants
  184. /// to unregister from.</typeparam>
  185. [SuppressMessage(
  186. "Microsoft.Design",
  187. "CA1004:GenericMethodsShouldProvideTypeParameter",
  188. Justification = "This syntax is more convenient than other alternatives.")]
  189. void Unregister<TMessage>(object recipient, object token);
  190. /// <summary>
  191. /// Unregisters a message recipient for a given type of messages and for
  192. /// a given action. Other message types will still be transmitted to the
  193. /// recipient (if it registered for them previously). Other actions that have
  194. /// been registered for the message type TMessage and for the given recipient (if
  195. /// available) will also remain available.
  196. /// </summary>
  197. /// <typeparam name="TMessage">The type of messages that the recipient wants
  198. /// to unregister from.</typeparam>
  199. /// <param name="recipient">The recipient that must be unregistered.</param>
  200. /// <param name="action">The action that must be unregistered for
  201. /// the recipient and for the message type TMessage.</param>
  202. void Unregister<TMessage>(object recipient, Action<TMessage> action);
  203. /// <summary>
  204. /// Unregisters a message recipient for a given type of messages, for
  205. /// a given action and a given token. Other message types will still be transmitted to the
  206. /// recipient (if it registered for them previously). Other actions that have
  207. /// been registered for the message type TMessage, for the given recipient and other tokens (if
  208. /// available) will also remain available.
  209. /// </summary>
  210. /// <typeparam name="TMessage">The type of messages that the recipient wants
  211. /// to unregister from.</typeparam>
  212. /// <param name="recipient">The recipient that must be unregistered.</param>
  213. /// <param name="token">The token for which the recipient must be unregistered.</param>
  214. /// <param name="action">The action that must be unregistered for
  215. /// the recipient and for the message type TMessage.</param>
  216. void Unregister<TMessage>(object recipient, object token, Action<TMessage> action);
  217. }
  218. }