You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/11/27 00:24:46 UTC

svn commit: r1545880 - in /activemq/activemq-dotnet/Apache.NMS.MQTT/trunk: ./ src/main/csharp/Commands/ src/main/csharp/Messages/ src/main/csharp/Protocol/ src/main/csharp/Transport/ src/test/csharp/ src/test/csharp/Protocol/

Author: tabish
Date: Tue Nov 26 23:24:45 2013
New Revision: 1545880

URL: http://svn.apache.org/r1545880
Log:
https://issues.apache.org/jira/browse/AMQNET-458

Implementation

Added:
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs   (with props)
Removed:
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/Header.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNACK.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNECT.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/DISCONNECT.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGREQ.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGRESP.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBACK.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBCOMP.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBLISH.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREC.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREL.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBACK.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBSCRIBE.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBACK.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBSCRIBE.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Messages/MessageDispatch.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTWireFormat.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/IWireFormat.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/Protocol/HeaderTest.cs
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt-tests.csproj
    activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNACK.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNACK.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNACK.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNACK.cs Tue Nov 26 23:24:45 2013
@@ -15,13 +15,25 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
-	public class CONNACK : BaseCommand
+	public class CONNACK : Response
 	{
 		public const byte TYPE = 2;
+		public const byte DEFAULT_HEADER = 0x20;
+		public const String PROTOCOL_NAME = "MQIsdp";
+
+		public CONNACK() : base(new Header(DEFAULT_HEADER))
+		{
+		}
+
+		public CONNACK(Header header) : base(header)
+		{
+		}
 
 		private byte returnCode;
 		public byte ReturnCode
@@ -35,14 +47,26 @@ namespace Apache.NMS.MQTT.Commands
 			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public override bool IsCONNACK
+		{
+			get { return true; }
+		}
+
+        public override bool IsErrorResponse
+        {
+            get { return ReturnCode != 0; }
+        }
+
+		public override void Encode(BinaryWriter writer)
 		{
-			get { return "CONNACK"; }
+			writer.Write((byte) 0);
+			writer.Write(ReturnCode);
 		}
 
-		public override bool IsCONNACK
+		public override void Decode(BinaryReader reader)
 		{
-			get { return true; }
+			reader.ReadByte();
+			ReturnCode = reader.ReadByte();
 		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNECT.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNECT.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNECT.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/CONNECT.cs Tue Nov 26 23:24:45 2013
@@ -15,7 +15,11 @@
 // limitations under the License.
 // 
 using System;
+using System.IO;
+using System.Text;
+using Apache.NMS.Util;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
@@ -30,16 +34,36 @@ namespace Apache.NMS.MQTT.Commands
 	public class CONNECT : BaseCommand
 	{
 		public const byte TYPE = 1;
+		public const byte DEFAULT_HEADER = 0x10;
 		public const String PROTOCOL_NAME = "MQIsdp";
+		private static byte[] PROTOCOL_NAME_ENCODED;
 
-		public override int CommandType
+		/// <summary>
+		/// Static init of properly encoded UTF8 bytes for the Protocol Name, this saves
+		/// us the work of encoding the same value for every message send.
+		/// </summary>
+		static CONNECT()
+		{
+			MemoryStream stream = new MemoryStream();
+			EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+			short value = (short) Encoding.UTF8.GetByteCount(PROTOCOL_NAME);
+			writer.Write(value);
+			writer.Write(Encoding.UTF8.GetBytes(PROTOCOL_NAME));
+
+			PROTOCOL_NAME_ENCODED = stream.ToArray();
+		}
+
+		public CONNECT() : base(new Header(DEFAULT_HEADER))
+		{
+		}
+
+		public CONNECT(Header header) : base(header)
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public override int CommandType
 		{
-			get { return "CONNECT"; }
+			get { return TYPE; }
 		}
 
 		public override bool IsCONNECT
@@ -116,6 +140,90 @@ namespace Apache.NMS.MQTT.Commands
 			get { return this.willMessage; }
 			set { this.willMessage = value; }
 		}
+
+		public override void Encode(BinaryWriter writer)
+		{
+			writer.Write(PROTOCOL_NAME_ENCODED);
+			writer.Write(Version);
+
+			byte contentFlags = 0;
+
+			if (!String.IsNullOrEmpty(username))
+			{
+				contentFlags |= 0x80;
+			}
+			if (!String.IsNullOrEmpty(username))
+			{
+				contentFlags |= 0x40;
+			}
+			if (!String.IsNullOrEmpty(WillTopic) && !String.IsNullOrEmpty(WillMessage))
+			{
+				contentFlags |= 0x04;
+				if (WillRetain)
+				{
+					contentFlags |= 0x20;
+				}
+				contentFlags |= (byte)((WillQoS << 3) & 0x18);
+			}
+			if (CleanSession)
+			{
+				contentFlags |= 0x02;
+			}
+
+			writer.Write(contentFlags);
+			writer.Write(KeepAliveTimer);
+			writer.Write(ClientId);
+
+			if (!String.IsNullOrEmpty(WillTopic) && !String.IsNullOrEmpty(WillMessage))
+			{
+				writer.Write(WillTopic);
+				writer.Write(WillMessage);
+			}
+			if (!String.IsNullOrEmpty(username))
+			{
+				writer.Write(UserName);
+			}
+			if (!String.IsNullOrEmpty(username))
+			{
+				writer.Write(Password);
+			}
+		}
+
+		public override void Decode(BinaryReader reader)
+		{
+			String protocolName = reader.ReadString();
+			if (!PROTOCOL_NAME.Equals(protocolName))
+			{
+				throw new IOException("Invalid Protocol Name: " + protocolName);
+			}
+
+			this.version = reader.ReadByte();
+			byte contentFlags = reader.ReadByte();
+
+			bool hasUsername = (contentFlags & 0x80) != 0;
+			bool hasPassword = (contentFlags & 0x40) != 0;
+			bool hasWillTopic = (contentFlags & 0x04) != 0;
+
+			WillRetain = (contentFlags & 0x20) != 0;
+			WillQoS = (byte)((contentFlags & 0x18) >> 3);
+			CleanSession = (contentFlags & 0x02) != 0;
+
+			KeepAliveTimer = reader.ReadInt16();
+			ClientId = reader.ReadString();
+			if (hasWillTopic)
+			{
+				WillTopic = reader.ReadString();
+				WillMessage = reader.ReadString();
+			}
+			if (hasUsername)
+			{
+				UserName = reader.ReadString();
+			}
+			if (hasPassword)
+			{
+				Password = reader.ReadString();
+			}
+		}
 	}
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/DISCONNECT.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/DISCONNECT.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/DISCONNECT.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/DISCONNECT.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class DISCONNECT : BaseCommand
 	{
 		public const byte TYPE = 14;
+		public const byte DEFAULT_HEADER = 0xE0;
 
-		public override int CommandType
+		public DISCONNECT() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public DISCONNECT(Header header) : base(header)
 		{
-			get { return "DISCONNECT"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsDISCONNECT

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGREQ.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGREQ.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGREQ.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGREQ.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PINGREQ : BaseCommand
 	{
-		public const byte TYPE = 11;
+		public const byte TYPE = 12;
+		public const byte DEFAULT_HEADER = 0xC0;
 
-		public override int CommandType
+		public PINGREQ() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PINGREQ(Header header) : base(header)
 		{
-			get { return "PINGREQ"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPINGREQ

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGRESP.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGRESP.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGRESP.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PINGRESP.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PINGRESP : BaseCommand
 	{
 		public const byte TYPE = 13;
+		public const byte DEFAULT_HEADER = 0xD0;
 
-		public override int CommandType
+		public PINGRESP() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PINGRESP(Header header) : base(header)
 		{
-			get { return "PINGRESP"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPINGRESP

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBACK.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBACK.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBACK.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBACK.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PUBACK : BaseCommand
 	{
 		public const byte TYPE = 4;
+		public const byte DEFAULT_HEADER = 0x40;
 
-		public override int CommandType
+		public PUBACK() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PUBACK(Header header) : base(header)
 		{
-			get { return "PUBACK"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPUBACK

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBCOMP.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBCOMP.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBCOMP.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBCOMP.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PUBCOMP : BaseCommand
 	{
 		public const byte TYPE = 7;
+		public const byte DEFAULT_HEADER = 0x70;
 
-		public override int CommandType
+		public PUBCOMP() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PUBCOMP(Header header) : base(header)
 		{
-			get { return "PUBCOMP"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPUBCOMP

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBLISH.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBLISH.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBLISH.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBLISH.cs Tue Nov 26 23:24:45 2013
@@ -15,7 +15,9 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
@@ -31,15 +33,19 @@ namespace Apache.NMS.MQTT.Commands
 	public class PUBLISH : BaseCommand
 	{
 		public const byte TYPE = 3;
+		public const byte DEFAULT_HEADER = 0x30;
 
-		public override int CommandType
+		public PUBLISH() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PUBLISH(Header header) : base(header)
 		{
-			get { return "PUBLISH"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPUBLISH

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREC.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREC.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREC.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREC.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PUBREC : BaseCommand
 	{
 		public const byte TYPE = 5;
+		public const byte DEFAULT_HEADER = 0x50;
 
-		public override int CommandType
+		public PUBREC() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PUBREC(Header header) : base(header)
 		{
-			get { return "PUBREC"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPUBREC

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREL.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREL.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREL.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/PUBREL.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class PUBREL : BaseCommand
 	{
 		public const byte TYPE = 6;
+		public const byte DEFAULT_HEADER = 0x62;
 
-		public override int CommandType
+		public PUBREL() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public PUBREL(Header header) : base(header)
 		{
-			get { return "PUBREL"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsPUBREL

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBACK.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBACK.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBACK.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBACK.cs Tue Nov 26 23:24:45 2013
@@ -15,7 +15,9 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
@@ -27,16 +29,20 @@ namespace Apache.NMS.MQTT.Commands
 	/// </summary>
 	public class SUBACK : BaseCommand
 	{
-		public const byte TYPE = 8;
+		public const byte TYPE = 9;
+		public const byte DEFAULT_HEADER = 0x90;
 
-		public override int CommandType
+		public SUBACK() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public SUBACK(Header header) : base(header)
 		{
-			get { return "SUBACK"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsSUBACK

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBSCRIBE.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBSCRIBE.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBSCRIBE.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/SUBSCRIBE.cs Tue Nov 26 23:24:45 2013
@@ -15,7 +15,9 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
@@ -25,16 +27,20 @@ namespace Apache.NMS.MQTT.Commands
 	/// </summary>
 	public class SUBSCRIBE : BaseCommand
 	{
-		public const byte TYPE = 7;
+		public const byte TYPE = 8;
+		public const byte DEFAULT_HEADER = 0x82;
 
-		public override int CommandType
+		public SUBSCRIBE() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public SUBSCRIBE(Header header) : base(header)
 		{
-			get { return "SUBSCRIBE"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsSUBSCRIBE

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBACK.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBACK.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBACK.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBACK.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class UNSUBACK : BaseCommand
 	{
-		public const byte TYPE = 10;
+		public const byte TYPE = 11;
+		public const byte DEFAULT_HEADER = 0xB0;
 
-		public override int CommandType
+		public UNSUBACK() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public UNSUBACK(Header header) : base(header)
 		{
-			get { return "UNSUBACK"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsUNSUBACK

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBSCRIBE.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBSCRIBE.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBSCRIBE.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Commands/UNSUBSCRIBE.cs Tue Nov 26 23:24:45 2013
@@ -15,22 +15,28 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 using Apache.NMS.MQTT.Transport;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Commands
 {
 	public class UNSUBSCRIBE : BaseCommand
 	{
-		public const byte TYPE = 9;
+		public const byte TYPE = 10;
+		public const byte DEFAULT_HEADER = 0xA2;
 
-		public override int CommandType
+		public UNSUBSCRIBE() : base(new Header(DEFAULT_HEADER))
 		{
-			get { return TYPE; }
 		}
 
-		public override string CommandName
+		public UNSUBSCRIBE(Header header) : base(header)
 		{
-			get { return "UNSUBSCRIBE"; }
+		}
+
+		public override int CommandType
+		{
+			get { return TYPE; }
 		}
 
 		public override bool IsUNSUBSCRIBE

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Messages/MessageDispatch.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Messages/MessageDispatch.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Messages/MessageDispatch.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Messages/MessageDispatch.cs Tue Nov 26 23:24:45 2013
@@ -29,7 +29,7 @@ namespace Apache.NMS.MQTT.Messages
      *         in the nms-activemq-openwire-generator module
      *
      */
-    public class MessageDispatch : BaseCommand
+    public class MessageDispatch
     {
         Topic destination;
         MQTTMessage message;
@@ -43,8 +43,6 @@ namespace Apache.NMS.MQTT.Messages
         public override string ToString()
         {
             return GetType().Name + "[ " + 
-                "commandId = " + this.CommandId + ", " + 
-                "responseRequired = " + this.ResponseRequired + ", " + 
                 "Destination = " + Destination + ", " + 
                 "Message = " + Message + " ]";
         }
@@ -65,8 +63,8 @@ namespace Apache.NMS.MQTT.Messages
         {
             int answer = 0;
 
-            answer = (answer * 37) + HashCode(Destination);
-            answer = (answer * 37) + HashCode(Message);
+            answer = (answer * 37) + Destination.GetHashCode();
+            answer = (answer * 37) + Message.GetHashCode();
 
             return answer;
         }
@@ -94,12 +92,13 @@ namespace Apache.NMS.MQTT.Messages
 
             return true;
         }
+
         ///
         /// <summery>
         ///  Return an answer of true to the isMessageDispatch() query.
         /// </summery>
         ///
-        public override bool IsMessageDispatch
+        public bool IsMessageDispatch
         {
             get { return true; }
         }

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs?rev=1545880&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs Tue Nov 26 23:24:45 2013
@@ -0,0 +1,97 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+using System;
+
+namespace Apache.NMS.MQTT.Protocol
+{
+	public class Header
+	{
+		private byte value;
+
+		public Header(int commandType, int qos, bool dup, bool retain)
+		{
+			Type = commandType;
+			QoS = qos;
+			Dup = dup;
+			Retain = retain;
+		}
+
+		public Header(byte value)
+		{
+			this.value = value;
+		}
+
+		public byte RawValue
+		{
+			get { return this.value; }
+			set { this.value = value; }
+		}
+
+		public int Type
+		{
+			get { return (this.value & 0xF0) >> 4; }
+			set
+			{
+				this.value &= 0x0F;
+				this.value |= (byte)((value << 4) & 0xF0);
+			}
+		}
+
+		public int QoS
+		{
+			get { return (this.value & 0x06) >> 1; }
+			set
+			{
+				this.value &= 0xF9;
+				this.value |= (byte)((value << 1) & 0x06);
+			}
+		}
+
+		public bool Dup
+		{
+			get { return (this.value & 0x08) > 0; }
+			set
+			{
+				if (value)
+				{
+					this.value |= 0x08;
+				}
+				else
+				{
+					this.value &= 0xF7;
+				}
+			}
+		}
+
+		public bool Retain
+		{
+			get { return (this.value & 0x01) > 0; }
+			set
+			{
+				if(value)
+				{
+					this.value |= 0x01;
+				}
+				else
+				{
+					this.value &= 0xFE;
+				}
+			}
+		}
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/Header.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs?rev=1545880&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs Tue Nov 26 23:24:45 2013
@@ -0,0 +1,87 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+using System;
+using Apache.NMS.MQTT.Commands;
+using Apache.NMS.MQTT.Transport;
+
+namespace Apache.NMS.MQTT.Protocol
+{
+	public class MQTTCommandFactory
+	{
+		private MQTTCommandFactory()
+		{
+		}
+
+		public static Command CreateCommand(byte fixedHeader)
+		{
+			Header header = new Header(fixedHeader);
+
+			Command result = null;
+
+			switch (header.Type)
+			{
+			case 1:
+				result = new CONNECT(header);
+				break;
+			case 2:
+				result = new CONNACK(header);
+				break;
+			case 3:
+				result = new PUBLISH(header);
+				break;
+			case 4:
+				result = new PUBACK(header);
+				break;
+			case 5:
+				result = new PUBREC(header);
+				break;
+			case 6:
+				result = new PUBREL(header);
+				break;
+			case 7:
+				result = new PUBCOMP(header);
+				break;
+			case 8:
+				result = new SUBSCRIBE(header);
+				break;
+			case 9:
+				result = new SUBACK(header);
+				break;
+			case 10:
+				result = new UNSUBSCRIBE(header);
+				break;
+			case 11:
+				result = new UNSUBACK(header);
+				break;
+			case 12:
+				result = new PINGREQ(header);
+				break;
+			case 13:
+				result = new PINGRESP(header);
+				break;
+			case 14:
+				result = new DISCONNECT(header);
+				break;
+			default:
+				throw new NMSException("Unknown Command received");
+			}
+
+			return result;
+		}
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTCommandFactory.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTExceptionFactory.cs Tue Nov 26 23:24:45 2013
@@ -26,7 +26,7 @@ namespace Apache.NMS.MQTT.Protocol
 		{
 		}
 
-		static NMSException CreateConnectionException(short errorCode)
+		public static NMSException CreateConnectionException(short errorCode)
 		{
 			NMSException result = null;
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTWireFormat.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTWireFormat.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Protocol/MQTTWireFormat.cs Tue Nov 26 23:24:45 2013
@@ -16,6 +16,8 @@
 //
 using System;
 using System.IO;
+using Apache.NMS.Util;
+using Apache.NMS.MQTT.Commands;
 using Apache.NMS.MQTT.Transport;
 
 namespace Apache.NMS.MQTT.Protocol
@@ -28,13 +30,54 @@ namespace Apache.NMS.MQTT.Protocol
 		{
 		}
 
-        public void Marshal(Object o, BinaryWriter ds)
+        public void Marshal(Command cmd, BinaryWriter ds)
 		{
+			MemoryStream buffer = new MemoryStream();
+			EndianBinaryWriter writer = new EndianBinaryWriter(buffer);
+
+			byte fixedHeader = cmd.Header;
+			cmd.Encode(writer);
+
+			ds.Write(fixedHeader);
+			WriteLength((int)buffer.Length, ds);
+            ds.Write(buffer.GetBuffer(), 0, (int) buffer.Length);
 		}
 
-        public Object Unmarshal(BinaryReader dis)
+        public Command Unmarshal(BinaryReader dis)
 		{
-			return null;
+			byte fixedHeader = dis.ReadByte();
+
+			Command cmd = MQTTCommandFactory.CreateCommand(fixedHeader);
+
+			// Variable length header gives us total Message length to buffer.
+			int length = ReadLength(dis);
+
+			if (length != 0)
+			{
+				byte[] buffer = dis.ReadBytes(length);
+
+				if (buffer.Length != length)
+				{
+					throw new IOException("Invalid stream read occurred.");
+				}
+
+				MemoryStream ms = new MemoryStream(buffer);
+				EndianBinaryReader reader = new EndianBinaryReader(ms);
+
+				cmd.Decode(reader);
+			}
+
+			// A CONNACK is a response, but if it has an error code, then we create a suitable
+			// ErrorResponse here with the correct NMSException in its payload.
+			if (cmd.IsCONNACK && cmd.IsErrorResponse)
+			{
+				CONNACK connAck = cmd as CONNACK;
+				ErrorResponse error = new ErrorResponse();
+				error.Error = MQTTExceptionFactory.CreateConnectionException(connAck.ReturnCode);
+				cmd = error;
+			}
+
+			return cmd;
 		}
 
 		public ITransport Transport
@@ -42,6 +85,48 @@ namespace Apache.NMS.MQTT.Protocol
 			get { return this.transport; }
 			set { this.transport = value; }
 		}
+
+		/// <summary>
+		/// Writes the variable length portion of the MQTT Message to the given stream
+		/// </summary>
+		internal void WriteLength(int length, BinaryWriter writer)
+		{
+			do 
+			{
+				byte digit = (byte) (length % 0x80);
+				length /= 0x80;
+				// if there are more digits to encode, set the top bit of this digit 
+				if(length > 0)
+				{
+					digit |= 0x80;
+				}
+
+				writer.Write(digit);
+			}
+			while (length > 0);
+		}
+
+		/// <summary>
+		/// Reads the varianle length header from the given stream.
+		/// </summary>
+		internal int ReadLength(BinaryReader reader)
+		{
+			int multiplier = 1;
+			int length = 0;
+
+			while (true)
+			{
+				byte digit = reader.ReadByte();
+				length += (digit & 0x7F) * multiplier;
+				if ((digit & 0x80) == 0)
+				{
+					break;
+				}
+				multiplier *= 0x80;
+			}
+
+			return length;
+		}
 	}
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs Tue Nov 26 23:24:45 2013
@@ -15,15 +15,29 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Transport
 {
     public abstract class BaseCommand : Command, ICloneable
     {
-        private int commandId;
+		private Header header;
+        private short commandId;
         private bool responseRequired = false;
 
-        public int CommandId
+		public BaseCommand(Header header)
+		{
+			this.header = header;
+		}
+
+		public byte Header
+		{
+			get { return this.header.RawValue; }
+			set { this.header.RawValue = value; }
+		}
+
+        public short CommandId
         {
             get { return commandId; }
             set { this.commandId = value; }
@@ -31,7 +45,7 @@ namespace Apache.NMS.MQTT.Transport
 
 		public virtual int CommandType
 		{
-			get { return 0; }
+			get { return -1; }
 		}
 
 		public virtual string CommandName
@@ -76,6 +90,11 @@ namespace Apache.NMS.MQTT.Transport
 			get { return false; }
 		}
 
+		public virtual bool IsErrorResponse
+		{
+			get { return false; }
+		}
+
 		public virtual bool IsMessageDispatch
 		{
 			get { return false; }
@@ -167,6 +186,16 @@ namespace Apache.NMS.MQTT.Transport
 				return -1;
 			}
 		}
+
+		public virtual void Encode(BinaryWriter writer)
+		{
+			throw new NotImplementedException("Command doesn't implement Encode");
+		}
+
+		public virtual void Decode(BinaryReader reader)
+		{
+			throw new NotImplementedException("Command doesn't implement Decode");
+		}
     }
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs Tue Nov 26 23:24:45 2013
@@ -15,6 +15,7 @@
 // limitations under the License.
 //
 using System;
+using System.IO;
 
 namespace Apache.NMS.MQTT.Transport
 {
@@ -24,6 +25,11 @@ namespace Apache.NMS.MQTT.Transport
     /// </summary>
     public interface Command : ICloneable
     {
+		byte Header
+		{
+			get;
+		}
+
 		int CommandType
 		{
 			get;
@@ -34,7 +40,7 @@ namespace Apache.NMS.MQTT.Transport
 			get;
 		}
 
-        int CommandId
+        short CommandId
         {
 			get;
         }
@@ -49,6 +55,11 @@ namespace Apache.NMS.MQTT.Transport
 			get; 
 		}
 
+		bool IsErrorResponse
+		{
+			get; 
+		}
+
 		bool IsMessageDispatch
 		{
 			get; 
@@ -123,6 +134,11 @@ namespace Apache.NMS.MQTT.Transport
         {
 			get;
         }
+
+		void Encode(BinaryWriter writer);
+
+		void Decode(BinaryReader reader);
+
     }
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ErrorResponse.cs Tue Nov 26 23:24:45 2013
@@ -28,12 +28,13 @@ namespace Apache.NMS.MQTT.Transport
 			set { this.error = value; }
 		}
 
+		public ErrorResponse() : base(null)
+		{
+		}
+
 		public override bool IsErrorResponse 
 		{
-			get 
-			{
-				return true;
-			}
+			get { return true; }
 		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/IWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/IWireFormat.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/IWireFormat.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/IWireFormat.cs Tue Nov 26 23:24:45 2013
@@ -27,14 +27,15 @@ namespace Apache.NMS.MQTT.Transport
         /// <summary>
         /// Marshalls the given command object onto the stream
         /// </summary>
-        void Marshal(Object o, BinaryWriter ds);
+        void Marshal(Command o, BinaryWriter ds);
 
         /// <summary>
         /// Unmarshalls the next command object from the stream
         /// </summary>
-        Object Unmarshal(BinaryReader dis);
+        Command Unmarshal(BinaryReader dis);
 
-        ITransport Transport {
+        ITransport Transport 
+		{
             get; set;
         }
     }

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs Tue Nov 26 23:24:45 2013
@@ -15,16 +15,21 @@
 // limitations under the License.
 //
 using System;
+using Apache.NMS.MQTT.Protocol;
 
 namespace Apache.NMS.MQTT.Transport
 {
 	/// <summary>
 	/// Response type.
 	/// </summary>
-    public class Response : BaseCommand
+    public abstract class Response : BaseCommand
     {
         short correlationId;
 
+		public Response(Header header) : base(header)
+		{
+		}
+
         ///
         /// <summery>
         ///  Returns a string containing the information for this DataStructure
@@ -55,11 +60,6 @@ namespace Apache.NMS.MQTT.Transport
             get { return true; }
         }
 
-        public virtual bool IsErrorResponse
-        {
-            get { return false; }
-        }
-
     };
 }
 

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs?rev=1545880&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs Tue Nov 26 23:24:45 2013
@@ -0,0 +1,58 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+using System;
+using System.Net.Sockets;
+using Apache.NMS.Test;
+using Apache.NMS.MQTT;
+using NUnit.Framework;
+
+namespace Apache.NMS.MQTT.Test
+{
+	[TestFixture]
+	public class ConnectionFactoryTest
+	{
+//      [Test]
+//      [TestCase("mqtt:tcp://${activemqhost}:61613")]
+//      [TestCase("stomp:failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)")]
+//      [TestCase("stomp:failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)?connection.asyncSend=false")]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.asyncsend=false")]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.InvalidParameter=true", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.InvalidParameter=true", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:(tcp://${activemqhost}:61613)?connection.asyncSend=false", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613?connection.asyncsend=false", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("ftp://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("http://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("discovery://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("sms://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:multicast://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("(tcp://${activemqhost}:61613,tcp://${activemqhost}:61613)", ExpectedException = typeof(UriFormatException))]
+//		[TestCase("tcp://${activemqhost}:61613,tcp://${activemqhost}:61613", ExpectedException = typeof(UriFormatException))]
+        public void TestURI(string connectionURI)
+        {
+            IConnectionFactory factory = new ConnectionFactory(
+				NMSTestSupport.ReplaceEnvVar(connectionURI));
+            Assert.IsNotNull(factory);
+            using(IConnection connection = factory.CreateConnection("", ""))
+            {
+                Assert.IsNotNull(connection);
+            }
+        }
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/ConnectionFactoryTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs?rev=1545880&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs Tue Nov 26 23:24:45 2013
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Net.Sockets;
+using Apache.NMS.Test;
+using NUnit.Framework;
+
+namespace Apache.NMS.MQTT.Test
+{
+    [TestFixture]
+    public class NMSConnectionFactoryTest
+    {
+//      [Test]
+//      [TestCase("mqtt:tcp://${activemqhost}:61613")]
+//      [TestCase("stomp:failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)")]
+//      [TestCase("stomp:failover:(tcp://${activemqhost}:61616?keepAlive=false&wireFormat.maxInactivityDuration=1000)?connection.asyncSend=false")]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.asyncsend=false")]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.InvalidParameter=true", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://${activemqhost}:61613?connection.InvalidParameter=true", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:(tcp://${activemqhost}:61613)?connection.asyncSend=false", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:tcp://InvalidHost:61613?connection.asyncsend=false", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("ftp://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("http://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("discovery://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("sms://${activemqhost}:61613", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("stomp:multicast://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
+//		[TestCase("(tcp://${activemqhost}:61613,tcp://${activemqhost}:61613)", ExpectedException = typeof(UriFormatException))]
+//		[TestCase("tcp://${activemqhost}:61613,tcp://${activemqhost}:61613", ExpectedException = typeof(UriFormatException))]
+        public void TestURI(string connectionURI)
+        {
+            NMSConnectionFactory factory = new NMSConnectionFactory(
+				NMSTestSupport.ReplaceEnvVar(connectionURI));
+            Assert.IsNotNull(factory);
+            Assert.IsNotNull(factory.ConnectionFactory);
+            using(IConnection connection = factory.CreateConnection("", ""))
+            {
+                Assert.IsNotNull(connection);
+            }
+        }
+	}
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs?rev=1545880&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs Tue Nov 26 23:24:45 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.NMS.MQTT.Test
+{
+	public class NmsConsoleTracer : Apache.NMS.ITrace
+	{
+		#region ITrace Members
+		public void Debug(string message)
+		{
+			System.Console.WriteLine(string.Format("DEBUG: {0}", message));
+		}
+
+		public void Error(string message)
+		{
+			System.Console.WriteLine(string.Format("ERROR: {0}", message));
+		}
+
+		public void Fatal(string message)
+		{
+			System.Console.WriteLine(string.Format("FATAL: {0}", message));
+		}
+
+		public void Info(string message)
+		{
+			System.Console.WriteLine(string.Format("INFO: {0}", message));
+		}
+
+		public void Warn(string message)
+		{
+			System.Console.WriteLine(string.Format("WARN: {0}", message));
+		}
+
+		public bool IsDebugEnabled
+		{
+			get { return true; }
+		}
+
+		public bool IsErrorEnabled
+		{
+			get { return true; }
+		}
+
+		public bool IsFatalEnabled
+		{
+			get { return true; }
+		}
+
+		public bool IsInfoEnabled
+		{
+			get { return true; }
+		}
+
+		public bool IsWarnEnabled
+		{
+			get { return true; }
+		}
+
+		#endregion
+	}
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/NmsConsoleTracer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/Protocol/HeaderTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/Protocol/HeaderTest.cs?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/Protocol/HeaderTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/test/csharp/Protocol/HeaderTest.cs Tue Nov 26 23:24:45 2013
@@ -16,7 +16,7 @@
 //
 using System;
 using Apache.NMS.Test;
-using Apache.NMS.MQTT.Commands;
+using Apache.NMS.MQTT.Protocol;
 using NUnit.Framework;
 
 namespace Apache.NMS.MQTT.Test.Protocol

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt-tests.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt-tests.csproj?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt-tests.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt-tests.csproj Tue Nov 26 23:24:45 2013
@@ -46,6 +46,9 @@
   <ItemGroup>
     <Compile Include="src\test\csharp\CommonAssemblyInfo.cs" />
     <Compile Include="src\test\csharp\Protocol\HeaderTest.cs" />
+    <Compile Include="src\test\csharp\NMSConnectionFactoryTest.cs" />
+    <Compile Include="src\test\csharp\NmsConsoleTracer.cs" />
+    <Compile Include="src\test\csharp\ConnectionFactoryTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="LICENSE.txt" />

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj?rev=1545880&r1=1545879&r2=1545880&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj Tue Nov 26 23:24:45 2013
@@ -106,7 +106,8 @@
     <Compile Include="src\main\csharp\Transport\ResponseCorrelator.cs" />
     <Compile Include="src\main\csharp\Transport\ErrorResponse.cs" />
     <Compile Include="src\main\csharp\Protocol\MQTTExceptionFactory.cs" />
-    <Compile Include="src\main\csharp\Commands\Header.cs" />
+    <Compile Include="src\main\csharp\Protocol\Header.cs" />
+    <Compile Include="src\main\csharp\Protocol\MQTTCommandFactory.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="keyfile\" />