From ccfde19d2d0b53901bb3caf161e907b782e1671c Mon Sep 17 00:00:00 2001 From: PsychoMark Date: Tue, 12 Jul 2016 16:57:24 +0200 Subject: [PATCH] Changed Model namespace to Connection, moved bits out to Infrastructure Added Mock connection Fixed AutoScroll failing with high rate message flow --- App.xaml.cs | 7 ++- {Model => Connection}/ConnectionInfo.cs | 2 +- {Model => Connection}/IConnection.cs | 2 +- {Model => Connection}/IConnectionFactory.cs | 2 +- .../IConnectionInfoBuilder.cs | 2 +- {Model => Connection}/MessageInfo.cs | 2 +- Connection/MockConnection.cs | 50 +++++++++++++++++++ Connection/MockConnectionFactory.cs | 17 +++++++ Connection/MockConnectionInfoBuilder.cs | 10 ++++ .../RabbitMQClientConnection.cs | 2 +- .../RabbitMQClientConnectionFactory.cs | 2 +- {Model => Connection}/RabbitMQProperties.cs | 2 +- Infrastructure/ListBoxAutoScroll.cs | 2 +- .../MessageBodyRenderer.cs | 2 +- {Model => Infrastructure}/UserSettings.cs | 2 +- PettingZoo.csproj | 23 +++++---- View/ConnectionWindow.xaml.cs | 3 +- ViewModel/ConnectionViewModel.cs | 2 +- ViewModel/MainViewModel.cs | 8 +-- 19 files changed, 114 insertions(+), 28 deletions(-) rename {Model => Connection}/ConnectionInfo.cs (91%) rename {Model => Connection}/IConnection.cs (96%) rename {Model => Connection}/IConnectionFactory.cs (78%) rename {Model => Connection}/IConnectionInfoBuilder.cs (72%) rename {Model => Connection}/MessageInfo.cs (95%) create mode 100644 Connection/MockConnection.cs create mode 100644 Connection/MockConnectionFactory.cs create mode 100644 Connection/MockConnectionInfoBuilder.cs rename {Model => Connection}/RabbitMQClientConnection.cs (99%) rename {Model => Connection}/RabbitMQClientConnectionFactory.cs (87%) rename {Model => Connection}/RabbitMQProperties.cs (95%) rename {Model => Infrastructure}/MessageBodyRenderer.cs (96%) rename {Model => Infrastructure}/UserSettings.cs (97%) diff --git a/App.xaml.cs b/App.xaml.cs index 4089151..fad383f 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -5,7 +5,8 @@ using System.Reflection; using System.Windows; using System.Windows.Markup; using Newtonsoft.Json; -using PettingZoo.Model; +using PettingZoo.Connection; +using PettingZoo.Infrastructure; using PettingZoo.View; using PettingZoo.ViewModel; using SimpleInjector; @@ -34,6 +35,10 @@ namespace PettingZoo container.Register(); container.Register(); + //container.Register(() => new MockConnectionFactory(10)); + //container.Register(); + + container.Register(); container.Register(); diff --git a/Model/ConnectionInfo.cs b/Connection/ConnectionInfo.cs similarity index 91% rename from Model/ConnectionInfo.cs rename to Connection/ConnectionInfo.cs index 8ba3ba4..ba4abd2 100644 --- a/Model/ConnectionInfo.cs +++ b/Connection/ConnectionInfo.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Connection { public class ConnectionInfo { diff --git a/Model/IConnection.cs b/Connection/IConnection.cs similarity index 96% rename from Model/IConnection.cs rename to Connection/IConnection.cs index 394a721..deabd60 100644 --- a/Model/IConnection.cs +++ b/Connection/IConnection.cs @@ -1,6 +1,6 @@ using System; -namespace PettingZoo.Model +namespace PettingZoo.Connection { public enum ConnectionStatus { diff --git a/Model/IConnectionFactory.cs b/Connection/IConnectionFactory.cs similarity index 78% rename from Model/IConnectionFactory.cs rename to Connection/IConnectionFactory.cs index e1b6bd5..adf0655 100644 --- a/Model/IConnectionFactory.cs +++ b/Connection/IConnectionFactory.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Connection { public interface IConnectionFactory { diff --git a/Model/IConnectionInfoBuilder.cs b/Connection/IConnectionInfoBuilder.cs similarity index 72% rename from Model/IConnectionInfoBuilder.cs rename to Connection/IConnectionInfoBuilder.cs index bdd683c..3c4e13e 100644 --- a/Model/IConnectionInfoBuilder.cs +++ b/Connection/IConnectionInfoBuilder.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Connection { public interface IConnectionInfoBuilder { diff --git a/Model/MessageInfo.cs b/Connection/MessageInfo.cs similarity index 95% rename from Model/MessageInfo.cs rename to Connection/MessageInfo.cs index 7a29779..35de946 100644 --- a/Model/MessageInfo.cs +++ b/Connection/MessageInfo.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace PettingZoo.Model +namespace PettingZoo.Connection { public class MessageInfo { diff --git a/Connection/MockConnection.cs b/Connection/MockConnection.cs new file mode 100644 index 0000000..605cdd7 --- /dev/null +++ b/Connection/MockConnection.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace PettingZoo.Connection +{ + public class MockConnection : IConnection + { + private Timer messageTimer; + private bool connected; + + public MockConnection(int interval) + { + messageTimer = new Timer(state => + { + if (!connected) + { + StatusChanged(this, new StatusChangedEventArgs(ConnectionStatus.Connected, "Mock")); + connected = true; + } + + MessageReceived(this, new MessageReceivedEventArgs(new MessageInfo + { + Exchange = "mock", + RoutingKey = "mock.mock", + Timestamp = DateTime.Now, + Body = Encoding.UTF8.GetBytes("Mock!"), + Properties = new Dictionary + { + { "mock", "mock" } + }})); + }, null, interval, interval); + } + + + public void Dispose() + { + if (messageTimer != null) + { + messageTimer.Dispose(); + messageTimer = null; + } + } + + + public event EventHandler StatusChanged; + public event EventHandler MessageReceived; + } +} diff --git a/Connection/MockConnectionFactory.cs b/Connection/MockConnectionFactory.cs new file mode 100644 index 0000000..8e91d1f --- /dev/null +++ b/Connection/MockConnectionFactory.cs @@ -0,0 +1,17 @@ +namespace PettingZoo.Connection +{ + public class MockConnectionFactory : IConnectionFactory + { + private readonly int interval; + + public MockConnectionFactory(int interval) + { + this.interval = interval; + } + + public IConnection CreateConnection(ConnectionInfo connectionInfo) + { + return new MockConnection(interval); + } + } +} diff --git a/Connection/MockConnectionInfoBuilder.cs b/Connection/MockConnectionInfoBuilder.cs new file mode 100644 index 0000000..0c526e5 --- /dev/null +++ b/Connection/MockConnectionInfoBuilder.cs @@ -0,0 +1,10 @@ +namespace PettingZoo.Connection +{ + public class MockConnectionInfoBuilder : IConnectionInfoBuilder + { + public ConnectionInfo Build() + { + return new ConnectionInfo(); + } + } +} diff --git a/Model/RabbitMQClientConnection.cs b/Connection/RabbitMQClientConnection.cs similarity index 99% rename from Model/RabbitMQClientConnection.cs rename to Connection/RabbitMQClientConnection.cs index 0cd573d..85678f7 100644 --- a/Model/RabbitMQClientConnection.cs +++ b/Connection/RabbitMQClientConnection.cs @@ -8,7 +8,7 @@ using PettingZoo.Properties; using RabbitMQ.Client; using RabbitMQ.Client.Events; -namespace PettingZoo.Model +namespace PettingZoo.Connection { public class RabbitMQClientConnection : IConnection { diff --git a/Model/RabbitMQClientConnectionFactory.cs b/Connection/RabbitMQClientConnectionFactory.cs similarity index 87% rename from Model/RabbitMQClientConnectionFactory.cs rename to Connection/RabbitMQClientConnectionFactory.cs index d61aa3e..77cbc78 100644 --- a/Model/RabbitMQClientConnectionFactory.cs +++ b/Connection/RabbitMQClientConnectionFactory.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Connection { public class RabbitMQClientConnectionFactory : IConnectionFactory { diff --git a/Model/RabbitMQProperties.cs b/Connection/RabbitMQProperties.cs similarity index 95% rename from Model/RabbitMQProperties.cs rename to Connection/RabbitMQProperties.cs index a8378b5..8d72610 100644 --- a/Model/RabbitMQProperties.cs +++ b/Connection/RabbitMQProperties.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Connection { static class RabbitMQProperties { diff --git a/Infrastructure/ListBoxAutoScroll.cs b/Infrastructure/ListBoxAutoScroll.cs index 4d2415c..25d3e00 100644 --- a/Infrastructure/ListBoxAutoScroll.cs +++ b/Infrastructure/ListBoxAutoScroll.cs @@ -109,7 +109,7 @@ namespace PettingZoo.Infrastructure return; } - if (Math.Abs(scrollViewer.VerticalOffset - scrollViewer.ScrollableHeight) < 1) + if (Math.Abs(scrollViewer.VerticalOffset - scrollViewer.ScrollableHeight) <= 1) target.ScrollIntoView(e.NewItems[e.NewItems.Count - 1]); } diff --git a/Model/MessageBodyRenderer.cs b/Infrastructure/MessageBodyRenderer.cs similarity index 96% rename from Model/MessageBodyRenderer.cs rename to Infrastructure/MessageBodyRenderer.cs index 1ba2e62..5030eb2 100644 --- a/Model/MessageBodyRenderer.cs +++ b/Infrastructure/MessageBodyRenderer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using Newtonsoft.Json; -namespace PettingZoo.Model +namespace PettingZoo.Infrastructure { public class MessageBodyRenderer { diff --git a/Model/UserSettings.cs b/Infrastructure/UserSettings.cs similarity index 97% rename from Model/UserSettings.cs rename to Infrastructure/UserSettings.cs index cefe00b..cd2e5eb 100644 --- a/Model/UserSettings.cs +++ b/Infrastructure/UserSettings.cs @@ -1,4 +1,4 @@ -namespace PettingZoo.Model +namespace PettingZoo.Infrastructure { public interface IUserSettingsSerializer { diff --git a/PettingZoo.csproj b/PettingZoo.csproj index 6b2b336..f0ac76d 100644 --- a/PettingZoo.csproj +++ b/PettingZoo.csproj @@ -113,21 +113,24 @@ App.xaml Code + + + - - - - - - - - - - + + + + + + + + + + diff --git a/View/ConnectionWindow.xaml.cs b/View/ConnectionWindow.xaml.cs index d0e94a0..0b91428 100644 --- a/View/ConnectionWindow.xaml.cs +++ b/View/ConnectionWindow.xaml.cs @@ -1,7 +1,8 @@ using System.Windows; using System.Windows.Input; using AutoMapper; -using PettingZoo.Model; +using PettingZoo.Connection; +using PettingZoo.Infrastructure; using PettingZoo.ViewModel; namespace PettingZoo.View diff --git a/ViewModel/ConnectionViewModel.cs b/ViewModel/ConnectionViewModel.cs index 367eb50..e4da5cb 100644 --- a/ViewModel/ConnectionViewModel.cs +++ b/ViewModel/ConnectionViewModel.cs @@ -1,8 +1,8 @@ using System; using System.Windows.Input; using AutoMapper; +using PettingZoo.Connection; using PettingZoo.Infrastructure; -using PettingZoo.Model; namespace PettingZoo.ViewModel { diff --git a/ViewModel/MainViewModel.cs b/ViewModel/MainViewModel.cs index e392b36..6fe8ef1 100644 --- a/ViewModel/MainViewModel.cs +++ b/ViewModel/MainViewModel.cs @@ -4,8 +4,8 @@ using System.Collections.ObjectModel; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; +using PettingZoo.Connection; using PettingZoo.Infrastructure; -using PettingZoo.Model; using PettingZoo.Properties; namespace PettingZoo.ViewModel @@ -188,13 +188,13 @@ namespace PettingZoo.ViewModel if (args != null) switch (args.Status) { - case Model.ConnectionStatus.Connecting: + case Connection.ConnectionStatus.Connecting: return String.Format(Resources.StatusConnecting, args.Context); - case Model.ConnectionStatus.Connected: + case Connection.ConnectionStatus.Connected: return String.Format(Resources.StatusConnected, args.Context); - case Model.ConnectionStatus.Error: + case Connection.ConnectionStatus.Error: return String.Format(Resources.StatusError, args.Context); }