Browse Source

Async

Former-commit-id: e8fbaa8147377bbc8e589d5cbac477f570e87f0e
af/merge-core
James South 13 years ago
parent
commit
529e7d7a89
  1. 2
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  2. 54
      src/ImageProcessor.Web/Caching/SQLContext.cs

2
src/ImageProcessor.Web/Caching/PersistantDictionary.cs

@ -131,7 +131,7 @@ namespace ImageProcessor.Web.Caching
{
if (remove)
{
return await SQLContext.RemoveImageAsync(key);
return await SQLContext.RemoveImageAsync(cachedImage);
}
return await SQLContext.AddImageAsync(cachedImage);

54
src/ImageProcessor.Web/Caching/SQLContext.cs

@ -45,7 +45,6 @@ namespace ImageProcessor.Web.Caching
#region Methods
#region Internal
/// <summary>
/// Creates the database if it doesn't already exist.
/// </summary>
@ -120,49 +119,12 @@ namespace ImageProcessor.Web.Caching
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
internal static async Task<int> AddImageAsync(CachedImage image)
{
// Create Action delegate for AddImage.
return await TaskHelpers.Run(() => AddImage(image));
}
/// <summary>
/// Removes a cached image from the database.
/// </summary>
/// <param name="key">
/// The key for the cached image.
/// </param>
/// <returns>
/// The true if the addition of the cached image is removed; otherwise, false.
/// </returns>
internal static async Task<int> RemoveImageAsync(string key)
{
// Create Action delegate for RemoveImage.
return await TaskHelpers.Run(() => RemoveImage(key));
}
#endregion
#region Private
/// <summary>
/// Adds a cached image to the database.
/// </summary>
/// <param name="image">
/// The cached image to add.
/// </param>
/// <returns>
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
private static int AddImage(CachedImage image)
{
try
{
int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
id = connection.Insert(image);
connection.Dispose();
SQLiteAsyncConnection connection = new SQLiteAsyncConnection(ConnectionString);
return id;
return await connection.InsertAsync(image);
}
catch
{
@ -173,23 +135,19 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// Removes a cached image from the database.
/// </summary>
/// <param name="key">
/// <param name="cachedImage">
/// The key for the cached image.
/// </param>
/// <returns>
/// The true if the addition of the cached image is removed; otherwise, false.
/// </returns>
private static int RemoveImage(string key)
internal static async Task<int> RemoveImageAsync(CachedImage cachedImage)
{
try
{
int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
id = connection.Delete<CachedImage>(key);
connection.Dispose();
SQLiteAsyncConnection connection = new SQLiteAsyncConnection(ConnectionString);
return id;
return await connection.DeleteAsync(cachedImage);
}
catch
{

Loading…
Cancel
Save