Browse Source

IImageService prefix is now configurable

Former-commit-id: 3c3ca80f246f8779ed84f6c0f7430d2927b2eb51
pull/17/head
James South 12 years ago
parent
commit
a1218ef9e5
  1. 16
      src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs
  2. 20
      src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs
  3. 2
      src/ImageProcessor.Web/Configuration/Resources/security.config
  4. 4
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  5. 4
      src/ImageProcessor.Web/Services/IImageService.cs
  6. 16
      src/ImageProcessor.Web/Services/LocalFileImageService.cs
  7. 16
      src/ImageProcessor.Web/Services/RemoteImageService.cs
  8. 2
      src/TestWebsites/MVC/config/imageprocessor/security.config

16
src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs

@ -281,7 +281,7 @@ namespace ImageProcessor.Web.Configuration
return settings;
}
#endregion
#endregion
#region ImageServices
/// <summary>
@ -345,7 +345,19 @@ namespace ImageProcessor.Web.Configuration
throw new TypeLoadException("Couldn't load IImageService: " + config.Type);
}
this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IWebGraphicsProcessor);
IImageService imageService = Activator.CreateInstance(type) as IImageService;
if (!string.IsNullOrWhiteSpace(config.Prefix))
{
if (!string.IsNullOrWhiteSpace(config.Prefix))
{
if (imageService != null)
{
imageService.Prefix = config.Prefix;
}
}
}
this.ImageServices.Add(imageService);
}
// Add the available settings.

20
src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs

@ -68,9 +68,9 @@ namespace ImageProcessor.Web.Configuration
public class ServiceElement : ConfigurationElement
{
/// <summary>
/// Gets or sets the name of the plugin file.
/// Gets or sets the name of the service.
/// </summary>
/// <value>The name of the plugin.</value>
/// <value>The name of the service.</value>
[ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
public string Name
{
@ -80,9 +80,21 @@ namespace ImageProcessor.Web.Configuration
}
/// <summary>
/// Gets or sets the type of the service file.
/// Gets or sets the prefix of the service.
/// </summary>
/// <value>The full Type definition of the plugin</value>
/// <value>The prefix of the service.</value>
[ConfigurationProperty("prefix", DefaultValue = "", IsRequired = false)]
public string Prefix
{
get { return (string)this["prefix"]; }
set { this["prefix"] = value; }
}
/// <summary>
/// Gets or sets the type of the service.
/// </summary>
/// <value>The full Type definition of the service</value>
[ConfigurationProperty("type", DefaultValue = "", IsRequired = true)]
public string Type
{

2
src/ImageProcessor.Web/Configuration/Resources/security.config

@ -1,7 +1,7 @@
<security>
<services autoLoadServices="true">
<service name="LocalFileImageService" type="ImageProcessor.Web.Services.LocalFileImageService, ImageProcessor.Web"/>
<service name="RemoteImageService" type="ImageProcessor.Web.Services.RemoteImageService, ImageProcessor.Web">
<service prefix="remote.axd" name="RemoteImageService" type="ImageProcessor.Web.Services.RemoteImageService, ImageProcessor.Web">
<settings>
<setting key="MaxBytes" value="4194304"/>
<setting key="Timeout" value="3000"/>

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

@ -530,7 +530,7 @@ namespace ImageProcessor.Web.HttpModules
string path = request.Path;
foreach (IImageService service in services)
{
string key = service.Key;
string key = service.Prefix;
if (!string.IsNullOrWhiteSpace(key) && path.EndsWith(key, StringComparison.InvariantCultureIgnoreCase))
{
imageService = service;
@ -545,7 +545,7 @@ namespace ImageProcessor.Web.HttpModules
// Return the file based service
if (ImageHelpers.IsValidImageExtension(path))
{
return services.FirstOrDefault(s => string.IsNullOrWhiteSpace(s.Key));
return services.FirstOrDefault(s => string.IsNullOrWhiteSpace(s.Prefix));
}
return null;

4
src/ImageProcessor.Web/Services/IImageService.cs

@ -20,12 +20,12 @@ namespace ImageProcessor.Web.Services
public interface IImageService
{
/// <summary>
/// Gets the key for the given implementation.
/// Gets or sets the prefix for the given implementation.
/// <remarks>
/// This value is used as a prefix for any image requests that should use this service.
/// </remarks>
/// </summary>
string Key { get; }
string Prefix { get; set; }
/// <summary>
/// Gets a value indicating whether the image service requests files from

16
src/ImageProcessor.Web/Services/LocalFileImageService.cs

@ -22,16 +22,26 @@ namespace ImageProcessor.Web.Services
public class LocalFileImageService : IImageService
{
/// <summary>
/// Gets the key for the given implementation.
/// The prefix for the given implementation.
/// </summary>
private string prefix = string.Empty;
/// <summary>
/// Gets or sets the prefix for the given implementation.
/// <remarks>
/// This value is used as a prefix for any image requests that should use this service.
/// </remarks>
/// </summary>
public string Key
public string Prefix
{
get
{
return string.Empty;
return this.prefix;
}
set
{
this.prefix = value;
}
}

16
src/ImageProcessor.Web/Services/RemoteImageService.cs

@ -24,6 +24,11 @@ namespace ImageProcessor.Web.Services
/// </summary>
public class RemoteImageService : IImageService
{
/// <summary>
/// The prefix for the given implementation.
/// </summary>
private string prefix = "remote.axd";
/// <summary>
/// Initializes a new instance of the <see cref="RemoteImageService"/> class.
/// </summary>
@ -39,16 +44,21 @@ namespace ImageProcessor.Web.Services
}
/// <summary>
/// Gets the key for the given implementation.
/// Gets or sets the prefix for the given implementation.
/// <remarks>
/// This value is used as a prefix for any image requests that should use this service.
/// </remarks>
/// </summary>
public string Key
public string Prefix
{
get
{
return "remote.axd";
return this.prefix;
}
set
{
this.prefix = value;
}
}

2
src/TestWebsites/MVC/config/imageprocessor/security.config

@ -2,7 +2,7 @@
<security>
<services autoLoadServices="true">
<service name="LocalFileImageService" type="ImageProcessor.Web.Services.LocalFileImageService, ImageProcessor.Web"/>
<service name="RemoteImageService" type="ImageProcessor.Web.Services.RemoteImageService, ImageProcessor.Web">
<service prefix="remote.axd" name="RemoteImageService" type="ImageProcessor.Web.Services.RemoteImageService, ImageProcessor.Web">
<settings>
<setting key="MaxBytes" value="4194304"/>
<setting key="Timeout" value="30000"/>

Loading…
Cancel
Save