phase 1
This commit is contained in:
52
ModVersionChecker/repository/filesystem/AppStatusManager.cs
Normal file
52
ModVersionChecker/repository/filesystem/AppStatusManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using ModVersionChecker.enums;
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
|
||||
public class AppStatusManager : IAppStatusManager
|
||||
{
|
||||
private Dictionary<string, AppStatus> _statuses = new Dictionary<string, AppStatus>();
|
||||
|
||||
public AppStatusManager() { }
|
||||
public AppStatus? GetAppStatus(string appId)
|
||||
{
|
||||
if (!_statuses.ContainsKey(appId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _statuses[appId];
|
||||
}
|
||||
public List<AppStatus> Load()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Save(List<AppStatus> appStatuses)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void UpdateAppStatus(string appId, AppStatus appStatus)
|
||||
{
|
||||
if (_statuses.ContainsKey(appId))
|
||||
{
|
||||
_statuses[appId] = appStatus;
|
||||
} else
|
||||
{
|
||||
_statuses.Add(appId, appStatus);
|
||||
}
|
||||
}
|
||||
public bool DeleteAppStatus(string appId) {
|
||||
return _statuses.Remove(appId);
|
||||
}
|
||||
public void ClearAll()
|
||||
{
|
||||
_statuses.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
42
ModVersionChecker/repository/filesystem/AppsManager.cs
Normal file
42
ModVersionChecker/repository/filesystem/AppsManager.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class AppsManager
|
||||
{
|
||||
private readonly string FilePath = Path.Combine(AppContext.BaseDirectory, "data", "apps.json");
|
||||
|
||||
public List<App> Load()
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
return new List<App>();
|
||||
var json = File.ReadAllText(FilePath);
|
||||
return JsonSerializer.Deserialize<List<App>>(json) ?? new();
|
||||
}
|
||||
|
||||
public void Save(List<App> apps)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(apps, options);
|
||||
File.WriteAllText(FilePath, json);
|
||||
}
|
||||
|
||||
public void Upsert(App app)
|
||||
{
|
||||
var apps = Load();
|
||||
var index = apps.FindIndex(a => a.Id == app.Id);
|
||||
if (index >= 0)
|
||||
{
|
||||
apps[index] = app;
|
||||
}
|
||||
else
|
||||
{
|
||||
apps.Add(app);
|
||||
}
|
||||
Save(apps);
|
||||
}
|
||||
}
|
||||
}
|
40
ModVersionChecker/repository/filesystem/ConfigManager.cs
Normal file
40
ModVersionChecker/repository/filesystem/ConfigManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.model;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class ConfigManager : IConfigManager
|
||||
{
|
||||
|
||||
private static readonly string _filePath = Path.Combine(AppContext.BaseDirectory, "data", "config.json");
|
||||
private Config _config;
|
||||
|
||||
public ConfigManager()
|
||||
{
|
||||
_config = Load();
|
||||
}
|
||||
|
||||
public Config Load()
|
||||
{
|
||||
if (!File.Exists(_filePath))
|
||||
return new Config();
|
||||
var json = File.ReadAllText(_filePath);
|
||||
return JsonSerializer.Deserialize<Config>(json) ?? new Config();
|
||||
}
|
||||
|
||||
public Config GetConfig()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public void Save(Config config)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(config, options);
|
||||
File.WriteAllText(_filePath, json);
|
||||
}
|
||||
}
|
||||
}
|
52
ModVersionChecker/repository/filesystem/SourcesDefManager.cs
Normal file
52
ModVersionChecker/repository/filesystem/SourcesDefManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.repository.api.dto;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModVersionChecker.managers.filesystem
|
||||
{
|
||||
public class SourcesDefManager
|
||||
{
|
||||
private readonly string _filePath = Path.Combine(AppContext.BaseDirectory, "data", "sourcesDef.json");
|
||||
private List<SourceResponse> _sourcesDef = new List<SourceResponse>();
|
||||
|
||||
public SourcesDefManager()
|
||||
{
|
||||
_sourcesDef = Load();
|
||||
}
|
||||
|
||||
private List<SourceResponse> Load()
|
||||
{
|
||||
if (!File.Exists(_filePath))
|
||||
return new List<SourceResponse>();
|
||||
var json = File.ReadAllText(_filePath);
|
||||
return JsonSerializer.Deserialize<List<SourceResponse>>(json) ?? new();
|
||||
}
|
||||
|
||||
public List<SourceResponse> GetSourcesDef()
|
||||
{
|
||||
return _sourcesDef;
|
||||
}
|
||||
|
||||
public void AddSourceDef(SourceResponse sourceDef)
|
||||
{
|
||||
_sourcesDef.Add(sourceDef);
|
||||
Save(_sourcesDef);
|
||||
}
|
||||
|
||||
public void RemoveSourceDef(string id)
|
||||
{
|
||||
_sourcesDef.RemoveAll(s => s.Id == id);
|
||||
Save(_sourcesDef);
|
||||
}
|
||||
|
||||
|
||||
public void Save(List<SourceResponse> sourcesDef)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
var json = JsonSerializer.Serialize(sourcesDef, options);
|
||||
File.WriteAllText(_filePath, json);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user