Skip to content

Commit

Permalink
update parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Mar 15, 2024
1 parent c1e905e commit f7b8869
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<None Update="db\example.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="db\example2.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Analogy.LogViewer.Sqlite.UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task ReadDBTest()
SqliteBroswerDataProvider reader = new SqliteBroswerDataProvider();
LoggerFactory factory = new LoggerFactory();
Microsoft.Extensions.Logging.ILogger logger = factory.CreateLogger("test");
await reader.InitializeDataProvider(null);
await reader.InitializeDataProvider(logger);
var messages = (await reader.Process(fileName, cts.Token, forTesting)).ToList();
Assert.IsTrue(messages.Count == 389);
}
Expand Down
Binary file added Analogy.LogViewer.Sqlite.UnitTests/db/example2.db
Binary file not shown.
2 changes: 1 addition & 1 deletion Analogy.LogViewer.Sqlite/Analogy.LogViewer.Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net8.0-windows;net7.0-windows;net6.0-windows;net48;net471</TargetFrameworks>
<Version>0.7.0</Version>
<Version>0.7.1</Version>
<Authors>Lior Banai</Authors>
<Company>Analogy.LogViewer</Company>
<Product>Analogy.LogViewer.Sqlite</Product>
Expand Down
61 changes: 32 additions & 29 deletions Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -43,7 +44,7 @@ public override IEnumerable<AnalogyLogMessagePropertyName> HideExistingColumns()
yield return AnalogyLogMessagePropertyName.Class;
yield return AnalogyLogMessagePropertyName.ProcessId;
yield return AnalogyLogMessagePropertyName.ThreadId;
yield return AnalogyLogMessagePropertyName.MachineName;
yield return AnalogyLogMessagePropertyName.MachineName;
yield return AnalogyLogMessagePropertyName.MethodName;
yield return AnalogyLogMessagePropertyName.LineNumber;
yield return AnalogyLogMessagePropertyName.RawText;
Expand All @@ -61,24 +62,25 @@ public override async Task<IEnumerable<IAnalogyLogMessage>> Process(string fileN
using (var conn = new SqliteConnection($"Data Source={fileName};Mode=readonly"))
{
await conn.OpenAsync(token);

// executes query that select names of all tables in master table of the database
string query = "SELECT name FROM sqlite_master " +
"WHERE type = 'table'" +
"ORDER BY 1";

try
var messages = new List<IAnalogyLogMessage>();
DataTable dt = new DataTable();
using (SqliteCommand cmd = new SqliteCommand(query, conn))
{
DataTable dt = new DataTable();
using (SqliteCommand cmd = new SqliteCommand(query, conn))
using (SqliteDataReader rdr = await cmd.ExecuteReaderAsync(token))
{
using (SqliteDataReader rdr = await cmd.ExecuteReaderAsync(token))
{
dt.Load(rdr);
}
dt.Load(rdr);
}
}
foreach (DataRow row in dt.Rows)
{
DataTable dtData = new DataTable();
foreach (DataRow row in dt.Rows)
try
{
string dataQuery = "SELECT * FROM " + row.ItemArray[0];
using SqliteCommand cmd = new SqliteCommand(dataQuery, conn);
Expand All @@ -93,30 +95,31 @@ public override async Task<IEnumerable<IAnalogyLogMessage>> Process(string fileN

dtData.Load(reader);
}
}
var messages = new List<IAnalogyLogMessage>();
foreach (DataRow entry in dtData.Rows)
{
AnalogyLogMessage m = new AnalogyLogMessage();
m.Source = dtData.TableName;
for (var i = 0; i < entry.ItemArray.Length; i++)
foreach (DataRow entry in dtData.Rows)
{
var key = dtData.Columns[i].ColumnName;
var itm = entry.ItemArray[i];
m.AddOrReplaceAdditionalProperty(key, itm.ToString());
AnalogyLogMessage m = new AnalogyLogMessage();
m.Source = $"Table: {dtData.TableName}";
StringBuilder sb = new StringBuilder(entry.ItemArray.Length);
for (var i = 0; i < entry.ItemArray.Length; i++)
{
var key = dtData.Columns[i].ColumnName;
var itm = entry.ItemArray[i];
sb.AppendLine($"{key}: {itm}");
m.AddOrReplaceAdditionalProperty(key, itm.ToString());

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Dereference of a possibly null reference.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference argument for parameter 'value' in 'void AnalogyLogMessage.AddOrReplaceAdditionalProperty(string key, string value)'.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Dereference of a possibly null reference.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference argument for parameter 'value' in 'void AnalogyLogMessage.AddOrReplaceAdditionalProperty(string key, string value)'.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Dereference of a possibly null reference.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Possible null reference argument for parameter 'value' in 'void AnalogyLogMessage.AddOrReplaceAdditionalProperty(string key, string value)'.

Check warning on line 108 in Analogy.LogViewer.Sqlite/IAnalogy/SqliteBroswerDataProvider.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)
}

m.Text = sb.ToString();
messages.Add(m);
messagesHandler.AppendMessage(m, fileName);
}
messages.Add(m);
messagesHandler.AppendMessage(m, fileName);
}
return messages;
}

catch (Exception e)
{
LogManager.Instance.LogError(e, $"error:{e.Message}", e);
catch (Exception e)
{
LogManager.Instance.LogError(e, $"error:{e.Message}", e);
}
}

return new List<IAnalogyLogMessage>(0);
return messages;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.145">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.146">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit f7b8869

Please sign in to comment.