ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
ImageResizer.Configuration.PluginConfig Class Reference

Provides thread-safe access to plugin addition, removal, and querying methods More...

Inheritance diagram for ImageResizer.Configuration.PluginConfig:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Configuration.PluginConfig:
Collaboration graph
[legend]

Public Member Functions

 PluginConfig (Config c)
 Creates a new plugin config section, attached to the specified parent More...
 
void LoadPlugins ()
 Processes the <plugins> section if they are not already loaded. Thread safe. Only executes once. More...
 
void ForceLoadPlugins ()
 Forces loading of the plugins specified in configuration, even if they have already been loaded. Will add duplicate plugins and throw exceptions if you do not call RemoveAll() first. More...
 
IList< IPluginGetPlugins (Type type)
 Returns the subset of installed plugins which implement the specified type or interface More...
 
IList< T > GetAll< T > ()
 Returns all registered instances of the specified plugins More...
 
bool HasPlugin (Type type)
 Returns true if at least one plugin of the specified type is registered. More...
 
bool Has< T > ()
 Returns true if 1 or more instances of the type are registered. More...
 
Get< T > ()
 Returns the first registerd instance of the specified plugin. For IMultiInstancePlugins, use GetAll() More...
 
GetOrInstall< T > ()
 Returns the first registered instance of the specified plugin, or creates a new instance if the plugin isn't installed. More...
 
GetOrInstall< T > (T newInstance)
 Returns the first registered instance of the specified plugin, or installs the given instance instead, then re-tries the query More...
 
IPlugin Install (IPlugin plugin)
 Installs the specified plugin, returning the plugin instance. Convenience method, same as plugin.Install(Config.Current). More...
 
bool Uninstall (IPlugin plugin)
 Attempts uninstallation of the specified plugin, returning true if successful. Convenience method, same as plugin.Uninstall(Config.Current). More...
 
delegate void LoggingAvaialableEvent (ILogManager logger)
 
IEncoder GetEncoder (ResizeSettings settings, object original)
 Returns an instance of the first encoder that claims to be able to handle the specified settings. Returns null if no encoders are available. More...
 
Type FindPluginType (string searchName)
 Searches all loaded assemblies for the specified type, applying rules and prefixes to resolve the namespace and assembly. Returns null if it could not find the type, and logs an issue. More...
 
void remove_plugin (object plugin)
 For use only by plugins during .Uninstall. Removes the specified plugin from AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuiderExtensions, based on which interfaces the instance implements. Plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method. More...
 
void add_plugin (IPlugin plugin)
 Only for use by plugins during IPlugin.Install. Call Plugin.Install instead of this method, since plugins often must perform other initialization actions. Adds the specified plugin to AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuiderExtensions, based on which interfaces the instance implements. For ICache and IEncoder, the plugin is inserted at the beginning of CachingSystems and ImageEncoders respectively. To reiterate, plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method. Will not register a plugin that is already installed, unless it implementes IMultiInstancePlugin. More...
 
void RemoveAll ()
 Removes all plugins, of every kind. Logs any errors encountered. (Not all plugins support uninstallation) More...
 
override IEnumerable< IIssueGetIssues ()
 Returns a copy of the list of reported issues. More...
 
- Public Member Functions inherited from ImageResizer.Configuration.Issues.IssueSink
 IssueSink (string defaultSource)
 
virtual void AcceptIssue (IIssue i)
 Adds the specified issue to the list unless it is an exact duplicate of another instance. More...
 

Public Attributes

LoggingAvaialableEvent LoggingAvailable
 

Protected Member Functions

void loadPluginsInternal ()
 Not thread safe. Performs actual work. More...
 
void remove_plugins_by_name (string name)
 
void add_plugin_by_name (string name, NameValueCollection args)
 
void clear_plugins_by_type (string type)
 
List< string > GetOptimizedAssemblyList (string assemblyName, string pluginName)
 This is called to get a sorted list of plugins based on their likelyhood of having the plugin. More...
 
IPlugin CreatePluginByName (string name, NameValueCollection args)
 
IPlugin CreatePluginByType (Type t, NameValueCollection args)
 

Protected Attributes

NativeDependencyManager ndeps = new NativeDependencyManager()
 
