ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
ImageResizer.Configuration.PipelineConfig Class Reference
Inheritance diagram for ImageResizer.Configuration.PipelineConfig:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Configuration.PipelineConfig:
Collaboration graph
[legend]

Public Member Functions

 PipelineConfig (Config c)
 
bool IsAcceptedImageType (string path)
 The specified path must not include a querystring. Slashes, spaces, question marks, ampersands, and colons are not permitted in the extension. If it contains a multipart extension like .txt.zip, only "zip" will be recognized. Must contain a dot - passing in "jpg" will fail. More...
 
bool HasPipelineDirective (System.Collections.Specialized.NameValueCollection q)
 Returns true if any of the querystring keys match any of the directives supported by the pipeline (such as width, height, format, bgcolor, etc) More...
 
string TrimFakeExtensions (string path)
 Removes the first fake extensionm detected at the end of 'path' More...
 
IVirtualFile GetFile (string virtualPath, NameValueCollection queryString)
 Returns either an IVirtualFile instance or a VirtualFile instance. More...
 
bool FileExists (string virtualPath, NameValueCollection queryString)
 Returns true if (a) A registered IVirtualImageProvider says it exists, or (b) if the VirtualPathProvider chain says it exists. More...
 
ImageBuilder GetImageBuilder ()
 Returns an ImageBuilder instance to use for image processing. More...
 
ICacheProvider GetCacheProvider ()
 Returns a ICacheProvider instance that provides caching system selection and creation. More...
 
void FirePostAuthorizeRequest (System.Web.IHttpModule sender, System.Web.HttpContext httpContext)
 
