PageRenderTime 116ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Katmai_February2008_CTP/ServiceBrokerInterface/cs/ServiceBrokerInterface/Message.cs

#
C# | 219 lines | 112 code | 28 blank | 79 comment | 1 complexity | 78ec949dab2b684440a23d44e9d916f7 MD5 | raw file
  1. //-----------------------------------------------------------------------
  2. // This file is part of the Microsoft Code Samples.
  3. //
  4. // Copyright (C) Microsoft Corporation. All rights reserved.
  5. //
  6. //This source code is intended only as a supplement to Microsoft
  7. //Development Tools and/or on-line documentation. See these other
  8. //materials for detailed information regarding Microsoft code samples.
  9. //
  10. //THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
  11. //KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. //IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  13. //PARTICULAR PURPOSE.
  14. //-----------------------------------------------------------------------
  15. #region Using directives
  16. using System;
  17. using System.Data;
  18. using System.Data.SqlClient;
  19. using System.Data.SqlTypes;
  20. using System.IO;
  21. #endregion
  22. namespace Microsoft.Samples.SqlServer
  23. {
  24. /// <remarks>
  25. /// The <c>Message</c> class is used both for sending as well as receiving
  26. /// messages from a <c>Service</c>. When used for sending messages, we only use
  27. /// the <c>Type</c> and the <c>Body</c> properties. When a message a received,
  28. /// the object contains all the properties describing the message received.
  29. /// </remarks>
  30. public class Message
  31. {
  32. # region Constant definitions
  33. /// <value>
  34. /// System message type for event notification messages.
  35. /// </value>
  36. public const string EventNotificationType = "http://schemas.microsoft.com/SQL/Notifications/EventNotification";
  37. /// <value>
  38. /// System message type for query notification messages.
  39. /// </value>
  40. public const string QueryNotificationType = "http://schemas.microsoft.com/SQL/Notifications/QueryNotification";
  41. /// <value>
  42. /// System message type for message indicating failed remote service binding.
  43. /// </value>
  44. public const string FailedRemoteServiceBindingType = "http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRemoteServiceBinding";
  45. /// <value>
  46. /// System message type for message indicating failed route.
  47. /// </value>
  48. public const string FailedRouteType = "http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRoute";
  49. /// <value>
  50. /// System message type for message indicating missing remote service binding.
  51. /// </value>
  52. public const string MissingRemoteServiceBindingType = "http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRemoteServiceBinding";
  53. /// <value>
  54. /// System message type for message indicating missing route.
  55. /// </value>
  56. public const string MissingRouteType = "http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRoute";
  57. /// <value>
  58. /// System message type for dialog timer messages.
  59. /// </value>
  60. public const string DialogTimerType = "http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer";
  61. /// <value>
  62. /// System message type for message indicating end of dialog.
  63. /// </value>
  64. public const string EndDialogType = "http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog";
  65. /// <value>
  66. /// System message type for error messages.
  67. /// </value>
  68. public const string ErrorType = "http://schemas.microsoft.com/SQL/ServiceBroker/Error";
  69. /// <value>
  70. /// System message type for diagnostic description messages.
  71. /// </value>
  72. public const string DescriptionType = "http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Description";
  73. /// <value>
  74. /// System message type for diagnostic query messages.
  75. /// </value>
  76. public const string QueryType = "http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Query";
  77. /// <value>
  78. /// System message type for diagnostic status messages.
  79. /// </value>
  80. public const string StatusType = "http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Status";
  81. /// <value>
  82. /// System message type for echo service messages.
  83. /// </value>
  84. public const string EchoType = "http://schemas.microsoft.com/SQL/ServiceBroker/ServiceEcho/Echo";
  85. # endregion
  86. #region Constructors
  87. /// <summary>
  88. /// Default constructor
  89. /// </summary>
  90. public Message()
  91. {
  92. }
  93. /// <summary>
  94. /// Creates a message object with given parameters.
  95. /// </summary>
  96. /// <param name="type">The message type</param>
  97. /// <param name="body">A stream referencing hte body of the message</param>
  98. public Message(string type, Stream body)
  99. {
  100. m_type = type;
  101. m_body = body;
  102. }
  103. #endregion
  104. #region private fields
  105. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  106. private SqlDataReader m_reader;
  107. #endregion
  108. #region Properties
  109. private Stream m_body;
  110. /// <value>A stream representing the message body.</value>
  111. public Stream Body
  112. {
  113. get { return m_body; }
  114. set { m_body = value; }
  115. }
  116. private string m_type;
  117. /// <value>The message type.</value>
  118. public string Type
  119. {
  120. get { return m_type; }
  121. set { m_type = value; }
  122. }
  123. private Conversation m_conv;
  124. /// <value>The conversation from which the message was received.</value>
  125. public Conversation Conversation
  126. {
  127. get { return m_conv; }
  128. set { m_conv = value; }
  129. }
  130. private Guid m_convGroupId;
  131. /// <value>The conversation group of the conversation from which the message was received.</value>
  132. public Guid ConversationGroupId
  133. {
  134. get { return m_convGroupId; }
  135. set { m_convGroupId = value; }
  136. }
  137. private long m_sequenceNumber;
  138. /// <value>The sequence number of the message in the queue.</value>
  139. public long SequenceNumber
  140. {
  141. get { return m_sequenceNumber; }
  142. set { m_sequenceNumber = value; }
  143. }
  144. private string m_validation;
  145. /// <value>The type of validation: 'E' means empty, 'N' means none, 'X' means well-formed XML.</value>
  146. public string Validation
  147. {
  148. get { return m_validation; }
  149. set { m_validation = value; }
  150. }
  151. private string m_serviceName;
  152. /// <value>The name of the service to which this message was sent.</value>
  153. public string ServiceName
  154. {
  155. get { return m_serviceName; }
  156. set { m_serviceName = value; }
  157. }
  158. private string m_contractName;
  159. /// <value>The contract that the message adhered to.</value>
  160. public string ContractName
  161. {
  162. get { return m_contractName; }
  163. set { m_contractName = value; }
  164. }
  165. #endregion
  166. #region Methods
  167. internal void Read(SqlDataReader reader, Service service)
  168. {
  169. // RECEIVE conversation_group_id, conversation_handle,
  170. // message_sequence_number, service_name, service_contract_name,
  171. // message_type_name, validation, message_body
  172. // FROM Queue
  173. m_reader = reader;
  174. m_convGroupId = reader.GetGuid(0);
  175. m_conv = new Conversation(service, reader.GetGuid(1));
  176. m_sequenceNumber = reader.GetInt64(2);
  177. m_serviceName = reader.GetString(3);
  178. m_contractName = reader.GetString(4);
  179. m_type = reader.GetString(5);
  180. m_validation = reader.GetString(6);
  181. if (!reader.IsDBNull(7))
  182. {
  183. SqlBytes sb = reader.GetSqlBytes(7);
  184. Body = sb.Stream;
  185. }
  186. else
  187. Body = null;
  188. }
  189. #endregion
  190. }
  191. }