Browse Source

IImageService prefix is now configurable

Former-commit-id: 74fe856e4bc2caa3dc9c9396cb5fd1c26f92341b
pull/17/head
James South 12 years ago
parent
commit
db619be08b
  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; return settings;
} }
#endregion #endregion
#region ImageServices #region ImageServices
/// <summary> /// <summary>
@ -345,7 +345,19 @@ namespace ImageProcessor.Web.Configuration
throw new TypeLoadException("Couldn't load IImageService: " + config.Type); 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. // Add the available settings.

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

@ -68,9 +68,9 @@ namespace ImageProcessor.Web.Configuration
public class ServiceElement : ConfigurationElement public class ServiceElement : ConfigurationElement
{ {
/// <summary> /// <summary>
/// Gets or sets the name of the plugin file. /// Gets or sets the name of the service.
/// </summary> /// </summary>
/// <value>The name of the plugin.</value> /// <value>The name of the service.</value>
[ConfigurationProperty("name", DefaultValue = "", IsRequired = true)] [ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
public string Name public string Name
{ {
@ -80,9 +80,21 @@ namespace ImageProcessor.Web.Configuration
} }
/// <summary> /// <summary>
/// Gets or sets the type of the service file. /// Gets or sets the prefix of the service.
/// </summary> /// </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)] [ConfigurationProperty("type", DefaultValue = "", IsRequired = true)]
public string Type public string Type
{ {

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

@ -1,7 +1,7 @@
<security> <security>
<services autoLoadServices="true"> <services autoLoadServices="true">
<service name="LocalFileImageService" type="ImageProcessor.Web.Services.LocalFileImageService, ImageProcessor.Web"/> <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> <settings>
<setting key="MaxBytes" value="4194304"/> <setting key="MaxBytes" value="4194304"/>
<setting key="Timeout" value="3000"/> <setting key="Timeout" value="3000"/>

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

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

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

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

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

@ -2,7 +2,7 @@
<security> <security>
<services autoLoadServices="true"> <services autoLoadServices="true">
<service name="LocalFileImageService" type="ImageProcessor.Web.Services.LocalFileImageService, ImageProcessor.Web"/> <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> <settings>
<setting key="MaxBytes" value="4194304"/> <setting key="MaxBytes" value="4194304"/>
<setting key="Timeout" value="30000"/> <setting key="Timeout" value="30000"/>

Loading…
Cancel
Save