Skip to content

Commit

Permalink
Fixed read only database issue with CreateDatabase command
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 committed Jan 22, 2025
1 parent 07fd798 commit 37a9a1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/EventLogExpert.EventDbTool/CreateDatabaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ public static void CreateDatabase(string path, string filter, bool verboseLoggin

HashSet<string> skipProviderNames = [];

if (!File.Exists(skipProvidersInFile))
if (!string.IsNullOrWhiteSpace(skipProvidersInFile))
{
Console.WriteLine($"File not found: {skipProvidersInFile}");
if (!File.Exists(skipProvidersInFile))
{
Console.WriteLine($"File not found: {skipProvidersInFile}");
}

using var skipDbContext = new EventProviderDbContext(skipProvidersInFile, readOnly: true);
foreach (var provider in skipDbContext.ProviderDetails)
{
skipProviderNames.Add(provider.ProviderName);
}

Console.WriteLine($"Found {skipProviderNames.Count} providers in file {skipProvidersInFile}. " +
"These will not be included in the new database.");
}

using var skipDbContext = new EventProviderDbContext(skipProvidersInFile, readOnly: true);
foreach (var provider in skipDbContext.ProviderDetails)
{
skipProviderNames.Add(provider.ProviderName);
}

Console.WriteLine($"Found {skipProviderNames.Count} providers in file {skipProvidersInFile}. " +
"These will not be included in the new database.");

var providerNames = GetLocalProviderNames(filter);

if (!providerNames.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace EventLogExpert.Eventing.EventProviderDatabase;

public class EventProviderDbContext : DbContext
public sealed class EventProviderDbContext : DbContext
{
private readonly bool _readOnly;

Expand All @@ -30,7 +30,7 @@ public EventProviderDbContext(string path, bool readOnly, ITraceLogger? logger =

public string Name { get; }

public string Path { get; }
private string Path { get; }

public DbSet<ProviderDetails> ProviderDetails { get; set; }

Expand Down

0 comments on commit 37a9a1d

Please sign in to comment.