| | |
| | | namespace IStation |
| | | { |
| | | internal class ConfigHelper |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class ConfigHelper |
| | | { |
| | | |
| | | #region PostgreSql-ConnectionConfig |
| | |
| | | #region SQLite-ConnectionConfig |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="dbFile"></param> |
| | | /// <returns></returns> |
| | | private static string GetConnectionString(string dbFile) |
| | | { |
| | | var filePath = Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\" + dbFile; |
| | | return $"DataSource={filePath}"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="dbFile"></param> |
| | | /// <returns></returns> |
| | | public static string DeleteDataBase(string dbFile) |
| | | { |
| | | var filePath = Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\" + dbFile; |
| | | if (File.Exists(filePath)) |
| | | File.Delete(filePath); |
| | | return filePath; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// Analysis SQLite连接配置 |
| | | /// </summary> |
| | | internal static ConnectionConfig AnalysisConnectionConfig |
| | |
| | | return new ConnectionConfig() |
| | | { |
| | | DbType = SqlSugar.DbType.Sqlite,//数据库类型 |
| | | ConnectionString = Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString, |
| | | ConnectionString = GetConnectionString(Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString), |
| | | IsAutoCloseConnection = true,//是否自动关闭 |
| | | MoreSettings = new ConnMoreSettings() |
| | | { |
| | |
| | | return new ConnectionConfig() |
| | | { |
| | | DbType = SqlSugar.DbType.Sqlite,//数据库类型 |
| | | ConnectionString = Settings.ParasHelper.DataBase.SQLite.ScheduleConnectString, |
| | | ConnectionString = GetConnectionString(Settings.ParasHelper.DataBase.SQLite.ScheduleConnectString), |
| | | IsAutoCloseConnection = true,//是否自动关闭 |
| | | MoreSettings = new ConnMoreSettings() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化 Analysis 数据库 |
| | | /// </summary> |
| | | public static void InitAnalysisDB(bool backup = false) |
| | | { |
| | | DeleteDataBase(Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString); |
| | | var sqlSugarClient = new SqlSugarClient(AnalysisConnectionConfig); |
| | | Type[] types = new Type[] { |
| | | typeof(Entity.AnalysisLog), |
| | | //typeof(Entity.AnalysisCombine), |
| | | //typeof(Entity.AnalysisConclusion), |
| | | }; |
| | | sqlSugarClient.DbMaintenance.CreateDatabase(); |
| | | if (backup) |
| | | { |
| | | sqlSugarClient.CodeFirst.BackupTable().InitTables(types); |
| | | } |
| | | else |
| | | { |
| | | sqlSugarClient.CodeFirst.InitTables(types); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 初始化 Schedule 数据库 |
| | | /// </summary> |
| | | public static void InitScheduleDB(bool backup = false) |
| | | { |
| | | var sqlSugarClient = new SqlSugarClient(ScheduleConnectionConfig); |
| | | Type[] types = new Type[] { |
| | | typeof(Entity.ScheduleRequest), |
| | | typeof(Entity.ScheduleScada), |
| | | typeof(Entity.ScheduleRule), |
| | | typeof(Entity.SchedulePump), |
| | | typeof(Entity.ScheduleConclusion), |
| | | }; |
| | | sqlSugarClient.DbMaintenance.CreateDatabase(); |
| | | if (backup) |
| | | { |
| | | sqlSugarClient.CodeFirst.BackupTable().InitTables(types); |
| | | } |
| | | else |
| | | { |
| | | sqlSugarClient.CodeFirst.InitTables(types); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region SQLite-Sql |