Config c
 
volatile bool _pluginsLoaded = false
 
object _loadPluginsSync = new object()
 
SafeList< ICurrentConfigProviderconfigProviders = null
 
SafeList< BuilderExtensionimageBuilderExtensions = null
 
SafeList< IEncoderimageEncoders = null
 
SafeList< ICachecachingSystems = null
 
SafeList< IQuerystringPluginquerystringPlugins = null
 
SafeList< IFileExtensionPluginfileExtensionPlugins = null
 
SafeList< IVirtualImageProvidervirtualProviderPlugins = null
 
SafeList< ISettingsModifiersettingsModifierPlugins = null
 
SafeList< IPluginallPlugins = null
 
ILogManager _logManager = null
 
- Protected Attributes inherited from ImageResizer.Configuration.Issues.IssueSink
string defaultSource = null
 

Properties

bool PluginsLoaded [get]
 Returns true if the <plugins> section has been processed More...
 
SafeList< ICurrentConfigProviderConfigProviders [get]
 Currently registered ICurrentConfigProviders. More...
 
SafeList< BuilderExtensionImageBuilderExtensions [get]
 Currently registered set of ImageBuilderExtensions. More...
 
SafeList< IEncoderImageEncoders [get]
 Currently registered IEncoders. More...
 
SafeList< ICacheCachingSystems [get]
 Currently registered ICache instances More...
 
SafeList< IQuerystringPluginQuerystringPlugins [get]
 Plugins which accept querystring arguments are registered here. More...
 
SafeList< IFileExtensionPluginFileExtensionPlugins [get]
 Plugins which accept new file extensions (in the url) are registered here. More...
 
SafeList< IVirtualImageProviderVirtualProviderPlugins [get]
 Plugins which provide virtual files are registered here. More...
 
SafeList< ISettingsModifierSettingsModifierPlugins [get]
 Plugins which modify image processing settings. More...
 
SafeList< IPluginAllPlugins [get]
 All plugins should be registered here. Used for diagnostic purposes. More...
 
IEncoderProvider EncoderProvider [get]
 
ILogManager LogManager [get, set]
 Returns the most recently registered Logging plugin, or null. More...
 

Detailed Description

Provides thread-safe access to plugin addition, removal, and querying methods

Definition at line 24 of file PluginConfig.cs.

Constructor & Destructor Documentation

ImageResizer.Configuration.PluginConfig.PluginConfig ( Config  c)
inline

Creates a new plugin config section, attached to the specified parent

Parameters
c

Definition at line 35 of file PluginConfig.cs.

35  : base("Plugins"){
36  this.c = c;
37  imageBuilderExtensions = new SafeList<BuilderExtension>();
38  imageEncoders = new SafeList<IEncoder>();
39  cachingSystems = new SafeList<ICache>();
40  querystringPlugins = new SafeList<IQuerystringPlugin>();
41  fileExtensionPlugins = new SafeList<IFileExtensionPlugin>();
42  allPlugins = new SafeList<IPlugin>();
43  virtualProviderPlugins = new SafeList<IVirtualImageProvider>();
44  settingsModifierPlugins = new SafeList<ISettingsModifier>();
45  configProviders = new SafeList<ICurrentConfigProvider>();
46  }

Member Function Documentation

void ImageResizer.Configuration.PluginConfig.add_plugin ( IPlugin  plugin)
inline

Only for use by plugins during IPlugin.Install. Call Plugin.Install instead of this method, since plugins often must perform other initialization actions. Adds the specified plugin to AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuiderExtensions, based on which interfaces the instance implements. For ICache and IEncoder, the plugin is inserted at the beginning of CachingSystems and ImageEncoders respectively. To reiterate, plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method. Will not register a plugin that is already installed, unless it implementes IMultiInstancePlugin.

Parameters
plugin

Definition at line 542 of file PluginConfig.cs.

