diff --git a/Infrastructure/BaseViewModel.cs b/Infrastructure/BaseViewModel.cs index 1899ac8..152d71b 100644 --- a/Infrastructure/BaseViewModel.cs +++ b/Infrastructure/BaseViewModel.cs @@ -10,7 +10,15 @@ namespace PettingZoo.Infrastructure protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) { var handler = PropertyChanged; - if (handler != null) + if (handler != null) + handler(this, new PropertyChangedEventArgs(propertyName)); + } + + + protected virtual void RaiseOtherPropertyChanged(string propertyName) + { + var handler = PropertyChanged; + if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/Model/ConnectionInfo.cs b/Model/ConnectionInfo.cs index d9e0ae9..44955da 100644 --- a/Model/ConnectionInfo.cs +++ b/Model/ConnectionInfo.cs @@ -7,5 +7,22 @@ public int Port { get; set; } public string Username { get; set; } public string Password { get; set; } + + public string Exchange { get; set; } + public string RoutingKey { get; set; } + + + public static ConnectionInfo Default() + { + return new ConnectionInfo() + { + Host = "localhost", + Port = 5672, + VirtualHost = "/", + Username = "guest", + Password = "guest", + RoutingKey = "#" + }; + } } } diff --git a/Model/IConnection.cs b/Model/IConnection.cs index fbca3a0..a0967e8 100644 --- a/Model/IConnection.cs +++ b/Model/IConnection.cs @@ -2,7 +2,20 @@ namespace PettingZoo.Model { + public class MessageReceivedEventArgs : EventArgs + { + public MessageInfo MessageInfo { get; private set; } + + + public MessageReceivedEventArgs(MessageInfo messageInfo) + { + MessageInfo = messageInfo; + } + } + + public interface IConnection : IDisposable { + event EventHandler MessageReceived; } } diff --git a/Model/MessageInfo.cs b/Model/MessageInfo.cs new file mode 100644 index 0000000..2c8249d --- /dev/null +++ b/Model/MessageInfo.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace PettingZoo.Model +{ + public class MessageInfo + { + public string RoutingKey { get; set; } + public byte[] Body { get; set; } + + public Dictionary Properties; + + public string ContentType + { + get + { + return Properties != null && Properties.ContainsKey("content-type") + ? Properties["content-type"] + : ""; + } + } + } +} diff --git a/Model/RabbitMQClientConnection.cs b/Model/RabbitMQClientConnection.cs index 36eeaa0..9570b07 100644 --- a/Model/RabbitMQClientConnection.cs +++ b/Model/RabbitMQClientConnection.cs @@ -1,15 +1,50 @@ -namespace PettingZoo.Model +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace PettingZoo.Model { public class RabbitMQClientConnection : IConnection { + private readonly CancellationTokenSource timer; + public RabbitMQClientConnection(ConnectionInfo connectionInfo) { - + timer = new CancellationTokenSource(); + var token = timer.Token; + + Task.Run(() => + { + while (true) + { + if (token.IsCancellationRequested) + break; + + if (MessageReceived != null) + MessageReceived(null, new MessageReceivedEventArgs(new MessageInfo() + { + RoutingKey = "test", + Body = Encoding.UTF8.GetBytes("{ \"hello\": \"world\" }"), + Properties = new Dictionary + { + { "content-type", "application/json" }, + { "classType", "LEF.Messaging.Internal.ActieNewMessage" } + } + })); + Thread.Sleep(1000); + } + }, token); } public void Dispose() { + timer.Cancel(); } + + + public event EventHandler MessageReceived; } } diff --git a/PettingZoo.csproj b/PettingZoo.csproj index 3aca9b9..52c51cc 100644 --- a/PettingZoo.csproj +++ b/PettingZoo.csproj @@ -54,6 +54,10 @@ + + packages\AutoMapper.4.2.1\lib\net45\AutoMapper.dll + True + packages\SimpleInjector.3.1.5\lib\net45\SimpleInjector.dll True @@ -101,6 +105,8 @@ + + diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 9dd44d7..fe8785f 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -158,5 +158,41 @@ namespace PettingZoo.Properties { return ResourceManager.GetString("MainWindowTitle", resourceCulture); } } + + /// + /// Looks up a localized string similar to Body. + /// + public static string PanelTitleBody { + get { + return ResourceManager.GetString("PanelTitleBody", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Properties. + /// + public static string PanelTitleProperties { + get { + return ResourceManager.GetString("PanelTitleProperties", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Name. + /// + public static string PropertyName { + get { + return ResourceManager.GetString("PropertyName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Value. + /// + public static string PropertyValue { + get { + return ResourceManager.GetString("PropertyValue", resourceCulture); + } + } } } diff --git a/Properties/Resources.resx b/Properties/Resources.resx index adb4605..3aa7bff 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -150,4 +150,16 @@ Petting Zoo - a RabbitMQ Message Viewer + + Body + + + Properties + + + Name + + + Value + \ No newline at end of file diff --git a/Style.xaml b/Style.xaml index 0d55ae3..c73d6b9 100644 --- a/Style.xaml +++ b/Style.xaml @@ -11,6 +11,16 @@ + + + + @@ -23,4 +33,11 @@ + + + \ No newline at end of file diff --git a/View/ConnectionWindow.xaml b/View/ConnectionWindow.xaml index 3db6fa0..29b3776 100644 --- a/View/ConnectionWindow.xaml +++ b/View/ConnectionWindow.xaml @@ -17,7 +17,7 @@ FocusManager.FocusedElement="{Binding ElementName=HostTextBox}"> -