#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 "Mini SQL Query Settings"; } } /// 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("If this value is set to a specific connections XML file it will be loaded in preferences to the default path " + "(%APPDATA%\\MiniSqlQuery\\Connections.xml). Note that changing this value will require a restart of the application.")] 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("Set to true to enable the batching feature, if false the 'GO' statements will be passed straight through.")] 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("Gets or sets the wait time before terminating the attempt to execute a command and generating an error. A value of 0 indicates no limit.")] 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("If true, external plugin files will be loaded (requires restart).")] 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("The file filter used for finding plugins (*.PlugIn.dll)")] public string PlugInFileFilter { get { return _plugInFileFilter; } set { if (_plugInFileFilter != value) { _plugInFileFilter = value; OnPropertyChanged("PlugInFileFilter"); } } } /// Gets or sets MostRecentFiles. [Category("Plugins")] [Description("The file filter used for finding plugins (*.PlugIn.dll)")] public StringCollection MostRecentFiles { get { return _mostRecentFiles; } set { if (_mostRecentFiles != value) { _mostRecentFiles = value; OnPropertyChanged("MostRecentFiles"); } } } /// Gets or sets PlugInFileFilter. [Category("Export Scripts")] [Description("If true, the readonly columns (e.g. identity) will be exported in the script.")] public bool IncludeReadOnlyColumnsInExport { get { return _includeReadOnlyColumnsInExport; } set { if (_includeReadOnlyColumnsInExport != value) { _includeReadOnlyColumnsInExport = value; OnPropertyChanged("PlugInFileFilter"); } } } } } }