542  {
543  if (!(plugin is IMultiInstancePlugin) && HasPlugin(plugin.GetType())) {
544  AcceptIssue(new Issue("An instance of the specified plugin (" + plugin.GetType().ToString() + ") has already been registered.",
545  "The plugin should implement IMultiInstancePlugin to support multiple instances.", IssueSeverity.Error));
546  return;
547  }
548 
549  AllPlugins.Add(plugin);
550  if (plugin is IQuerystringPlugin) QuerystringPlugins.Add(plugin as IQuerystringPlugin);
551  if (plugin is IFileExtensionPlugin) FileExtensionPlugins.Add(plugin as IFileExtensionPlugin);
552  if (plugin is ICache) CachingSystems.AddFirst(plugin as ICache);
553  if (plugin is IEncoder) ImageEncoders.AddFirst(plugin as IEncoder);
554  if (plugin is BuilderExtension) ImageBuilderExtensions.Add(plugin as BuilderExtension);
555  if (plugin is IVirtualImageProvider) VirtualProviderPlugins.Add(plugin as IVirtualImageProvider);
556  if (plugin is ISettingsModifier) SettingsModifierPlugins.Add(plugin as ISettingsModifier);
557  if (plugin is ICurrentConfigProvider) ConfigProviders.Add(plugin as ICurrentConfigProvider);
558  if (plugin is ILogManager) LogManager = plugin as ILogManager;
559  }
Provides caching behavior
Definition: ICache.cs:12
virtual void AcceptIssue(IIssue i)
Adds the specified issue to the list unless it is an exact duplicate of another instance.
Definition: IssueSink.cs:30
Implement this to allow your class (or VirtualPathProvider subclass) to be used without registering i...
Provides a way to modify settings before they reach the managed API. Does not execute early enough to...
For plugins that access the query string (important!)
ILogManager LogManager
Returns the most recently registered Logging plugin, or null.
Tag your plugin with this interface if it supports having multiple instances registered at once ...
bool HasPlugin(Type type)
Returns true if at least one plugin of the specified type is registered.
For plugins that add support for new source file image extensions.
Provides a useable base class that can be used to modify the behavior of ImageBuilder. When registered with an ImageBuilder instance, the ImageBuilder will call the corresponding methods on the extension prior to executing its own methods.
Allows multi-tenancy support. The &#39;root&#39; config only needs one plugin, which implements this interfac...
An image encoder. Exposes methods for suitability checking, encoding, transparency compatibility chec...
Definition: IEncoder.cs:13
Type ImageResizer.Configuration.PluginConfig.FindPluginType ( string  searchName)
inline

Searches all loaded assemblies for the specified type, applying rules and prefixes to resolve the namespace and assembly. Returns null if it could not find the type, and logs an issue.

Parameters
searchName
Returns

Definition at line 377 of file PluginConfig.cs.

