C# Class Masonry.Core.Hosting.EmbeddedFileProvider

Used to provide embedded files (other than views).
Can be used to provide embedded content files such as images, scripts etc.
Inheritance: IVirtualFileProvider
Mostra file Open project: DenisVuyka/Masonry Class Usage Examples

Public Methods

Method Description
Add ( Assembly assembly ) : void
Add ( NamespaceMapping mapping ) : void

Add a namespace mapping for embedded resources.

EmbeddedFileProvider ( ) : System
EmbeddedFileProvider ( string siteRoot ) : System

Initializes a new instance of the EmbeddedFileProvider class.

FileExists ( string virtualPath ) : bool

Checks if a file exits

GetCacheDependency ( string virtualPath, IEnumerable dependencies, System.DateTime utcStart ) : System.Web.Caching.CacheDependency

Creates a cache dependency based on the specified virtual paths

GetCacheKey ( string virtualPath ) : string

GetFile ( string virtualPath ) : System.Web.Hosting.VirtualFile

Get the view

GetFileHash ( string virtualPath, IEnumerable dependencies ) : string

Get file hash.

Protected Methods

Method Description
IsFileAllowed ( string resourceName ) : bool

Determines if the found embedded file might be mapped and provided.

Default implementation uses AllowedFileExtensions to determine which files to servce.

LoadStream ( string virtualPath, MappedResource resource ) : Stream

Resource to load

The default implementation uses resource.Assembly.GetManifestResourceStream(resource.FullResourceName)

Map ( NamespaceMapping mapping ) : void

Create mappings for all resources in a specific namespace (and all sub namespaces).

Private Methods

Method Description
GetResource ( string uri ) : MappedResource

Get resource name by scanning all mapped namespaces.

Method Details

Add() public method

public Add ( Assembly assembly ) : void
assembly System.Reflection.Assembly
return void

Add() public method

Add a namespace mapping for embedded resources.
public Add ( NamespaceMapping mapping ) : void
mapping NamespaceMapping Mapping to add
return void

EmbeddedFileProvider() public method

public EmbeddedFileProvider ( ) : System
return System

EmbeddedFileProvider() public method

Initializes a new instance of the EmbeddedFileProvider class.
public EmbeddedFileProvider ( string siteRoot ) : System
siteRoot string Root directory of the web site
return System

FileExists() public method

Checks if a file exits
public FileExists ( string virtualPath ) : bool
virtualPath string Virtual path like "~/Views/Home/Index.cshtml"
return bool

GetCacheDependency() public method

Creates a cache dependency based on the specified virtual paths
public GetCacheDependency ( string virtualPath, IEnumerable dependencies, System.DateTime utcStart ) : System.Web.Caching.CacheDependency
virtualPath string Virtual path like "~/Views/Home/Index.cshtml"
dependencies IEnumerable The dependencies.
utcStart System.DateTime The UTC start.
return System.Web.Caching.CacheDependency

GetCacheKey() public method

public GetCacheKey ( string virtualPath ) : string
virtualPath string Virtual path like "~/Views/Home/Index.cshtml"
return string

GetFile() public method

Get the view
public GetFile ( string virtualPath ) : System.Web.Hosting.VirtualFile
virtualPath string Virtual path like "~/Views/Home/Index.cshtml"
return System.Web.Hosting.VirtualFile

GetFileHash() public method

Get file hash.
public GetFileHash ( string virtualPath, IEnumerable dependencies ) : string
virtualPath string Virtual path like "~/Views/Home/Index.cshtml"
dependencies IEnumerable The dependencies.
return string

IsFileAllowed() protected method

Determines if the found embedded file might be mapped and provided.
Default implementation uses AllowedFileExtensions to determine which files to servce.
protected IsFileAllowed ( string resourceName ) : bool
resourceName string
return bool

LoadStream() protected method

Resource to load
The default implementation uses resource.Assembly.GetManifestResourceStream(resource.FullResourceName)
protected LoadStream ( string virtualPath, MappedResource resource ) : Stream
virtualPath string Requested virtual path
resource MappedResource Identified resource (i.e. the one to load)
return Stream

Map() protected method

Create mappings for all resources in a specific namespace (and all sub namespaces).
protected Map ( NamespaceMapping mapping ) : void
mapping NamespaceMapping Mapping to load embedded resources in
return void