mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 08:30:46 -05:00
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System.Collections.Concurrent;
|
|
using LootDumpProcessor.Storage.Implementations.File;
|
|
using LootDumpProcessor.Storage.Implementations.Memory;
|
|
|
|
namespace LootDumpProcessor.Storage;
|
|
|
|
public static class DataStorageFactory
|
|
{
|
|
private static readonly ConcurrentDictionary<DataStorageTypes, IDataStorage> DataStorage = new();
|
|
|
|
/**
|
|
* Requires LootDumpProcessorContext to be initialized before using
|
|
*/
|
|
public static IDataStorage GetInstance() =>
|
|
GetInstance(LootDumpProcessorContext.GetConfig().DataStorageConfig.DataStorageType);
|
|
|
|
private static IDataStorage GetInstance(DataStorageTypes type)
|
|
{
|
|
if (DataStorage.TryGetValue(type, out var dataStorage)) return dataStorage;
|
|
|
|
dataStorage = type switch
|
|
{
|
|
DataStorageTypes.File => new FileDataStorage(),
|
|
DataStorageTypes.Memory => new MemoryDataStorage(),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
};
|
|
|
|
DataStorage.TryAdd(type, dataStorage);
|
|
|
|
return dataStorage;
|
|
}
|
|
} |