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