1
0
mirror of synced 2024-11-25 04:03:08 +01:00

Changed Model namespace to Connection, moved bits out to Infrastructure

Added Mock connection
Fixed AutoScroll failing with high rate message flow
This commit is contained in:
PsychoMark 2016-07-12 16:57:24 +02:00
parent 12d2161117
commit ccfde19d2d
19 changed files with 114 additions and 28 deletions

View File

@ -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<IConnectionFactory, RabbitMQClientConnectionFactory>();
container.Register<IConnectionInfoBuilder, WindowConnectionInfoBuilder>();
//container.Register<IConnectionFactory>(() => new MockConnectionFactory(10));
//container.Register<IConnectionInfoBuilder, MockConnectionInfoBuilder>();
container.Register<MainWindow>();
container.Register<MainViewModel>();

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public class ConnectionInfo
{

View File

@ -1,6 +1,6 @@
using System;
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public enum ConnectionStatus
{

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public interface IConnectionFactory
{

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public interface IConnectionInfoBuilder
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public class MessageInfo
{

View File

@ -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<string, string>
{
{ "mock", "mock" }
}}));
}, null, interval, interval);
}
public void Dispose()
{
if (messageTimer != null)
{
messageTimer.Dispose();
messageTimer = null;
}
}
public event EventHandler<StatusChangedEventArgs> StatusChanged;
public event EventHandler<MessageReceivedEventArgs> MessageReceived;
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,10 @@
namespace PettingZoo.Connection
{
public class MockConnectionInfoBuilder : IConnectionInfoBuilder
{
public ConnectionInfo Build()
{
return new ConnectionInfo();
}
}
}

View File

@ -8,7 +8,7 @@ using PettingZoo.Properties;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public class RabbitMQClientConnection : IConnection
{

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
public class RabbitMQClientConnectionFactory : IConnectionFactory
{

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Connection
{
static class RabbitMQProperties
{

View File

@ -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]);
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
namespace PettingZoo.Model
namespace PettingZoo.Infrastructure
{
public class MessageBodyRenderer
{

View File

@ -1,4 +1,4 @@
namespace PettingZoo.Model
namespace PettingZoo.Infrastructure
{
public interface IUserSettingsSerializer
{

View File

@ -113,21 +113,24 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Connection\MockConnection.cs" />
<Compile Include="Connection\MockConnectionFactory.cs" />
<Compile Include="Connection\MockConnectionInfoBuilder.cs" />
<Compile Include="Infrastructure\DelegateCommand.cs" />
<Compile Include="Infrastructure\BaseViewModel.cs" />
<Compile Include="Infrastructure\GridLayout.cs" />
<Compile Include="Infrastructure\ListBoxAutoScroll.cs" />
<Compile Include="Infrastructure\PasswordBoxAssistant.cs" />
<Compile Include="Model\UserSettings.cs" />
<Compile Include="Model\IConnection.cs" />
<Compile Include="Model\IConnectionFactory.cs" />
<Compile Include="Model\IConnectionInfoBuilder.cs" />
<Compile Include="Model\ConnectionInfo.cs" />
<Compile Include="Model\MessageBodyRenderer.cs" />
<Compile Include="Model\MessageInfo.cs" />
<Compile Include="Model\RabbitMQClientConnection.cs" />
<Compile Include="Model\RabbitMQClientConnectionFactory.cs" />
<Compile Include="Model\RabbitMQProperties.cs" />
<Compile Include="Infrastructure\UserSettings.cs" />
<Compile Include="Connection\IConnection.cs" />
<Compile Include="Connection\IConnectionFactory.cs" />
<Compile Include="Connection\IConnectionInfoBuilder.cs" />
<Compile Include="Connection\ConnectionInfo.cs" />
<Compile Include="Infrastructure\MessageBodyRenderer.cs" />
<Compile Include="Connection\MessageInfo.cs" />
<Compile Include="Connection\RabbitMQClientConnection.cs" />
<Compile Include="Connection\RabbitMQClientConnectionFactory.cs" />
<Compile Include="Connection\RabbitMQProperties.cs" />
<Compile Include="ViewModel\ConnectionViewModel.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="View\ConnectionWindow.xaml.cs">

View File

@ -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

View File

@ -1,8 +1,8 @@
using System;
using System.Windows.Input;
using AutoMapper;
using PettingZoo.Connection;
using PettingZoo.Infrastructure;
using PettingZoo.Model;
namespace PettingZoo.ViewModel
{

View File

@ -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);
}