Browse Source

2.0.1.0

Former-commit-id: 1decdd0c6f5a5cc4b794bc37f4a4c3c5d023fd24
af/merge-core
JimBobSquarePants 13 years ago
parent
commit
6d76e72a79
  1. 3
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  2. 2
      src/ImageProcessor.Web/Helpers/LockedDictionary.cs
  3. 133
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  4. 2
      src/ImageProcessor.Web/ImageProcessor.Web.csproj
  5. 4
      src/ImageProcessor.Web/Properties/AssemblyInfo.cs
  6. BIN
      src/Nuget/ImageProcessor.Web.2.0.1.0.nupkg

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

@ -10,6 +10,9 @@ namespace ImageProcessor.Web.Caching
#region Using #region Using
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ImageProcessor.Web.Helpers;
#endregion #endregion
/// <summary> /// <summary>

2
src/ImageProcessor.Web/Caching/LockedDictionary.cs → src/ImageProcessor.Web/Helpers/LockedDictionary.cs

@ -5,7 +5,7 @@
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
namespace ImageProcessor.Web.Caching namespace ImageProcessor.Web.Helpers
{ {
#region Using #region Using
using System.Collections.Generic; using System.Collections.Generic;

133
src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

@ -19,9 +19,6 @@ namespace ImageProcessor.Web.HttpModules
using ImageProcessor.Web.Caching; using ImageProcessor.Web.Caching;
using ImageProcessor.Web.Config; using ImageProcessor.Web.Config;
using ImageProcessor.Web.Helpers; using ImageProcessor.Web.Helpers;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading;
#endregion #endregion
/// <summary> /// <summary>
@ -51,15 +48,19 @@ namespace ImageProcessor.Web.HttpModules
private static readonly string AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); private static readonly string AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
/// <summary> /// <summary>
/// The thread safe fifo queue. /// A value indicating whether the application has started.
/// </summary> /// </summary>
private static ConcurrentQueue<Action> imageOperations; private static bool hasModuleInitialized;
#endregion
/// <summary> /// <summary>
/// A value indicating whether the application has started. /// The delegate void representing the ProcessImage method.
/// </summary> /// </summary>
private static bool hasAppStarted = false; /// <param name="context">
#endregion /// the <see cref="T:System.Web.HttpContext">HttpContext</see> object that provides
/// references to the intrinsic server objects
/// </param>
private delegate void ProcessImageDelegate(HttpContext context);
#region IHttpModule Members #region IHttpModule Members
/// <summary> /// <summary>
@ -72,23 +73,20 @@ namespace ImageProcessor.Web.HttpModules
/// </param> /// </param>
public void Init(HttpApplication context) public void Init(HttpApplication context)
{ {
if (!hasAppStarted) if (!hasModuleInitialized)
{ {
lock (SyncRoot) lock (SyncRoot)
{ {
if (!hasAppStarted) if (!hasModuleInitialized)
{ {
imageOperations = new ConcurrentQueue<Action>();
DiskCache.CreateCacheDirectories(); DiskCache.CreateCacheDirectories();
hasAppStarted = true; hasModuleInitialized = true;
} }
} }
} }
context.AddOnBeginRequestAsync(OnBeginAsync, OnEndAsync); context.AddOnBeginRequestAsync(this.OnBeginAsync, this.OnEndAsync);
//context.BeginRequest += this.ContextBeginRequest;
context.PreSendRequestHeaders += this.ContextPreSendRequestHeaders; context.PreSendRequestHeaders += this.ContextPreSendRequestHeaders;
} }
/// <summary> /// <summary>
@ -102,28 +100,30 @@ namespace ImageProcessor.Web.HttpModules
/// <summary> /// <summary>
/// The <see cref="T:System.Web.BeginEventHandler"/> that starts asynchronous processing /// The <see cref="T:System.Web.BeginEventHandler"/> that starts asynchronous processing
/// of the <see cref="T:System.Web.HttpApplication.BeginRequest"/>. /// of the <see cref="System.Web.HttpApplication.BeginRequest"/>.
/// </summary> /// </summary>
/// <param name="sender">The source of the event.</param> /// <param name="sender">The source of the event.</param>
/// <param name="e"> /// <param name="e">
/// An <see cref="T:System.EventArgs">EventArgs</see> that contains /// An <see cref="T:System.EventArgs">EventArgs</see> that contains
/// the event data. /// the event data.
/// </param> /// </param>
/// <param name="cb"> /// <param name="callBack">
/// The delegate to call when the asynchronous method call is complete. /// The delegate to call when the asynchronous method call is complete.
/// If cb is null, the delegate is not called. /// If the callback is null, the delegate is not called.
/// </param> /// </param>
/// <param name="extraData"> /// <param name="state">
/// Any additional data needed to process the request. /// Any additional data needed to process the request.
/// </param> /// </param>
/// <returns></returns> /// <returns>
IAsyncResult OnBeginAsync(object sender, EventArgs e, AsyncCallback cb, object extraData) /// The status of the asynchronous operation.
/// </returns>
private IAsyncResult OnBeginAsync(object sender, EventArgs e, AsyncCallback callBack, object state)
{ {
HttpContext context = ((HttpApplication)sender).Context; HttpContext context = ((HttpApplication)sender).Context;
EnqueueDelegate enqueueDelegate = new EnqueueDelegate(Enqueue);
return enqueueDelegate.BeginInvoke(context, cb, extraData); ProcessImageDelegate processImage = this.ProcessImage;
return processImage.BeginInvoke(context, callBack, state);
} }
/// <summary> /// <summary>
@ -133,53 +133,13 @@ namespace ImageProcessor.Web.HttpModules
/// The <see cref="T:System.IAsyncResult"/> that is the result of the /// The <see cref="T:System.IAsyncResult"/> that is the result of the
/// <see cref="T:System.Web.BeginEventHandler"/> operation. /// <see cref="T:System.Web.BeginEventHandler"/> operation.
/// </param> /// </param>
public void OnEndAsync(IAsyncResult result) private void OnEndAsync(IAsyncResult result)
{ {
// An action to consume the ConcurrentQueue. // Ensure our ProcessImage has completed in the background.
Action action = () => while (!result.IsCompleted)
{ {
Action op; System.Threading.Thread.Sleep(1);
}
while (imageOperations.TryDequeue(out op))
{
op();
}
};
// Start 4 concurrent consuming actions.
Parallel.Invoke(action, action, action, action);
}
/// <summary>
/// The delegate void representing the Enqueue method.
/// </summary>
/// <param name="context">
/// the <see cref="T:System.Web.HttpContext">HttpContext</see> object that provides
/// references to the intrinsic server objects
/// </param>
private delegate void EnqueueDelegate(HttpContext context);
/// <summary>
/// Adds the method to the queue.
/// </summary>
/// <param name="context">
/// the <see cref="T:System.Web.HttpContext">HttpContext</see> object that provides
/// references to the intrinsic server objects
/// </param>
private void Enqueue(HttpContext context)
{
imageOperations.Enqueue(() => ProcessImage(context));
}
/// <summary>
/// Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An <see cref="T:System.EventArgs">EventArgs</see> that contains the event data.</param>
private void ContextBeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
imageOperations.Enqueue(() => ProcessImage(context));
} }
/// <summary> /// <summary>
@ -197,6 +157,7 @@ namespace ImageProcessor.Web.HttpModules
{ {
string responseType = (string)responseTypeObject; string responseType = (string)responseTypeObject;
// Set the headers
this.SetHeaders(context, responseType); this.SetHeaders(context, responseType);
context.Items[CachedResponseTypeKey] = null; context.Items[CachedResponseTypeKey] = null;
@ -270,21 +231,21 @@ namespace ImageProcessor.Web.HttpModules
{ {
//lock (SyncRoot) //lock (SyncRoot)
//{ //{
// Trim the cache. // Trim the cache.
DiskCache.TrimCachedFolders(); DiskCache.TrimCachedFolders();
responseStream.CopyTo(memoryStream); responseStream.CopyTo(memoryStream);
imageFactory.Load(memoryStream) imageFactory.Load(memoryStream)
.AddQueryString(queryString) .AddQueryString(queryString)
.Format(ImageUtils.GetImageFormat(imageName)) .Format(ImageUtils.GetImageFormat(imageName))
.AutoProcess().Save(cachedPath); .AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, true); DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, true);
// Add to the cache. // Add to the cache.
DiskCache.AddImageToCache(cachedPath, dateTime); DiskCache.AddImageToCache(cachedPath, dateTime);
//} //}
} }
} }
@ -294,16 +255,16 @@ namespace ImageProcessor.Web.HttpModules
{ {
//lock (SyncRoot) //lock (SyncRoot)
//{ //{
// Trim the cache. // Trim the cache.
DiskCache.TrimCachedFolders(); DiskCache.TrimCachedFolders();
imageFactory.Load(fullPath).AutoProcess().Save(cachedPath); imageFactory.Load(fullPath).AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, false); DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, false);
// Add to the cache. // Add to the cache.
DiskCache.AddImageToCache(cachedPath, dateTime); DiskCache.AddImageToCache(cachedPath, dateTime);
//} //}
} }
} }

2
src/ImageProcessor.Web/ImageProcessor.Web.csproj

@ -88,7 +88,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Caching\CachedImage.cs" /> <Compile Include="Caching\CachedImage.cs" />
<Compile Include="Caching\DiskCache.cs" /> <Compile Include="Caching\DiskCache.cs" />
<Compile Include="Caching\LockedDictionary.cs" /> <Compile Include="Helpers\LockedDictionary.cs" />
<Compile Include="Caching\PersistantDictionary.cs" /> <Compile Include="Caching\PersistantDictionary.cs" />
<Compile Include="Caching\SQLContext.cs" /> <Compile Include="Caching\SQLContext.cs" />
<Compile Include="Config\ImageCacheSection.cs" /> <Compile Include="Config\ImageCacheSection.cs" />

4
src/ImageProcessor.Web/Properties/AssemblyInfo.cs

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("2.0.0.0")] [assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.0.0")] [assembly: AssemblyFileVersion("2.0.1.0")]

BIN
src/Nuget/ImageProcessor.Web.2.0.1.0.nupkg

Binary file not shown.
Loading…
Cancel
Save