51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using YY.Admin.Core.Util;
|
|
|
|
namespace YY.Admin.Services.Service.Jeecg
|
|
{
|
|
/// <summary>
|
|
/// 读写本地 Jeecg 同步状态文件(用户可写目录,避免 Program Files 无写权限)。
|
|
/// </summary>
|
|
public class JeecgSyncStateStore
|
|
{
|
|
private readonly string _filePath;
|
|
|
|
public JeecgSyncStateStore()
|
|
{
|
|
var dir = AppWritablePaths.EnsureDirectoryExists(AppWritablePaths.ConfigurationDirectory);
|
|
_filePath = Path.Combine(dir, "jeecg-sync-state.json");
|
|
}
|
|
|
|
public JeecgSyncState Load()
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(_filePath))
|
|
{
|
|
return new JeecgSyncState();
|
|
}
|
|
|
|
var json = File.ReadAllText(_filePath);
|
|
return JsonSerializer.Deserialize<JeecgSyncState>(json) ?? new JeecgSyncState();
|
|
}
|
|
catch
|
|
{
|
|
return new JeecgSyncState();
|
|
}
|
|
}
|
|
|
|
public void Save(JeecgSyncState state)
|
|
{
|
|
var dir = Path.GetDirectoryName(_filePath);
|
|
if (!string.IsNullOrEmpty(dir))
|
|
{
|
|
Directory.CreateDirectory(dir);
|
|
}
|
|
|
|
var json = JsonSerializer.Serialize(state, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(_filePath, json);
|
|
}
|
|
}
|
|
}
|