void FireRewritingEvents (System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 
void FireAuthorizeImage (System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlAuthorizationEventArgs e)
 
void FireImageMissing (System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 
void FirePreHandleImage (System.Web.IHttpModule sender, System.Web.HttpContext context, IResponseArgs e)
 
ICache GetCachingSystem (System.Web.HttpContext context, IResponseArgs args)
 Cache selection occurs as follows: (1) The first registered CachingSystem that returns true from .CanProcess() is the default (2) The SelectCachingSystem event is fired, allowing handlers to modify the selected cache. This method may return null. More...
 
ResizeSettings Modify (ResizeSettings settings)
 Implementations should support being called on their own result multiple times without behavioral differences. Currently only executed in the managed API, too late to affect the disk cache, but that will probably change (it's likely all ISettingsModifiers will get executed twice, once after PostRewrite and once before the managed API executes). More...
 
- Public Member Functions inherited from ImageResizer.Configuration.IPipelineConfig
bool HasPipelineDirective (NameValueCollection q)
 True if the querystring contains any directives that are understood by the pipeline More...
 
void FirePostAuthorizeRequest (IHttpModule sender, System.Web.HttpContext httpContext)
 
void FireRewritingEvents (IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs ue)
 
void FireAuthorizeImage (IHttpModule sender, System.Web.HttpContext context, IUrlAuthorizationEventArgs urlEventArgs)
 
void FirePreHandleImage (IHttpModule sender, System.Web.HttpContext context, IResponseArgs e)
 
void FireImageMissing (IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs urlEventArgs)
 

Protected Member Functions

void urlModifyingPlugins_Changed (SafeList< IQuerystringPlugin > sender)
 
void _cacheUrlData ()
 Populates the cache if it is empty. Not thread safe. More...
 
Dictionary< string, bool > getCachedDirectives ()
 
Dictionary< string, bool > getCachedExtensions ()
 
string getExtension (string path)
 

Protected Attributes

Config c
 
object _cachedUrlDataSync = new object()
 
volatile Dictionary< string, bool > _cachedDirectives = null
 
volatile Dictionary< string, bool > _cachedExtensions = null
 
volatile IList< string > _fakeExtensions = null
 
volatile bool firedFirstRequest = false
 
volatile bool firstRequestFinished = false
 
object firedFirstRequestSync = new object()
 
long processedCount = 0
 

Properties

ICollection< string > AcceptedImageExtensions [get]
 Returns a unqiue copy of the image extensions supported by the pipeline. Performs a cached query to all registered IQuerystringPlugin instances. Use IsAcceptedImageType for better performance. More...
 
ICollection< string > SupportedQuerystringKeys [get]
 Returns a unqiue copy of all querystring keys supported by the pipeline. Performs a cached query to all registered IQuerystringPlugin instances. Use HasPipelineDirective for better performance. (binary search) More...
 
IList< string > FakeExtensions [get]
 Cached access to pipeline.fakeExtensions More...
 
string ModifiedPathKey [get]
 
string StopRoutingKey [get]
 
string PreRewritePath [get, set]
 Returns the value of Context.Items["resizer.newPath"] if present. If not, returns FilePath + PathInfo. Sets Context.Items["resizer.newPath"]. Only useful during the Pipeline.PostAuthorizeRequestStart event. More...
 
string ModifiedQueryStringKey [get]
 
NameValueCollection ModifiedQueryString [get, set]
 Returns the modified query string. If never set, returns a copy of Request.QueryString. Returns the same instance if called multiple times. Copy it if you want to make changes without causing issues. More...
 
string SkipFileTypeCheckKey [get]
 
bool SkipFileTypeCheck [get, set]
 Get or sets whether the file extension check should be applied to the current request. Defaults to true. If set to true, will only affect the current request, and will only cause the Resizer to evaluate the rewriting rules on the request. Processing may still not occur if no querystring values are specified. Add 'cache=always' to force caching to occur. More...
 
string ResponseArgsKey [get]
 
bool IsHandlingRequest [get]
 Returns true if the current request is being processed and/or cached by the pipeline. Will return false until after the FileExists method is called on the VirtualPathProviders, which is after the AuthorizeImage event fires. This will return a usable value if used from VirtualFile.Open(), or if used inside the PreHandleImage event or later. More...
 
VppUsageOption VppUsage [get]
 
long ProcessedCount [get]
 The number of images processed by this pipeline. More...
 
bool ModuleInstalled [get, set]
 True once the InterceptModule has been installed and is intercepting requests. More...
 
- Properties inherited from ImageResizer.Configuration.IPipelineConfig
string ModifiedQueryStringKey [get]
 The key in Context.Items to store the modified querystring (i.e, post-rewrite). Allows VirtualPathProviders to access the rewritten data. More...
 
string ResponseArgsKey [get]
 The key in Context.Items to store the IResponseArgs object More...
 
string StopRoutingKey [get]
 The key in Context.Items to set if we want to cancel MVC routing for the request More...
 
string ModifiedPathKey [get]
 The key in Context.Items to access a the path to use instead of Request.path More...
 
VppUsageOption VppUsage [get]
 The behavior to use when accessing the file system. More...
 
string SkipFileTypeCheckKey [get]
 
bool SkipFileTypeCheck [get]
 Get or sets whether the file extension check should be applied to the current request. Defaults to true. If set to true, will only affect the current request, and will only cause the Resizer to evaluate the rewriting rules on the request. Processing may still not occur if no querystring values are specified. Add 'cache=always' to force caching to occur. More...
 
bool ModuleInstalled [get, set]
 True once the InterceptModule has been installed. More...
 
string PreRewritePath [get]
 Returns the value of Context.Items["resizer.newPath"] if present. If not, returns FilePath + PathInfo. Sets Context.Items["resizer.newPath"]. Only useful during the Pipeline.PostAuthorizeRequestStart event. More...
 
NameValueCollection ModifiedQueryString [get, set]
 

Events

RequestEventHandler OnFirstRequest
 Fired once, on the first PostAuthorizeRequest event. More...
 
RequestEventHandler PostAuthorizeRequestStart
 Fires during the PostAuthorizeRequest phase, prior to any module-specific logic. Executes for every request to the website. Use only as a last resort. Other events occur only for image requests, and thus have lower overhead. More...
 
UrlRewritingEventHandler Rewrite
 Fired during PostAuthorizeRequest, after ResizeExtension has been removed. On fired on requests with extensions that match supported image types. More...
 
UrlRewritingEventHandler RewriteDefaults
 Fired during PostAuthorizeRequest, after Rewrite. Any changes made here (which conflict) will be overwritten by the the current querystring values. I.e, this is a good place to specify default settings. More...
 
UrlRewritingEventHandler PostRewrite
 Fired after all other rewrite events. More...
 
UrlAuthorizationEventHandler AuthorizeImage
 Fired after all rewriting is finished. e.AllowAccess defaults to the result of the UrlAuthorization module's verdict. It can be changed. Set e.AllowAccess to true to cause and 403 Access Dened result. More...
 
UrlEventHandler ImageMissing
 Fired when the specified image doesn't exist. Only called for images that would normally be processed. May be called during PostAuthorizeRequest or later - End the request completely with a redirect if you want alternate behavior. More...
 
PreHandleImageEventHandler PreHandleImage
 Fired immediately before the image request is sent off to the caching system for proccessing. Allows modification of response headers, caching arguments, and callbacks. More...
 
CacheSelectionHandler SelectCachingSystem
 

Detailed Description

Definition at line 19 of file PipelineConfig.cs.

Member Function Documentation

void ImageResizer.Configuration.PipelineConfig._cacheUrlData ( )
inlineprotected

Populates the cache if it is empty. Not thread safe.

Definition at line 47 of file PipelineConfig.cs.

47  {
48  if (_cachedDirectives != null && _cachedExtensions != null) return;
49 
50  Dictionary<string, bool> directives = new Dictionary<string, bool>(48,StringComparer.OrdinalIgnoreCase);
51  Dictionary<string, bool> exts = new Dictionary<string, bool>(24,StringComparer.OrdinalIgnoreCase);
52  IEnumerable<string> vals = null;
53  //Check the plugins
55 
56  vals = p.GetSupportedQuerystringKeys();
57  if (vals != null)
58  foreach (string s in vals)
59  directives[s] = true;
60  }
62  vals = p.GetSupportedFileExtensions();
63  if (vals != null)
64  foreach (string e in vals)
65  exts[e.TrimStart('.')] = true;
66  }
67 
68 
69  //Now check the imagebuider instance
70  ImageBuilder b = c.CurrentImageBuilder;
71  if (b != null) {
72  vals = b.GetSupportedFileExtensions();
73  if (vals != null)
74  foreach (string e in vals)
75  exts[e.TrimStart('.')] = true;
76 
77  vals = b.GetSupportedQuerystringKeys();
78  if (vals != null)
79  foreach (string s in vals)
80  directives[s] = true;
81  }
82 
83  _cachedDirectives = directives;
84  _cachedExtensions = exts;
85 
86  }
SafeList< IFileExtensionPlugin > FileExtensionPlugins
Plugins which accept new file extensions (in the url) are registered here.
For plugins that access the query string (important!)
For plugins that add support for new source file image extensions.
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
SafeList< IQuerystringPlugin > QuerystringPlugins
Plugins which accept querystring arguments are registered here.
bool ImageResizer.Configuration.PipelineConfig.FileExists ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns true if (a) A registered IVirtualImageProvider says it exists, or (b) if the VirtualPathProvider chain says it exists.

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 298 of file PipelineConfig.cs.

298  {
300  if (p.FileExists(virtualPath, queryString)) return true;
301  }
302  return HostingEnvironment.VirtualPathProvider != null ? HostingEnvironment.VirtualPathProvider.FileExists(virtualPath) : false;
303  }
Implement this to allow your class (or VirtualPathProvider subclass) to be used without registering i...
bool FileExists(string virtualPath, NameValueCollection queryString)
Returns true if the specified file exists.
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
SafeList< IVirtualImageProvider > VirtualProviderPlugins
Plugins which provide virtual files are registered here.
ICacheProvider ImageResizer.Configuration.PipelineConfig.GetCacheProvider ( )
inline