377  {
378  Type t = null;
379 
380  int commaAt = searchName.IndexOf(',');
381  int dotAt = searchName.IndexOf('.');
382 
383  //If there is a dot or period, try the exact name first.
384  if (dotAt > -1 || commaAt > -1)
385  t = Type.GetType(searchName, false, true);
386 
387  if (t != null) return t;
388 
389  //Split the name and assembly apart
390  string assembly = commaAt > -1 ? searchName.Substring(commaAt) : null;
391  string name = commaAt > -1 ? searchName.Substring(0, commaAt) : searchName;
392 
393  //Without the assembly specified, does it still have a name?
394  bool hasDot = name.IndexOf('.') > -1;
395 
396  List<string> alternateNames = new List<string>();
397  //ImageResizer.Plugins.Basic.DefaultEncoder
398  if (hasDot) alternateNames.Add(name);
399  //DefaultEncoder, NoCache, etc.
400  alternateNames.Add("ImageResizer.Plugins.Basic." + name.TrimStart('.'));
401  //Apr4-2012 - Deleted, never used: alternateNames.Add("ImageResizer.Plugins.Pro." + name.TrimStart('.'));
402  //AnimatedGifs
403  if (!hasDot) alternateNames.Add("ImageResizer.Plugins." + name.Trim('.') + "." + name.Trim('.') + "Plugin");
404  //AnimatedGifsPlugin
405  if (!hasDot && name.EndsWith("Plugin"))
406  alternateNames.Add("ImageResizer.Plugins." + name.Substring(0, name.Length - 6).Trim('.') + "." + name.Trim('.'));
407  //Apr4-2012 - Deleted, never used: //Basic.DefaultEncoder
408  //Apr4-2012 - Deleted, never used: alternateNames.Add("ImageResizer.Plugins." + name.TrimStart('.'));
409  //For the deprecated convention of naming the plugin namespace and class the same.
410  if (!hasDot) alternateNames.Add("ImageResizer.Plugins." + name.Trim('.') + "." + name.Trim('.'));
411  //Apr4-2012 - Deleted, never used: //Plugins.Basic.DefaultEncoder
412  //Apr4-2012 - Deleted, never used: alternateNames.Add("ImageResizer." + name.TrimStart('.'));
413  //PluginWithNoNamespace
414  if (!hasDot) alternateNames.Add(name);
415 
416  //Get a list of assemblies, sorted by likelyhood of a match
417  List<string> assemblies = GetOptimizedAssemblyList(assembly,name);
418  //Now multiply
419  List<string> qualifiedNames = new List<string>(assemblies.Count * alternateNames.Count);
420 
421  //For each assembly, try each namespace-qualified class name.
422  foreach (string assemblyName in assemblies) {
423  foreach (string className in alternateNames)
424  qualifiedNames.Add(className + assemblyName);
425  }
426 
427  try {
428  //Now, try them all.
429  foreach (string s in qualifiedNames) {
430  Debug.WriteLine("Trying " + s);
431  t = Type.GetType(s, false, true);
432  if (t != null) {
433  Debug.WriteLine("Success!");
434  return t;
435  }
436  }
437  } catch (System.Security.SecurityException sx) {
438  this.AcceptIssue(new Issue("Failed to load plugin \"" + searchName + "\" due to ASP.NET trust configuration. ",
439  "You may need to increase the trust level for this plugin to load properly. Error details: \n" +
440  sx.Message + "\n" + sx.StackTrace, IssueSeverity.Error));
441  return null;
442  }
443 
444  //Ok, time to log problem.
445  if (t == null) {
446  StringBuilder attempts = new StringBuilder();
447  foreach (string s in qualifiedNames)
448  attempts.Append(", \"" + s + "\"");
449  this.AcceptIssue(new Issue("Failed to load plugin by name \"" + searchName + "\"",
450  "Verify the plugin DLL is located in /bin, and that the name is spelled correctly. \n" +
451  "Attempted using \"" + searchName + "\"" + attempts.ToString() + ".", IssueSeverity.ConfigurationError));
452  }
453  return t;
454  }
List< string > GetOptimizedAssemblyList(string assemblyName, string pluginName)
This is called to get a sorted list of plugins based on their likelyhood of having the plugin...
void ImageResizer.Configuration.PluginConfig.ForceLoadPlugins ( )
inline

Forces loading of the plugins specified in configuration, even if they have already been loaded. Will add duplicate plugins and throw exceptions if you do not call RemoveAll() first.

Definition at line 66 of file PluginConfig.cs.

67  {
68  lock (_loadPluginsSync)
69  {
71  _pluginsLoaded = true;
72  }
73  }
void loadPluginsInternal()
Not thread safe. Performs actual work.
Definition: PluginConfig.cs:86
T ImageResizer.Configuration.PluginConfig.Get< T > ( )
inline

Returns the first registerd instance of the specified plugin. For IMultiInstancePlugins, use GetAll()

Template Parameters
T
Returns

Definition at line 156 of file PluginConfig.cs.

156  {
157  Type t = typeof(T);
158  foreach (IPlugin p in AllPlugins)
159  if (t.IsAssignableFrom(p.GetType())) //Like instance of. Can be a subclass
160  return (T)p;
161  return default(T);
162  }
SafeList< IPlugin > AllPlugins
All plugins should be registered here. Used for diagnostic purposes.
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
IList<T> ImageResizer.Configuration.PluginConfig.GetAll< T > ( )
inline

Returns all registered instances of the specified plugins

Template Parameters
T
Returns

Definition at line 120 of file PluginConfig.cs.

120  {
121  List<T> results = new List<T>();
122  Type t = typeof(T);
123  foreach (IPlugin p in AllPlugins)
124  if (t.IsAssignableFrom(p.GetType())) //Like instance of. Can be a subclass
125  results.Add((T)p);
126  return results;
127  }
SafeList< IPlugin > AllPlugins
All plugins should be registered here. Used for diagnostic purposes.
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
IEncoder ImageResizer.Configuration.PluginConfig.GetEncoder ( ResizeSettings  settings,
object  original 
)
inline

