Skip to content

Commit

Permalink
Merge pull request #1681 from pybride/BetterUC
Browse files Browse the repository at this point in the history
Improving handling of custom control linked to log tabs
  • Loading branch information
LiorBanai authored Mar 31, 2023
2 parents 14c212c + e263416 commit 311d56d
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 78 deletions.
6 changes: 3 additions & 3 deletions Analogy.Common/Analogy.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

</ItemGroup>
<ItemGroup>
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.0" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.2" />
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
Expand Down
4 changes: 1 addition & 3 deletions Analogy.Common/Interfaces/ILogWindow.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Analogy.Interfaces;

namespace Analogy.Common.Interfaces
{
public interface ILogWindow
{
List<IAnalogyLogMessage> GetMessages();
Guid Id { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.0" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'net471' ">
<PackageReference Include="PolySharp" Version="1.12.1">
Expand Down
5 changes: 2 additions & 3 deletions Analogy.CommonControls/Analogy.CommonControls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.0" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.2" />
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.3" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="MessagePack" Version="2.5.108" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
Expand Down
72 changes: 47 additions & 25 deletions Analogy.CommonControls/UserControls/LogMessagesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public bool RealTimeMode
public LogMessagesUC(IUserSettingsManager userSettingsManager, IExtensionsManager extensionManager, IFactoriesManager factoriesManager, IAnalogyLogger logger)
{
Logger = logger;
Id = Guid.NewGuid();
Settings = userSettingsManager;
ExtensionManager = extensionManager;
FactoriesManager = factoriesManager;
Expand Down Expand Up @@ -303,7 +304,6 @@ public LogMessagesUC(IUserSettingsManager userSettingsManager, IExtensionsManage
_filterCriteria.IncludeFilterCriteriaUIOptions = IncludeFilterCriteriaUIOptions;
_filterCriteria.ExcludeFilterCriteriaUIOptions = ExcludeFilterCriteriaUIOptions;


}

private async void LogMessagesUC_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -347,6 +347,16 @@ private async void LogMessagesUC_Load(object sender, EventArgs e)
LoadReplacementHeaders();
HideColumns();
BookmarkModeUI();


if (!string.IsNullOrEmpty(Settings.LogsLayoutFileName) && File.Exists(Settings.LogsLayoutFileName))
{
string name = Path.GetFileNameWithoutExtension(Settings.LogsLayoutFileName);
wsLogs.LoadWorkspace(name, Settings.LogsLayoutFileName);
wsLogs.ApplyWorkspace(name);
}
LoadWorkspace(CurrentLogLayoutFileName);

await LoadExtensions();
SetupEventsHandlers();

Expand Down Expand Up @@ -392,9 +402,9 @@ private async void LogMessagesUC_Load(object sender, EventArgs e)

private void HideColumns()
{
if (DataProvider.HideColumns() != null)
if (DataProvider.HideAdditionalColumns() != null)
{
foreach (string columnFieldName in DataProvider.HideColumns())
foreach (string columnFieldName in DataProvider.HideAdditionalColumns())
{
var column = logGrid.Columns.ColumnByFieldName(columnFieldName);
if (column != null)
Expand All @@ -403,6 +413,17 @@ private void HideColumns()
}
}
}
if (DataProvider.HideExistingColumns() != null)
{
foreach (AnalogyLogMessagePropertyName columnFieldName in DataProvider.HideExistingColumns())
{
var column = logGrid.Columns.ColumnByFieldName(columnFieldName.ToString());
if (column != null)
{
column.Visible = false;
}
}
}
}

public void LoadWorkspace(string fileName)
Expand Down Expand Up @@ -1071,18 +1092,13 @@ private void LogGrid_MouseUp(object sender, MouseEventArgs e)
}
private void LoadReplacementHeaders()
{
if (DataProvider == null)
if (DataProvider?.GetReplacementHeaders() == null)
{
return;
}

try
{
if (DataProvider.GetReplacementHeaders() == null || !DataProvider.GetReplacementHeaders().Any())
{
return;
}

foreach ((string fieldName, string replacementHeader) in DataProvider.GetReplacementHeaders())
{
var column = logGrid.Columns.FirstOrDefault((col) => col.FieldName == fieldName);
Expand All @@ -1091,15 +1107,6 @@ private void LoadReplacementHeaders()
column.Caption = replacementHeader;
}
}

foreach (string fieldName in DataProvider.HideColumns())
{
var column = logGrid.Columns.FirstOrDefault((col) => col.FieldName == fieldName);
if (column != null)
{
column.Visible = false;
}
}
}
catch (Exception)
{
Expand Down Expand Up @@ -1439,11 +1446,25 @@ public async Task LoadExtensions()
}
foreach (IAnalogyExtensionUserControl extension in UserControlRegisteredExtensions)
{
var page = dockManager1.AddPanel(DockingStyle.Float);
page.Text = extension.Title;
page.Controls.Add(extension.UserControl);
await extension.InitializeUserControl(this, Logger);
page.DockedAsTabbedDocument = true;
DockPanel? pnl = dockManager1.Panels.FirstOrDefault(i => i.ID == extension.Id);
if (pnl == null)
{
pnl = dockManager1.AddPanel(DockingStyle.Float);
pnl.Text = extension.Title;
pnl.ID = extension.Id;
pnl.DockedAsTabbedDocument = true;
}
pnl.Controls.Add(extension.CreateUserControl(Id, Logger));
pnl.SizeChanged += ExtensionPanel_SizeChanged;
await extension.InitializeUserControl(this, Id, Logger);
}
}

private void ExtensionPanel_SizeChanged(object? sender, EventArgs e)
{
if (sender is DockPanel { Controls.Count: > 0 } pnl)
{
pnl.Controls[0].Size = pnl.Size;
}
}

Expand Down Expand Up @@ -1635,6 +1656,7 @@ internal DataTable GetFilteredDataTable()
}