Returns a ICacheProvider instance that provides caching system selection and creation.

Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 310 of file PipelineConfig.cs.

310  {
311  return this;
312  }
ICache ImageResizer.Configuration.PipelineConfig.GetCachingSystem ( System.Web.HttpContext  context,
IResponseArgs  args 
)
inline

Cache selection occurs as follows: (1) The first registered CachingSystem that returns true from .CanProcess() is the default (2) The SelectCachingSystem event is fired, allowing handlers to modify the selected cache. This method may return null.

Parameters
context
args
Returns

Implements ImageResizer.Caching.ICacheProvider.

Definition at line 444 of file PipelineConfig.cs.

444  {
445  ICache defaultCache = null;
446  //Grab the first cache that claims it can process the request.
447  foreach (ICache cache in c.Plugins.CachingSystems) {
448  if (cache.CanProcess(context, args)) {
449  defaultCache = cache;
450  break;
451  }
452  }
453 
454  CacheSelectionEventArgs e = new CacheSelectionEventArgs(context, args, defaultCache);
455  if (SelectCachingSystem != null) SelectCachingSystem(this, e);
456  return e.SelectedCache;
457  }
Provides caching behavior
Definition: ICache.cs:12
SafeList< ICache > CachingSystems
Currently registered ICache instances
bool CanProcess(HttpContext current, IResponseArgs e)
Returns false if the cache is unable to process the request. If false, the caller should fall back to...
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
IVirtualFile ImageResizer.Configuration.PipelineConfig.GetFile ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns either an IVirtualFile instance or a VirtualFile instance.

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 270 of file PipelineConfig.cs.

