1
0
mirror of synced 2024-11-14 17:33:49 +00:00
PettingZoo/PettingZoo.Settings.LiteDB/BaseLiteDBRepository.cs
Mark van Renswoude 28d3548088 Implemented JSON syntax checking
Implemented (re)storing of main window position
2021-12-20 11:51:28 +01:00

36 lines
1.0 KiB
C#

using LiteDB;
using LiteDB.Async;
namespace PettingZoo.Settings.LiteDB
{
public class BaseLiteDBRepository
{
private readonly string databaseFilename;
protected static readonly BsonMapper Mapper = new()
{
EmptyStringToNull = false
};
public BaseLiteDBRepository(string databaseName)
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (appDataPath == null)
throw new IOException("Could not resolve application data path");
var databasePath = Path.Combine(appDataPath, @"PettingZoo");
if (!Directory.CreateDirectory(databasePath).Exists)
throw new IOException($"Failed to create directory: {databasePath}");
databaseFilename = Path.Combine(databasePath, $"{databaseName}.litedb");
}
protected ILiteDatabaseAsync GetDatabase()
{
return new LiteDatabaseAsync(databaseFilename, Mapper);
}
}
}