加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Persist.cs 4.36 KB
一键复制 编辑 原始数据 按行查看 历史
using System;
using System.Collections.Generic;
using System.IO;
namespace MySqlDataBuild
{
public class Persist
{
private static Persist i;
public static Persist I
{
get
{
if (i == null)
{
i = new Persist();
LoadData(ref i);
}
return i;
}
}
public string version;
public string dbName;
internal string ip
{
get => this[dbName].ip;
set => this[dbName].ip = value;
}
internal string port
{
get => this[dbName].port;
set => this[dbName].port = value;
}
internal string pwd
{
get => this[dbName].pwd;
set => this[dbName].pwd = value;
}
internal string user
{
get => this[dbName].user;
set => this[dbName].user = value;
}
public string sqliteDBPath { get; set; }
public string sqliteGeneratePath { get; set; }
public int sqliteIncrementIdType { get; set; }
public int sqliteNamespaceIndex { get; set; }
internal int namespaceIndex
{
get => this[dbName].namespaceIndex;
set => this[dbName].namespaceIndex = value;
}
internal bool clearOldFiles
{
get => this[dbName].clearOldFiles;
set => this[dbName].clearOldFiles = value;
}
internal bool compatible
{
get => this[dbName].compatible;
set => this[dbName].compatible = value;
}
internal bool creatDbPath
{
get => this[dbName].creatDbPath;
set => this[dbName].creatDbPath = value;
}
internal int incrementIdType
{
get => this[dbName].incrementIdType;
set => this[dbName].incrementIdType = value;
}
internal int pathIndex
{
get => this[dbName].pathIndex;
set => this[dbName].pathIndex = value;
}
internal int exPathIndex
{
get => this[dbName].exIndex;
set => this[dbName].exIndex = value;
}
internal string path
{
get
{
if (string.IsNullOrEmpty(dbName))
return string.Empty;
if (datas.TryGetValue(dbName, out var data))
if (pathIndex != -1 & pathIndex < data.paths.Count)
return data.paths[pathIndex];
return string.Empty;
}
}
internal string exPath
{
get
{
if (string.IsNullOrEmpty(dbName))
return string.Empty;
if (datas.TryGetValue(dbName, out var data))
if (exPathIndex != -1 & exPathIndex < data.exPaths.Count)
return data.exPaths[exPathIndex];
return string.Empty;
}
}
internal List<string> paths
{
get => this[dbName].paths;
set => this[dbName].paths = value;
}
internal List<string> exPaths
{
get => this[dbName].exPaths;
set => this[dbName].exPaths = value;
}
public Dictionary<string, DataEntity> datas = new Dictionary<string, DataEntity>();
public DataEntity this[string name]
{
get
{
if (string.IsNullOrEmpty(dbName))
return new DataEntity();
if (datas.TryGetValue(dbName, out var data))
return data;
return new DataEntity();
}
}
public static void LoadData(ref Persist persist)
{
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "persist.data"))
return;
var jsonText = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "persist.data");
persist = Newtonsoft.Json.JsonConvert.DeserializeObject<Persist>(jsonText);
}
public static void SaveData()
{
var jsonText = Newtonsoft.Json.JsonConvert.SerializeObject(I);
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "persist.data", jsonText);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化