public List<IAnalogyLogMessage> GetMessages() => PagingManager.GetAllMessages();
public Guid Id { get; }

private string GetFilterDisplayText(DateRangeFilter filterType)
{
Expand Down Expand Up @@ -1792,7 +1814,7 @@ public void AppendMessage(IAnalogyLogMessage message, string dataSource)
{
if (IsHandleCreated)
{
BeginInvoke(new MethodInvoker(() => extension.NewMessage(message)));
BeginInvoke(new MethodInvoker(() => extension.NewMessage(message, Id)));
}
}
}
Expand Down Expand Up @@ -1909,7 +1931,7 @@ public void AppendMessages(List<IAnalogyLogMessage> messages, string dataSource)
{
foreach (var extension in UserControlRegisteredExtensions)
{
BeginInvoke(new MethodInvoker(() => extension.NewMessages(messages)));
BeginInvoke(new MethodInvoker(() => extension.NewMessages(messages, Id)));
}
}

Expand Down
52 changes: 34 additions & 18 deletions Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public bool RealTimeMode
public ServerSideLogMessagesUC(IUserSettingsManager userSettingsManager, IExtensionsManager extensionManager, IFactoriesManager factoriesManager, IAnalogyLogger logger)
{
Logger = logger;
Id = Guid.NewGuid();
Settings = userSettingsManager;
ExtensionManager = extensionManager;
FactoriesManager = factoriesManager;
Expand Down Expand Up @@ -260,6 +261,7 @@ private async void LogMessagesUC_Load(object sender, EventArgs e)

LoadUISettings();
LoadReplacementHeaders();
HideColumns();
BookmarkModeUI();
await LoadExtensions();
SetupEventsHandlers();
Expand Down Expand Up @@ -936,20 +938,41 @@ private void LogGrid_MouseUp(object sender, MouseEventArgs e)
LogGridPopupMenu.ShowPopup(Cursor.Position);
}
}
private void HideColumns()
{
if (DataProvider.HideAdditionalColumns() != null)
{
foreach (string columnFieldName in DataProvider.HideAdditionalColumns())
{
var column = logGrid.Columns.ColumnByFieldName(columnFieldName);
if (column != null)
{
column.Visible = false;
}
}
}
if (DataProvider.HideExistingColumns() != null)
{
foreach (AnalogyLogMessagePropertyName columnFieldName in DataProvider.HideExistingColumns())
{
var column = logGrid.Columns.ColumnByFieldName(columnFieldName.ToString());
if (column != null)
{
column.Visible = false;
}
}
}
}

