diff --git a/.editorconfig b/.editorconfig index fa05938..d0f7487 100644 --- a/.editorconfig +++ b/.editorconfig @@ -273,6 +273,8 @@ dotnet_diagnostic.SA1122.severity = suggestion dotnet_diagnostic.SA1108.severity = silent dotnet_diagnostic.SA1012.severity = error dotnet_diagnostic.SA1500.severity = error +dotnet_diagnostic.SA1316.severity = error +dotnet_diagnostic.SA0001.severity = none [*.{cs,vb}] dotnet_style_operator_placement_when_wrapping = beginning_of_line diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml index 5938607..041b41e 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -28,13 +28,13 @@ jobs: # Install the .NET Core workload - name: Install .NET Core - uses: actions/setup-dotnet@v3.0.3 + uses: actions/setup-dotnet@v3.2.0 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild - name: Setup MSBuild.exe - uses: microsoft/setup-msbuild@v1.1.3 + uses: microsoft/setup-msbuild@v1.3.1 # Restore the application to populate the obj folder with RuntimeIdentifiers - name: Restore the application diff --git a/Analogy.LogViewer.LoggersTree.sln b/Analogy.LogViewer.LoggersTree.sln index 23ff712..af49296 100644 --- a/Analogy.LogViewer.LoggersTree.sln +++ b/Analogy.LogViewer.LoggersTree.sln @@ -1,10 +1,18 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.33423.256 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analogy.LogViewer.LoggersTree", "Analogy.LogViewer.LoggersTree\Analogy.LogViewer.LoggersTree.csproj", "{64D48D17-F26B-4DD7-94B5-72C5A9D47B8D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{778229A3-FA54-4CBF-86AA-8002445FAD0B}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props + .github\workflows\dotnet-core-desktop.yml = .github\workflows\dotnet-core-desktop.yml + nuget.config = nuget.config + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Analogy.LogViewer.LoggersTree/Analogy.LogViewer.LoggersTree.csproj b/Analogy.LogViewer.LoggersTree/Analogy.LogViewer.LoggersTree.csproj index 00e0161..276fcf7 100644 --- a/Analogy.LogViewer.LoggersTree/Analogy.LogViewer.LoggersTree.csproj +++ b/Analogy.LogViewer.LoggersTree/Analogy.LogViewer.LoggersTree.csproj @@ -1,35 +1,19 @@ - net7.0-windows;net6.0-windows;net48;net471 - true - true - true - snupkg - true - true + net8.0-windows;net7.0-windows;net6.0-windows;net48;net471 CAMAG CAMAG Analogy.LogViewer.LoggersTree Analogy.LogViewer.LoggersTree - true - true true - snupkg - true - CAMAG © 2023 - MIT + CAMAG © 2023-2024 https://github.com/Analogy-LogViewer/Analogy.LogViewer.LoggersTree https://github.com/Analogy-LogViewer/Analogy.LogViewer.LoggersTree - git icon.png Loggers tree extension - Improvements - true - enable - latest - 2.0.2.0 + 3.0.0 @@ -64,25 +48,11 @@ True - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + @@ -92,7 +62,7 @@ - + ..\DevExpress\.net core\DevExpress.Utils.v21.2.dll Always diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionFactory.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionFactory.cs index 7af60c5..382d805 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionFactory.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionFactory.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; -using Analogy.Interfaces; +using Analogy.Interfaces; using Analogy.Interfaces.Factories; +using System; +using System.Collections.Generic; namespace Analogy.LogViewer.LoggersTree.LoggersTree { @@ -10,6 +10,6 @@ public class ExtensionFactory : IAnalogyExtensionsFactory { public Guid FactoryId { get; set; } = PrimaryFactory.Id; public string Title { get; set; } = "Loggers tree extension"; - public IEnumerable Extensions { get; } = new List { new ExtensionLoggersTreeSerilog(), new ExtensionLoggersTreeLog4jXml()}; + public IEnumerable Extensions { get; } = new List { new ExtensionLoggersTreeSerilog(), new ExtensionLoggersTreeLog4jXml() }; } } \ No newline at end of file diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionLoggersTree.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionLoggersTree.cs index a882fb3..e468abe 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionLoggersTree.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/ExtensionLoggersTree.cs @@ -1,9 +1,9 @@ -using System; +using Analogy.Interfaces; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; -using Analogy.Interfaces; -using Microsoft.Extensions.Logging; namespace Analogy.LogViewer.LoggersTree.LoggersTree { @@ -16,34 +16,35 @@ public abstract class ExtensionLoggersTree : IAnalogyExtensionUserControl public string AuthorMail { get; set; } = "info@camag.com"; public List AdditionalContributors { get; } = new List(0); public abstract string Description { get; set; } - private readonly Dictionary _userControls; + private readonly Dictionary userControls; protected ExtensionLoggersTree() { - _userControls = new Dictionary(); + userControls = new Dictionary(); } - public UserControl CreateUserControl(Guid logWindowsId, ILogger logger) { UcLoggersTree control = new UcLoggersTree(); - _userControls.Add(logWindowsId, control); + userControls.Add(logWindowsId, control); return control; } public UserControl GetUserControl(Guid logWindowsId) { - return _userControls[logWindowsId]; + return userControls[logWindowsId]; } Task IAnalogyExtensionUserControl.InitializeUserControl(Control hostingControl, Guid logWindowsId, ILogger logger) { (GetUserControl(logWindowsId) as UcLoggersTree)?.Init(); if (hostingControl is ILogRawSQL logRawSQL) + { (GetUserControl(logWindowsId) as UcLoggersTree)?.SetLogRawSQL(logRawSQL); + } + return Task.CompletedTask; } - public virtual void NewMessage(IAnalogyLogMessage message, Guid logWindowsId) { diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/Logger.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/Logger.cs index 1c33cca..a866098 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/Logger.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/Logger.cs @@ -2,7 +2,7 @@ { internal class Logger { - public static char Separator = ':'; + public static char Separator => ':'; public string? Source { get; set; } public string? Machine { get; set; } @@ -10,7 +10,7 @@ internal class Logger public string ProcessKey { - get { return Machine?.ToLower() + Separator + ProcessName?.ToLower(); } + get { return Machine?.ToLowerInvariant() + Separator + ProcessName?.ToLowerInvariant(); } } public string SourceKey diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/PrimaryFactory.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/PrimaryFactory.cs index ab6719d..8b42795 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/PrimaryFactory.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/PrimaryFactory.cs @@ -1,8 +1,8 @@ -using System; +using Analogy.Interfaces; +using Analogy.LogViewer.LoggersTree.Properties; +using System; using System.Collections.Generic; using System.Drawing; -using Analogy.Interfaces; -using Analogy.LogViewer.LoggersTree.Properties; namespace Analogy.LogViewer.LoggersTree.LoggersTree { @@ -16,12 +16,12 @@ public class PrimaryFactory : global::Analogy.LogViewer.Template.PrimaryFactory public override Image? LargeImage { get; set; } = Resources.Analogy_image_32x32; public override IEnumerable ChangeLog { get; set; } = new List - { - new AnalogyChangeLog("Update Nuget dependencies",AnalogChangeLogType.None, "Lior Banai",new DateTime(2023, 08, 04), ""), - new AnalogyChangeLog("Corrected loggers' name in case of C# generics, corrected SQL generation, prettified displayed SQL",AnalogChangeLogType.Bug, "CAMAG",new DateTime(2023, 04, 04), ""), - new AnalogyChangeLog("Corrected query and added auto resize",AnalogChangeLogType.Bug, "CAMAG",new DateTime(2023, 03, 22), "") + { + new AnalogyChangeLog("Update Nuget dependencies", AnalogChangeLogType.None, "Lior Banai", new DateTime(2023, 08, 04), ""), + new AnalogyChangeLog("Corrected loggers' name in case of C# generics, corrected SQL generation, prettified displayed SQL", AnalogChangeLogType.Bug, "CAMAG", new DateTime(2023, 04, 04), ""), + new AnalogyChangeLog("Corrected query and added auto resize", AnalogChangeLogType.Bug, "CAMAG", new DateTime(2023, 03, 22), ""), }; public override IEnumerable Contributors { get; set; } = new List { "CAMAG" }; public override string About { get; set; } = "Loggers tree"; } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.Designer.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.Designer.cs index ac3f0b2..7a51e14 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.Designer.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.Designer.cs @@ -84,7 +84,7 @@ private void InitializeComponent() allToolStripMenuItem.Name = "allToolStripMenuItem"; allToolStripMenuItem.Size = new System.Drawing.Size(137, 22); allToolStripMenuItem.Text = "All"; - allToolStripMenuItem.Click += allToolStripMenuItem_Click; + allToolStripMenuItem.Click += AllToolStripMenuItem_Click; // // verboseToolStripMenuItem // @@ -92,7 +92,7 @@ private void InitializeComponent() verboseToolStripMenuItem.Name = "verboseToolStripMenuItem"; verboseToolStripMenuItem.Size = new System.Drawing.Size(137, 22); verboseToolStripMenuItem.Text = "Verbose"; - verboseToolStripMenuItem.Click += verboseToolStripMenuItem_Click; + verboseToolStripMenuItem.Click += VerboseToolStripMenuItem_Click; // // traceToolStripMenuItem // @@ -100,7 +100,7 @@ private void InitializeComponent() traceToolStripMenuItem.Name = "traceToolStripMenuItem"; traceToolStripMenuItem.Size = new System.Drawing.Size(137, 22); traceToolStripMenuItem.Text = "Trace"; - traceToolStripMenuItem.Click += traceToolStripMenuItem_Click; + traceToolStripMenuItem.Click += TraceToolStripMenuItem_Click; // // debugToolStripMenuItem // @@ -108,7 +108,7 @@ private void InitializeComponent() debugToolStripMenuItem.Name = "debugToolStripMenuItem"; debugToolStripMenuItem.Size = new System.Drawing.Size(137, 22); debugToolStripMenuItem.Text = "Debug"; - debugToolStripMenuItem.Click += debugToolStripMenuItem_Click; + debugToolStripMenuItem.Click += DebugToolStripMenuItem_Click; // // informationToolStripMenuItem // @@ -116,7 +116,7 @@ private void InitializeComponent() informationToolStripMenuItem.Name = "informationToolStripMenuItem"; informationToolStripMenuItem.Size = new System.Drawing.Size(137, 22); informationToolStripMenuItem.Text = "Information"; - informationToolStripMenuItem.Click += informationToolStripMenuItem_Click; + informationToolStripMenuItem.Click += InformationToolStripMenuItem_Click; // // warningToolStripMenuItem // @@ -124,7 +124,7 @@ private void InitializeComponent() warningToolStripMenuItem.Name = "warningToolStripMenuItem"; warningToolStripMenuItem.Size = new System.Drawing.Size(137, 22); warningToolStripMenuItem.Text = "Warning"; - warningToolStripMenuItem.Click += warningToolStripMenuItem_Click; + warningToolStripMenuItem.Click += WarningToolStripMenuItem_Click; // // errorToolStripMenuItem // @@ -132,7 +132,7 @@ private void InitializeComponent() errorToolStripMenuItem.Name = "errorToolStripMenuItem"; errorToolStripMenuItem.Size = new System.Drawing.Size(137, 22); errorToolStripMenuItem.Text = "Error"; - errorToolStripMenuItem.Click += errorToolStripMenuItem_Click; + errorToolStripMenuItem.Click += ErrorToolStripMenuItem_Click; // // criticalToolStripMenuItem // @@ -140,7 +140,7 @@ private void InitializeComponent() criticalToolStripMenuItem.Name = "criticalToolStripMenuItem"; criticalToolStripMenuItem.Size = new System.Drawing.Size(137, 22); criticalToolStripMenuItem.Text = "Critical"; - criticalToolStripMenuItem.Click += criticalToolStripMenuItem_Click; + criticalToolStripMenuItem.Click += CriticalToolStripMenuItem_Click; // // offToolStripMenuItem // @@ -148,7 +148,7 @@ private void InitializeComponent() offToolStripMenuItem.Name = "offToolStripMenuItem"; offToolStripMenuItem.Size = new System.Drawing.Size(137, 22); offToolStripMenuItem.Text = "Off"; - offToolStripMenuItem.Click += offToolStripMenuItem_Click; + offToolStripMenuItem.Click += OffToolStripMenuItem_Click; // // Split // diff --git a/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.cs b/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.cs index b85525c..2beabb5 100644 --- a/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.cs +++ b/Analogy.LogViewer.LoggersTree/LoggersTree/UcLoggersTree.cs @@ -1,4 +1,9 @@ -using System; +using Analogy.Interfaces; +using Analogy.LogViewer.LoggersTree.Properties; +using Analogy.LogViewer.LoggersTree.Utils; +using DevExpress.Skins; +using DevExpress.XtraBars.Docking; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Drawing; @@ -6,26 +11,23 @@ using System.Threading; using System.Timers; using System.Windows.Forms; -using Analogy.Interfaces; -using Analogy.LogViewer.LoggersTree.Properties; -using Analogy.LogViewer.LoggersTree.Utils; -using DevExpress.Skins; -using DevExpress.XtraBars.Docking; namespace Analogy.LogViewer.LoggersTree.LoggersTree { + /// + /// The UI. + /// public partial class UcLoggersTree : UserControl { - - private ILogRawSQL? _parent; - private string? _currentQuery; - private string? _overloadedQuery; - private readonly ConcurrentQueue _msgQueue; - private readonly System.Timers.Timer _timer; - private DockPanel? _dockPanel; - private ControlContainer? _container; - - enum LogLevel + private ILogRawSQL? parent; + private string? currentQuery; + private string? overloadedQuery; + private ConcurrentQueue MsgQueue { get; set; } + private readonly System.Timers.Timer timer; + private DockPanel? dockPanel; + private ControlContainer? container; + + private enum LogLevel { Critical, Error, @@ -35,7 +37,7 @@ enum LogLevel Verbose, Trace, All, - Off + Off, } public UcLoggersTree() @@ -56,8 +58,7 @@ public UcLoggersTree() TrvLoggers.ImageIndex = (int)LogLevel.All; TrvLoggers.SelectedImageIndex = (int)LogLevel.All; - _msgQueue = new ConcurrentQueue(); - + MsgQueue = new ConcurrentQueue(); Skin currentSkin = CommonSkins.GetSkin(DevExpress.LookAndFeel.UserLookAndFeel.Default); if (currentSkin != null) @@ -69,22 +70,22 @@ public UcLoggersTree() TxtQuery.BackColor = bg; TxtQuery.ForeColor = fg; } - _timer = new System.Timers.Timer(1000); - _timer.Elapsed += ReadQueue; - _timer.Start(); + timer = new System.Timers.Timer(1000); + timer.Elapsed += ReadQueue; + timer.Start(); } private void ReadAll() { int sleep = 0; - for (int i = 0; i < _msgQueue.Count; i++) + for (int i = 0; i < MsgQueue.Count; i++) { - if (!_msgQueue.TryDequeue(out IAnalogyLogMessage? message)) + if (!MsgQueue.TryDequeue(out IAnalogyLogMessage? message)) { - _timer.Start(); + timer.Start(); return; } - TrvLoggers.BeginInvoke((MethodInvoker)delegate { AppendMessage(message); }); + TrvLoggers.BeginInvoke((MethodInvoker)(() => { AppendMessage(message); })); sleep++; if (sleep >= 500) { @@ -92,15 +93,14 @@ private void ReadAll() sleep = 0; } } - TrvLoggers.BeginInvoke((MethodInvoker)delegate { TrvLoggers.ExpandAll(); }); + TrvLoggers.BeginInvoke((MethodInvoker)(() => { TrvLoggers.ExpandAll(); })); } - private void ReadQueue(object? sender, ElapsedEventArgs elapsedEventArgs) { - _timer.Stop(); + timer.Stop(); ReadAll(); - _timer.Start(); + timer.Start(); } private void AppendMessage(IAnalogyLogMessage message) @@ -112,8 +112,11 @@ private void AppendMessage(IAnalogyLogMessage message) } TreeNode? node = TrvLoggers.Nodes.Find(log.ProcessKey, false).FirstOrDefault(); if (node == null) + { return; - string[] generics = log.Source?.Split('`') ?? new string[] { }; + } + + string[] generics = log.Source?.Split('`') ?? Array.Empty(); if (generics.Any()) { string[] path = generics[0].Split('.'); @@ -122,58 +125,65 @@ private void AppendMessage(IAnalogyLogMessage message) string current = string.Empty; for (int j = 0; j <= i; j++) { - if (current != String.Empty) + if (current != string.Empty) + { current += "."; + } + current += path[j]; } if (!node.Nodes.ContainsKey(current)) + { node = node.Nodes.Add(current, current, (int)LogLevel.All); + } else + { node = node.Nodes.Find(current, false).Single(); + } } } if (!node.Nodes.ContainsKey(log.Source)) { node.Nodes.Add(log.Source, log.Source, (int)LogLevel.All); } - } public void Clear() { TrvLoggers.Nodes.Clear(); #if NET5_0_OR_GREATER - _msgQueue.Clear(); + MsgQueue.Clear(); #else - while (!_msgQueue.IsEmpty) - _msgQueue.TryDequeue(out _); + while (!MsgQueue.IsEmpty) + { + MsgQueue.TryDequeue(out _); + } #endif } public void NewMessage(IAnalogyLogMessage message) { - _msgQueue.Enqueue(message); - + MsgQueue.Enqueue(message); } public void SetLogRawSQL(ILogRawSQL logRawSql) { - _parent = logRawSql; - _parent.OnRawSQLFilterChanged += Parent_OnSetRawSQLFilter; + parent = logRawSql; + parent.OnRawSQLFilterChanged += Parent_OnSetRawSQLFilter; } private void Parent_OnSetRawSQLFilter(object? sender, string query) { - if (query != _overloadedQuery) - _currentQuery = query; + if (!string.Equals(query, overloadedQuery, StringComparison.OrdinalIgnoreCase)) + { + currentQuery = query; + } } - - private string CreateLevelQuery(string requestedLevel) { - string levelQuery = String.Empty; + string levelQuery = string.Empty; List levels = new List() { "Critical", @@ -182,12 +192,14 @@ private string CreateLevelQuery(string requestedLevel) "Information", "Debug", "Verbose", - "Trace" + "Trace", }; foreach (string l in levels) { if (QueryLevel(ref levelQuery, l, requestedLevel)) + { break; + } } return levelQuery; } @@ -195,30 +207,43 @@ private string CreateLevelQuery(string requestedLevel) private bool QueryLevel(ref string levelQuery, string level, string requestedLevel) { if (levelQuery.Length > 0) + { levelQuery += " OR "; + } + levelQuery += $"Level = '{level}'"; - if (requestedLevel == level) + if (string.Equals(requestedLevel, level, StringComparison.OrdinalIgnoreCase)) + { return true; + } + return false; } - private void SetLogLevel(LogLevel level) { TreeNode node = TrvLoggers.SelectedNode; SetLogLevel(node, level); + //set default query if we didn't get it from event - if (String.IsNullOrEmpty(_currentQuery)) - _currentQuery = "( Text like '%%') AND (Date >= '01/01/0001 00:00:00' and Date <= '31/12/9999 23:59:59')"; - _overloadedQuery = _currentQuery; + if (string.IsNullOrEmpty(currentQuery)) + { + currentQuery = "( Text like '%%') AND (Date >= '01/01/0001 00:00:00' and Date <= '31/12/9999 23:59:59')"; + } + + overloadedQuery = currentQuery; foreach (TreeNode root in TrvLoggers.Nodes) { if (root != null) + { CreateQuery(root, LogLevel.All); + } + } + TxtQuery.Text = SqlPrettify.Pretty(overloadedQuery); + if (overloadedQuery != null) + { + parent?.ApplyRawSQLFilter(overloadedQuery); } - TxtQuery.Text = SqlPrettify.Pretty(_overloadedQuery); - if (_overloadedQuery != null) - _parent?.ApplyRawSQLFilter(_overloadedQuery); } private void CreateQuery(TreeNode node, LogLevel parentLevel) @@ -229,39 +254,59 @@ private void CreateQuery(TreeNode node, LogLevel parentLevel) TreeNode root = GetRootNode(node); string[] data = root.Text.Split(Logger.Separator); if (data.Length != 2) + { throw new NotSupportedException($"ProcessKey is malformed: {root.Text}"); + } + string processQuery = $"([MachineName] = '{data.First()}' AND Module = '{data.Last()}')"; string nodeTextEscaped = node.Text.Replace("[", "[[]").Replace("=", "[=]"); if (level == LogLevel.Off) { if (root == node) - _overloadedQuery += $" AND NOT {processQuery}"; + { + overloadedQuery += $" AND NOT {processQuery}"; + } else - _overloadedQuery += $" AND ((Source not like '{nodeTextEscaped}%') OR not {processQuery})"; + { + overloadedQuery += $" AND ((Source not like '{nodeTextEscaped}%') OR not {processQuery})"; + } } else { string levelQuery = CreateLevelQuery(level.ToString()); if (root == node) - _overloadedQuery += $" AND ((({levelQuery}) AND {processQuery}) OR not {processQuery})"; + { + overloadedQuery += $" AND ((({levelQuery}) AND {processQuery}) OR not {processQuery})"; + } else { if (parentLevel != LogLevel.Off && level <= parentLevel) - _overloadedQuery += $" AND ((Source like '{nodeTextEscaped}%' AND ({levelQuery}) AND {processQuery}) OR Source not like '{nodeTextEscaped}%' OR not {processQuery})"; + { + overloadedQuery += $" AND ((Source like '{nodeTextEscaped}%' AND ({levelQuery}) AND {processQuery}) OR Source not like '{nodeTextEscaped}%' OR not {processQuery})"; + } else - _overloadedQuery += $" OR (Source like '{nodeTextEscaped}%' AND ({levelQuery}) AND {processQuery})"; + { + overloadedQuery += $" OR (Source like '{nodeTextEscaped}%' AND ({levelQuery}) AND {processQuery})"; + } } } } foreach (TreeNode child in node.Nodes) + { if (child != null) + { CreateQuery(child, level); + } + } } private TreeNode GetRootNode(TreeNode node) { if (node.Parent == null) + { return node; + } + return GetRootNode(node.Parent); } @@ -271,51 +316,55 @@ private void SetLogLevel(TreeNode node, LogLevel level) node.ImageIndex = (int)level; node.SelectedImageIndex = (int)level; foreach (TreeNode child in node.Nodes) + { if (child != null) + { SetLogLevel(child, level); + } + } } - private void allToolStripMenuItem_Click(object sender, EventArgs e) + private void AllToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.All); } - private void verboseToolStripMenuItem_Click(object sender, EventArgs e) + private void VerboseToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Verbose); } - private void traceToolStripMenuItem_Click(object sender, EventArgs e) + private void TraceToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Trace); } - private void debugToolStripMenuItem_Click(object sender, EventArgs e) + private void DebugToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Debug); } - private void informationToolStripMenuItem_Click(object sender, EventArgs e) + private void InformationToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Information); } - private void warningToolStripMenuItem_Click(object sender, EventArgs e) + private void WarningToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Warning); } - private void errorToolStripMenuItem_Click(object sender, EventArgs e) + private void ErrorToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Error); } - private void criticalToolStripMenuItem_Click(object sender, EventArgs e) + private void CriticalToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Critical); } - private void offToolStripMenuItem_Click(object sender, EventArgs e) + private void OffToolStripMenuItem_Click(object sender, EventArgs e) { SetLogLevel(LogLevel.Off); } @@ -330,24 +379,26 @@ private void TrvLoggers_NodeMouseClick(object sender, TreeNodeMouseClickEventArg public void Init() { - if (_dockPanel != null) + if (dockPanel != null) { - _dockPanel.Resize -= _dockPanel_Resize; + dockPanel.Resize -= DockPanel_Resize; } Clear(); if (Parent is ControlContainer cc) { - _container = cc; - Size = _container.Size; - _dockPanel = cc.Panel; - _dockPanel.Resize += _dockPanel_Resize; + container = cc; + Size = container.Size; + dockPanel = cc.Panel; + dockPanel.Resize += DockPanel_Resize; } } - private void _dockPanel_Resize(object? sender, EventArgs e) + private void DockPanel_Resize(object? sender, EventArgs e) { - if (_dockPanel != null && _container != null) - Size = new Size(_dockPanel.Size.Width - _container.Margin.Left - _container.Margin.Right, _dockPanel.Size.Height - _container.Margin.Top - _container.Margin.Bottom); + if (dockPanel != null && container != null) + { + Size = new Size(dockPanel.Size.Width - container.Margin.Left - container.Margin.Right, dockPanel.Size.Height - container.Margin.Top - container.Margin.Bottom); + } } private void BtnExpand_Click(object sender, EventArgs e) @@ -360,4 +411,4 @@ private void BtnCollapse_Click(object sender, EventArgs e) TrvLoggers.CollapseAll(); } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.LoggersTree/Utils/SqlPrettify.cs b/Analogy.LogViewer.LoggersTree/Utils/SqlPrettify.cs index 1b290d0..1fa23d9 100644 --- a/Analogy.LogViewer.LoggersTree/Utils/SqlPrettify.cs +++ b/Analogy.LogViewer.LoggersTree/Utils/SqlPrettify.cs @@ -27,13 +27,13 @@ public static string Pretty(string? q) "join", "group", "order", - "by" + "by", }; List stringList2 = new List() { "and", "or", - "between" + "between", }; List stringList3 = new List() { @@ -41,12 +41,12 @@ public static string Pretty(string? q) "right", "inner", "outer", - "full" + "full", }; List stringList4 = new List() { "order", - "group" + "group", }; string str2 = string.Empty; string str3 = string.Empty; @@ -56,9 +56,14 @@ public static string Pretty(string? q) char ch = q[index]; str4 += ch.ToString(); if (ch == '\'' && q[index - 1] != '\\') + { num2 = (num2 + 1) % 2; + } + if (num2 == 0 && ch == ',') + { str4 += " "; + } } q = str4; bool isText = false; @@ -67,37 +72,55 @@ public static string Pretty(string? q) char ch = q[index]; bool isSpace = ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t'; if (ch == '\'' && q[index - 1] != '\\') + { isText = !isText; + } + if (!isSpace || isText) { str3 += ch.ToString(); if (ch == '(') + { ++num1; + } + if (ch == ')') + { --num1; + } } else if (str3 != string.Empty) { - if (stringList1.Contains(str3.Trim().ToLower())) + if (stringList1.Contains(str3.Trim().ToLowerInvariant())) { - if (str3.Trim().ToLower() == "join") + if (string.Equals(str3.Trim(), "join", StringComparison.OrdinalIgnoreCase)) { if (stringList3.Contains(str1)) - str2 = str2.Substring(0, str2.Length - 1 - (num1 + 1) * 4) + " " + " " + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + { + str2 = str2.Substring(0, str2.Length - 1 - ((num1 + 1) * 4)) + " " + " " + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + } else + { str2 = str2 + Environment.NewLine + SpaceAdder(num1 * 4) + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + } } - else if (str3.Trim().ToLower() == "by") + else if (string.Equals(str3.Trim(), "by", StringComparison.OrdinalIgnoreCase)) { if (stringList4.Contains(str1)) - str2 = str2.Substring(0, str2.Length - 1 - (num1 + 1) * 4) + " " + " " + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + { + str2 = str2.Substring(0, str2.Length - 1 - ((num1 + 1) * 4)) + " " + " " + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + } else + { str2 = str2 + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + } } else + { str2 = str2 + Environment.NewLine + SpaceAdder(num1 * 4) + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); + } } - else if (stringList2.Contains(str3.Trim().ToLower())) + else if (stringList2.Contains(str3.Trim().ToLowerInvariant())) { str2 = str2 + Environment.NewLine + SpaceAdder((num1 + 1) * 4) + str3 + " "; } @@ -106,12 +129,15 @@ public static string Pretty(string? q) string str5 = str3; str2 = str5[^1] != ',' ? str2 + str3 + " " : str2 + str3 + Environment.NewLine + SpaceAdder((num1 + 1) * 4); } - str1 = str3.ToLower(); + str1 = str3.ToLowerInvariant(); str3 = string.Empty; } } if (str2[0] != '\n') + { return str2; + } + string str6 = str2; int length1 = str6.Length; int startIndex = 1; @@ -124,7 +150,10 @@ private static string SpaceAdder(int spaces) { string str = string.Empty; for (; spaces > 0; --spaces) + { str += " "; + } + return str; } } diff --git a/BannedSymbols.txt b/BannedSymbols.txt new file mode 100644 index 0000000..26002bb --- /dev/null +++ b/BannedSymbols.txt @@ -0,0 +1,9 @@ +#https://github.com/dotnet/csharplang/blob/main/spec/documentation-comments.md#id-string-format + +M:System.String.ToLower;Use ToLowerInvariant instead +M:System.String.ToUpper;Use ToUpperInvariant instead + +F:System.StringComparison.CurrentCulture;Consider using Ordinal +F:System.StringComparison.CurrentCultureIgnoreCase;Consider using OrdinalIgnoreCase +F:System.StringComparison.InvariantCurrent;Consider using Ordinal +F:System.StringComparison.InvariantCurrentIgnoreCase;Consider using OrdinalIgnoreCase diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..92e4444 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,61 @@ + + + true + true + True + snupkg + true + true + true + MIT + true + False + git + portable + + + enable + latest + + + $(DefineContants);DEBUG + false + + + true + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..3a9f6b3 --- /dev/null +++ b/nuget.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file