Returns an instance of the first encoder that claims to be able to handle the specified settings. Returns null if no encoders are available.

Parameters
settingsRequest settings, like format, quality, colors, dither, etc.
originalMay be a Drawing.Image instance, a path, or null. To provide both, set Image.tag to the path. Helps the encoder detect the original format if the format was not specified. May also be used for palette generation hinting by some encoders.
Returns

Implements ImageResizer.Encoding.IEncoderProvider.

Definition at line 295 of file PluginConfig.cs.

295  {
296 
297  foreach (IEncoder e in this.ImageEncoders) {
298  IEncoder result = e.CreateIfSuitable(settings, original);
299  if (result != null) return result;
300  }
301  return null;
302  }
SafeList< IEncoder > ImageEncoders
Currently registered IEncoders.
An image encoder. Exposes methods for suitability checking, encoding, transparency compatibility chec...
Definition: IEncoder.cs:13
override IEnumerable<IIssue> ImageResizer.Configuration.PluginConfig.GetIssues ( )
inlinevirtual

Returns a copy of the list of reported issues.

Returns

Reimplemented from ImageResizer.Configuration.Issues.IssueSink.

Definition at line 590 of file PluginConfig.cs.

590  {
591  List<IIssue> issues = new List<IIssue>(base.GetIssues());
592  //Verify all plugins are registered as IPlugins also.
593 
594 
595  //Verify there is something other than NoCache registered
596  if (c.Plugins.CachingSystems.First is ImageResizer.Plugins.Basic.NoCache)
597  issues.Add(new Issue("NoCache is only for development usage, and cannot scale to production use.", "Add DiskCache or CloudFront for production use", IssueSeverity.Warning));
598 
599  //Verify NoCache is registered
600  if (!c.Plugins.Has<ImageResizer.Plugins.Basic.NoCache>())
601  issues.Add(new Issue("NoCache should not be removed from the plugins collection.",
602  "Simply add the new ICache plugin later for it to take precedence. NoCache is still required as a fallback by most caching plugins.",
603  IssueSeverity.Error));
604 
605 
606  if (c.Plugins.ImageEncoders.First == null)
607  issues.Add(new Issue("No encoders are registered! Without an image encoder, the pipeline cannot function.", IssueSeverity.Error));
608 
609  issues.AddRange(ndeps.GetIssues());
610 
611  return issues;
612  }
SafeList< IEncoder > ImageEncoders
Currently registered IEncoders.
SafeList< ICache > CachingSystems
Currently registered ICache instances
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
List<string> ImageResizer.Configuration.PluginConfig.GetOptimizedAssemblyList ( string  assemblyName,
string  pluginName 
)
inlineprotected

This is called to get a sorted list of plugins based on their likelyhood of having the plugin.

Parameters
assemblyName
pluginName
Returns

Definition at line 346 of file PluginConfig.cs.

346  {
347  List<string> assemblies = new List<string>();
348  //1) If an assembly was specified, search it first
349  if (assemblyName != null) assemblies.Add(assemblyName);
350  //2) Follow by searching the Core, the currently executing assembly
351  assemblies.Add(""); // Defaults to current assembly
352  //3) Add ImageResizer.Plugins.X if it has no dot.
353  if (!pluginName.Contains(".")) assemblies.Add("ImageResizer.Plugins." + pluginName);
354 
355  //4) Next, add all assemblies that have "ImageResizer" in their name
356 
357 
358  List<string> otherAssemblies = new List<string>();
359  //Add ImageResizer-related assemblies first
360  foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {// AppDomain.CurrentDomain.GetAssemblies()
361  string aname = a.FullName;
362  if (aname.IndexOf("ImageResizer", StringComparison.OrdinalIgnoreCase) > -1) assemblies.Add(", " + aname);
363  else
364  otherAssemblies.Add(", " + aname);
365  }
366  //5) Last, add all remaining assemblies
367  assemblies.AddRange(otherAssemblies);
368  return assemblies;
369  }
T ImageResizer.Configuration.PluginConfig.GetOrInstall< T > ( )
inline