private void LoadReplacementHeaders()
{
if (DataProvider == null)
if (DataProvider?.GetReplacementHeaders() == null)
{
return;
}

try
{
if (DataProvider.GetReplacementHeaders() == null || !DataProvider.GetReplacementHeaders().Any())
{
return;
}

foreach ((string fieldName, string replacementHeader) in DataProvider.GetReplacementHeaders())
{
var column = logGrid.Columns.FirstOrDefault((col) => col.FieldName == fieldName);
Expand All @@ -959,14 +982,6 @@ private void LoadReplacementHeaders()
}
}

foreach (string fieldName in DataProvider.HideColumns())
{
var column = logGrid.Columns.FirstOrDefault((col) => col.FieldName == fieldName);
if (column != null)
{
column.Visible = false;
}
}
}
catch (Exception)
{
Expand Down Expand Up @@ -1307,8 +1322,8 @@ public async Task LoadExtensions()
{
var page = dockManager1.AddPanel(DockingStyle.Float);
page.Text = extension.Title;
page.Controls.Add(extension.UserControl);
await extension.InitializeUserControl(this, Logger);
page.Controls.Add(extension.CreateUserControl(Id, Logger));
await extension.InitializeUserControl(this, Id, Logger);
page.DockedAsTabbedDocument = true;
}
}
Expand Down Expand Up @@ -1501,6 +1516,7 @@ internal DataTable GetFilteredDataTable()
}

public List<IAnalogyLogMessage> GetMessages() => PagingManager.GetAllMessages();
public Guid Id { get; }

private string GetFilterDisplayText(DateRangeFilter filterType)
{
Expand Down Expand Up @@ -1650,7 +1666,7 @@ public void AppendMessage(IAnalogyLogMessage message, string dataSource)
{
if (IsHandleCreated)
{
BeginInvoke(new MethodInvoker(() => extension.NewMessage(message)));
BeginInvoke(new MethodInvoker(() => extension.NewMessage(message, Id)));
}
}
}
Expand Down Expand Up @@ -1763,7 +1779,7 @@ public void AppendMessages(List<IAnalogyLogMessage> messages, string dataSource)
{
foreach (var extension in UserControlRegisteredExtensions)
{
BeginInvoke(new MethodInvoker(() => extension.NewMessages(messages)));
BeginInvoke(new MethodInvoker(() => extension.NewMessages(messages, Id)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Analogy.UnitTests/Analogy.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
</PropertyGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<ItemGroup>
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.0" />
<PackageReference Include="Analogy.LogViewer.Serilog" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Serilog" Version="3.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
Expand Down
5 changes: 5 additions & 0 deletions Analogy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analogy.CommonControls.Exam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analogy.Common", "Analogy.Common\Analogy.Common.csproj", "{42A38B8A-CDCF-477A-8BC6-1A4685CD5255}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F5E34202-7C91-45AB-94DA-A8934FE3D3B6}"
ProjectSection(SolutionItems) = preProject
nuget.config = nuget.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
38 changes: 19 additions & 19 deletions Analogy/Analogy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@
<EmbeddedResource Remove="UserControls\UCLogsNonFloatable.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.0" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.2" />
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.XMLParser" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Example" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.IISLogsProvider" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Log4Net" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.NLogProvider" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.PlainTextParser" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.RegexParser" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.WindowsEventLogs" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Serilog" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.GitHistory" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Github" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.gRPC" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.JsonParser" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.WordsSearch" Version="3.8.2" />
<PackageReference Include="Analogy.LogViewer.Sqlite" Version="0.4.0" />
<PackageReference Include="Analogy.LogViewer.PowerToys" Version="0.11.0" />
<PackageReference Include="Analogy.LogViewer.Interfaces" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Template" Version="3.8.3" />
<PackageReference Include="Analogy.CommonUtilities" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.XMLParser" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Example" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.IISLogsProvider" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Log4Net" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.NLogProvider" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.PlainTextParser" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.RegexParser" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.WindowsEventLogs" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Serilog" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.GitHistory" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Github" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.gRPC" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.JsonParser" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.WordsSearch" Version="3.8.3" />
<PackageReference Include="Analogy.LogViewer.Sqlite" Version="0.4.1" />
<PackageReference Include="Analogy.LogViewer.PowerToys" Version="0.12.0" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="MessagePack" Version="2.5.108" />
Expand Down
Loading

0 comments on commit 311d56d

Please sign in to comment.