From 48083a90d2d0792cb9930cf0aa35c93d1845e5ae Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Thu, 4 Aug 2022 14:11:22 +0800 Subject: [PATCH] Use DBreeze Impl Preferences/SettingsHost fix StringExtensions.Trim --- Directory.Packages.props | 3 + SteamToolsV2+.sln | 2 +- .../PreferencesPlatformServiceImpl.cs | 295 +++++++++++----- .../ServiceCollectionExtensions.cs | 2 +- .../Settings/FileSettingsProvider.cs | 188 +++++----- .../Settings/ISerializationProvider.cs | 32 +- .../Settings/SerializableProperty.cs | 320 +++++++++--------- .../Application/Settings/SettingsHost.cs | 136 ++++---- .../Settings/V3/SerializableProperty.cs | 166 +++++++++ .../Application/Settings/V3/SettingsHost.cs | 26 ++ .../Settings/V3/SettingsProviderV3.cs | 88 +++++ .../Settings/ValueChangedEventArgs.cs | 2 +- src/Common.CoreLib/Common.CoreLib.csproj | 1 + .../Extensions/StringExtensions.Trim.cs | 24 +- .../Application.Repositories/Repository.cs | 54 +-- src/ST.Client.CommandLine/CommandLineHost.cs | 34 +- src/Startup.cs | 2 + 17 files changed, 889 insertions(+), 486 deletions(-) create mode 100644 src/Common.CoreLib/Application/Settings/V3/SerializableProperty.cs create mode 100644 src/Common.CoreLib/Application/Settings/V3/SettingsHost.cs create mode 100644 src/Common.CoreLib/Application/Settings/V3/SettingsProviderV3.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index a90042030..2cada0587 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -323,5 +323,8 @@ + + + diff --git a/SteamToolsV2+.sln b/SteamToolsV2+.sln index 2c0cc7968..dab821388 100644 --- a/SteamToolsV2+.sln +++ b/SteamToolsV2+.sln @@ -2608,7 +2608,7 @@ Global {8C996C50-B29F-4CB6-90A7-77C9CD3B0B70} = {910D6A0F-42AB-4B65-B532-852E864EC006} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9313F2B4-10DA-43AA-A481-CAA7571C740C} RESX_NeutralResourcesLanguage = zh-Hans + SolutionGuid = {9313F2B4-10DA-43AA-A481-CAA7571C740C} EndGlobalSection EndGlobal diff --git a/src/Common.ClientLib/Application/Services/Implementation/PreferencesPlatformServiceImpl.cs b/src/Common.ClientLib/Application/Services/Implementation/PreferencesPlatformServiceImpl.cs index 9a0dbe17e..de5fc5d24 100644 --- a/src/Common.ClientLib/Application/Services/Implementation/PreferencesPlatformServiceImpl.cs +++ b/src/Common.ClientLib/Application/Services/Implementation/PreferencesPlatformServiceImpl.cs @@ -1,6 +1,7 @@ using SQLite; using System.Application.Entities; using System.Application.Repositories; +using System.Application.Settings; using System.Diagnostics; using System.Globalization; using SQLiteNotNull = SQLite.NotNullAttribute; @@ -8,55 +9,125 @@ using SQLiteTable = SQLite.TableAttribute; namespace System.Application.Services.Implementation; -internal sealed class PreferencesPlatformServiceImpl : IPreferencesGenericPlatformService +//sealed class PreferencesPlatformServiceImpl : IPreferencesGenericPlatformService +partial class PreferencesPlatformServiceImplV2 { - readonly SQLiteConnection conn; + //readonly SQLiteConnection conn; - public PreferencesPlatformServiceImpl() + //public PreferencesPlatformServiceImpl() + //{ + // conn = Repository.GetDbConnectionSync(); + //} + + //internal static string GetId(string key) => $"{key}_K"; + + //internal static string GetId(string key, string? sharedName) + //{ + // if (sharedName == null) return GetId(key); + // return $"{key}_{sharedName}_S"; + //} + + //public void PlatformClear(string? sharedName) + //{ + // conn.Execute(Sql_Delete_Where_SharedName_Equals, sharedName ?? string.Empty); + //} + + //public bool PlatformContainsKey(string key, string? sharedName) + //{ + // var id = GetId(key, sharedName); + // sharedName ??= string.Empty; + // var item = conn.Table() + // .Where(x => x.Id == id && x.SharedName == sharedName) + // .FirstOrDefault(); + // return item != null; + //} + + //public T? PlatformGet(string key, T? defaultValue, string? sharedName) where T : notnull, IConvertible + //{ + // var id = GetId(key, sharedName); + // sharedName ??= string.Empty; + // var item = conn.Table() + // .Where(x => x.Id == id && x.SharedName == sharedName) + // .FirstOrDefault(); + // if (item == null) return defaultValue; + // var value = ConvertibleHelper.Convert(item.Value); + // return value; + //} + + //public void PlatformRemove(string key, string? sharedName) + //{ + // var id = GetId(key, sharedName); + // conn.Delete(id); + //} + + //public void PlatformSet(string key, T? value, string? sharedName) where T : notnull, IConvertible + //{ + // if (value == null) + // { + // PlatformRemove(key, sharedName); + // } + // else + // { + // var id = GetId(key, sharedName); + // conn.InsertOrReplace(new Entity + // { + // Id = id, + // Value = value.ToString(CultureInfo.InvariantCulture), + // SharedName = sharedName ?? string.Empty, + // }); + // } + //} + + const string TableName = "1984415E"; + const string ColumnName_Id = "0F5E4BAA"; + const string ColumnName_Value = "4FC331D7"; + const string ColumnName_SharedName = "F6A739AA"; + + //const string Sql_Delete_Where_SharedName_Equals = + // $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_SharedName}\" = ?"; + + ////const string Sql_Delete_Where_Id_Equals_And_SharedName_IsNull = + //// $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; + + ////const string Sql_Delete_Where_Id_Equals_And_SharedName_Equals = + //// $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; + + ////const string Sql_Select_SharedName_Where_Key_Equals_And_SharedName_IsNull = + //// $"SELECT \"{ColumnName_SharedName}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; + + ////const string Sql_Select_SharedName_Where_Key_Equals_And_SharedName_Equals = + //// $"SELECT \"{ColumnName_SharedName}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; + + ////const string Sql_Select_Value_Where_Key_Equals_And_SharedName_IsNull = + //// $"SELECT \"{ColumnName_Value}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; + + ////const string Sql_Select_Value_Where_Key_Equals_And_SharedName_Equals = + //// $"SELECT \"{ColumnName_Value}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; + + [SQLiteTable(TableName)] + [DebuggerDisplay("{DebuggerDisplay(),nq}")] + public sealed class Entity : IEntity { - conn = Repository.GetDbConnectionSync(); - } + [Column(ColumnName_Id)] + [PrimaryKey] + [SQLiteNotNull] + public string Id { get; set; } = string.Empty; - static string GetId(string key) => $"{key}_K"; + [Column(ColumnName_Value)] + [SQLiteNotNull] + public string Value { get; set; } = string.Empty; - static string GetId(string key, string? sharedName) - { - if (sharedName == null) return GetId(key); - return $"{key}_{sharedName}_S"; - } + [Column(ColumnName_SharedName)] + [SQLiteNotNull] + public string SharedName { get; set; } = string.Empty; - public void PlatformClear(string? sharedName) - { - conn.Execute(Sql_Delete_Where_SharedName_Equals, sharedName ?? string.Empty); + string DebuggerDisplay() => SharedName == string.Empty ? $"{Id}, {Value}" : $"{Id}, {Value}, {SharedName}"; } +} - public bool PlatformContainsKey(string key, string? sharedName) - { - var id = GetId(key, sharedName); - sharedName ??= string.Empty; - var item = conn.Table() - .Where(x => x.Id == id && x.SharedName == sharedName) - .FirstOrDefault(); - return item != null; - } - - public T? PlatformGet(string key, T? defaultValue, string? sharedName) where T : notnull, IConvertible - { - var id = GetId(key, sharedName); - sharedName ??= string.Empty; - var item = conn.Table() - .Where(x => x.Id == id && x.SharedName == sharedName) - .FirstOrDefault(); - if (item == null) return defaultValue; - var value = ConvertibleHelper.Convert(item.Value); - return value; - } - - public void PlatformRemove(string key, string? sharedName) - { - var id = GetId(key, sharedName); - conn.Delete(id); - } +public sealed partial class PreferencesPlatformServiceImplV2 : IPreferencesGenericPlatformService +{ + static string GetTableName(string? sharedName) => $"Preferences.{sharedName}"; public void PlatformSet(string key, T? value, string? sharedName) where T : notnull, IConvertible { @@ -66,61 +137,105 @@ internal sealed class PreferencesPlatformServiceImpl : IPreferencesGenericPlatfo } else { - var id = GetId(key, sharedName); - conn.InsertOrReplace(new Entity - { - Id = id, - Value = value.ToString(CultureInfo.InvariantCulture), - SharedName = sharedName ?? string.Empty, - }); + using var t = SettingsProviderV3.Provider.GetTransaction(); + t.Insert(GetTableName(sharedName), key, value.ToString(CultureInfo.InvariantCulture)); + t.Commit(); } } - const string TableName = "1984415E"; - const string ColumnName_Id = "0F5E4BAA"; - const string ColumnName_Value = "4FC331D7"; - const string ColumnName_SharedName = "F6A739AA"; - - const string Sql_Delete_Where_SharedName_Equals = - $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_SharedName}\" = ?"; - - //const string Sql_Delete_Where_Id_Equals_And_SharedName_IsNull = - // $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; - - //const string Sql_Delete_Where_Id_Equals_And_SharedName_Equals = - // $"DELETE FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; - - //const string Sql_Select_SharedName_Where_Key_Equals_And_SharedName_IsNull = - // $"SELECT \"{ColumnName_SharedName}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; - - //const string Sql_Select_SharedName_Where_Key_Equals_And_SharedName_Equals = - // $"SELECT \"{ColumnName_SharedName}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; - - //const string Sql_Select_Value_Where_Key_Equals_And_SharedName_IsNull = - // $"SELECT \"{ColumnName_Value}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = NULL"; - - //const string Sql_Select_Value_Where_Key_Equals_And_SharedName_Equals = - // $"SELECT \"{ColumnName_Value}\" FROM \"{TableName}\" WHERE \"{ColumnName_Id}\" = ? AND \"{ColumnName_SharedName}\" = ?"; - - [SQLiteTable(TableName)] - [DebuggerDisplay("{DebuggerDisplay(),nq}")] - public sealed class Entity : IEntity + public void PlatformClear(string? sharedName) { -#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 - [Column(ColumnName_Id)] - [PrimaryKey] - [SQLiteNotNull] - public string Id { get; set; } = string.Empty; + using var t = SettingsProviderV3.Provider.GetTransaction(); + t.RemoveAllKeys(GetTableName(sharedName), true); + t.Commit(); + } - [Column(ColumnName_Value)] - [SQLiteNotNull] - public string Value { get; set; } = string.Empty; -#pragma warning restore CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 + public bool PlatformContainsKey(string key, string? sharedName) + { + using var t = SettingsProviderV3.Provider.GetTransaction(); + var row = t.Select(GetTableName(sharedName), key); + return row != null; + } - [Column(ColumnName_SharedName)] - [SQLiteNotNull] - public string SharedName { get; set; } = string.Empty; + public T? PlatformGet(string key, T? defaultValue, string? sharedName) where T : notnull, IConvertible + { + using var t = SettingsProviderV3.Provider.GetTransaction(); + var row = t.Select(GetTableName(sharedName), key); + if (row == null) return defaultValue; + var value = ConvertibleHelper.Convert(row.Value); + return value; + } - string DebuggerDisplay() => SharedName == string.Empty ? $"{Id}, {Value}" : $"{Id}, {Value}, {SharedName}"; + public void PlatformRemove(string key, string? sharedName) + { + using var t = SettingsProviderV3.Provider.GetTransaction(); + t.RemoveKey(GetTableName(sharedName), key); + t.Commit(); + } + + /// + /// 将数据从 + /// 使用 SQLiteConnection 的 PreferencesPlatformServiceImpl + /// 迁移到 + /// 使用 DBreeze 的 PreferencesPlatformServiceImplV2 + /// + public static void Migrate() + { + var dbPath = Repository.DataBaseDirectory; + bool isOK = false; + bool exists = false; + try + { + var dbFilePath = Path.Combine(dbPath, "application2.dbf"); + try + { + exists = File.Exists(dbFilePath); + } + catch + { + + } + if (!exists) return; + var conn = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache); + var items = conn.Table().ToArray(); + if (items.Any()) + { + var itemGroups = items.GroupBy(x => x.SharedName).ToArray(); + foreach (var itemGroup in itemGroups) + { + using var t = SettingsProviderV3.Provider.GetTransaction(); + foreach (var item in itemGroup) + { + if (item.Value != null) + { + string key; + if (string.IsNullOrEmpty(item.SharedName)) key = item.Id.TrimEnd("_K"); + else key = item.Id.TrimEnd($"_{item.SharedName}_S"); + var tableName = GetTableName(item.SharedName); + t.Insert(tableName, key, item.Value.ToString(CultureInfo.InvariantCulture)); + } + } + t.Commit(); + } + } + conn.Close(); + conn.Dispose(); + isOK = true; + } + catch + { + + } + finally + { + if (isOK) + { + var files = Directory.GetFiles(dbPath, "application2*"); + foreach (var item in files) + { + IOPath.FileTryDelete(item); + } + } + } } } diff --git a/src/Common.ClientLib/ServiceCollectionExtensions.cs b/src/Common.ClientLib/ServiceCollectionExtensions.cs index 8d75a39a5..87a0f4cd7 100644 --- a/src/Common.ClientLib/ServiceCollectionExtensions.cs +++ b/src/Common.ClientLib/ServiceCollectionExtensions.cs @@ -62,7 +62,7 @@ public static class ServiceCollectionExtensions /// public static IServiceCollection AddRepositoryPreferences(this IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(); return services; } } \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/FileSettingsProvider.cs b/src/Common.CoreLib/Application/Settings/FileSettingsProvider.cs index 17d768023..2ba547d49 100644 --- a/src/Common.CoreLib/Application/Settings/FileSettingsProvider.cs +++ b/src/Common.CoreLib/Application/Settings/FileSettingsProvider.cs @@ -1,110 +1,110 @@ -using System.Diagnostics.CodeAnalysis; +//using System.Diagnostics.CodeAnalysis; -namespace System.Application.Settings; +//namespace System.Application.Settings; -public sealed class FileSettingsProvider : ISerializationProvider -{ - private readonly string _path; - private readonly object _sync = new(); - private SortedDictionary _settings = new(); +//public sealed class FileSettingsProvider : ISerializationProvider +//{ +// private readonly string _path; +// private readonly object _sync = new(); +// private SortedDictionary _settings = new(); - public bool IsLoaded { get; private set; } +// public bool IsLoaded { get; private set; } - public FileSettingsProvider(string path) - { - _path = path; - } +// public FileSettingsProvider(string path) +// { +// _path = path; +// } - public void SetValue(string key, T value) - { - lock (_sync) - { - _settings[key] = value; - } - } +// public void SetValue(string key, T value) +// { +// lock (_sync) +// { +// _settings[key] = value; +// } +// } - public bool TryGetValue(string key, [NotNullWhen(true)] out T? value) where T : notnull - { - lock (_sync) - { - if (_settings.TryGetValue(key, out object? obj) && obj is T t) - { - value = t; - return true; - } - } +// public bool TryGetValue(string key, [NotNullWhen(true)] out T? value) where T : notnull +// { +// lock (_sync) +// { +// if (_settings.TryGetValue(key, out object? obj) && obj is T t) +// { +// value = t; +// return true; +// } +// } - value = default; - return false; - } +// value = default; +// return false; +// } - public bool RemoveValue(string key) - { - lock (_sync) - { - return _settings.Remove(key); - } - } +// public bool RemoveValue(string key) +// { +// lock (_sync) +// { +// return _settings.Remove(key); +// } +// } - public void Save() - { - if (_settings.Count == 0) return; +// public void Save() +// { +// if (_settings.Count == 0) return; - var dir = Path.GetDirectoryName(_path); - if (dir == null) throw new DirectoryNotFoundException(); +// var dir = Path.GetDirectoryName(_path); +// if (dir == null) throw new DirectoryNotFoundException(); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } +// if (!Directory.Exists(dir)) +// { +// Directory.CreateDirectory(dir); +// } - lock (_sync) - { - using var stream = new FileStream(_path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete); - if (stream.Position > 0) - { - stream.Position = 0; - } - var data = Serializable.SMP(_settings); - stream.Write(data); - //XamlServices.Save(stream, this._settings); - } - } +// lock (_sync) +// { +// using var stream = new FileStream(_path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete); +// if (stream.Position > 0) +// { +// stream.Position = 0; +// } +// var data = Serializable.SMP(_settings); +// stream.Write(data); +// //XamlServices.Save(stream, this._settings); +// } +// } - public void Load() - { - if (File.Exists(_path)) - { - using var stream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); - lock (_sync) - { - if (stream.Position > 0) - { - stream.Position = 0; - } - var source = stream.Length == 0 ? null : Serializable.DMP>(stream); - //var source = XamlServices.Load(stream) as IDictionary; - _settings = source == null - ? new SortedDictionary() - : new SortedDictionary(source); - } - } - else - { - lock (_sync) - { - _settings = new SortedDictionary(); - } - } +// public void Load() +// { +// if (File.Exists(_path)) +// { +// using var stream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); +// lock (_sync) +// { +// if (stream.Position > 0) +// { +// stream.Position = 0; +// } +// var source = stream.Length == 0 ? null : Serializable.DMP>(stream); +// //var source = XamlServices.Load(stream) as IDictionary; +// _settings = source == null +// ? new SortedDictionary() +// : new SortedDictionary(source); +// } +// } +// else +// { +// lock (_sync) +// { +// _settings = new SortedDictionary(); +// } +// } - IsLoaded = true; - } +// IsLoaded = true; +// } - public string ToJsonString() => Serializable.SJSON(_settings, writeIndented: true); +// public string ToJsonString() => Serializable.SJSON(_settings, writeIndented: true); - event EventHandler ISerializationProvider.Reloaded - { - add { } - remove { } - } -} \ No newline at end of file +// event EventHandler ISerializationProvider.Reloaded +// { +// add { } +// remove { } +// } +//} \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/ISerializationProvider.cs b/src/Common.CoreLib/Application/Settings/ISerializationProvider.cs index 878b208a2..9505674b7 100644 --- a/src/Common.CoreLib/Application/Settings/ISerializationProvider.cs +++ b/src/Common.CoreLib/Application/Settings/ISerializationProvider.cs @@ -1,25 +1,25 @@ -using System.Diagnostics.CodeAnalysis; +//using System.Diagnostics.CodeAnalysis; -namespace System.Application.Settings; +//namespace System.Application.Settings; -public interface ISerializationProvider -{ - bool IsLoaded { get; } +//public interface ISerializationProvider +//{ +// bool IsLoaded { get; } - void Save(); +// void Save(); - void Load(); +// void Load(); - /// - /// 在 provider 已重新加载到期时发生 - /// - event EventHandler Reloaded; +// /// +// /// 在 provider 已重新加载到期时发生 +// /// +// event EventHandler Reloaded; - void SetValue(string key, T value); +// void SetValue(string key, T value); - bool TryGetValue(string key, [NotNullWhen(true)] out T? value) where T : notnull; +// bool TryGetValue(string key, [NotNullWhen(true)] out T? value) where T : notnull; - bool RemoveValue(string key); +// bool RemoveValue(string key); - string ToJsonString(); -} \ No newline at end of file +// string ToJsonString(); +//} \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/SerializableProperty.cs b/src/Common.CoreLib/Application/Settings/SerializableProperty.cs index daa68bd96..3a4a844b3 100644 --- a/src/Common.CoreLib/Application/Settings/SerializableProperty.cs +++ b/src/Common.CoreLib/Application/Settings/SerializableProperty.cs @@ -1,197 +1,197 @@ -using System.ComponentModel; -using System.Diagnostics; +//using System.ComponentModel; +//using System.Diagnostics; -namespace System.Application.Settings; +//namespace System.Application.Settings; -[DebuggerDisplay("Value={Value}, Key={Key}, Default={Default}")] -public class SerializableProperty : INotifyPropertyChanged -{ - protected T? _value; - protected bool _cached; +//[DebuggerDisplay("Value={Value}, Key={Key}, Default={Default}")] +//public class SerializableProperty : INotifyPropertyChanged +//{ +// protected T? _value; +// protected bool _cached; - public string Key { get; } +// public string Key { get; } - public ISerializationProvider Provider { get; } +// public ISerializationProvider Provider { get; } - public bool AutoSave { get; set; } +// public bool AutoSave { get; set; } - public T? Default { get; } +// public T? Default { get; } - public virtual T? Value - { - get - { - if (_cached) return _value; +// public virtual T? Value +// { +// get +// { +// if (_cached) return _value; - if (!Provider.IsLoaded) - { - Provider.Load(); - } +// if (!Provider.IsLoaded) +// { +// Provider.Load(); +// } - if (Provider.TryGetValue(Key, out object? obj)) - { - _value = DeserializeCore(obj); - _cached = true; - } - else - { - _value = Default; - } +// if (Provider.TryGetValue(Key, out object? obj)) +// { +// _value = DeserializeCore(obj); +// _cached = true; +// } +// else +// { +// _value = Default; +// } - return _cached ? _value : Default; - } +// return _cached ? _value : Default; +// } - set - { - if (_cached && Equals(_value, value)) return; +// set +// { +// if (_cached && Equals(_value, value)) return; - if (!Provider.IsLoaded) - { - Provider.Load(); - } +// if (!Provider.IsLoaded) +// { +// Provider.Load(); +// } - var old = _value; - _value = value; - _cached = true; - Provider.SetValue(Key, value); - OnValueChanged(old, value); +// var old = _value; +// _value = value; +// _cached = true; +// Provider.SetValue(Key, value); +// OnValueChanged(old, value); - if (AutoSave) Provider.Save(); - } - } +// if (AutoSave) Provider.Save(); +// } +// } - public override string ToString() => Value?.ToString() ?? string.Empty; +// public override string ToString() => Value?.ToString() ?? string.Empty; - public virtual void RaiseValueChanged() - { - Provider.SetValue(Key, _value); - OnValueChanged(_value, _value); - if (AutoSave) Provider.Save(); - } +// public virtual void RaiseValueChanged() +// { +// Provider.SetValue(Key, _value); +// OnValueChanged(_value, _value); +// if (AutoSave) Provider.Save(); +// } - public SerializableProperty(string key, ISerializationProvider provider) : this(key, provider, default) - { - } +// public SerializableProperty(string key, ISerializationProvider provider) : this(key, provider, default) +// { +// } - public SerializableProperty(string key, ISerializationProvider provider, T? defaultValue) - { - Key = key ?? throw new ArgumentNullException(nameof(key)); - Provider = provider ?? throw new ArgumentNullException(nameof(provider)); - Default = defaultValue; +// public SerializableProperty(string key, ISerializationProvider provider, T? defaultValue) +// { +// Key = key ?? throw new ArgumentNullException(nameof(key)); +// Provider = provider ?? throw new ArgumentNullException(nameof(provider)); +// Default = defaultValue; - Provider.Reloaded += (sender, args) => - { - if (_cached) - { - _cached = false; +// Provider.Reloaded += (sender, args) => +// { +// if (_cached) +// { +// _cached = false; - var oldValue = _value; - var newValue = Value; - if (!Equals(oldValue, newValue)) - { - OnValueChanged(oldValue, newValue); - } - } - else - { - var oldValue = default(T); - var newValue = Value; - OnValueChanged(oldValue, newValue); - } - }; - } +// var oldValue = _value; +// var newValue = Value; +// if (!Equals(oldValue, newValue)) +// { +// OnValueChanged(oldValue, newValue); +// } +// } +// else +// { +// var oldValue = default(T); +// var newValue = Value; +// OnValueChanged(oldValue, newValue); +// } +// }; +// } - protected virtual T? DeserializeCore(object value) - { - if (typeof(T).IsValueType || typeof(T) == typeof(string)) - { - return (T)value; - } - var temp = Serializable.SMP(value); - return Serializable.DMP(temp); - } +// protected virtual T? DeserializeCore(object value) +// { +// if (typeof(T).IsValueType || typeof(T) == typeof(string)) +// { +// return (T)value; +// } +// var temp = Serializable.SMP(value); +// return Serializable.DMP(temp); +// } - public virtual IDisposable Subscribe(Action listener, bool notifyOnInitialValue = true) - { - if (notifyOnInitialValue) - listener(Value); - return new ValueChangedEventListener(this, listener); - } +// public virtual IDisposable Subscribe(Action listener, bool notifyOnInitialValue = true) +// { +// if (notifyOnInitialValue) +// listener(Value); +// return new ValueChangedEventListener(this, listener); +// } - public virtual void Reset() - { - if (!Provider.IsLoaded) - { - Provider.Load(); - } +// public virtual void Reset() +// { +// if (!Provider.IsLoaded) +// { +// Provider.Load(); +// } - if (Provider.TryGetValue(Key, out object? old)) - { - if (Provider.RemoveValue(Key)) - { - _value = default; - _cached = false; - OnValueChanged(DeserializeCore(old), Default); +// if (Provider.TryGetValue(Key, out object? old)) +// { +// if (Provider.RemoveValue(Key)) +// { +// _value = default; +// _cached = false; +// OnValueChanged(DeserializeCore(old), Default); - if (AutoSave) Provider.Save(); - } - } - } +// if (AutoSave) Provider.Save(); +// } +// } +// } - protected class ValueChangedEventListener : IDisposable - { - private readonly Action _listener; - private readonly SerializableProperty _source; +// protected class ValueChangedEventListener : IDisposable +// { +// private readonly Action _listener; +// private readonly SerializableProperty _source; - public ValueChangedEventListener(SerializableProperty property, Action listener) - { - _listener = listener; - _source = property; - _source.ValueChanged += HandleValueChanged; - } +// public ValueChangedEventListener(SerializableProperty property, Action listener) +// { +// _listener = listener; +// _source = property; +// _source.ValueChanged += HandleValueChanged; +// } - private void HandleValueChanged(object? sender, ValueChangedEventArgs args) - { - _listener(args.NewValue); - } +// private void HandleValueChanged(object? sender, ValueChangedEventArgs args) +// { +// _listener(args.NewValue); +// } - public void Dispose() - { - _source.ValueChanged -= HandleValueChanged; - } - } +// public void Dispose() +// { +// _source.ValueChanged -= HandleValueChanged; +// } +// } - public static implicit operator T?(SerializableProperty property) => property.Value; +// public static implicit operator T?(SerializableProperty property) => property.Value; - #region events +// #region events - public event EventHandler>? ValueChanged; +// public event EventHandler>? ValueChanged; - protected virtual void OnValueChanged(T? oldValue, T? newValue) - { - ValueChanged?.Invoke(this, new ValueChangedEventArgs(oldValue, newValue)); - } +// protected virtual void OnValueChanged(T? oldValue, T? newValue) +// { +// ValueChanged?.Invoke(this, new ValueChangedEventArgs(oldValue, newValue)); +// } - protected readonly Dictionary>> _handlers = new(); +// protected readonly Dictionary>> _handlers = new(); - event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged - { - add - { - if (value == null) return; - ValueChanged += _handlers[value] = (sender, args) => value(sender, new PropertyChangedEventArgs(nameof(Value))); - } +// event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged +// { +// add +// { +// if (value == null) return; +// ValueChanged += _handlers[value] = (sender, args) => value(sender, new PropertyChangedEventArgs(nameof(Value))); +// } - remove - { - if (value == null) return; - if (_handlers.TryGetValue(value, out var handler)) - { - ValueChanged -= handler; - _handlers.Remove(value); - } - } - } +// remove +// { +// if (value == null) return; +// if (_handlers.TryGetValue(value, out var handler)) +// { +// ValueChanged -= handler; +// _handlers.Remove(value); +// } +// } +// } - #endregion -} \ No newline at end of file +// #endregion +//} \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/SettingsHost.cs b/src/Common.CoreLib/Application/Settings/SettingsHost.cs index 22be3cc92..7544bc661 100644 --- a/src/Common.CoreLib/Application/Settings/SettingsHost.cs +++ b/src/Common.CoreLib/Application/Settings/SettingsHost.cs @@ -1,89 +1,89 @@ -using System.Runtime.CompilerServices; +//using System.Runtime.CompilerServices; -namespace System.Application.Settings; +//namespace System.Application.Settings; -public abstract class SettingsHostBase -{ - static readonly Dictionary instances = new(); +//public abstract class SettingsHostBase +//{ +// static readonly Dictionary instances = new(); - public string CategoryName => GetCategoryName(); +// public string CategoryName => GetCategoryName(); - protected internal virtual string GetCategoryName() => GetType().Name; +// protected internal virtual string GetCategoryName() => GetType().Name; - protected SettingsHostBase() - { - instances[GetType()] = this; - } +// protected SettingsHostBase() +// { +// instances[GetType()] = this; +// } - const string ConfigName = "Config" + FileEx.MPO; +// const string ConfigName = "Config" + FileEx.MPO; - protected static string GetLocalFilePath(string configName) => Path.Combine(IOPath.AppDataDirectory, configName); +// protected static string GetLocalFilePath(string configName) => Path.Combine(IOPath.AppDataDirectory, configName); - static readonly Lazy _LocalFilePath = new(() => GetLocalFilePath(ConfigName)); +// static readonly Lazy _LocalFilePath = new(() => GetLocalFilePath(ConfigName)); - public static string LocalFilePath => _LocalFilePath.Value; +// public static string LocalFilePath => _LocalFilePath.Value; - public static ISerializationProvider Local { get; } = new FileSettingsProvider(LocalFilePath); +// public static ISerializationProvider Local { get; } = new FileSettingsProvider(LocalFilePath); - protected static T GetInstance() where T : SettingsHostBase, new() - { - return instances.TryGetValue(typeof(T), out var host) ? (T)host : new T(); - } +// protected static T GetInstance() where T : SettingsHostBase, new() +// { +// return instances.TryGetValue(typeof(T), out var host) ? (T)host : new T(); +// } - protected internal static SerializableProperty GetProperty(Func getKey, ISerializationProvider provider, T? defaultValue, bool autoSave, string propertyName) => new(getKey(propertyName), provider, defaultValue) { AutoSave = autoSave }; -} +// protected internal static SerializableProperty GetProperty(Func getKey, ISerializationProvider provider, T? defaultValue, bool autoSave, string propertyName) => new(getKey(propertyName), provider, defaultValue) { AutoSave = autoSave }; +//} -public static class SettingsHost -{ - public static void Save() - { - try - { - SettingsHostBase.Local.Save(); - } - catch (Exception ex) - { - Log.Error(nameof(SettingsHost), ex, "Config Save"); - throw; - } - } +//public static class SettingsHost +//{ +// public static void Save() +// { +// try +// { +// SettingsHostBase.Local.Save(); +// } +// catch (Exception ex) +// { +// Log.Error(nameof(SettingsHost), ex, "Config Save"); +// throw; +// } +// } - public static void Load() - { - try - { - SettingsHostBase.Local.Load(); - } - catch (Exception ex) - { - File.Delete(SettingsHostBase.LocalFilePath); - Log.Error(nameof(SettingsHost), ex, "Config Load"); +// public static void Load() +// { +// try +// { +// SettingsHostBase.Local.Load(); +// } +// catch (Exception ex) +// { +// File.Delete(SettingsHostBase.LocalFilePath); +// Log.Error(nameof(SettingsHost), ex, "Config Load"); - SettingsHostBase.Local.Load(); - } - } -} +// SettingsHostBase.Local.Load(); +// } +// } +//} -/// -/// 将全部设置项存储在一个文件中的静态实现版本 -/// -/// -public abstract class SettingsHost2 : SettingsHostBase where TSettings : SettingsHost2, new() -{ - protected SettingsHost2() : this(false) - { - } +///// +///// 将全部设置项存储在一个文件中的静态实现版本 +///// +///// +//public abstract class SettingsHost2 : SettingsHostBase where TSettings : SettingsHost2, new() +//{ +// protected SettingsHost2() : this(false) +// { +// } - protected SettingsHost2(bool isSupported) : base() - { - if (!isSupported) throw new NotSupportedException(); - } +// protected SettingsHost2(bool isSupported) : base() +// { +// if (!isSupported) throw new NotSupportedException(); +// } - static readonly Lazy _CategoryName = new(() => typeof(TSettings).Name); +// static readonly Lazy _CategoryName = new(() => typeof(TSettings).Name); - public static new string CategoryName => _CategoryName.Value; +// public static new string CategoryName => _CategoryName.Value; - static string GetKey(string propertyName) => $"{CategoryName}.{propertyName}"; +// static string GetKey(string propertyName) => $"{CategoryName}.{propertyName}"; - public static SerializableProperty GetProperty(T? defaultValue, bool autoSave, [CallerMemberName] string propertyName = "") => GetProperty(GetKey, Local, defaultValue, autoSave, propertyName); -} \ No newline at end of file +// public static SerializableProperty GetProperty(T? defaultValue, bool autoSave, [CallerMemberName] string propertyName = "") => GetProperty(GetKey, Local, defaultValue, autoSave, propertyName); +//} \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/V3/SerializableProperty.cs b/src/Common.CoreLib/Application/Settings/V3/SerializableProperty.cs new file mode 100644 index 000000000..9de38e4c1 --- /dev/null +++ b/src/Common.CoreLib/Application/Settings/V3/SerializableProperty.cs @@ -0,0 +1,166 @@ +using DBreeze; +using System.ComponentModel; +using System.Diagnostics; +using static System.Application.Settings.ISerializableProperty; + +namespace System.Application.Settings; + +public interface ISerializableProperty : INotifyPropertyChanged +{ + public const string tableName = "SerializableProperty"; +} + +[DebuggerDisplay("Value={Value}, Key={Key}, Default={Default}")] +public sealed class SerializableProperty : ISerializableProperty, INotifyPropertyChanged +{ + T? _value; + bool _cached; + DBreezeEngine? _Provider; + + public string Key { get; } + + public DBreezeEngine Provider { get => _Provider ?? throw new ArgumentNullException(nameof(_Provider)); set => _Provider = value; } + + public T? Default { get; } + + public T? Value + { + get + { + if (!_cached) + { + { + using var t = Provider.GetTransaction(); + var row = t.Select(tableName, Key); + if (row?.Value == null) + { + _value = Default; + } + else + { + try + { + _value = Serializable.DMP(row.Value); + } + catch + { + _value = Default; + } + } + } + _cached = true; + } + + return _value; + } + + set + { + var comparer = EqualityComparer.Default; + if (_cached && comparer.Equals(_value, value)) return; + var old = _value; + _value = value; + _cached = true; + SetValue(comparer, old, value); + } + } + + void SetValue(EqualityComparer comparer, T? oldValue, T? newValue) + { + { + using var t = Provider.GetTransaction(); + if (comparer.Equals(newValue, Default)) + t.RemoveKey(tableName, Key); + else + t.Insert(tableName, Key, Serializable.SMP(newValue)); + t.Commit(); + } + OnValueChanged(oldValue, newValue); + } + + public override string ToString() => Value?.ToString() ?? string.Empty; + + public void RaiseValueChanged() + { + var comparer = EqualityComparer.Default; + SetValue(comparer, _value, _value); + } + + public SerializableProperty(string key, DBreezeEngine provider) : this(key, provider, default) + { + } + + public SerializableProperty(string key, DBreezeEngine provider, T? defaultValue) + { + Key = key; + Provider = provider; + Default = defaultValue; + } + + public IDisposable Subscribe(Action listener, bool notifyOnInitialValue = true) + { + if (notifyOnInitialValue) + listener(Value); + return new ValueChangedEventListener(this, listener); + } + + public void Reset() + { + var comparer = EqualityComparer.Default; + SetValue(comparer, _value, Default); + } + + sealed class ValueChangedEventListener : IDisposable + { + private readonly Action _listener; + private readonly SerializableProperty _source; + + public ValueChangedEventListener(SerializableProperty property, Action listener) + { + _listener = listener; + _source = property; + _source.ValueChanged += HandleValueChanged; + } + + private void HandleValueChanged(object? sender, ValueChangedEventArgs args) + { + _listener(args.NewValue); + } + + public void Dispose() + { + _source.ValueChanged -= HandleValueChanged; + } + } + + public static implicit operator T?(SerializableProperty property) => property.Value; + + #region events + + public event EventHandler>? ValueChanged; + + void OnValueChanged(T? oldValue, T? newValue) => ValueChanged?.Invoke(this, new ValueChangedEventArgs(oldValue, newValue)); + + readonly Dictionary>> _handlers = new(); + + event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged + { + add + { + if (value == null) return; + ValueChanged += _handlers[value] = (sender, args) => value(sender, new PropertyChangedEventArgs(nameof(Value))); + } + + remove + { + if (value == null) return; + if (_handlers.TryGetValue(value, out var handler)) + { + ValueChanged -= handler; + _handlers.Remove(value); + } + } + } + + #endregion +} \ No newline at end of file diff --git a/src/Common.CoreLib/Application/Settings/V3/SettingsHost.cs b/src/Common.CoreLib/Application/Settings/V3/SettingsHost.cs new file mode 100644 index 000000000..bc3581c82 --- /dev/null +++ b/src/Common.CoreLib/Application/Settings/V3/SettingsHost.cs @@ -0,0 +1,26 @@ +using System.Runtime.CompilerServices; + +namespace System.Application.Settings; + +public static class SettingsHost +{ + public static void Load() => SettingsProviderV3.Load(); + + [Obsolete] + public static void Save() + { + + } +} + +public abstract class SettingsHost2 where TSettings : SettingsHost2, new() +{ + static readonly string CategoryName = typeof(TSettings).Name; + + static string GetKey(string propertyName) => $"{CategoryName}.{propertyName}"; + + public static SerializableProperty GetProperty(T? defaultValue, [CallerMemberName] string propertyName = "") => new(GetKey(propertyName), SettingsProviderV3.Provider, defaultValue); + + [Obsolete("autoSave N/A")] + public static SerializableProperty GetProperty(T? defaultValue, bool autoSave, [CallerMemberName] string propertyName = "") => new(GetKey(propertyName), SettingsProviderV3.Provider, defaultValue); +} diff --git a/src/Common.CoreLib/Application/Settings/V3/SettingsProviderV3.cs b/src/Common.CoreLib/Application/Settings/V3/SettingsProviderV3.cs new file mode 100644 index 000000000..7e577e4aa --- /dev/null +++ b/src/Common.CoreLib/Application/Settings/V3/SettingsProviderV3.cs @@ -0,0 +1,88 @@ +using DBreeze; +using DBreeze.Utils; + +namespace System.Application.Settings; + +public static class SettingsProviderV3 +{ + static DBreezeEngine? _Provider; + static readonly object lock_obj = new(); + + public static DBreezeEngine Provider + { + get + { + lock (lock_obj) + { + if (_Provider == null) Load(); + return _Provider ?? throw new ArgumentNullException(nameof(_Provider)); + } + } + set => _Provider = value; + } + + public static void Load() + { + if (_Provider == null) + { + _Provider = new(Path.Combine(IOPath.AppDataDirectory, "Config")); + + //Setting up NetJSON serializer (from NuGet) to be used by DBreeze + CustomSerializator.ByteArraySerializator = value => Serializable.SMP(value == null ? typeof(object) : value.GetType(), value!); + CustomSerializator.ByteArrayDeSerializator = (buffer, type) => Serializable.DMP(type, buffer); + } + } + + /// + /// 将数据从 + /// 使用 + 单文件 的 FileSettingsProvider + /// 迁移到 + /// 使用 DBreeze 的 SettingsProviderV3 + /// + public static void Migrate() + { + var filePath = Path.Combine(IOPath.AppDataDirectory, "Config" + FileEx.MPO); + bool exists = false; + try + { + exists = File.Exists(filePath); + } + catch + { + + } + if (exists) + { + try + { + using var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); + if (stream.Position > 0) + { + stream.Position = 0; + } + var source = stream.Length == 0 ? null : Serializable.DMP>(stream); + if (source.Any_Nullable()) + { + if (_Provider == null) Load(); + using var t = Provider.GetTransaction(); + foreach (var item in source) + { + if (item.Value == null) continue; + var valueType = item.Value.GetType(); + var value = Serializable.SMP(valueType, item.Value); + t.Insert(ISerializableProperty.tableName, item.Key, value); + } + t.Commit(); + } + } + catch + { + + } + finally + { + IOPath.FileTryDelete(filePath); + } + } + } +} diff --git a/src/Common.CoreLib/Application/Settings/ValueChangedEventArgs.cs b/src/Common.CoreLib/Application/Settings/ValueChangedEventArgs.cs index b182c190b..fc0a9d50b 100644 --- a/src/Common.CoreLib/Application/Settings/ValueChangedEventArgs.cs +++ b/src/Common.CoreLib/Application/Settings/ValueChangedEventArgs.cs @@ -1,6 +1,6 @@ namespace System.Application.Settings; -public sealed class ValueChangedEventArgs : EventArgs where T : notnull +public sealed class ValueChangedEventArgs : EventArgs { public T? OldValue { get; } diff --git a/src/Common.CoreLib/Common.CoreLib.csproj b/src/Common.CoreLib/Common.CoreLib.csproj index 075b41180..5ee1a089b 100644 --- a/src/Common.CoreLib/Common.CoreLib.csproj +++ b/src/Common.CoreLib/Common.CoreLib.csproj @@ -20,6 +20,7 @@ + diff --git a/src/Common.CoreLib/Extensions/StringExtensions.Trim.cs b/src/Common.CoreLib/Extensions/StringExtensions.Trim.cs index 5c47e4e82..10408a4d5 100644 --- a/src/Common.CoreLib/Extensions/StringExtensions.Trim.cs +++ b/src/Common.CoreLib/Extensions/StringExtensions.Trim.cs @@ -3,11 +3,11 @@ namespace System; public static partial class StringExtensions { - public static string TrimStart(this string s, string trimString) + public static string TrimStart(this string s, string value) { - if (trimString.StartsWith(trimString)) + if (s.StartsWith(value)) { - return s[trimString.Length..]; + return s[value.Length..]; } else { @@ -15,11 +15,11 @@ public static partial class StringExtensions } } - public static string TrimEnd(this string s, string trimString) + public static string TrimEnd(this string s, string value) { - if (trimString.EndsWith(trimString)) + if (s.EndsWith(value)) { - return s[..^trimString.Length]; + return s[..^value.Length]; } else { @@ -27,11 +27,11 @@ public static partial class StringExtensions } } - public static string TrimStart(this string s, string trimString, StringComparison comparisonType) + public static string TrimStart(this string s, string value, StringComparison comparisonType) { - if (trimString.StartsWith(trimString, comparisonType)) + if (s.StartsWith(value, comparisonType)) { - return s[trimString.Length..]; + return s[value.Length..]; } else { @@ -39,11 +39,11 @@ public static partial class StringExtensions } } - public static string TrimEnd(this string s, string trimString, StringComparison comparisonType) + public static string TrimEnd(this string s, string value, StringComparison comparisonType) { - if (trimString.EndsWith(trimString, comparisonType)) + if (s.EndsWith(value, comparisonType)) { - return s[..^trimString.Length]; + return s[..^value.Length]; } else { diff --git a/src/Repositories.sqlite-net-pcl/Application.Repositories/Repository.cs b/src/Repositories.sqlite-net-pcl/Application.Repositories/Repository.cs index 0a6f421e6..b04f4dc94 100644 --- a/src/Repositories.sqlite-net-pcl/Application.Repositories/Repository.cs +++ b/src/Repositories.sqlite-net-pcl/Application.Repositories/Repository.cs @@ -31,22 +31,23 @@ public abstract class Repository : IRepository } } - static SQLiteConnection? connectionSync; + //static SQLiteConnection? connectionSync; - static SQLiteConnection ConnectionSync - { - get - { - if (connectionSync == null) - { - var dbPath = DataBaseDirectory; - IOPath.DirCreateByNotExists(dbPath); - dbPath = Path.Combine(dbPath, "application2.dbf"); // 与异步连接使用不同的数据库文件隔离 - connectionSync = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache); - } - return connectionSync; - } - } + //[Obsolete("",true)] + //static SQLiteConnection ConnectionSync + //{ + // get + // { + // if (connectionSync == null) + // { + // var dbPath = DataBaseDirectory; + // IOPath.DirCreateByNotExists(dbPath); + // dbPath = Path.Combine(dbPath, "application2.dbf"); // 与异步连接使用不同的数据库文件隔离 + // connectionSync = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache); + // } + // return connectionSync; + // } + //} static SQLiteAsyncConnection GetConnection() { @@ -71,17 +72,18 @@ public abstract class Repository : IRepository return DbConnection; } - public static SQLiteConnection GetDbConnectionSync() - { - var conn = ConnectionSync; - if (!conn.TableMappings.Any(x => x.MappedType == typeof(T))) - { - // On sqlite-net v1.6.0+, enabling write-ahead logging allows for faster database execution - conn.EnableWriteAheadLogging(); - conn.CreateTables(CreateFlags.None, typeof(T)); - } - return conn; - } + //[Obsolete("",true)] + //public static SQLiteConnection GetDbConnectionSync() + //{ + // var conn = ConnectionSync; + // if (!conn.TableMappings.Any(x => x.MappedType == typeof(T))) + // { + // // On sqlite-net v1.6.0+, enabling write-ahead logging allows for faster database execution + // conn.EnableWriteAheadLogging(); + // conn.CreateTables(CreateFlags.None, typeof(T)); + // } + // return conn; + //} protected static Task AttemptAndRetry(Func> action, int numRetries = 10) { diff --git a/src/ST.Client.CommandLine/CommandLineHost.cs b/src/ST.Client.CommandLine/CommandLineHost.cs index 10f26064e..dcad3076c 100644 --- a/src/ST.Client.CommandLine/CommandLineHost.cs +++ b/src/ST.Client.CommandLine/CommandLineHost.cs @@ -311,27 +311,27 @@ public abstract class CommandLineHost : IDisposable // -clt show -config -cert var show = new Command("show", "显示信息"); - show.AddOption(new Option("-config", "显示 Config.mpo 值")); + //show.AddOption(new Option("-config", "显示 Config.mpo 值")); show.AddOption(new Option("-cert", "显示当前根证书信息")); - show.Handler = CommandHandler.Create((bool config, bool cert) => + show.Handler = CommandHandler.Create((/*bool config,*/ bool cert) => { if (OperatingSystem.IsWindows()) if (!AttachConsole()) AllocConsole(); - if (config) - { - Console.WriteLine("Config: "); - try - { - SettingsHost.Load(); - var configValue = SettingsHostBase.Local.ToJsonString(); - Console.WriteLine(configValue); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - } - Console.WriteLine(); - } + //if (config) + //{ + // Console.WriteLine("Config: "); + // try + // { + // SettingsHost.Load(); + // var configValue = SettingsHostBase.Local.ToJsonString(); + // Console.WriteLine(configValue); + // } + // catch (Exception e) + // { + // Console.WriteLine(e.ToString()); + // } + // Console.WriteLine(); + //} if (cert) { diff --git a/src/Startup.cs b/src/Startup.cs index 5fc15e49a..08fe532f2 100644 --- a/src/Startup.cs +++ b/src/Startup.cs @@ -607,6 +607,8 @@ namespace System.Application.UI if (!isDesignMode) { + SettingsProviderV3.Migrate(); + PreferencesPlatformServiceImplV2.Migrate(); SettingsHost.Load(); if (isTrace) StartWatchTrace.Record("SettingsHost"); }