2025-01-11 11:26:11 +03:00
|
|
|
using System.Collections.Concurrent;
|
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
|
|
|
|
{
|
2025-01-11 11:26:11 +03:00
|
|
|
private static readonly ConcurrentDictionary<DataStorageTypes, IDataStorage> DataStorage = new();
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Requires LootDumpProcessorContext to be initialized before using
|
|
|
|
*/
|
2025-01-11 10:52:23 +03:00
|
|
|
public static IDataStorage GetInstance() =>
|
|
|
|
GetInstance(LootDumpProcessorContext.GetConfig().DataStorageConfig.DataStorageType);
|
2023-08-12 19:08:38 +01:00
|
|
|
|
2025-01-11 11:26:11 +03:00
|
|
|
private static IDataStorage GetInstance(DataStorageTypes type)
|
2023-08-12 19:08:38 +01:00
|
|
|
{
|
2025-01-11 11:26:11 +03:00
|
|
|
if (DataStorage.TryGetValue(type, out var dataStorage)) return dataStorage;
|
|
|
|
|
|
|
|
dataStorage = type switch
|
2023-08-12 19:08:38 +01:00
|
|
|
{
|
2025-01-11 11:26:11 +03:00
|
|
|
DataStorageTypes.File => new FileDataStorage(),
|
|
|
|
DataStorageTypes.Memory => new MemoryDataStorage(),
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
|
|
};
|
2023-08-12 19:08:38 +01:00
|
|
|
|
2025-01-11 11:26:11 +03:00
|
|
|
DataStorage.TryAdd(type, dataStorage);
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
return dataStorage;
|
|
|
|
}
|
|
|
|
}
|