Browse Source

Whoop! It's alive :)

Former-commit-id: 129e3abe7772d08ba133de10da6e25a380f88731
af/merge-core
James South 13 years ago
parent
commit
13c120a0cd
  1. 21
      src/ImageProcessor.Web/Caching/CachedImage.cs
  2. 16
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  3. 34
      src/ImageProcessor.Web/Caching/SQLContext.cs
  4. 4
      src/ImageProcessor.Web/ImageProcessor.Web.csproj

21
src/ImageProcessor.Web/Caching/CachedImage.cs

@ -17,35 +17,38 @@ namespace ImageProcessor.Web.Caching
/// <summary> /// <summary>
/// Describes a cached image /// Describes a cached image
/// </summary> /// </summary>
internal sealed class CachedImage public sealed class CachedImage
{ {
//[PrimaryKey, AutoIncrement] /// <summary>
//public int Id { get; set; } /// Gets or sets the id identifying the cached image.
/// </summary>
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
/// <summary> /// <summary>
/// Gets or sets the key identifying the cached image. /// Gets or sets the key identifying the cached image.
/// </summary> /// </summary>
[PrimaryKey] [Unique]
internal string Key { get; set; } public string Key { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value of the cached image. /// Gets or sets the value of the cached image.
/// </summary> /// </summary>
internal string Path { get; set; } public string Path { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum age of the cached image in days. /// Gets or sets the maximum age of the cached image in days.
/// </summary> /// </summary>
internal int MaxAge { get; set; } public int MaxAge { get; set; }
/// <summary> /// <summary>
/// Gets or sets the last write time of the cached image. /// Gets or sets the last write time of the cached image.
/// </summary> /// </summary>
internal DateTime LastWriteTimeUtc { get; set; } public DateTime LastWriteTimeUtc { get; set; }
/// <summary> /// <summary>
/// Gets or sets when the cached image should expire from the cache. /// Gets or sets when the cached image should expire from the cache.
/// </summary> /// </summary>
internal DateTime ExpiresUtc { get; set; } public DateTime ExpiresUtc { get; set; }
} }
} }

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

@ -76,10 +76,14 @@ namespace ImageProcessor.Web.Caching
// Remove the CachedImage. // Remove the CachedImage.
CachedImage value = this[key]; CachedImage value = this[key];
this.Remove(key);
await this.SaveCacheAsync(key, value, true); if (await this.SaveCacheAsync(key, value, true) > 0)
return true; {
this.Remove(key);
return true;
}
return false;
} }
/// <summary> /// <summary>
@ -97,7 +101,7 @@ namespace ImageProcessor.Web.Caching
public async Task<CachedImage> AddAsync(string key, CachedImage cachedImage) public async Task<CachedImage> AddAsync(string key, CachedImage cachedImage)
{ {
// Add the CachedImage. // Add the CachedImage.
if (await this.SaveCacheAsync(key, cachedImage, false)) if (await this.SaveCacheAsync(key, cachedImage, false) > 0)
{ {
this.Add(key, cachedImage); this.Add(key, cachedImage);
} }
@ -121,7 +125,7 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// true, if the dictionary is saved to the file-system; otherwise, false. /// true, if the dictionary is saved to the file-system; otherwise, false.
/// </returns> /// </returns>
private async Task<bool> SaveCacheAsync(string key, CachedImage cachedImage, bool remove) private async Task<int> SaveCacheAsync(string key, CachedImage cachedImage, bool remove)
{ {
try try
{ {
@ -134,7 +138,7 @@ namespace ImageProcessor.Web.Caching
} }
catch catch
{ {
return false; return 0;
} }
} }

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

@ -119,7 +119,7 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The true if the addition of the cached image is added; otherwise, false. /// The true if the addition of the cached image is added; otherwise, false.
/// </returns> /// </returns>
internal static async Task<bool> AddImageAsync(CachedImage image) internal static async Task<int> AddImageAsync(CachedImage image)
{ {
// Create Action delegate for AddImage. // Create Action delegate for AddImage.
return await TaskHelpers.Run(() => AddImage(image)); return await TaskHelpers.Run(() => AddImage(image));
@ -134,7 +134,7 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The true if the addition of the cached image is removed; otherwise, false. /// The true if the addition of the cached image is removed; otherwise, false.
/// </returns> /// </returns>
internal static async Task<bool> RemoveImageAsync(string key) internal static async Task<int> RemoveImageAsync(string key)
{ {
// Create Action delegate for RemoveImage. // Create Action delegate for RemoveImage.
return await TaskHelpers.Run(() => RemoveImage(key)); return await TaskHelpers.Run(() => RemoveImage(key));
@ -152,24 +152,21 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The true if the addition of the cached image is added; otherwise, false. /// The true if the addition of the cached image is added; otherwise, false.
/// </returns> /// </returns>
private static bool AddImage(CachedImage image) private static int AddImage(CachedImage image)
{ {
try try
{ {
int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString); SQLiteConnection connection = new SQLiteConnection(ConnectionString);
connection.RunInTransaction(() => id = connection.Insert(image);
{ connection.Dispose();
// Database calls inside the transaction
connection.Insert(image);
connection.Dispose();
});
return true; return id;
} }
catch catch
{ {
return false; return 0;
} }
} }
@ -182,24 +179,21 @@ namespace ImageProcessor.Web.Caching
/// <returns> /// <returns>
/// The true if the addition of the cached image is removed; otherwise, false. /// The true if the addition of the cached image is removed; otherwise, false.
/// </returns> /// </returns>
private static bool RemoveImage(string key) private static int RemoveImage(string key)
{ {
try try
{ {
int id = 0;
SQLiteConnection connection = new SQLiteConnection(ConnectionString); SQLiteConnection connection = new SQLiteConnection(ConnectionString);
connection.RunInTransaction(() => id = connection.Delete<CachedImage>(key);
{ connection.Dispose();
// Database calls inside the transaction
connection.Delete<CachedImage>(key);
connection.Dispose();
});
return true; return id;
} }
catch catch
{ {
return false; return 0;
} }
} }
#endregion #endregion

4
src/ImageProcessor.Web/ImageProcessor.Web.csproj

@ -26,14 +26,14 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE;USE_CSHARP_SQLITE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'All|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'All|AnyCPU'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\All\</OutputPath> <OutputPath>bin\All\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>

Loading…
Cancel
Save