Returns the first registered instance of the specified plugin, or creates a new instance if the plugin isn't installed.

Template Parameters
T
Returns
Type Constraints
T :IPlugin 
T :new() 

Definition at line 169 of file PluginConfig.cs.

169  : IPlugin, new() {
170  T instance = Get<T>();
171  if (instance != null) return instance;
172 
173  new T().Install(this.c);
174 
175  return Get<T>();
176  }
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
T Get< T >()
Returns the first registerd instance of the specified plugin. For IMultiInstancePlugins, use GetAll()
T ImageResizer.Configuration.PluginConfig.GetOrInstall< T > ( newInstance)
inline

Returns the first registered instance of the specified plugin, or installs the given instance instead, then re-tries the query

Template Parameters
T
Parameters
newInstance
Returns
Type Constraints
T :IPlugin 

Definition at line 184 of file PluginConfig.cs.

184  : IPlugin {
185  T instance = Get<T>();
186  if (instance != null) return instance;
187 
188  //Our instance may not get installed if there is a duplicate already
189  newInstance.Install(this.c);
190 
191  return Get<T>();
192  }
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
T Get< T >()
Returns the first registerd instance of the specified plugin. For IMultiInstancePlugins, use GetAll()
IList<IPlugin> ImageResizer.Configuration.PluginConfig.GetPlugins ( Type  type)
inline

Returns the subset of installed plugins which implement the specified type or interface

Parameters
type
Returns

Definition at line 108 of file PluginConfig.cs.

108  {
109  List<IPlugin> results = new List<IPlugin>();
110  foreach (IPlugin p in AllPlugins)
111  if (type.IsAssignableFrom(p.GetType())) //Like instance of. Can be a subclass
112  results.Add(p);
113  return results;
114  }
SafeList< IPlugin > AllPlugins
All plugins should be registered here. Used for diagnostic purposes.
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
bool ImageResizer.Configuration.PluginConfig.Has< T > ( )
inline

Returns true if 1 or more instances of the type are registered.

Template Parameters
T
Returns

Definition at line 146 of file PluginConfig.cs.

146  {
147  return Comparer<T>.Default.Compare(Get<T>(), default(T)) != 0;
148  }
T Get< T >()
Returns the first registerd instance of the specified plugin. For IMultiInstancePlugins, use GetAll()
bool ImageResizer.Configuration.PluginConfig.HasPlugin ( Type  type)
inline

Returns true if at least one plugin of the specified type is registered.

Parameters
type
Returns

Definition at line 134 of file PluginConfig.cs.

134  {
135  foreach (IPlugin p in AllPlugins)
136  if (type.IsAssignableFrom(p.GetType())) //Like instance of. Can be a subclass
137  return true;
138  return false;
139  }
SafeList< IPlugin > AllPlugins
All plugins should be registered here. Used for diagnostic purposes.
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
IPlugin ImageResizer.Configuration.PluginConfig.Install ( IPlugin  plugin)
inline

Installs the specified plugin, returning the plugin instance. Convenience method, same as plugin.Install(Config.Current).

Parameters
plugin
Returns

Definition at line 201 of file PluginConfig.cs.

201  {
202  return plugin.Install(this.c);
203  }
void ImageResizer.Configuration.PluginConfig.LoadPlugins ( )
inline

Processes the <plugins> section if they are not already loaded. Thread safe. Only executes once.

Definition at line 56 of file PluginConfig.cs.

56  {
57  lock (_loadPluginsSync) {
58  if (_pluginsLoaded) return;
60  _pluginsLoaded = true;
61  }
62  }
void loadPluginsInternal()
Not thread safe. Performs actual work.
Definition: PluginConfig.cs:86
void ImageResizer.Configuration.PluginConfig.loadPluginsInternal ( )
inlineprotected

Not thread safe. Performs actual work.

Definition at line 86 of file PluginConfig.cs.

