Browse Source

Merge branch 'chriskoiak-master' into Plugins

Former-commit-id: b07fc9d0108e69889af64f1304aae5138563ed0a
af/merge-core
James South 12 years ago
parent
commit
4890e9bd29
  1. 26
      src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs
  2. 88
      src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
  3. 33
      src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

26
src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs

@ -71,13 +71,25 @@ namespace ImageProcessor.Web.Config
set { this["name"] = value; }
}
/// <summary>
/// Gets or sets the type of the plugin file.
/// </summary>
/// <value>The full Type definition of the plugin</value>
[ConfigurationProperty("type", DefaultValue = "", IsRequired = true)]
public string Type
{
get { return (string)this["type"]; }
set { this["type"] = value; }
}
/// <summary>
/// Gets the <see cref="T:ImageProcessor.Web.Config.ImageProcessingSection.SettingElementCollection"/>.
/// </summary>
/// <value>
/// The <see cref="T:ImageProcessor.Web.Config.ImageProcessingSection.SettingElementCollection"/>.
/// </value>
[ConfigurationProperty("settings", IsRequired = true)]
[ConfigurationProperty("settings", IsRequired = false)]
public SettingElementCollection Settings
{
get
@ -114,6 +126,18 @@ namespace ImageProcessor.Web.Config
get { return "plugin"; }
}
/// <summary>
/// Gets or sets the autoLoadPlugins of the plugin file.
/// </summary>
/// <value>If True plugins are auto discovered and loaded from all assemblies otherwise they must be defined in the configuration file</value>
[ConfigurationProperty("autoLoadPlugins", DefaultValue = true, IsRequired = false)]
public bool AutoLoadPlugins
{
get { return (bool)this["autoLoadPlugins"]; }
set { this["autoLoadPlugins"] = value; }
}
/// <summary>
/// Gets or sets the <see cref="T:ImageProcessor.Web.Config.ImageProcessingSection.PluginElement"/>
/// at the specified index within the collection.

88
src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs

@ -9,6 +9,8 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System.Collections;
namespace ImageProcessor.Web.Config
{
#region Using
@ -253,49 +255,73 @@ namespace ImageProcessor.Web.Config
{
if (this.GraphicsProcessors == null)
{
try
if (GetImageProcessingSection().Plugins.AutoLoadPlugins)
{
// Build a list of native IGraphicsProcessor instances.
Type type = typeof(IGraphicsProcessor);
IEnumerable<Type> types =
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
.ToList();
// Create them and add.
this.GraphicsProcessors =
types.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList();
// Add the available settings.
foreach (IGraphicsProcessor processor in this.GraphicsProcessors)
try
{
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
// Build a list of native IGraphicsProcessor instances.
Type type = typeof (IGraphicsProcessor);
IEnumerable<Type> types =
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
.ToList();
// Create them and add.
this.GraphicsProcessors =
types.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList();
// Add the available settings.
foreach (IGraphicsProcessor processor in this.GraphicsProcessors)
{
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
}
}
}
catch (ReflectionTypeLoadException ex)
{
StringBuilder sb = new StringBuilder();
foreach (Exception exception in ex.LoaderExceptions)
catch (ReflectionTypeLoadException ex)
{
sb.AppendLine(exception.Message);
if (exception is FileNotFoundException)
StringBuilder sb = new StringBuilder();
foreach (Exception exception in ex.LoaderExceptions)
{
FileNotFoundException fileNotFoundException = exception as FileNotFoundException;
if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog))
sb.AppendLine(exception.Message);
if (exception is FileNotFoundException)
{
sb.AppendLine("Fusion Log:");
sb.AppendLine(fileNotFoundException.FusionLog);
FileNotFoundException fileNotFoundException = exception as FileNotFoundException;
if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog))
{
sb.AppendLine("Fusion Log:");
sb.AppendLine(fileNotFoundException.FusionLog);
}
}
sb.AppendLine();
}
sb.AppendLine();
string errorMessage = sb.ToString();
// Display or log the error based on your application.
throw new Exception(errorMessage);
}
}
else
{
var pluginConfigs = imageProcessingSection.Plugins;
this.GraphicsProcessors = new List<IGraphicsProcessor>();
foreach (ImageProcessingSection.PluginElement pluginConfig in pluginConfigs)
{
var type = Type.GetType(pluginConfig.Type);
string errorMessage = sb.ToString();
if (type == null)
{
throw new ArgumentException("Couldn't load IGraphicsProcessor: " + pluginConfig.Type);
}
this.GraphicsProcessors.Add((Activator.CreateInstance(type) as IGraphicsProcessor));
}
// Display or log the error based on your application.
throw new Exception(errorMessage);
// Add the available settings.
foreach (IGraphicsProcessor processor in this.GraphicsProcessors)
{
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
}
}
}
}

33
src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config

@ -1,27 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<processing>
<plugins>
<plugin name="Resize">
<settings>
<setting key="MaxWidth" value="3000"/>
<setting key="MaxHeight" value="3000"/>
</settings>
</plugin>
<plugin name="GaussianBlur">
<plugins autoLoadPlugins="false">
<plugin name="Alpha" type="ImageProcessor.Processors.Alpha, ImageProcessor"/>
<plugin name="Brightness" type="ImageProcessor.Processors.Brightness, ImageProcessor"/>
<plugin name="Contrast" type="ImageProcessor.Processors.Contrast, ImageProcessor"/>
<plugin name="Crop" type="ImageProcessor.Processors.Crop, ImageProcessor"/>
<plugin name="Filter" type="ImageProcessor.Processors.Filter, ImageProcessor"/>
<plugin name="Flip" type="ImageProcessor.Processors.Flip, ImageProcessor"/>
<plugin name="Format" type="ImageProcessor.Processors.Format, ImageProcessor"/>
<plugin name="GaussianBlur" type="ImageProcessor.Processors.GaussianBlur, ImageProcessor">
<settings>
<setting key="MaxSize" value="22"/>
<setting key="MaxSigma" value="5.1"/>
<setting key="MaxThreshold" value="100"/>
</settings>
</plugin>
<plugin name="GaussianSharpen">
<plugin name="GaussianSharpen" type="ImageProcessor.Processors.GaussianSharpen, ImageProcessor">
<settings>
<setting key="MaxSize" value="22"/>
<setting key="MaxSigma" value="5.1"/>
<setting key="MaxThreshold" value="100"/>
</settings>
</plugin>
<plugin name="Preset">
<plugin name="Quality" type="ImageProcessor.Processors.Quality, ImageProcessor"/>
<plugin name="Resize" type="ImageProcessor.Processors.Resize, ImageProcessor">
<settings>
<setting key="MaxWidth" value="3000"/>
<setting key="MaxHeight" value="3000"/>
</settings>
</plugin>
<plugin name="Rotate" type="ImageProcessor.Processors.Rotate, ImageProcessor"/>
<plugin name="RoundedCorners" type="ImageProcessor.Processors.RoundedCorners, ImageProcessor"/>
<plugin name="Saturation" type="ImageProcessor.Processors.Saturation, ImageProcessor"/>
<plugin name="Vignette" type="ImageProcessor.Processors.Vignette, ImageProcessor"/>
<plugin name="Watermark" type="ImageProcessor.Processors.Watermark, ImageProcessor"/>
<plugin name="Preset" type="ImageProcessor.Web.Preset, ImageProcessor">
<settings>
<setting key="demo" value="width=300&#038;height=150&#038;&#038;bgcolor=transparent"/>
</settings>

Loading…
Cancel
Save