Add project files.
This commit is contained in:
70
ModVersionChecker/managers/litedb/AppConfigLiteDb.cs
Normal file
70
ModVersionChecker/managers/litedb/AppConfigLiteDb.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class AppConfigLiteDb : LiteDb, IAppsManager
|
||||
{
|
||||
private string collection = LiteDb.APPS_COLLECTION;
|
||||
public List<AppConfig> Load()
|
||||
{
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Insert(AppConfig app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.CreatedAt = now;
|
||||
app.UpdatedAt = now;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Insert(app);
|
||||
}
|
||||
|
||||
public void Update(AppConfig app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.UpdatedAt = now;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Update(app);
|
||||
}
|
||||
|
||||
//public void Upsert(AppConfig app)
|
||||
//{
|
||||
// var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
// app.UpdatedAt = now;
|
||||
// var col = _db.GetCollection<AppConfig>(collection);
|
||||
// if (string.IsNullOrEmpty(app.Id))
|
||||
// {
|
||||
// app.CreatedAt = now;
|
||||
// col.Insert(app);
|
||||
// }
|
||||
// col.Update(app);
|
||||
//}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Delete(id);
|
||||
}
|
||||
|
||||
public void Save(List<AppConfig> apps)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UpdateStatus(AppConfig app, AppStatus status)
|
||||
{
|
||||
app.LastCheckedAt = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.Status = status;
|
||||
var col = _db.GetCollection<AppConfig>(collection);
|
||||
col.Update(app);
|
||||
}
|
||||
}
|
||||
}
|
24
ModVersionChecker/managers/litedb/ConfigLiteDb.cs
Normal file
24
ModVersionChecker/managers/litedb/ConfigLiteDb.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class ConfigLiteDb : LiteDb, IConfigManager
|
||||
{
|
||||
private string collection = LiteDb.CONFIG_COLLECTION;
|
||||
public GlobalConfig Load()
|
||||
{
|
||||
var col = _db.GetCollection<GlobalConfig>(collection);
|
||||
return col.FindAll().FirstOrDefault() ?? new GlobalConfig();
|
||||
}
|
||||
public void Save(GlobalConfig config)
|
||||
{
|
||||
var col = _db.GetCollection<GlobalConfig>(collection);
|
||||
col.Upsert(config);
|
||||
}
|
||||
public GlobalConfig GetConfig()
|
||||
{
|
||||
return Load();
|
||||
}
|
||||
}
|
||||
}
|
32
ModVersionChecker/managers/litedb/FlightSimsLiteDb.cs
Normal file
32
ModVersionChecker/managers/litedb/FlightSimsLiteDb.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
internal class FlightSimsLiteDb : LiteDb, IFlightSimsManager
|
||||
{
|
||||
private string collection = FLIGHT_SIMS_COLLECTION;
|
||||
public List<FsModPathConfig> Load()
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Save(FsModPathConfig config)
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
col.Upsert(config);
|
||||
}
|
||||
|
||||
public FsModPathConfig? GetByShortName(string id)
|
||||
{
|
||||
var col = _db.GetCollection<FsModPathConfig>(collection);
|
||||
return col.FindOne(x => x.ShortName == id);
|
||||
}
|
||||
}
|
||||
}
|
16
ModVersionChecker/managers/litedb/LiteDb.cs
Normal file
16
ModVersionChecker/managers/litedb/LiteDb.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using LiteDB;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class LiteDb
|
||||
{
|
||||
public static string DB_PATH = "ModVersionChecker.db";
|
||||
public static string APPS_COLLECTION = "apps";
|
||||
public static string CHECKER_TYPES_DEF_COLLECTION = "checker_types_def";
|
||||
public static string SOURCES_DEF_COLLECTION = "sources_def";
|
||||
public static string CONFIG_COLLECTION = "config";
|
||||
public static string FLIGHT_SIMS_COLLECTION = "flight_sims";
|
||||
|
||||
protected LiteDatabase _db = LiteDbSingleton.Instance;
|
||||
}
|
||||
}
|
12
ModVersionChecker/managers/litedb/LiteDbSingleton.cs
Normal file
12
ModVersionChecker/managers/litedb/LiteDbSingleton.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using LiteDB;
|
||||
|
||||
public static class LiteDbSingleton
|
||||
{
|
||||
private static readonly LiteDatabase _db = new LiteDatabase(new ConnectionString
|
||||
{
|
||||
Filename = "ModVersionChecker.db",
|
||||
Connection = ConnectionType.Shared
|
||||
});
|
||||
|
||||
public static LiteDatabase Instance => _db;
|
||||
}
|
43
ModVersionChecker/managers/litedb/SourcesLiteDb.cs
Normal file
43
ModVersionChecker/managers/litedb/SourcesLiteDb.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using ModVersionChecker.data.model;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class SourcesLiteDb : LiteDb, ISourcesDefManager
|
||||
{
|
||||
private string collection = SOURCES_DEF_COLLECTION;
|
||||
public List<SourceDef> List()
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
return col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public SourceDef? GetById(string id)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
return col.FindOne(x => x.Id == id);
|
||||
}
|
||||
|
||||
public void AddSourceDef(SourceDef sourceDef)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Insert(sourceDef);
|
||||
}
|
||||
public void RemoveSourceDef(string id)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Delete(id);
|
||||
}
|
||||
|
||||
public void Save(SourceDef sourceDef)
|
||||
{
|
||||
var col = _db.GetCollection<SourceDef>(collection);
|
||||
col.Upsert(sourceDef);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user