86  {
87  Node plugins = c.getNode("plugins");
88  if (plugins == null) return;
89  foreach (Node n in plugins.Children) {
90  if (n.Name.Equals("add", StringComparison.OrdinalIgnoreCase)) {
91  add_plugin_by_name(n["name"],(n.Attrs.Count > 1) ? n.Attrs : null);
92 
93  } else if (n.Name.Equals("remove", StringComparison.OrdinalIgnoreCase))
94  remove_plugins_by_name(n["name"]);
95  else if (n.Name.Equals("clear", StringComparison.OrdinalIgnoreCase))
96  clear_plugins_by_type(n["type"]);
97  else {
98  this.AcceptIssue(new Issue("Plugins", "Unexpected element <" + n.Name + "> in <plugins></plugins>.",
99  "Element XML: " + n.ToXmlElement().OuterXml, IssueSeverity.Warning));
100  }
101  }
102  }
No support for namespaces, no intention of eventual serialization. Everything is case-insensitive, but preserves case. Not thread safe.
Definition: Node.cs:15
NameValueCollection Attrs
Attributes
Definition: Node.cs:56
List< Node > Children
Child nodes
Definition: Node.cs:93
string Name
The name of the element.
Definition: Node.cs:84
void ImageResizer.Configuration.PluginConfig.remove_plugin ( object  plugin)
inline

For use only by plugins during .Uninstall. Removes the specified plugin from AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuiderExtensions, based on which interfaces the instance implements. Plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method.

Parameters
plugin

Definition at line 521 of file PluginConfig.cs.

521  {
522  if (plugin is IPlugin) AllPlugins.Remove(plugin as IPlugin);
523  if (plugin is IQuerystringPlugin) QuerystringPlugins.Remove(plugin as IQuerystringPlugin);
524  if (plugin is IFileExtensionPlugin) FileExtensionPlugins.Remove(plugin as IFileExtensionPlugin);
525  if (plugin is ICache) CachingSystems.Remove(plugin as ICache);
526  if (plugin is IEncoder) ImageEncoders.Remove(plugin as IEncoder);
527  if (plugin is BuilderExtension) ImageBuilderExtensions.Remove(plugin as BuilderExtension);
528  if (plugin is IVirtualImageProvider) VirtualProviderPlugins.Remove(plugin as IVirtualImageProvider);
529  if (plugin is ISettingsModifier) SettingsModifierPlugins.Remove(plugin as ISettingsModifier);
530  if (plugin is ICurrentConfigProvider) ConfigProviders.Remove(plugin as ICurrentConfigProvider);
531  if (plugin is ILogManager && LogManager == plugin) LogManager = null;
532  }
Provides caching behavior
Definition: ICache.cs:12
Implement this to allow your class (or VirtualPathProvider subclass) to be used without registering i...
Provides a way to modify settings before they reach the managed API. Does not execute early enough to...
For plugins that access the query string (important!)
ILogManager LogManager
Returns the most recently registered Logging plugin, or null.
For plugins that add support for new source file image extensions.
Provides a useable base class that can be used to modify the behavior of ImageBuilder. When registered with an ImageBuilder instance, the ImageBuilder will call the corresponding methods on the extension prior to executing its own methods.
Allows multi-tenancy support. The &#39;root&#39; config only needs one plugin, which implements this interfac...
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
An image encoder. Exposes methods for suitability checking, encoding, transparency compatibility chec...
Definition: IEncoder.cs:13
void ImageResizer.Configuration.PluginConfig.RemoveAll ( )
inline

Removes all plugins, of every kind. Logs any errors encountered. (Not all plugins support uninstallation)

Definition at line 567 of file PluginConfig.cs.

