Skip to content

Commit

Permalink
Merge pull request #18 from dojo90/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
djonasdev committed Feb 17, 2020
2 parents 4adbf27 + f4701dd commit 5bf556d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/NLogViewer.TestApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<dj:NLogViewer x:Name="NLogViewer1" Grid.Row="2" MaxCount="1000" TargetName="target1"/>
<TextBlock Grid.Row="4" Text="Target 2 (Warn and Error)" FontSize="18"></TextBlock>
<dj:NLogViewer Grid.Row="6" MaxCount="1000" TargetName="target2"/>
<Button Grid.Row="0" Grid.RowSpan="2" Margin="5" Content="Open Popup" HorizontalAlignment="Right" VerticalAlignment="Top" Click="ButtonBase_OnClick"/>
</Grid>
</Window>
6 changes: 6 additions & 0 deletions src/NLogViewer.TestApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public MainWindow()
}
});
}

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
TestPopup popup = new TestPopup();
popup.Show();
}
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions src/NLogViewer.TestApp/TestPopup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window x:Class="TestApplication.TestPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestApplication"
xmlns:dj="clr-namespace:DJ;assembly=NLogViewer"
mc:Ignorable="d"
Title="TestPopup" Height="450" Width="800">
<Grid>
<dj:NLogViewer TargetName="target1"/>
</Grid>
</Window>
25 changes: 25 additions & 0 deletions src/NLogViewer.TestApp/TestPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TestApplication
{
/// <summary>
/// Interaktionslogik für TestPopup.xaml
/// </summary>
public partial class TestPopup : Window
{
public TestPopup()
{
InitializeComponent();
}
}
}
37 changes: 32 additions & 5 deletions src/NLogViewer/NLogViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,8 @@ public ILogEventInfoResolver MessageResolver
// ##########################################################################################

private ObservableCollection<LogEventInfo> _LogEventInfos { get; } = new ObservableCollection<LogEventInfo>();




private IDisposable _Subscription;

#endregion

// ##############################################################################################################################
Expand All @@ -471,13 +469,42 @@ public NLogViewer()
ClearCommand = new ActionCommand(_LogEventInfos.Clear);
}

private void _ParentWindowOnClosed(object? sender, EventArgs e)
{
_Dispose();
}

// check if the parent visual has been changed
// can happen if you use the control on a page
protected override void OnVisualParentChanged(DependencyObject oldParent)
{
if (oldParent != null)
{
_Dispose();
}
base.OnVisualParentChanged(oldParent);
}

private void _Dispose()
{
_Subscription?.Dispose();
}

private void _OnLoaded(object sender, RoutedEventArgs e)
{
// removed loaded handler to prevent duplicate subscribing
Loaded -= _OnLoaded;

// add hook to parent window to dispose subscription
var parentWindow = Window.GetWindow(this);
if(parentWindow != null)
parentWindow.Closed += _ParentWindowOnClosed;

ListView.ScrollToEnd();

var target = CacheTarget.GetInstance(targetName: TargetName);

target.Cache.SubscribeOn(Scheduler.Default).Buffer(TimeSpan.FromMilliseconds(100)).Where (x => x.Any()).ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(infos =>
_Subscription = target.Cache.SubscribeOn(Scheduler.Default).Buffer(TimeSpan.FromMilliseconds(100)).Where (x => x.Any()).ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(infos =>
{
if (Pause) return;
using (LogEvents.DeferRefresh())
Expand Down

0 comments on commit 5bf556d

Please sign in to comment.