From be11bb3a40493f37d0c3bbccc4a2acca961ad337 Mon Sep 17 00:00:00 2001 From: Lior Banai Date: Thu, 16 Nov 2023 17:23:25 +0200 Subject: [PATCH] NET8 --- .editorconfig | 1 + .github/workflows/dotnet-core-desktop.yml | 6 +- ...logy.LogViewer.JsonParser.UnitTests.csproj | 2 +- .../UnitTest1.cs | 1 - .../Analogy.LogViewer.JsonParser.csproj | 47 +++----------- Analogy.LogViewer.JsonParser/ChangeLog.cs | 6 +- Analogy.LogViewer.JsonParser/Enums.cs | 4 +- .../IAnalogy/AnalogyJsonFactory.cs | 8 +-- .../IAnalogy/DownloadInformation.cs | 6 +- .../IAnalogy/JsonDataProvider.cs | 12 +--- .../IAnalogy/JsonUserSettingsFactory.cs | 10 ++- .../JsonFileLoader.cs | 29 ++++----- Analogy.LogViewer.JsonParser/JsonSettings.cs | 4 +- .../JsonSettingsUC.cs | 4 +- .../Managers/UserSettingsManager.cs | 12 ++-- Analogy.LogViewer.JsonParser/Utils.cs | 3 +- BannedSymbols.txt | 9 +++ Directory.Build.props | 61 +++++++++++++++++++ logs/multipleDates.json | 2 +- 19 files changed, 120 insertions(+), 107 deletions(-) create mode 100644 BannedSymbols.txt create mode 100644 Directory.Build.props diff --git a/.editorconfig b/.editorconfig index fa05938..0f27dd6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -273,6 +273,7 @@ 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 [*.{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 3aadf88..7a0435a 100644 --- a/.github/workflows/dotnet-core-desktop.yml +++ b/.github/workflows/dotnet-core-desktop.yml @@ -32,13 +32,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.JsonParser.UnitTests/Analogy.LogViewer.JsonParser.UnitTests.csproj b/Analogy.LogViewer.JsonParser.UnitTests/Analogy.LogViewer.JsonParser.UnitTests.csproj index 7485289..352fe66 100644 --- a/Analogy.LogViewer.JsonParser.UnitTests/Analogy.LogViewer.JsonParser.UnitTests.csproj +++ b/Analogy.LogViewer.JsonParser.UnitTests/Analogy.LogViewer.JsonParser.UnitTests.csproj @@ -48,7 +48,7 @@ - 5.0.3 + 6.0.0.1 3.1.1 diff --git a/Analogy.LogViewer.JsonParser.UnitTests/UnitTest1.cs b/Analogy.LogViewer.JsonParser.UnitTests/UnitTest1.cs index b891158..2ae28ab 100644 --- a/Analogy.LogViewer.JsonParser.UnitTests/UnitTest1.cs +++ b/Analogy.LogViewer.JsonParser.UnitTests/UnitTest1.cs @@ -18,7 +18,6 @@ public async Task TestMethod1() MessageHandlerForTesting handler = new MessageHandlerForTesting(); var msgs = await fp.Process("test.json", ts.Token, handler); Assert.IsTrue(msgs.Count() == 4); - } [TestMethod] public async Task TestMethod2() diff --git a/Analogy.LogViewer.JsonParser/Analogy.LogViewer.JsonParser.csproj b/Analogy.LogViewer.JsonParser/Analogy.LogViewer.JsonParser.csproj index 8d46007..9b1b538 100644 --- a/Analogy.LogViewer.JsonParser/Analogy.LogViewer.JsonParser.csproj +++ b/Analogy.LogViewer.JsonParser/Analogy.LogViewer.JsonParser.csproj @@ -2,56 +2,25 @@ Library - net7.0-windows;net6.0-windows;net48;net471 - true + net8.0-windows;net7.0-windows;net6.0-windows;net48;net471 + 6.0.0 + Lior Banai Analogy.LogViewer - true - true - snupkg - true - true - MIT https://github.com/Analogy-LogViewer/Analogy.LogViewer.JsonParser AnalogyJson.png https://github.com/Analogy-LogViewer/Analogy.LogViewer.JsonParser - git Analogy.LogViewer, Json - Lior Banai @ 2020-2023 - true - enable - latest - true - 5.0.3.1 - + Lior Banai @ 2020-2024 - - - + + + - - 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 - - - True diff --git a/Analogy.LogViewer.JsonParser/ChangeLog.cs b/Analogy.LogViewer.JsonParser/ChangeLog.cs index bcda5b4..5847b5e 100644 --- a/Analogy.LogViewer.JsonParser/ChangeLog.cs +++ b/Analogy.LogViewer.JsonParser/ChangeLog.cs @@ -1,6 +1,6 @@ -using System; +using Analogy.Interfaces; +using System; using System.Collections.Generic; -using Analogy.Interfaces; namespace Analogy.LogViewer.JsonParser { @@ -12,4 +12,4 @@ public static IEnumerable GetChangeLog() yield return new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2019, 12, 23), ""); } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/Enums.cs b/Analogy.LogViewer.JsonParser/Enums.cs index 5ed86b0..35fdf55 100644 --- a/Analogy.LogViewer.JsonParser/Enums.cs +++ b/Analogy.LogViewer.JsonParser/Enums.cs @@ -10,6 +10,6 @@ public enum FileFormat public enum FileFormatDetection { Automatic, - Manual + Manual, } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/IAnalogy/AnalogyJsonFactory.cs b/Analogy.LogViewer.JsonParser/IAnalogy/AnalogyJsonFactory.cs index 03fc07d..e895303 100644 --- a/Analogy.LogViewer.JsonParser/IAnalogy/AnalogyJsonFactory.cs +++ b/Analogy.LogViewer.JsonParser/IAnalogy/AnalogyJsonFactory.cs @@ -17,7 +17,6 @@ public class JsonFactory : Template.PrimaryFactory public override Image? SmallImage { get; set; } = Resources.jsonfile16x16; public override IEnumerable Contributors { get; set; } = new List { "Lior Banai" }; public override string About { get; set; } = "Json Log Parser"; - } public class AnalogyJsonDataProviderFactory : Template.DataProvidersFactory @@ -26,7 +25,7 @@ public class AnalogyJsonDataProviderFactory : Template.DataProvidersFactory public override string Title { get; set; } = "Json Data Provider"; public override IEnumerable DataProviders { get; set; } = new List() { - new JsonDataProvider() + new JsonDataProvider(), }; } @@ -35,8 +34,5 @@ public class AnalogyJsonCustomActionFactory : IAnalogyCustomActionsFactory public Guid FactoryId { get; set; } = JsonFactory.Id; public string Title { get; set; } = "Json tools"; public IEnumerable Actions { get; } = new List(0); - } - - -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/IAnalogy/DownloadInformation.cs b/Analogy.LogViewer.JsonParser/IAnalogy/DownloadInformation.cs index 02af720..0651434 100644 --- a/Analogy.LogViewer.JsonParser/IAnalogy/DownloadInformation.cs +++ b/Analogy.LogViewer.JsonParser/IAnalogy/DownloadInformation.cs @@ -1,4 +1,5 @@ -using System; +using Analogy.LogViewer.Template; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -6,7 +7,6 @@ using System.Runtime.Versioning; using System.Text; using System.Threading.Tasks; -using Analogy.LogViewer.Template; namespace Analogy.LogViewer.JsonParser.IAnalogy { @@ -34,4 +34,4 @@ public override string InstalledVersionNumber } } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/IAnalogy/JsonDataProvider.cs b/Analogy.LogViewer.JsonParser/IAnalogy/JsonDataProvider.cs index 4e71747..e956ba9 100644 --- a/Analogy.LogViewer.JsonParser/IAnalogy/JsonDataProvider.cs +++ b/Analogy.LogViewer.JsonParser/IAnalogy/JsonDataProvider.cs @@ -31,10 +31,10 @@ public class JsonDataProvider : Template.OfflineDataProvider public JsonFileLoader JsonParser { get; set; } public override bool UseCustomColors { get; set; } - public override IEnumerable<(string originalHeader, string replacementHeader)> GetReplacementHeaders() + public override IEnumerable<(string OriginalHeader, string ReplacementHeader)> GetReplacementHeaders() => Array.Empty<(string, string)>(); - public override (Color backgroundColor, Color foregroundColor) GetColorForMessage(IAnalogyLogMessage logMessage) + public override (Color BackgroundColor, Color ForegroundColor) GetColorForMessage(IAnalogyLogMessage logMessage) => (Color.Empty, Color.Empty); public JsonDataProvider() { @@ -59,15 +59,12 @@ public override async Task> Process(string fileN UserSettingsManager.UserSettings.Settings.Format = TryDetectFormat(fileName); } - return await JsonParser.Process(fileName, token, messagesHandler); } return new List(0); - } - private static FileFormat TryDetectFormat(string fileName) { string jsonData = string.Empty; @@ -102,7 +99,6 @@ private static FileFormat TryParsePerLine(string fileName) { try { - var lines = File.ReadAllLines(fileName); foreach (var line in lines) { @@ -147,7 +143,6 @@ private static string SafeReadAllLines(string path) } } - public override Task SaveAsync(List messages, string fileName) { return Task.CompletedTask; @@ -160,7 +155,6 @@ public override bool CanOpenFile(string fileName) => Path.GetExtension(fileName) protected override List GetSupportedFilesInternal(DirectoryInfo dirInfo, bool recursive) { - List files = dirInfo.GetFiles("*.json") .Where(f => CanOpenFile(f.FullName)).ToList(); if (!recursive) @@ -183,4 +177,4 @@ protected override List GetSupportedFilesInternal(DirectoryInfo dirInf return files; } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/IAnalogy/JsonUserSettingsFactory.cs b/Analogy.LogViewer.JsonParser/IAnalogy/JsonUserSettingsFactory.cs index 00490a9..af6cea8 100644 --- a/Analogy.LogViewer.JsonParser/IAnalogy/JsonUserSettingsFactory.cs +++ b/Analogy.LogViewer.JsonParser/IAnalogy/JsonUserSettingsFactory.cs @@ -1,10 +1,10 @@ -using Analogy.LogViewer.JsonParser.Properties; +using Analogy.Interfaces; +using Analogy.LogViewer.JsonParser.Properties; +using Microsoft.Extensions.Logging; using System; using System.Drawing; using System.Threading.Tasks; using System.Windows.Forms; -using Analogy.Interfaces; -using Microsoft.Extensions.Logging; namespace Analogy.LogViewer.JsonParser.IAnalogy { @@ -28,6 +28,4 @@ public override Task SaveSettingsAsync() return Task.CompletedTask; } } - - -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/JsonFileLoader.cs b/Analogy.LogViewer.JsonParser/JsonFileLoader.cs index eb17bef..56a2a79 100644 --- a/Analogy.LogViewer.JsonParser/JsonFileLoader.cs +++ b/Analogy.LogViewer.JsonParser/JsonFileLoader.cs @@ -1,4 +1,5 @@ using Analogy.Interfaces; +using Analogy.Interfaces.DataTypes; using Analogy.LogViewer.JsonParser.Managers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -8,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Analogy.Interfaces.DataTypes; namespace Analogy.LogViewer.JsonParser { @@ -20,7 +20,7 @@ public JsonFileLoader(JsonSettings jsonSettings) JsonSettings = jsonSettings; JsonConvert.DefaultSettings = () => new JsonSerializerSettings { - DateParseHandling = jsonSettings.DateParseHandling + DateParseHandling = jsonSettings.DateParseHandling, }; } @@ -33,7 +33,7 @@ public async Task> Process(string fileName, Canc AnalogyLogLevel.Critical, AnalogyLogClass.General, "Analogy", "None") { Source = "Analogy", - Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName + Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName, }; messagesHandler.AppendMessage(empty, Utils.GetFileNameAsDataSource(fileName)); return new List { empty }; @@ -46,7 +46,7 @@ public async Task> Process(string fileName, Canc AnalogyLogLevel.Critical, AnalogyLogClass.General, "Analogy", "None") { Source = "Analogy", - Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName + Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName, }; messagesHandler.AppendMessage(empty, Utils.GetFileNameAsDataSource(fileName)); return new List { empty }; @@ -61,7 +61,7 @@ public async Task> Process(string fileName, Canc AnalogyLogMessage none = new AnalogyLogMessage($"Unknown file format", AnalogyLogLevel.Critical, AnalogyLogClass.General, "Analogy", "None") { Source = "Analogy", - Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName + Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName, }; messagesHandler.AppendMessage(none, Utils.GetFileNameAsDataSource(fileName)); return new List { none }; @@ -71,8 +71,7 @@ public async Task> Process(string fileName, Canc private List ProcessJsonFile(string fileName, CancellationToken token, ILogMessageCreatedHandler messagesHandler) { string json = File.ReadAllText(fileName); - return ProcessJsonData(json, fileName, messagesHandler,true); - + return ProcessJsonData(json, fileName, messagesHandler, true); } private List ProcessJsonData(string json, string fileName, ILogMessageCreatedHandler messagesHandler, bool reportProgress) @@ -112,7 +111,7 @@ private List ProcessJsonData(string json, string fileName, I messages.Add(m); if (reportProgress) { - messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage, 1,i, jArray.Count)); + messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage, 1, i, jArray.Count)); } } } @@ -127,13 +126,11 @@ private List ProcessJsonData(string json, string fileName, I if (UserSettingsManager.UserSettings.Settings.TryGetAnalogyValue(jprop.Name, out var prop)) { tuples.Add((prop.ToString(), jprop.Value.ToString())); - } else { nonAnalogyTuples.Add((jprop.Name, jprop.Value.ToString())); } - } var m = AnalogyLogMessage.Parse(tuples); @@ -146,7 +143,7 @@ private List ProcessJsonData(string json, string fileName, I messages.Add(m); if (reportProgress) { - messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage,1, 1, 1)); + messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage, 1, 1, 1)); } } messagesHandler.AppendMessages(messages, fileName); @@ -158,11 +155,10 @@ private List ProcessJsonData(string json, string fileName, I AnalogyLogLevel.Critical, AnalogyLogClass.General, "Analogy", "None") { Source = "Analogy", - Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName + Module = System.Diagnostics.Process.GetCurrentProcess().ProcessName, }; messagesHandler.AppendMessage(empty, Utils.GetFileNameAsDataSource(fileName)); - return new List { empty - }; + return new List { empty, }; } } @@ -177,11 +173,10 @@ private List ProcessJsonPerLine(string fileName, Cancellatio var json = jsons[i]; var msgs = ProcessJsonData(json, fileName, messagesHandler, false); messages.AddRange(msgs); - messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage, 1,i, jsons.Length)); - + messagesHandler.ReportFileReadProgress(new AnalogyFileReadProgress(AnalogyFileReadProgressType.Percentage, 1, i, jsons.Length)); } return messages; } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/JsonSettings.cs b/Analogy.LogViewer.JsonParser/JsonSettings.cs index ac4f0b5..54de385 100644 --- a/Analogy.LogViewer.JsonParser/JsonSettings.cs +++ b/Analogy.LogViewer.JsonParser/JsonSettings.cs @@ -30,14 +30,12 @@ public void AddField(AnalogyLogMessagePropertyName analogyProperty, string jsonF if (!Fields[analogyProperty].Contains(jsonFieldName)) { Fields[analogyProperty].Add(jsonFieldName); - } } public void DeleteField(AnalogyLogMessagePropertyName analogyProperty, string jsonFieldName) { Fields[analogyProperty].Remove(jsonFieldName); - } public bool TryGetAnalogyValue(string jpropName, out string prop) @@ -60,4 +58,4 @@ public List GetValues(AnalogyLogMessagePropertyName selectedField) return Fields[selectedField]; } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/JsonSettingsUC.cs b/Analogy.LogViewer.JsonParser/JsonSettingsUC.cs index 53d5d86..6ac6f1b 100644 --- a/Analogy.LogViewer.JsonParser/JsonSettingsUC.cs +++ b/Analogy.LogViewer.JsonParser/JsonSettingsUC.cs @@ -31,12 +31,10 @@ private void LoadSettings() private void btnSave_Click(object sender, EventArgs e) { SaveSettings(); - } public void SaveSettings() { - Settings.FileFormatDetection = rbDetectionModeAutomatic.Checked ? FileFormatDetection.Automatic : FileFormatDetection.Manual; @@ -90,4 +88,4 @@ private void btnDeleteField_Click(object sender, EventArgs e) } } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/Managers/UserSettingsManager.cs b/Analogy.LogViewer.JsonParser/Managers/UserSettingsManager.cs index e32cace..aa0291c 100644 --- a/Analogy.LogViewer.JsonParser/Managers/UserSettingsManager.cs +++ b/Analogy.LogViewer.JsonParser/Managers/UserSettingsManager.cs @@ -1,8 +1,8 @@ -using Newtonsoft.Json; +using Analogy.LogViewer.Template.Managers; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using System; using System.IO; -using Analogy.LogViewer.Template.Managers; -using Microsoft.Extensions.Logging; namespace Analogy.LogViewer.JsonParser.Managers { @@ -14,7 +14,6 @@ public class UserSettingsManager private string JsonFileSetting { get; } = "AnalogyJsonParserSettings.json"; public JsonSettings Settings { get; set; } - private UserSettingsManager() { if (File.Exists(JsonFileSetting)) @@ -33,10 +32,7 @@ private UserSettingsManager() else { Settings = new JsonSettings(); - - } - } public void Save() @@ -51,4 +47,4 @@ public void Save() } } } -} +} \ No newline at end of file diff --git a/Analogy.LogViewer.JsonParser/Utils.cs b/Analogy.LogViewer.JsonParser/Utils.cs index 67bb27b..1ee85c3 100644 --- a/Analogy.LogViewer.JsonParser/Utils.cs +++ b/Analogy.LogViewer.JsonParser/Utils.cs @@ -138,7 +138,6 @@ public static string GetFileNameAsDataSource(string fileName) { string file = Path.GetFileName(fileName); return fileName.Equals(file) ? fileName : $"{file} ({fileName})"; - } } public static class GeneralExtensionMethods @@ -167,4 +166,4 @@ public static bool Contains(this IEnumerable source, string toCheck, Str source.Any(itm => itm.Contains(toCheck, comp)); } } -} +} \ No newline at end of file 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/logs/multipleDates.json b/logs/multipleDates.json index e72c6c4..0b76f7b 100644 --- a/logs/multipleDates.json +++ b/logs/multipleDates.json @@ -1,2 +1,2 @@ {"instant":{"epochSecond":1685544384,"nanoOfSecond":611206994},"thread":"taskScheduler-3","level":"DEBUG","loggerName":"com.corp.cbu.cnc.nrfc.NRFCManagement","message":"NfInstanceId c1b51db4-7ac6-11ec-90d6-0242ac120003 present in list of configuredNfProfiles","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":54,"threadPriority":5,"messageTimestamp":"2023-05-31T14:46:24.611+0000"} -{"messageTimestamp":"2023-05-31T15:06:10.497Z","logLevel":"DEBUG","pid":1,"workerId":"master","message":"Fetching data from URI: http://occnp-2310-26507-gyltj-occnp-config-server:8000/topics/common.logging.pre for topic common.logging.pre with param false"} \ No newline at end of file +{"messageTimestamp":"2023-05-31T15:06:10.497Z","logLevel":"DEBUG","pid":1,"workerId":"master","message":"Fetching data from URI: http://occnp-2310-26507-gyltj-occnp-config-server:8000/topics/common.logging.pre for topic common.logging.pre with param false"}