phase 1
This commit is contained in:
50
ModVersionChecker/repository/litedb/AppLiteDb.cs
Normal file
50
ModVersionChecker/repository/litedb/AppLiteDb.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using ModVersionChecker.enums;
|
||||
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 AppLiteDb : LiteDb, IAppsManager
|
||||
{
|
||||
protected override string collection => LiteDb.APPS_COLLECTION;
|
||||
|
||||
public List<App> Load()
|
||||
{
|
||||
return GetCollection<App>().FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Insert(App app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
GetCollection<App>().Insert(app);
|
||||
}
|
||||
|
||||
public void Update(App app)
|
||||
{
|
||||
var now = TimeUtils.GetUnixTimeMillis(null);
|
||||
GetCollection<App>().Update(app);
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
GetCollection<App>().Delete(id);
|
||||
}
|
||||
|
||||
public void Save(List<App> apps)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UpdateStatus(App app, AppStatus status)
|
||||
{
|
||||
app.LastCheckedAt = TimeUtils.GetUnixTimeMillis(null);
|
||||
app.Status = status;
|
||||
GetCollection<App>().Update(app);
|
||||
}
|
||||
}
|
||||
}
|
22
ModVersionChecker/repository/litedb/ConfigLiteDb.cs
Normal file
22
ModVersionChecker/repository/litedb/ConfigLiteDb.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.model;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public class ConfigLiteDb : LiteDb, IConfigManager
|
||||
{
|
||||
protected override string collection => LiteDb.CONFIG_COLLECTION;
|
||||
public Config Load()
|
||||
{
|
||||
return GetCollection<Config>().FindAll().FirstOrDefault() ?? new Config();
|
||||
}
|
||||
public void Save(Config config)
|
||||
{
|
||||
GetCollection<Config>().Upsert(config);
|
||||
}
|
||||
public Config GetConfig()
|
||||
{
|
||||
return Load();
|
||||
}
|
||||
}
|
||||
}
|
25
ModVersionChecker/repository/litedb/LiteDb.cs
Normal file
25
ModVersionChecker/repository/litedb/LiteDb.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using LiteDB;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
public abstract 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";
|
||||
public static string TYPES_COLLECTION = "types";
|
||||
public static string LOCAL_APPS_COLLECTION = "local_apps";
|
||||
|
||||
protected LiteDatabase _db = LiteDbSingleton.Instance;
|
||||
|
||||
protected abstract string collection { get; }
|
||||
|
||||
protected ILiteCollection<T> GetCollection<T>()
|
||||
{
|
||||
return _db.GetCollection<T>(collection);
|
||||
}
|
||||
}
|
||||
}
|
44
ModVersionChecker/repository/litedb/SourcesLiteDb.cs
Normal file
44
ModVersionChecker/repository/litedb/SourcesLiteDb.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.repository.api.dto;
|
||||
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
|
||||
{
|
||||
protected override string collection => SOURCES_DEF_COLLECTION;
|
||||
|
||||
public List<SourceResponse> List()
|
||||
{
|
||||
return GetCollection<SourceResponse>().FindAll().ToList();
|
||||
}
|
||||
|
||||
public SourceResponse? GetById(string id)
|
||||
{
|
||||
return GetCollection<SourceResponse>().FindOne(x => x.Id == id);
|
||||
}
|
||||
|
||||
public void AddSourceDef(SourceResponse sourceDef)
|
||||
{
|
||||
GetCollection<SourceResponse>().Insert(sourceDef);
|
||||
}
|
||||
public void RemoveSourceDef(string id)
|
||||
{
|
||||
GetCollection<SourceResponse>().Delete(id);
|
||||
}
|
||||
|
||||
public void Save(SourceResponse sourceDef)
|
||||
{
|
||||
GetCollection<SourceResponse>().Upsert(sourceDef);
|
||||
}
|
||||
|
||||
public void DeleteAll()
|
||||
{
|
||||
GetCollection<SourceResponse>().DeleteAll();
|
||||
}
|
||||
}
|
||||
}
|
35
ModVersionChecker/repository/litedb/TypeConfigLiteDb.cs
Normal file
35
ModVersionChecker/repository/litedb/TypeConfigLiteDb.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.model;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
internal class TypeConfigLiteDb : LiteDb, ITypeManager
|
||||
{
|
||||
protected override string collection => TYPES_COLLECTION;
|
||||
|
||||
public void DeleteTypeConfig(string id)
|
||||
{
|
||||
GetCollection<TypeConfig>().Delete(id);
|
||||
}
|
||||
|
||||
public TypeConfig? GetTypeConfigById(string id)
|
||||
{
|
||||
return GetCollection<TypeConfig>().FindOne(x => x.Id == id);
|
||||
}
|
||||
|
||||
public List<TypeConfig> GetTypeConfigs()
|
||||
{
|
||||
return GetCollection<TypeConfig>().FindAll().ToList();
|
||||
}
|
||||
|
||||
public void SaveTypeConfig(TypeConfig type)
|
||||
{
|
||||
GetCollection<TypeConfig>().Upsert(type);
|
||||
}
|
||||
|
||||
public void SaveTypeConfigs(List<TypeConfig> types)
|
||||
{
|
||||
GetCollection<TypeConfig>().InsertBulk(types);
|
||||
}
|
||||
}
|
||||
}
|
35
ModVersionChecker/repository/litedb/TypeLiteDb.cs
Normal file
35
ModVersionChecker/repository/litedb/TypeLiteDb.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.repository.api.dto;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.litedb
|
||||
{
|
||||
internal class TypeLiteDb : LiteDb, IFlightSimsManager
|
||||
{
|
||||
protected override string collection => FLIGHT_SIMS_COLLECTION;
|
||||
|
||||
public List<TypeResponse> Load()
|
||||
{
|
||||
return GetCollection<TypeResponse>().FindAll().ToList();
|
||||
}
|
||||
|
||||
public void Save(TypeResponse config)
|
||||
{
|
||||
GetCollection<TypeResponse>().Upsert(config);
|
||||
}
|
||||
|
||||
public TypeResponse? GetByShortName(string id)
|
||||
{
|
||||
return GetCollection<TypeResponse>().FindOne(x => x.ShortName == id);
|
||||
}
|
||||
|
||||
public void DeleteAll()
|
||||
{
|
||||
GetCollection<TypeResponse>().DeleteAll();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user