Skip to content

Commit

Permalink
do not force date time format . support multiple date time formats. fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Oct 25, 2023
1 parent 9be190a commit fd0daf7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
14 changes: 11 additions & 3 deletions Analogy.LogViewer.JsonParser.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.181
# Visual Studio Version 17
VisualStudioVersion = 17.8.34205.153
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Analogy.LogViewer.JsonParser.UnitTests", "Analogy.LogViewer.JsonParser.UnitTests\Analogy.LogViewer.JsonParser.UnitTests.csproj", "{620FCC2B-6362-40E5-B545-5D338A66C9EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Analogy.LogViewer.JsonParser", "Analogy.LogViewer.JsonParser\Analogy.LogViewer.JsonParser.csproj", "{32EF1AE4-07BC-4B4C-AB98-F0754975829D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analogy.LogViewer.JsonParser", "Analogy.LogViewer.JsonParser\Analogy.LogViewer.JsonParser.csproj", "{32EF1AE4-07BC-4B4C-AB98-F0754975829D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B744D517-04D9-4CED-B808-560DA00FFA7B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\dotnet-core-desktop.yml = .github\workflows\dotnet-core-desktop.yml
nuget.config = nuget.config
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<VersionPrefix>5.0.3.0</VersionPrefix>
<VersionPrefix>5.0.3.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>

Expand Down
3 changes: 1 addition & 2 deletions Analogy.LogViewer.JsonParser/ChangeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ public static class ChangeLog
{
public static IEnumerable<AnalogyChangeLog> GetChangeLog()
{

yield return new AnalogyChangeLog("support multiple date time formats. #217", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2023, 25, 10), "5.0.3.1");
yield return new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2019, 12, 23), "");

}
}
}
10 changes: 7 additions & 3 deletions Analogy.LogViewer.JsonParser/JsonFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class JsonFileLoader
public JsonFileLoader(JsonSettings jsonSettings)
{
JsonSettings = jsonSettings;
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
DateParseHandling = jsonSettings.DateParseHandling
};
}

public async Task<IEnumerable<IAnalogyLogMessage>> Process(string fileName, CancellationToken token,
Expand Down Expand Up @@ -73,7 +77,7 @@ private List<IAnalogyLogMessage> ProcessJsonFile(string fileName, CancellationTo

private List<IAnalogyLogMessage> ProcessJsonData(string json, string fileName, ILogMessageCreatedHandler messagesHandler, bool reportProgress)
{
List<IAnalogyLogMessage> messages = new List<IAnalogyLogMessage>();
List<IAnalogyLogMessage> messages = new();
try
{
var items = JsonConvert.DeserializeObject<dynamic>(json);
Expand All @@ -83,8 +87,8 @@ private List<IAnalogyLogMessage> ProcessJsonData(string json, string fileName, I
{
var item = jArray[i];
var itemProperties = item.Children<JProperty>().ToList();
List<(string, string)> tuples = new List<(string, string)>(itemProperties.Count);
List<(string, string)> nonAnalogyTuples = new List<(string, string)>(itemProperties.Count);
List<(string, string)> tuples = new(itemProperties.Count);
List<(string, string)> nonAnalogyTuples = new(itemProperties.Count);

foreach (var jprop in itemProperties)
{
Expand Down
6 changes: 5 additions & 1 deletion Analogy.LogViewer.JsonParser/JsonSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Analogy.Interfaces;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Analogy.LogViewer.JsonParser
Expand All @@ -8,9 +9,12 @@ public class JsonSettings
public FileFormat Format { get; set; }
public FileFormatDetection FileFormatDetection { get; set; }
public Dictionary<AnalogyLogMessagePropertyName, List<string>> Fields { get; set; }

public List<string> DateFormats { get; set; }
public DateParseHandling DateParseHandling { get; set; }
public JsonSettings()
{
DateParseHandling = DateParseHandling.None;
DateFormats = new List<string>();
Fields = new Dictionary<AnalogyLogMessagePropertyName, List<string>>();
foreach (var property in AnalogyLogMessage.LogMessagePropertyNames.Values)
{
Expand Down

0 comments on commit fd0daf7

Please sign in to comment.