567  {
568  //Follow uninstall protocol
569  foreach (IPlugin p in AllPlugins)
570  if (!p.Uninstall(c))
571  this.AcceptIssue(new Issue("Uninstall of " + p.ToString() + " reported failure.", IssueSeverity.Error));
572 
573  IList[] collections = new IList[]{AllPlugins.GetCollection(),QuerystringPlugins.GetCollection(),FileExtensionPlugins.GetCollection()
574  ,CachingSystems.GetCollection(),ImageEncoders.GetCollection(),ImageBuilderExtensions.GetCollection()};
575  //Then check all collections, logging an issue if they aren't empty.
576  foreach(IList coll in collections){
577  if (coll.Count > 0){
578  string items = "";
579  foreach(object item in coll)
580  items += item.ToString() + ", ";
581 
582  this.AcceptIssue(new Issue("Collection " + coll.ToString() + " was not empty after RemoveAllPlugins() executed!",
583  "Remaining items: " + items, IssueSeverity.Error));
584  }
585  }
586  }
virtual void AcceptIssue(IIssue i)
Adds the specified issue to the list unless it is an exact duplicate of another instance.
Definition: IssueSink.cs:30
SafeList< ICache > CachingSystems
Currently registered ICache instances
bool Uninstall(Config c)
Uninstalls the plugin. Should reverse all changes made during Install
SafeList< IPlugin > AllPlugins
All plugins should be registered here. Used for diagnostic purposes.
SafeList< BuilderExtension > ImageBuilderExtensions
Currently registered set of ImageBuilderExtensions.
All plugins must implement this. Enables web.config addition and removal.
Definition: IPlugin.cs:11
SafeList< IQuerystringPlugin > QuerystringPlugins
Plugins which accept querystring arguments are registered here.
bool ImageResizer.Configuration.PluginConfig.Uninstall ( IPlugin  plugin)
inline

Attempts uninstallation of the specified plugin, returning true if successful. Convenience method, same as plugin.Uninstall(Config.Current).

Parameters
plugin
Returns

Definition at line 211 of file PluginConfig.cs.

211  {
212  return plugin.Uninstall(this.c);
213  }

Property Documentation

SafeList<IPlugin> ImageResizer.Configuration.PluginConfig.AllPlugins
get

All plugins should be registered here. Used for diagnostic purposes.

Definition at line 272 of file PluginConfig.cs.

SafeList<ICache> ImageResizer.Configuration.PluginConfig.CachingSystems
get

Currently registered ICache instances

Definition at line 239 of file PluginConfig.cs.

Referenced by ImageResizer.Configuration.PipelineConfig.GetCachingSystem().

SafeList<ICurrentConfigProvider> ImageResizer.Configuration.PluginConfig.ConfigProviders
get

Currently registered ICurrentConfigProviders.

Definition at line 220 of file PluginConfig.cs.

SafeList<IFileExtensionPlugin> ImageResizer.Configuration.PluginConfig.FileExtensionPlugins
get

Plugins which accept new file extensions (in the url) are registered here.

Definition at line 252 of file PluginConfig.cs.

Referenced by ImageResizer.Configuration.PipelineConfig._cacheUrlData().

SafeList<BuilderExtension> ImageResizer.Configuration.PluginConfig.ImageBuilderExtensions
get

Currently registered set of ImageBuilderExtensions.

Definition at line 227 of file PluginConfig.cs.

SafeList<IEncoder> ImageResizer.Configuration.PluginConfig.ImageEncoders
get

Currently registered IEncoders.

Definition at line 233 of file PluginConfig.cs.

ILogManager ImageResizer.Configuration.PluginConfig.LogManager
getset

Returns the most recently registered Logging plugin, or null.

Definition at line 281 of file PluginConfig.cs.

Referenced by ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Install(), and ImageResizer.Plugins.DiskCache.DiskCache.Install().

bool ImageResizer.Configuration.PluginConfig.PluginsLoaded
get

Returns true if the <plugins> section has been processed

Definition at line 77 of file PluginConfig.cs.

SafeList<IQuerystringPlugin> ImageResizer.Configuration.PluginConfig.QuerystringPlugins
get

Plugins which accept querystring arguments are registered here.

Definition at line 245 of file PluginConfig.cs.

Referenced by ImageResizer.Configuration.PipelineConfig._cacheUrlData().

SafeList<ISettingsModifier> ImageResizer.Configuration.PluginConfig.SettingsModifierPlugins
get

Plugins which modify image processing settings.

Definition at line 265 of file PluginConfig.cs.

Referenced by ImageResizer.Configuration.PipelineConfig.Modify().

SafeList<IVirtualImageProvider> ImageResizer.Configuration.PluginConfig.VirtualProviderPlugins
get

Plugins which provide virtual files are registered here.

Definition at line 259 of file PluginConfig.cs.

Referenced by ImageResizer.Configuration.PipelineConfig.FileExists(), and ImageResizer.Configuration.PipelineConfig.GetFile().


The documentation for this class was generated from the following file: