// -----------------------------------------------------------------------
//
// Copyright (c) James South.
// Dual licensed under the MIT or GPL Version 2 licenses.
//
// -----------------------------------------------------------------------
namespace ImageProcessor.Web
{
#region Using
using System.Collections.Generic;
using System.Linq;
using ImageProcessor.Processors;
using ImageProcessor.Web.Config;
#endregion
///
/// Extends the ImageFactory class to provide a fluent API.
///
public static class ImageFactoryExtensions
{
///
/// The object to lock against.
///
private static readonly object SyncRoot = new object();
///
/// Auto processes image files based on any query string parameters added to the image path.
///
///
/// The current instance of the class
/// that this method extends.
///
///
/// The current instance of the class.
///
public static ImageFactory AutoProcess(this ImageFactory factory)
{
if (factory.ShouldProcess)
{
// TODO: This is going to be a bottleneck for speed. Find a faster way.
//lock (SyncRoot)
//{
// Get a list of all graphics processors that have parsed and matched the querystring.
List list =
ImageProcessorConfig.Instance.GraphicsProcessors
.Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue)
.OrderBy(y => y.SortOrder)
.ToList();
// Loop through and process the image.
foreach (IGraphicsProcessor graphicsProcessor in list)
{
factory.Image = graphicsProcessor.ProcessImage(factory);
}
//}
}
return factory;
}
}
}