#region License // Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved. // This source code is made available under the terms of the GNU Lesser General Public License v3.0 // https://github.com/paulkohler/minisqlquery/blob/master/LICENSE #endregion using System.Collections.Specialized; using System.ComponentModel; using MiniSqlQuery.Core; namespace MiniSqlQuery.PlugIns { /// The core mini sql query configuration. public class CoreMiniSqlQueryConfiguration : NotifyPropertyChangedBase, IConfigurationObject { /// The application settings. private readonly IApplicationSettings _settings; /// The settings wrapper. private readonly CoreMiniSqlQuerySettingsWrapper _settingsWrapper; /// The dirty record. private static bool _isDirty; /// Initializes a new instance of the class. /// The settings. public CoreMiniSqlQueryConfiguration(IApplicationSettings settings) { _settings = settings; _settingsWrapper = new CoreMiniSqlQuerySettingsWrapper(_settings); _settingsWrapper.PropertyChanged += ProxyPropertyChanged; _isDirty = false; } /// Gets a value indicating whether IsDirty. public bool IsDirty { get { return _isDirty; } private set { if (_isDirty != value) { _isDirty = value; OnPropertyChanged("IsDirty"); } } } /// Gets Name. public string Name { get { return "迷你SQL查询设置"; } } /// Gets Settings. public object Settings { get { return _settingsWrapper; } } /// Save the settings back. public void Save() { _settings.EnableQueryBatching = _settingsWrapper.EnableQueryBatching; _settings.CommandTimeout = _settingsWrapper.CommandTimeout; _settings.PlugInFileFilter = _settingsWrapper.PlugInFileFilter; _settings.MostRecentFiles = _settingsWrapper.MostRecentFiles; _settings.LoadExternalPlugins = _settingsWrapper.LoadExternalPlugins; _settings.DefaultConnectionDefinitionFilename = _settingsWrapper.DefaultConnectionDefinitionFilename; _settings.DateTimeFormat = _settingsWrapper.DateTimeFormat; _settings.NullText = _settingsWrapper.NullText; _settings.IncludeReadOnlyColumnsInExport = _settingsWrapper.IncludeReadOnlyColumnsInExport; IsDirty = false; } /// The proxy property changed. /// The sender. /// The events. private void ProxyPropertyChanged(object sender, PropertyChangedEventArgs e) { IsDirty = true; } /// The core mini sql query settings wrapper. public class CoreMiniSqlQuerySettingsWrapper : NotifyPropertyChangedBase { /// The _settings. private readonly IApplicationSettings _settings; /// The _date time format. private string _dateTimeFormat; /// The _default connection definition filename. private string _defaultConnectionDefinitionFilename; /// The _enable query batching. private bool _enableQueryBatching; /// The _load plugins. private bool _loadPlugins; /// The _null text. private string _nullText; /// The _plug in file filter. private string _plugInFileFilter; StringCollection _mostRecentFiles; /// The include ReadOnly Columns in Export value. private bool _includeReadOnlyColumnsInExport; /// The command timout. private int _commandTimeout; /// Initializes a new instance of the class. /// The settings. public CoreMiniSqlQuerySettingsWrapper(IApplicationSettings settings) { _settings = settings; EnableQueryBatching = _settings.EnableQueryBatching; CommandTimeout = _settings.CommandTimeout; PlugInFileFilter = _settings.PlugInFileFilter; MostRecentFiles = _settings.MostRecentFiles; LoadExternalPlugins = _settings.LoadExternalPlugins; DefaultConnectionDefinitionFilename = _settings.DefaultConnectionDefinitionFilename; DateTimeFormat = _settings.DateTimeFormat; NullText = _settings.NullText; IncludeReadOnlyColumnsInExport = _settings.IncludeReadOnlyColumnsInExport; } /// Gets or sets DateTimeFormat. [Category("Query Results")] [Description("")] public string DateTimeFormat { get { return _dateTimeFormat; } set { if (_dateTimeFormat != value) { _dateTimeFormat = value; OnPropertyChanged("DateTimeFormat"); } } } /// Gets or sets DefaultConnectionDefinitionFilename. [Category("Query")] [Description("如果将该值设置为特定的连接XML文件,它将在首选项中加载到默认路径 " + "(%APPDATA%\\MiniSqlQuery\\Connections.xml). 请注意,更改此值需要重新启动应用程序。")] public string DefaultConnectionDefinitionFilename { get { return _defaultConnectionDefinitionFilename; } set { if (_defaultConnectionDefinitionFilename != value) { _defaultConnectionDefinitionFilename = value; OnPropertyChanged("DefaultConnectionDefinitionFilename"); } } } /// Gets or sets a value indicating whether EnableQueryBatching. [Category("Query")] [Description("设置为true以启用批处理功能,如果为false,则将直接传递“GO”语句。")] public bool EnableQueryBatching { get { return _enableQueryBatching; } set { if (_enableQueryBatching != value) { _enableQueryBatching = value; OnPropertyChanged("EnableQueryBatching"); } } } /// Gets or sets a value indicating the command timeout. [Category("Query")] [Description("获取或设置终止执行命令的尝试并生成错误之前的等待时间。值为0表示没有限制。")] public int CommandTimeout { get { return _commandTimeout; } set { if (_commandTimeout != value) { _commandTimeout = value; OnPropertyChanged("CommandTimeout"); } } } /// Gets or sets a value indicating whether LoadExternalPlugins. [Category("Plugins")] [Description("如果为true,则将加载外部插件文件(需要重新启动)。")] public bool LoadExternalPlugins { get { return _loadPlugins; } set { if (_loadPlugins != value) { _loadPlugins = value; OnPropertyChanged("LoadExternalPlugins"); } } } /// Gets or sets NullText. [Category("Query Results")] [Description("")] public string NullText { get { return _nullText; } set { if (_nullText != value) { _nullText = value; OnPropertyChanged("NullText"); } } } /// Gets or sets PlugInFileFilter. [Category("Plugins")] [Description("用于查找插件的文件筛选器(*.PlugIn.dll)")] public string PlugInFileFilter { get { return _plugInFileFilter; } set { if (_plugInFileFilter != value) { _plugInFileFilter = value; OnPropertyChanged("PlugInFileFilter"); } } } /// Gets or sets MostRecentFiles. [Category("Plugins")] [Description("用于查找插件的文件筛选器(*.PlugIn.dll)")] public StringCollection MostRecentFiles { get { return _mostRecentFiles; } set { if (_mostRecentFiles != value) { _mostRecentFiles = value; OnPropertyChanged("MostRecentFiles"); } } } /// Gets or sets PlugInFileFilter. [Category("Export Scripts")] [Description("如果为true,则将在脚本中导出只读列(例如标识)。")] public bool IncludeReadOnlyColumnsInExport { get { return _includeReadOnlyColumnsInExport; } set { if (_includeReadOnlyColumnsInExport != value) { _includeReadOnlyColumnsInExport = value; OnPropertyChanged("PlugInFileFilter"); } } } } } }