using System;
namespace EmbedIO.Files
{
///
/// Provides extension methods for and derived classes.
///
public static class FileModuleExtensions
{
///
/// Sets the used by a module to store hashes and,
/// optionally, file contents and rendered directory listings.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// An instance of .
/// with its Cache property
/// set to .
/// is .
/// The configuration of is locked.
/// is .
///
public static TModule WithCache(this TModule @this, FileCache value)
where TModule : FileModule
{
@this.Cache = value;
return @this;
}
///
/// Sets a value indicating whether a module caches the contents of files
/// and directory listings.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// to enable caching of contents;
/// to disable it.
/// with its ContentCaching property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithContentCaching(this TModule @this, bool value)
where TModule : FileModule
{
@this.ContentCaching = value;
return @this;
}
///
/// Enables caching of file contents and directory listings on a module.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// with its ContentCaching property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithContentCaching(this TModule @this)
where TModule : FileModule
{
@this.ContentCaching = true;
return @this;
}
///
/// Enables caching of file contents and directory listings on a module.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// sets the maximum size of a single cached file in kilobytes
/// sets the maximum total size of cached data in kilobytes
/// with its ContentCaching property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithContentCaching(this TModule @this, int maxFileSizeKb, int maxSizeKb)
where TModule : FileModule
{
@this.ContentCaching = true;
@this.Cache.MaxFileSizeKb = maxFileSizeKb;
@this.Cache.MaxSizeKb = maxSizeKb;
return @this;
}
///
/// Disables caching of file contents and directory listings on a module.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// with its ContentCaching property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithoutContentCaching(this TModule @this)
where TModule : FileModule
{
@this.ContentCaching = false;
return @this;
}
///
/// Sets the name of the default document served, if it exists, instead of a directory listing
/// when the path of a requested URL maps to a directory.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// The name of the default document.
/// with its DefaultDocument property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithDefaultDocument(this TModule @this, string value)
where TModule : FileModule
{
@this.DefaultDocument = value;
return @this;
}
///
/// Sets the name of the default document to .
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// with its DefaultDocument property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithoutDefaultDocument(this TModule @this)
where TModule : FileModule
{
@this.DefaultDocument = null;
return @this;
}
///
/// Sets the default extension appended to requested URL paths that do not map
/// to any file or directory.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// The default extension.
/// with its DefaultExtension property
/// set to .
/// is .
/// The configuration of is locked.
/// is a non-,
/// non-empty string that does not start with a period (.).
///
public static TModule WithDefaultExtension(this TModule @this, string value)
where TModule : FileModule
{
@this.DefaultExtension = value;
return @this;
}
///
/// Sets the default extension to .
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// with its DefaultExtension property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithoutDefaultExtension(this TModule @this)
where TModule : FileModule
{
@this.DefaultExtension = null;
return @this;
}
///
/// Sets the interface used to generate
/// directory listing in a module.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// An interface, or
/// to disable the generation of directory listings.
/// with its DirectoryLister property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithDirectoryLister(this TModule @this, IDirectoryLister value)
where TModule : FileModule
{
@this.DirectoryLister = value;
return @this;
}
///
/// Sets a module's DirectoryLister property
/// to , disabling the generation of directory listings.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// with its DirectoryLister property
/// set to .
/// is .
/// The configuration of is locked.
///
public static TModule WithoutDirectoryLister(this TModule @this)
where TModule : FileModule
{
@this.DirectoryLister = null;
return @this;
}
///
/// Sets a that is called by a module whenever
/// the requested URL path could not be mapped to any file or directory.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// The method to call.
/// with its OnMappingFailed property
/// set to .
/// is .
/// The configuration of is locked.
/// is .
///
///
public static TModule HandleMappingFailed(this TModule @this, FileRequestHandlerCallback callback)
where TModule : FileModule
{
@this.OnMappingFailed = callback;
return @this;
}
///
/// Sets a that is called by a module whenever
/// the requested URL path has been mapped to a directory, but directory listing has been
/// disabled.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// The method to call.
/// with its OnDirectoryNotListable property
/// set to .
/// is .
/// The configuration of is locked.
/// is .
///
///
public static TModule HandleDirectoryNotListable(this TModule @this, FileRequestHandlerCallback callback)
where TModule : FileModule
{
@this.OnDirectoryNotListable = callback;
return @this;
}
///
/// Sets a that is called by a module whenever
/// the requested URL path has been mapped to a file or directory, but the request's
/// HTTP method is neither GET nor HEAD.
///
/// The type of the module on which this method is called.
/// The module on which this method is called.
/// The method to call.
/// with its OnMethodNotAllowed property
/// set to .
/// is .
/// The configuration of is locked.
/// is .
///
///
public static TModule HandleMethodNotAllowed(this TModule @this, FileRequestHandlerCallback callback)
where TModule : FileModule
{
@this.OnMethodNotAllowed = callback;
return @this;
}
}
}