Files
qhmes/yy-admin-master/YY.Admin.Services/Service/Jeecg/JeecgSyncStateStore.cs

50 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.IO;
using System.Text.Json;
namespace YY.Admin.Services.Service.Jeecg
{
/// <summary>
/// 读写本地 Jeecg 同步状态文件(与 appsettings 同目录下的 Configuration
/// </summary>
public class JeecgSyncStateStore
{
private readonly string _filePath;
public JeecgSyncStateStore()
{
var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configuration");
_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);
}
}
}