270  {
271  IVirtualFile f = null;
273  if (p.FileExists(virtualPath, queryString)) { f = p.GetFile(virtualPath, queryString); break; }
274  }
275  if (f == null && HostingEnvironment.VirtualPathProvider != null && HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
276  {
277  var vf = HostingEnvironment.VirtualPathProvider.GetFile(virtualPath);
278  if (vf is IVirtualFile) f = (IVirtualFile)vf;
279  else f = new VirtualFileWrapper(vf);
280  }
281  if (f == null) return null;
282 
283  //Now we have a reference to the real virtual file, let's see if it is source-cached.
284  IVirtualFile cached = null;
285  foreach (IVirtualFileCache p in c.Plugins.GetAll<IVirtualFileCache>()) {
286  cached = p.GetFileIfCached(virtualPath,queryString,f);
287  if (cached != null) return cached;
288  }
289  return f;
290  }
Implement this if you are caching files provided by a virtual image provider (For example...
A virtual file to support IVirtualImageProvider
Definition: IVirtualFile.cs:10
Implement this to allow your class (or VirtualPathProvider subclass) to be used without registering i...
Wraps a standard ASP.NET VirtualFile instance in an IVirtualFile-compatible wrapper.
bool FileExists(string virtualPath, NameValueCollection queryString)
Returns true if the specified file exists.
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
SafeList< IVirtualImageProvider > VirtualProviderPlugins
Plugins which provide virtual files are registered here.
ImageBuilder ImageResizer.Configuration.PipelineConfig.GetImageBuilder ( )
inline

Returns an ImageBuilder instance to use for image processing.

Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 306 of file PipelineConfig.cs.

306  {
307  return c.CurrentImageBuilder;
308  }
bool ImageResizer.Configuration.PipelineConfig.HasPipelineDirective ( System.Collections.Specialized.NameValueCollection  q)
inline

Returns true if any of the querystring keys match any of the directives supported by the pipeline (such as width, height, format, bgcolor, etc)

Parameters
q
Returns

Definition at line 141 of file PipelineConfig.cs.

141  {
142  //Did you know that ASP.NET puts null keys into the QueryString?
143  Dictionary<string, bool> dirs = getCachedDirectives();
144  //The querystring always has fewer items than the cachedDirectives, so loop it instead.
145  foreach (string key in q.Keys) {
146  if (key != null && dirs.ContainsKey(key)) return true; //Binary search, hashtable impl
147  }
148  return false;
149  }
bool ImageResizer.Configuration.PipelineConfig.IsAcceptedImageType ( string  path)
inline

The specified path must not include a querystring. Slashes, spaces, question marks, ampersands, and colons are not permitted in the extension. If it contains a multipart extension like .txt.zip, only "zip" will be recognized. Must contain a dot - passing in "jpg" will fail.

Parameters
path
Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 131 of file PipelineConfig.cs.

131  {
132  string ext = getExtension(path);
133  if (string.IsNullOrEmpty(ext)) return false;
134  return getCachedExtensions().ContainsKey(ext);
135  }
ResizeSettings ImageResizer.Configuration.PipelineConfig.Modify ( ResizeSettings  settings)
inline

Implementations should support being called on their own result multiple times without behavioral differences. Currently only executed in the managed API, too late to affect the disk cache, but that will probably change (it's likely all ISettingsModifiers will get executed twice, once after PostRewrite and once before the managed API executes).

Parameters
settings
Returns

Implements ImageResizer.Plugins.ISettingsModifier.

Definition at line 463 of file PipelineConfig.cs.

463  {
465  settings = m.Modify(settings);
466  return settings;
467  }
Provides a way to modify settings before they reach the managed API. Does not execute early enough to...
SafeList< ISettingsModifier > SettingsModifierPlugins
Plugins which modify image processing settings.
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
string ImageResizer.Configuration.PipelineConfig.TrimFakeExtensions ( string  path)
inline

Removes the first fake extensionm detected at the end of 'path'

Parameters
path
Returns

Implements ImageResizer.Configuration.IPipelineConfig.

Definition at line 174 of file PipelineConfig.cs.

174  {
175  foreach (string s in FakeExtensions) {
176  if (path.EndsWith(s, StringComparison.OrdinalIgnoreCase)) {
177  path = path.Substring(0, path.Length - s.Length).TrimEnd('.');
178  break;
179  }
180  }
181  return path;
182  }
IList< string > FakeExtensions
Cached access to pipeline.fakeExtensions

Property Documentation

ICollection<string> ImageResizer.Configuration.PipelineConfig.AcceptedImageExtensions
get

Returns a unqiue copy of the image extensions supported by the pipeline. Performs a cached query to all registered IQuerystringPlugin instances. Use IsAcceptedImageType for better performance.

Definition at line 103 of file PipelineConfig.cs.

IList<string> ImageResizer.Configuration.PipelineConfig.FakeExtensions
get

Cached access to pipeline.fakeExtensions

Definition at line 157 of file PipelineConfig.cs.

bool ImageResizer.Configuration.PipelineConfig.IsHandlingRequest
get

Returns true if the current request is being processed and/or cached by the pipeline. Will return false until after the FileExists method is called on the VirtualPathProviders, which is after the AuthorizeImage event fires. This will return a usable value if used from VirtualFile.Open(), or if used inside the PreHandleImage event or later.

Definition at line 253 of file PipelineConfig.cs.

NameValueCollection ImageResizer.Configuration.PipelineConfig.ModifiedQueryString
getset

Returns the modified query string. If never set, returns a copy of Request.QueryString. Returns the same instance if called multiple times. Copy it if you want to make changes without causing issues.

Definition at line 217 of file PipelineConfig.cs.

bool ImageResizer.Configuration.PipelineConfig.ModuleInstalled
getset

True once the InterceptModule has been installed and is intercepting requests.

Definition at line 474 of file PipelineConfig.cs.

string ImageResizer.Configuration.PipelineConfig.PreRewritePath
getset

Returns the value of Context.Items["resizer.newPath"] if present. If not, returns FilePath + PathInfo. Sets Context.Items["resizer.newPath"]. Only useful during the Pipeline.PostAuthorizeRequestStart event.

Definition at line 196 of file PipelineConfig.cs.

long ImageResizer.Configuration.PipelineConfig.ProcessedCount
get

The number of images processed by this pipeline.

Definition at line 425 of file PipelineConfig.cs.

bool ImageResizer.Configuration.PipelineConfig.SkipFileTypeCheck
getset

Get or sets whether the file extension check should be applied to the current request. Defaults to true. If set to true, will only affect the current request, and will only cause the Resizer to evaluate the rewriting rules on the request. Processing may still not occur if no querystring values are specified. Add 'cache=always' to force caching to occur.

Definition at line 237 of file PipelineConfig.cs.

ICollection<string> ImageResizer.Configuration.PipelineConfig.SupportedQuerystringKeys
get

Returns a unqiue copy of all querystring keys supported by the pipeline. Performs a cached query to all registered IQuerystringPlugin instances. Use HasPipelineDirective for better performance. (binary search)

Definition at line 112 of file PipelineConfig.cs.

Event Documentation

UrlAuthorizationEventHandler ImageResizer.Configuration.PipelineConfig.AuthorizeImage

Fired after all rewriting is finished. e.AllowAccess defaults to the result of the UrlAuthorization module's verdict. It can be changed. Set e.AllowAccess to true to cause and 403 Access Dened result.

Definition at line 348 of file PipelineConfig.cs.

UrlEventHandler ImageResizer.Configuration.PipelineConfig.ImageMissing

Fired when the specified image doesn't exist. Only called for images that would normally be processed. May be called during PostAuthorizeRequest or later - End the request completely with a redirect if you want alternate behavior.

Definition at line 355 of file PipelineConfig.cs.

RequestEventHandler ImageResizer.Configuration.PipelineConfig.OnFirstRequest

Fired once, on the first PostAuthorizeRequest event.

Definition at line 317 of file PipelineConfig.cs.

RequestEventHandler ImageResizer.Configuration.PipelineConfig.PostAuthorizeRequestStart

Fires during the PostAuthorizeRequest phase, prior to any module-specific logic. Executes for every request to the website. Use only as a last resort. Other events occur only for image requests, and thus have lower overhead.

Definition at line 322 of file PipelineConfig.cs.

UrlRewritingEventHandler ImageResizer.Configuration.PipelineConfig.PostRewrite

Fired after all other rewrite events.

Only fired on accepted image types. (see Rewrite)

Definition at line 342 of file PipelineConfig.cs.

PreHandleImageEventHandler ImageResizer.Configuration.PipelineConfig.PreHandleImage

Fired immediately before the image request is sent off to the caching system for proccessing. Allows modification of response headers, caching arguments, and callbacks.

Definition at line 361 of file PipelineConfig.cs.

UrlRewritingEventHandler ImageResizer.Configuration.PipelineConfig.Rewrite

Fired during PostAuthorizeRequest, after ResizeExtension has been removed. On fired on requests with extensions that match supported image types.

You can add additonal supported image extentions by registering a plugin that implementes IQuerystringPlugin, or you can add an extra extension in the URL and remove it here. Example: .psd.jpg

Definition at line 331 of file PipelineConfig.cs.

UrlRewritingEventHandler ImageResizer.Configuration.PipelineConfig.RewriteDefaults

Fired during PostAuthorizeRequest, after Rewrite. Any changes made here (which conflict) will be overwritten by the the current querystring values. I.e, this is a good place to specify default settings.

Only fired on accepted image types. (see Rewrite)

Definition at line 337 of file PipelineConfig.cs.


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