Remove legacy name file backing store
This commit is contained in:
parent
22a50151ec
commit
596534896f
4 changed files with 13 additions and 66 deletions
|
|
@ -20,21 +20,12 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
private readonly object addLock = new object();
|
||||
|
||||
private List<CacheBackingStore> _backingStores = new List<CacheBackingStore>();
|
||||
|
||||
private readonly Dictionary<CacheBackingStore, Type[]> _storeTypes = new Dictionary<CacheBackingStore, Type[]>();
|
||||
|
||||
private readonly Dictionary<Guid, DatabaseEntry> _entries = new Dictionary<Guid, DatabaseEntry>();
|
||||
|
||||
public void AddBackingStore(CacheBackingStore store, params Type[] domain)
|
||||
public void AddBackingStore(CacheBackingStore store)
|
||||
{
|
||||
if (domain.Length > 0)
|
||||
{
|
||||
_storeTypes[store] = domain;
|
||||
}
|
||||
else
|
||||
{
|
||||
_backingStores.Add(store);
|
||||
}
|
||||
_backingStores.Add(store);
|
||||
store.EntryAdded.Subscribe(entry =>
|
||||
{
|
||||
AddInternal(entry, store);
|
||||
|
|
@ -44,7 +35,6 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
public void PullAllBackingStores()
|
||||
{
|
||||
foreach(var store in _backingStores) store.PullAll();
|
||||
foreach(var store in _storeTypes.Keys) store.PullAll();
|
||||
}
|
||||
|
||||
private void AddInternal(DatabaseEntry entry, CacheBackingStore source = null)
|
||||
|
|
@ -85,55 +75,6 @@ public abstract class CacheBackingStore
|
|||
protected Dictionary<Guid, DatabaseEntry> Entries = new Dictionary<Guid, DatabaseEntry>();
|
||||
}
|
||||
|
||||
public abstract class MultiFileBackingStore : CacheBackingStore
|
||||
{
|
||||
public DirectoryInfo DirectoryInfo { get; }
|
||||
protected Dictionary<Type, DirectoryInfo> _entryTypeDirectories = new Dictionary<Type, DirectoryInfo>();
|
||||
|
||||
public abstract DatabaseEntry Deserialize(byte[] data);
|
||||
public abstract string Extension { get; }
|
||||
|
||||
public MultiFileBackingStore(string path)
|
||||
{
|
||||
DirectoryInfo = new DirectoryInfo(path);
|
||||
foreach (var type in typeof(DatabaseEntry).GetAllChildClasses())
|
||||
{
|
||||
_entryTypeDirectories[type] = new DirectoryInfo(Path.Combine(DirectoryInfo.FullName, type.Name));
|
||||
}
|
||||
}
|
||||
|
||||
public override void PullAll()
|
||||
{
|
||||
if (!DirectoryInfo.Exists) return;
|
||||
|
||||
foreach (var directory in _entryTypeDirectories.Values)
|
||||
{
|
||||
foreach (var file in directory.EnumerateFiles($"*.{Extension}"))
|
||||
{
|
||||
var entry = Deserialize(File.ReadAllBytes(file.FullName));
|
||||
Entries[entry.ID] = entry;
|
||||
EntryAdded.OnNext(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MultiFileMessagePackBackingStore : MultiFileBackingStore
|
||||
{
|
||||
public MultiFileMessagePackBackingStore(string path) : base(path)
|
||||
{
|
||||
RegisterResolver.Register();
|
||||
}
|
||||
|
||||
public override DatabaseEntry Deserialize(byte[] data)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<DatabaseEntry>(data);
|
||||
}
|
||||
|
||||
public override string Extension => "msgpack";
|
||||
}
|
||||
|
||||
public abstract class SingleFileBackingStore : CacheBackingStore
|
||||
{
|
||||
public FileInfo FileInfo { get; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue