ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Classes | Public Member Functions | Protected Member Functions | Properties | List of all members
ImageResizer.Plugins.Basic.VirtualFolder Class Reference

Functions exactly like an IIS virtual folder, but doesn't require IIS configuration. More...

Inheritance diagram for ImageResizer.Plugins.Basic.VirtualFolder:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.Basic.VirtualFolder:
Collaboration graph
[legend]

Classes

class  VirtualFolderProviderVirtualFile
 

Public Member Functions

 VirtualFolder (string virtualPath, string physicalPath)
 
 VirtualFolder (string virtualPath, string physicalPath, bool registerAsVpp)
 
 VirtualFolder (NameValueCollection args)
 
IPlugin Install (Config c)
 Registers the VirtualFolder plugin as a virtual path provider. More...
 
bool Uninstall (Config c)
 Uninstalls the plugin. Should reverse all changes made during Install More...
 
string VirtualToPhysical (string virtualPath)
 
string LocalMapPath (string virtualPath)
 Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outside the folder. More...
 
bool IsVirtualPath (string virtualPath)
 Returns true if the specified path is inside this virtual folder More...
 
DateTime GetDateModifiedUtc (string virtualPath)
 Returns the LastWriteTimeUtc value for the specified virtual file in this folder, or DateTime.MinValue if missing. More...
 
bool FileExists (string virtualPath, NameValueCollection queryString)
 Returns true if the file exists in this virtual folder, and would not be masking an existing file. Returns false if NoIOPermission is true. More...
 
IVirtualFile GetFile (string virtualPath, NameValueCollection queryString)
 Unless the path is not within the virtual folder, or IO permissions are missing, will return an IVirtualFile instance for the path. The file may or may not exist. More...
 
override bool FileExists (string virtualPath)
 For internal use only by the .NET VPP system. More...
 
override VirtualFile GetFile (string virtualPath)
 For internal use only by the .NET VPP system. More...
 
override CacheDependency GetCacheDependency (string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
 For internal use only by the .NET VPP system. More...
 
IEnumerable< IIssueGetIssues ()
 

Protected Member Functions

string normalizeVirtualPath (string path)
 Converts relative and app-relative paths to domain-relative virtual paths. More...
 
string resolvePhysicalPath (string path)
 Attempts to convert a phyiscal path into a collapsed rooted physical path. More...
 
string collapsePath (string path)
 Collapses any .. segments More...
 
string collapseOneLevel (string path)
 
Stream getStream (string virtualPath)
 

Properties

bool FailedToRegisterVpp [get]
 True if the provider attempted to register itself as a VirtualPathProvider and failed due to limited security clearance. False if it did not attempt (say, due to missing IOPermission) , or if it succeeded. More...
 
bool RegisterAsVpp [get, set]
 If true, the plugin will attempt to register itself as an application-wide VirtualPathProvider instead of a image resizer-specific IVirtualImageProvider. More...
 
string VirtualPath [get, set]
 The virtual path served by the VirtualFolder More...
 
string PhysicalPath [get, set]
 The physical path More...
 
bool NoIOPermission [get]
 True if the plugin has detected it doesn't have sufficient IOPermission to operate. More...
 

Detailed Description

Functions exactly like an IIS virtual folder, but doesn't require IIS configuration.

Definition at line 22 of file VirtualFolder.cs.

Member Function Documentation

string ImageResizer.Plugins.Basic.VirtualFolder.collapsePath ( string  path)
inlineprotected

Collapses any .. segments

Parameters
path
Returns

Definition at line 137 of file VirtualFolder.cs.

137  {
138  string oldPath = path;
139  do {
140  oldPath = path;
141  path = collapseOneLevel(oldPath);
142  } while (oldPath != path);
143  return path;
144  }
bool ImageResizer.Plugins.Basic.VirtualFolder.FileExists ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Returns true if the file exists in this virtual folder, and would not be masking an existing file. Returns false if NoIOPermission is true.

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Plugins.IVirtualImageProvider.

Definition at line 230 of file VirtualFolder.cs.

230  {
231  if (NoIOPermission) return false; //Because File.Exists is always false when IOPermission is missing, anyhow.
232  if (!IsVirtualPath(virtualPath)) return false; //It's not even in our area.
233  if (File.Exists(LocalMapPath(virtualPath))){
234  //Ok, we could serve it, but existing files take precedence.
235  //Return false if we would be masking an existing file.
236  return !File.Exists(HostingEnvironment.MapPath(normalizeVirtualPath(virtualPath)));
237  }
238  return false;
239  }
bool IsVirtualPath(string virtualPath)
Returns true if the specified path is inside this virtual folder
string LocalMapPath(string virtualPath)
Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outs...
bool NoIOPermission
True if the plugin has detected it doesn&#39;t have sufficient IOPermission to operate.
string normalizeVirtualPath(string path)
Converts relative and app-relative paths to domain-relative virtual paths.
override bool ImageResizer.Plugins.Basic.VirtualFolder.FileExists ( string  virtualPath)
inline

For internal use only by the .NET VPP system.

Parameters
virtualPath
Returns

Definition at line 258 of file VirtualFolder.cs.

258  {
259  if (isOnlyVirtualPath(virtualPath))
260  return File.Exists(LocalMapPath(virtualPath));
261  else
262  return Previous.FileExists(virtualPath);
263  }
string LocalMapPath(string virtualPath)
Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outs...
override CacheDependency ImageResizer.Plugins.Basic.VirtualFolder.GetCacheDependency ( string  virtualPath,
System.Collections.IEnumerable  virtualPathDependencies,
DateTime  utcStart 
)
inline

For internal use only by the .NET VPP system.

Parameters
virtualPath
virtualPathDependencies
utcStart
Returns

Definition at line 282 of file VirtualFolder.cs.

285  {
286 
287  if (!isOnlyVirtualPath(virtualPath)) return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
288 
289  List<String> deps = new List<string>();
290  foreach (string s in virtualPathDependencies) {
291  deps.Add(s);
292  }
293 
294 
295  return new CacheDependency(new string[] { LocalMapPath(virtualPath) }, deps.ToArray(), utcStart);
296 
297  }
string LocalMapPath(string virtualPath)
Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outs...
DateTime ImageResizer.Plugins.Basic.VirtualFolder.GetDateModifiedUtc ( string  virtualPath)
inline

Returns the LastWriteTimeUtc value for the specified virtual file in this folder, or DateTime.MinValue if missing.

Parameters
virtualPath
Returns

Definition at line 216 of file VirtualFolder.cs.

216  {
217  string physicalPath = LocalMapPath(virtualPath);
218  if (System.IO.File.Exists(physicalPath))
219  return System.IO.File.GetLastWriteTimeUtc(physicalPath);
220  else return DateTime.MinValue;
221  }
string LocalMapPath(string virtualPath)
Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outs...
IVirtualFile ImageResizer.Plugins.Basic.VirtualFolder.GetFile ( string  virtualPath,
NameValueCollection  queryString 
)
inline

Unless the path is not within the virtual folder, or IO permissions are missing, will return an IVirtualFile instance for the path. The file may or may not exist.

Parameters
virtualPath
queryString
Returns

Implements ImageResizer.Plugins.IVirtualImageProvider.

Definition at line 247 of file VirtualFolder.cs.

247  {
248  if (NoIOPermission) return null;
249  if (!IsVirtualPath(virtualPath)) return null; //It's not even in our area.
250  return new VirtualFolderProviderVirtualFile(virtualPath, this);
251  }
bool IsVirtualPath(string virtualPath)
Returns true if the specified path is inside this virtual folder
bool NoIOPermission
True if the plugin has detected it doesn&#39;t have sufficient IOPermission to operate.
override VirtualFile ImageResizer.Plugins.Basic.VirtualFolder.GetFile ( string  virtualPath)
inline

For internal use only by the .NET VPP system.

Parameters
virtualPath
Returns

Definition at line 269 of file VirtualFolder.cs.

269  {
270  if (isOnlyVirtualPath(virtualPath))
271  return new VirtualFolderProviderVirtualFile(virtualPath, this);
272  else
273  return Previous.GetFile(virtualPath);
274  }
IPlugin ImageResizer.Plugins.Basic.VirtualFolder.Install ( Config  c)
inline

Registers the VirtualFolder plugin as a virtual path provider.

Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 81 of file VirtualFolder.cs.

81  {
82  if (!NoIOPermission && RegisterAsVpp) {
83  try {
84  HostingEnvironment.RegisterVirtualPathProvider(this);
85  registeredVpp = true;
86  } catch (SecurityException) {
87  this._failedToRegisterVpp =true;
88  }
89  }
90  c.Plugins.add_plugin(this);
91  return this;
92  }
bool RegisterAsVpp
If true, the plugin will attempt to register itself as an application-wide VirtualPathProvider instea...
bool NoIOPermission
True if the plugin has detected it doesn&#39;t have sufficient IOPermission to operate.
bool ImageResizer.Plugins.Basic.VirtualFolder.IsVirtualPath ( string  virtualPath)
inline

Returns true if the specified path is inside this virtual folder

Parameters
virtualPath
Returns

Definition at line 186 of file VirtualFolder.cs.

186  {
187  virtualPath = normalizeVirtualPath(virtualPath);
188  return virtualPath.StartsWith(this.VirtualPath, StringComparison.OrdinalIgnoreCase);
189  }
string normalizeVirtualPath(string path)
Converts relative and app-relative paths to domain-relative virtual paths.
string ImageResizer.Plugins.Basic.VirtualFolder.LocalMapPath ( string  virtualPath)
inline

Converts any virtual path in this folder to a physical path. Returns null if the virtual path is outside the folder.

Parameters
virtualPath
Returns

Definition at line 174 of file VirtualFolder.cs.

174  {
175  virtualPath = normalizeVirtualPath(virtualPath);
176  if (virtualPath.StartsWith(this.VirtualPath, StringComparison.OrdinalIgnoreCase)) {
177  return Path.Combine(PhysicalPath, virtualPath.Substring(this.VirtualPath.Length).TrimStart('/').Replace('/', Path.DirectorySeparatorChar));
178  }
179  return null;
180  }
string PhysicalPath
The physical path
string normalizeVirtualPath(string path)
Converts relative and app-relative paths to domain-relative virtual paths.
string ImageResizer.Plugins.Basic.VirtualFolder.normalizeVirtualPath ( string  path)
inlineprotected

Converts relative and app-relative paths to domain-relative virtual paths.

Parameters
path
Returns

Definition at line 111 of file VirtualFolder.cs.

111  {
112  if (!path.StartsWith("/")) path = HostingEnvironment.ApplicationVirtualPath.TrimEnd('/') + '/' + (path.StartsWith("~") ? path.Substring(1) : path).TrimStart('/');
113  return path;
114  }
string ImageResizer.Plugins.Basic.VirtualFolder.resolvePhysicalPath ( string  path)
inlineprotected

Attempts to convert a phyiscal path into a collapsed rooted physical path.

Parameters
path
Returns

Definition at line 120 of file VirtualFolder.cs.

120  {
121 
122  if (!Path.IsPathRooted(path)) path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, path);
123  if (NoIOPermission) return collapsePath(path);
124 
125  try {
126  return Path.GetFullPath(path);
127  } catch (SecurityException) {
128  noIOPermission = true;
129  return collapsePath(path);
130  }
131  }
bool NoIOPermission
True if the plugin has detected it doesn&#39;t have sufficient IOPermission to operate.
string collapsePath(string path)
Collapses any .. segments
bool ImageResizer.Plugins.Basic.VirtualFolder.Uninstall ( Config  c)
inline

Uninstalls the plugin. Should reverse all changes made during Install

Parameters
c
Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 93 of file VirtualFolder.cs.

93  {
94  c.Plugins.remove_plugin(this);
95  return !registeredVpp;//Cannot truly remove a VPP
96  }

Property Documentation

bool ImageResizer.Plugins.Basic.VirtualFolder.FailedToRegisterVpp
get

True if the provider attempted to register itself as a VirtualPathProvider and failed due to limited security clearance. False if it did not attempt (say, due to missing IOPermission) , or if it succeeded.

Definition at line 48 of file VirtualFolder.cs.

bool ImageResizer.Plugins.Basic.VirtualFolder.NoIOPermission
get

True if the plugin has detected it doesn't have sufficient IOPermission to operate.

Definition at line 102 of file VirtualFolder.cs.

string ImageResizer.Plugins.Basic.VirtualFolder.PhysicalPath
getset

The physical path

Definition at line 70 of file VirtualFolder.cs.

bool ImageResizer.Plugins.Basic.VirtualFolder.RegisterAsVpp
getset

If true, the plugin will attempt to register itself as an application-wide VirtualPathProvider instead of a image resizer-specific IVirtualImageProvider.

Definition at line 55 of file VirtualFolder.cs.

string ImageResizer.Plugins.Basic.VirtualFolder.VirtualPath
getset

The virtual path served by the VirtualFolder

Definition at line 61 of file VirtualFolder.cs.


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