This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move AssetCatalog to using a local database
- Loading branch information
Showing
6 changed files
with
140 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Threading.Tasks; | ||
using LiteDB; | ||
|
||
namespace AssetCatalog.Model | ||
{ | ||
public class LocalCatalogDb : ICatalogDb | ||
{ | ||
private LiteDatabase _db; | ||
private ILiteCollection<CatalogEntry> _catalog; | ||
|
||
/// <inheritdoc /> | ||
public bool NeedsAuth() | ||
{ | ||
return false; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task Connect(string email, string password) | ||
{ | ||
_db = new LiteDatabase("catalog.db"); | ||
_catalog = _db.GetCollection<CatalogEntry>("catalog"); | ||
_catalog.EnsureIndex(entry => entry.Uid); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public CatalogEntry Get(ulong uid) | ||
{ | ||
var entry = _catalog.FindById(uid); | ||
|
||
if (entry != null) | ||
return entry; | ||
|
||
return new CatalogEntry | ||
{ | ||
Uid = uid, | ||
Status = CatalogEntryStatus.Incomplete, | ||
Category = CatalogAssetCategory.Uncategorized | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Put(ulong uid, CatalogEntry entry) | ||
{ | ||
_catalog.Upsert(uid, entry); | ||
ForgeCatalog.Instance.OnCatalogChanged(); | ||
} | ||
} | ||
} |