📄 datastore.cs
字号:
/// </summary>
/// <param name="connectionString">connection string</param>
/// <returns>a specific implementation of a datastore</returns>
public static DataStore GetDataStore(string connectionString)
{
return GetDataStore(_defaultProvider, connectionString,
_defaultParameters);
}
/// <summary>
/// This method creates a data store of the type passed into the
/// method. In creating the datastore it must construct it with a
/// connecion string and parameters.
/// </summary>
/// <param name="connectionString">connection string</param>
/// <param name="implementationParameters">data store parameters</param>
/// <returns>a specific implementation of a datastore</returns>
public static DataStore GetDataStore(string connectionString,
Parameters implementationParameters)
{
return GetDataStore(_defaultProvider, connectionString,
implementationParameters);
}
/// <summary>
/// This method creates a data store of the type passed into the
/// method. In creating the datastore it must construct it with a
/// connecion string and parameters.
/// </summary>
/// <param name="providerType">type of provider</param>
/// <param name="connectionString">connection string</param>
/// <param name="implementationParameters">data store parameters</param>
/// <returns>a specific implementation of a datastore</returns>
public static DataStore GetDataStore(string providerType,
string connectionString,
Parameters implementationParameters)
{
Type dataStoreType = null;
ConstructorInfo constructor = null;
DataStore result = null;
if (!_dataStores.ContainsKey(connectionString))
{
dataStoreType = Type.GetType(providerType, true, false);
constructor = dataStoreType.GetConstructor(new Type[] { typeof(string), typeof(Parameters) });
result = (DataStore)constructor.Invoke(new object[] { connectionString, implementationParameters });
_dataStores.Add(connectionString, result);
}
else
{
result = _dataStores[connectionString];
}
return result;
}
/// <summary>
/// Get a single value from the data store.
/// </summary>
/// <param name="selector">
/// string to direct the method on what to retrieve
/// </param>
/// <returns>
/// The first value that matches the selection criteria
/// </returns>
public abstract object GetValue(string selector);
/// <summary>
/// Get a single value from the data store.
/// </summary>
/// <param name="selector">
/// string to direct the method on what to retrieve
/// </param>
/// <param name="parameters">
/// collections of parameters for the selector
/// </param>
/// <returns>
/// The first value that matches the selection criteria
/// </returns>
public abstract object GetValue(string selector,
Parameters parameters);
/// <summary>
/// Method used to fire the trigger event.
/// </summary>
/// <param name="action">type of trigger</param>
/// <param name="identifier">
/// name of the table or view the action was performed upon
/// </param>
[SuppressMessage("Microsoft.Design",
"CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "Allows all exceptions but system ones to be sent to the TriggerError event.")]
protected void OnTrigger(TriggerType action,
string identifier)
{
TriggerEventArgs eventArg;
EventHandler<TriggerEventArgs> currentSubscriber;
// create event argument
eventArg = new TriggerEventArgs(action, identifier);
// trigger delegate
if (Trigger != null)
{
foreach (Delegate currentHandler in Trigger.GetInvocationList())
{
currentSubscriber = (EventHandler<TriggerEventArgs>)currentHandler;
try
{
currentSubscriber(this, eventArg);
}
catch (Exception ex)
{
OnTriggerError(currentSubscriber, ex);
}
}
}
}
/// <summary>
/// Method used to fire the trigger event.
/// </summary>
/// <param name="source">Event handler </param>
/// <param name="exception">
/// name of the table or view the action was performed upon
/// </param>
[SuppressMessage("Microsoft.Design",
"CA1031:DoNotCatchGeneralExceptionTypes",
Justification="Protects this method from having any exceptions thrown")]
protected void OnTriggerError(EventHandler<TriggerEventArgs> source,
Exception exception)
{
TriggerErrorEventArgs eventArg;
// create event argument
eventArg = new TriggerErrorEventArgs(source, exception);
// trigger delegate
try
{
if (TriggerError != null)
{
TriggerError(this, eventArg);
}
}
catch
{
// ensure that this method does not throw an exception
}
}
/// <summary>
/// Get an enumerator to return a collection of named values.
/// </summary>
/// <param name="selector">
/// string to direct the method on what to retrieve
/// </param>
/// <returns>enumerator of data in a row column heirarchy</returns>
public abstract RowEnumerator Read(string selector);
/// <summary>
/// Get an enumerator to return a collection of named values.
/// </summary>
/// <param name="selector">
/// string to direct the method on what to retrieve
/// </param>
/// <param name="parameters">
/// collections of parameters for the selector
/// </param>
/// <returns>enumerator of data in a row column heirarchy</returns>
public abstract RowEnumerator Read(string selector,
Parameters parameters);
/// <summary>
/// Rollback changes since the start of a transaction.
/// </summary>
public abstract void Rollback();
/// <summary>
/// Method for insert, updating and deleting from a data store.
/// </summary>
/// <param name="update">
/// string to direct the method on to update the date store.
/// </param>
public abstract void Save(string update);
/// <summary>
/// Method for insert, updating and deleting from a data store.
/// </summary>
/// <param name="update">
/// string to direct the method on to update the date store.
/// </param>
/// <param name="parameters">
/// collections of parameters for the selector
/// </param>
public abstract void Save(string update, Parameters parameters);
#endregion
#region Events
/// <summary>
/// Event for when data is changed. Subscribers are told what type of
/// change delete, insert, update and an identifier of what data was
/// changed.
/// </summary>
public event EventHandler<TriggerEventArgs> Trigger;
/// <summary>
/// Event for when a trigger event subscriber throws an exception.
/// </summary>
public event EventHandler<TriggerErrorEventArgs> TriggerError;
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -