From 831193626ca85d088b971f849d5e71c7ebe73d79 Mon Sep 17 00:00:00 2001 From: DJGosnell Date: Sat, 10 Sep 2016 22:05:27 -0400 Subject: [PATCH] Moved frame creation methods into Sessions to further break logic between the socket and the MqSessions. --- DtronixMessageQueue.Tests/MqClientTests.cs | 6 +++--- DtronixMessageQueue/MqClient.cs | 3 +-- DtronixMessageQueue/MqSession.cs | 21 ++++++++++++++++++++- DtronixMessageQueue/Socket/SocketBase.cs | 5 ----- DtronixMessageQueue/Socket/SocketClient.cs | 20 -------------------- DtronixMessageQueue/Socket/SocketServer.cs | 21 --------------------- 6 files changed, 24 insertions(+), 52 deletions(-) diff --git a/DtronixMessageQueue.Tests/MqClientTests.cs b/DtronixMessageQueue.Tests/MqClientTests.cs index 897f067..d8cb049 100644 --- a/DtronixMessageQueue.Tests/MqClientTests.cs +++ b/DtronixMessageQueue.Tests/MqClientTests.cs @@ -76,8 +76,8 @@ public void Client_does_not_send_empty_message() { [Fact] public void Client_does_not_notify_on_command_frame() { - var command_frame = Client.CreateFrame(new byte[21]); - command_frame.FrameType = MqFrameType.Command; + + var command_frame = new MqFrame(new byte[21], MqFrameType.Command, Config); Client.Connected += (sender, args) => { Client.Send(command_frame); @@ -96,7 +96,7 @@ public void Client_does_not_notify_on_command_frame() { [Fact] public void Client_does_not_notify_on_ping_frame() { - var command_frame = Client.CreateFrame(null, MqFrameType.Ping); + var command_frame = new MqFrame(null, MqFrameType.Ping, Config); Client.Connected += (sender, args) => { Client.Send(command_frame); diff --git a/DtronixMessageQueue/MqClient.cs b/DtronixMessageQueue/MqClient.cs index 581a16b..c43879c 100644 --- a/DtronixMessageQueue/MqClient.cs +++ b/DtronixMessageQueue/MqClient.cs @@ -27,7 +27,6 @@ public class MqClient : SocketClient /// private readonly Timer timeout_timer; - /// /// Initializes a new instance of a message queue. /// @@ -66,7 +65,7 @@ protected override void OnClose(TSession session, SocketCloseReason reason) { /// /// Concurrent dictionary of the sessions. private void TimeoutCallback(object state) { - Session.Send(CreateFrame(null, MqFrameType.Ping)); + Session.Send(Session.CreateFrame(null, MqFrameType.Ping)); } /// diff --git a/DtronixMessageQueue/MqSession.cs b/DtronixMessageQueue/MqSession.cs index a07a1af..b1b06ba 100644 --- a/DtronixMessageQueue/MqSession.cs +++ b/DtronixMessageQueue/MqSession.cs @@ -240,7 +240,7 @@ public override void Close(SocketCloseReason reason) { if (CurrentState == State.Connected) { CurrentState = State.Closing; - close_frame = BaseSocket.CreateFrame(new byte[2]); + close_frame = CreateFrame(new byte[2]); close_frame.FrameType = MqFrameType.Command; close_frame.Write(0, (byte) 0); @@ -284,6 +284,25 @@ public void Send(MqMessage message) { EnqueueOutgoingMessage(message); } + /// + /// Creates a frame with the specified bytes and the current configurations. + /// + /// Bytes to put in the frame. + /// Configured frame. + public MqFrame CreateFrame(byte[] bytes) { + return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig)Config); + } + + /// + /// Creates a frame with the specified bytes and the current configurations. + /// + /// Bytes to put in the frame. + /// Type of frame to create. + /// Configured frame. + public MqFrame CreateFrame(byte[] bytes, MqFrameType type) { + return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config); + } + /// /// Processes an incoming command frame from the connection. diff --git a/DtronixMessageQueue/Socket/SocketBase.cs b/DtronixMessageQueue/Socket/SocketBase.cs index e9c47b5..252d766 100644 --- a/DtronixMessageQueue/Socket/SocketBase.cs +++ b/DtronixMessageQueue/Socket/SocketBase.cs @@ -109,10 +109,5 @@ protected virtual TSession CreateSession(System.Net.Sockets.Socket socket) { session.Closed += (sender, args) => OnClose(session, args.CloseReason); return session; } - - - public abstract MqFrame CreateFrame(byte[] bytes); - - public abstract MqFrame CreateFrame(byte[] bytes, MqFrameType type); } } diff --git a/DtronixMessageQueue/Socket/SocketClient.cs b/DtronixMessageQueue/Socket/SocketClient.cs index 94c4e80..bd2b73a 100644 --- a/DtronixMessageQueue/Socket/SocketClient.cs +++ b/DtronixMessageQueue/Socket/SocketClient.cs @@ -56,25 +56,5 @@ public void Connect(IPEndPoint end_point) { MainSocket.ConnectAsync(event_arg); } - - - /// - /// Creates a frame with the specified bytes and the current configurations. - /// - /// Bytes to put in the frame. - /// Configured frame. - public override MqFrame CreateFrame(byte[] bytes) { - return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig) Config); - } - - /// - /// Creates a frame with the specified bytes and the current configurations. - /// - /// Bytes to put in the frame. - /// Type of frame to create. - /// Configured frame. - public override MqFrame CreateFrame(byte[] bytes, MqFrameType type) { - return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config); - } } } diff --git a/DtronixMessageQueue/Socket/SocketServer.cs b/DtronixMessageQueue/Socket/SocketServer.cs index a08ecea..b41cf4f 100644 --- a/DtronixMessageQueue/Socket/SocketServer.cs +++ b/DtronixMessageQueue/Socket/SocketServer.cs @@ -124,27 +124,6 @@ private void RemoveClientEvent(object sender, SessionClosedEventArgs - /// Creates a frame with the specified bytes and the current configurations. - /// - /// Bytes to put in the frame. - /// Configured frame. - public override MqFrame CreateFrame(byte[] bytes) { - return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig)Config); - } - - /// - /// Creates a frame with the specified bytes and the current configurations. - /// - /// Bytes to put in the frame. - /// Type of frame to create. - /// Configured frame. - public override MqFrame CreateFrame(byte[] bytes, MqFrameType type) { - return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config); - } - - - /// /// Terminates this server and notify all connected clients. ///