diff --git a/PettingZoo.Test/Tapeti/TypeToJObjectTest.cs b/PettingZoo.Test/Tapeti/TypeToJObjectTest.cs
index a02dcb0..de554a0 100644
--- a/PettingZoo.Test/Tapeti/TypeToJObjectTest.cs
+++ b/PettingZoo.Test/Tapeti/TypeToJObjectTest.cs
@@ -34,7 +34,7 @@ namespace PettingZoo.Test.Tapeti
objectValue.Should().HaveElement("RecursiveValue").Which.Type.Should().Be(JTokenType.Null);
// Via type mapping
- // TODO
+ // TODO test type mappings
}
}
diff --git a/PettingZoo/UI/Tab/Subscriber/SameMessageVisibilityConverter.cs b/PettingZoo/UI/Tab/Subscriber/SameMessageVisibilityConverter.cs
new file mode 100644
index 0000000..4f6df58
--- /dev/null
+++ b/PettingZoo/UI/Tab/Subscriber/SameMessageVisibilityConverter.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PettingZoo.UI.Tab.Subscriber
+{
+ public class SameMessageVisibilityConverter : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ return ReferenceEquals(values[0], values[1])
+ ? Visibility.Visible
+ : Visibility.Collapsed;
+ }
+
+
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}
diff --git a/PettingZoo/UI/Tab/Subscriber/SubscriberView.xaml b/PettingZoo/UI/Tab/Subscriber/SubscriberView.xaml
index 95a1f1b..5684e93 100644
--- a/PettingZoo/UI/Tab/Subscriber/SubscriberView.xaml
+++ b/PettingZoo/UI/Tab/Subscriber/SubscriberView.xaml
@@ -11,6 +11,9 @@
d:DesignWidth="800"
d:DataContext="{d:DesignInstance res:DesignTimeSubscriberViewModel, IsDesignTimeCreatable=True}"
Background="White">
+
+
+
@@ -30,11 +33,37 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -66,6 +95,8 @@
+
+
newMessage;
+ set => SetField(ref newMessage, value);
+ }
+
+
public string SelectedMessageBody =>
SelectedMessage != null
? MessageBodyRenderer.Render(SelectedMessage.Body, SelectedMessage.Properties.ContentType)
@@ -70,8 +82,8 @@ namespace PettingZoo.UI.Tab.Subscriber
this.tabFactory = tabFactory;
this.connection = connection;
this.subscriber = subscriber;
-
- uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
+
+ dispatcher = Dispatcher.CurrentDispatcher;
Messages = new ObservableCollection();
clearCommand = new DelegateCommand(ClearExecute, ClearCanExecute);
@@ -116,12 +128,14 @@ namespace PettingZoo.UI.Tab.Subscriber
private void SubscriberMessageReceived(object? sender, MessageReceivedEventArgs args)
{
- RunFromUiScheduler(() =>
+ dispatcher.BeginInvoke(() =>
{
if (!tabActive)
{
unreadCount++;
RaisePropertyChanged(nameof(Title));
+
+ NewMessage ??= args.MessageInfo;
}
Messages.Add(args.MessageInfo);
@@ -140,22 +154,39 @@ namespace PettingZoo.UI.Tab.Subscriber
}
- private void RunFromUiScheduler(Action action)
- {
- _ = Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, uiScheduler);
- }
-
-
public void Activate()
{
tabActive = true;
unreadCount = 0;
RaisePropertyChanged(nameof(Title));
+
+ if (NewMessage == null)
+ return;
+
+ newMessageTimer?.Dispose();
+ newMessageTimer = new Timer(
+ _ =>
+ {
+ dispatcher.BeginInvoke(() =>
+ {
+ NewMessage = null;
+ });
+ },
+ null,
+ TimeSpan.FromSeconds(5),
+ Timeout.InfiniteTimeSpan);
}
public void Deactivate()
{
+ if (newMessageTimer != null)
+ {
+ newMessageTimer.Dispose();
+ newMessageTimer = null;
+ }
+
+ NewMessage = null;
tabActive = false;
}
}
@@ -165,6 +196,20 @@ namespace PettingZoo.UI.Tab.Subscriber
{
public DesignTimeSubscriberViewModel() : base(null!, null!, null!, new DesignTimeSubscriber())
{
+ for (var i = 1; i <= 5; i++)
+ Messages.Add(new ReceivedMessageInfo(
+ "designtime",
+ $"designtime.message.{i}",
+ Encoding.UTF8.GetBytes(@"Design-time message"),
+ new MessageProperties(null)
+ {
+ ContentType = "text/fake",
+ ReplyTo = "/dev/null"
+ },
+ DateTime.Now));
+
+ SelectedMessage = Messages[2];
+ NewMessage = Messages[2];
}
diff --git a/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.Designer.cs b/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.Designer.cs
index 11f6be5..38af1ff 100644
--- a/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.Designer.cs
+++ b/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.Designer.cs
@@ -96,6 +96,15 @@ namespace PettingZoo.UI.Tab.Subscriber {
}
}
+ ///
+ /// Looks up a localized string similar to New messages.
+ ///
+ public static string LabelNewMessages {
+ get {
+ return ResourceManager.GetString("LabelNewMessages", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Body.
///
diff --git a/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.resx b/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.resx
index 459982b..e0d0afa 100644
--- a/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.resx
+++ b/PettingZoo/UI/Tab/Subscriber/SubscriberViewStrings.resx
@@ -112,10 +112,10 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Clear
@@ -129,6 +129,9 @@
Persistent
+
+ New messages
+
Body
diff --git a/PettingZoo/UI/Tab/Undocked/UndockedTabHostViewModel.cs b/PettingZoo/UI/Tab/Undocked/UndockedTabHostViewModel.cs
index 9c139bc..bd46f75 100644
--- a/PettingZoo/UI/Tab/Undocked/UndockedTabHostViewModel.cs
+++ b/PettingZoo/UI/Tab/Undocked/UndockedTabHostViewModel.cs
@@ -8,7 +8,7 @@ using PettingZoo.WPF.ViewModel;
namespace PettingZoo.UI.Tab.Undocked
{
- public class UndockedTabHostViewModel : BaseViewModel
+ public class UndockedTabHostViewModel : BaseViewModel, ITabActivate
{
private readonly ITabHost tabHost;
private readonly ITab tab;
@@ -51,6 +51,17 @@ namespace PettingZoo.UI.Tab.Undocked
{
tabHost.UndockedTabClosed(tab);
}
+
+
+ public void Activate()
+ {
+ (tab as ITabActivate)?.Activate();
+ }
+
+ public void Deactivate()
+ {
+ (tab as ITabActivate)?.Deactivate();
+ }
}
diff --git a/PettingZoo/UI/Tab/Undocked/UndockedTabHostWindow.xaml.cs b/PettingZoo/UI/Tab/Undocked/UndockedTabHostWindow.xaml.cs
index 21ac421..1ea5fa5 100644
--- a/PettingZoo/UI/Tab/Undocked/UndockedTabHostWindow.xaml.cs
+++ b/PettingZoo/UI/Tab/Undocked/UndockedTabHostWindow.xaml.cs
@@ -1,5 +1,7 @@
-using System.Windows;
+using System;
+using System.Windows;
using System.Windows.Controls;
+using System.Windows.Threading;
namespace PettingZoo.UI.Tab.Undocked
{
@@ -30,6 +32,16 @@ namespace PettingZoo.UI.Tab.Undocked
{
viewModel.WindowClosed();
};
+
+ Activated += (_, _) =>
+ {
+ viewModel.Activate();
+ };
+
+ Deactivated += (_, _) =>
+ {
+ viewModel.Deactivate();
+ };
}
private void Toolbar_Loaded(object sender, RoutedEventArgs e)