2024-04-16 18:29:40 +00:00
|
|
|
using LootDumpProcessor.Storage.Implementations.File;
|
2023-08-12 19:08:38 +01:00
|
|
|
using LootDumpProcessor.Storage.Implementations.Memory;
|
|
|
|
|
|
|
|
namespace LootDumpProcessor.Storage;
|
|
|
|
|
|
|
|
public static class DataStorageFactory
|
|
|
|
{
|
2024-04-16 18:29:40 +00:00
|
|
|
private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage = new();
|
2023-08-12 19:08:38 +01:00
|
|
|
|
2024-04-16 18:29:40 +00:00
|
|
|
private static object lockObject = new();
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Requires LootDumpProcessorContext to be initialized before using
|
|
|
|
*/
|
|
|
|
public static IDataStorage GetInstance()
|
|
|
|
{
|
|
|
|
return GetInstance(LootDumpProcessorContext.GetConfig().DataStorageConfig.DataStorageType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static IDataStorage GetInstance(DataStorageTypes type)
|
|
|
|
{
|
|
|
|
IDataStorage dataStorage;
|
|
|
|
lock (lockObject)
|
|
|
|
{
|
|
|
|
if (!_dataStorage.TryGetValue(type, out dataStorage))
|
|
|
|
{
|
2024-04-16 18:29:40 +00:00
|
|
|
dataStorage = type switch
|
2023-08-12 19:08:38 +01:00
|
|
|
{
|
2024-04-16 18:29:40 +00:00
|
|
|
DataStorageTypes.File => new FileDataStorage(),
|
|
|
|
DataStorageTypes.Memory => new MemoryDataStorage(),
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
|
|
};
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
_dataStorage.Add(type, dataStorage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataStorage;
|
|
|
|
}
|
|
|
|
}
|