using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using ScrewTurn.Wiki.PluginFramework;
namespace ScrewTurn.Wiki.Plugins.SqlCommon {
///
/// Implements a base class for a SQL storage provider.
///
public abstract class SqlStorageProviderBase : SqlClassBase {
///
/// The connection string.
///
protected string connString;
///
/// The host.
///
protected IHostV30 host;
///
/// Gets a new command builder object.
///
/// The command builder.
protected abstract ICommandBuilder GetCommandBuilder();
///
/// Logs an exception.
///
/// The exception.
protected override void LogException(Exception ex) {
try {
host.LogEntry(ex.ToString(), LogEntryType.Error, null, this);
}
catch { }
}
#region IProvider Members
///
/// Validates a connection string.
///
/// The connection string to validate.
/// If the connection string is invalid, the method throws .
protected abstract void ValidateConnectionString(string connString);
///
/// Creates or updates the database schema if necessary.
///
protected abstract void CreateOrUpdateDatabaseIfNecessary();
///
/// Tries to load the configuration from a corresponding v2 provider.
///
/// The configuration, or an empty string.
protected abstract string TryLoadV2Configuration();
///
/// Tries to load the configuration of the corresponding settings storage provider.
///
/// The configuration, or an empty string.
protected abstract string TryLoadSettingsStorageProviderConfiguration();
///
/// Initializes the Storage Provider.
///
/// The Host of the Component.
/// The Configuration data, if any.
/// If host or config are null.
/// If config is not valid or is incorrect.
public void Init(IHostV30 host, string config) {
if(host == null) throw new ArgumentNullException("host");
if(config == null) throw new ArgumentNullException("config");
this.host = host;
if(config.Length == 0) {
// Try to load v2 provider configuration
config = TryLoadV2Configuration();
}
if(config == null || config.Length == 0) {
// Try to load Settings Storage Provider configuration
config = TryLoadSettingsStorageProviderConfiguration();
}
if(config == null) config = "";
ValidateConnectionString(config);
connString = config;
CreateOrUpdateDatabaseIfNecessary();
}
///
/// Method invoked on shutdown.
///
/// This method might not be invoked in some cases.
public void Shutdown() {
}
///
/// Gets the Information about the Provider.
///
public abstract ComponentInformation Information {
get;
}
///
/// Gets a brief summary of the configuration string format, in HTML. Returns null if no configuration is needed.
///
public abstract string ConfigHelpHtml {
get;
}
#endregion
}
}