ClassResourceStorage
Provides file system-based resource storage for managing report assets in a local directory structure.
Definition
Namespace:Telerik.WebReportDesigner.Services
Assembly:Telerik.WebReportDesigner.Services.dll
Syntax:
public class ResourceStorage : ResourceStorageBase, IResourceStorage, IAssetsStorage
Inheritance: objectResourceStorageBaseResourceStorage
Derived Classes:
Implements:
Inherited Members
Constructors
ResourceStorage(string)
Initializes a new ResourceStorage instance with the specified base directory and default folder configuration.
Declaration
public ResourceStorage(string baseDir)
Parameters
baseDir
string
The base directory path where report resources will be stored and managed.
Remarks
Creates storage with no excluded folders and uses the standard default folder structure (Data, Images, Styles).
ResourceStorage(string, CreateFolderModel[], string[])
Initializes a new ResourceStorage instance with full configuration control over default folders and exclusions.
Declaration
public ResourceStorage(string baseDir, CreateFolderModel[] defaultFolders, string[] excludedFolders)
Parameters
baseDir
string
The base directory path where report resources will be stored and managed.
defaultFolders
Array of folder models that define which default folders will be created during initialization.
excludedFolders
string[]
Array of relative folder paths to exclude from folder content operations; wildcards are not supported.
Exceptions
ArgumentNullException
Thrown when defaultFolders parameter is null.
Remarks
This is the primary constructor that provides complete control over storage configuration and folder management behavior.
ResourceStorage(string, Dictionary<string, string>)
Initializes a new ResourceStorage instance with the specified base directory and extension mapping (obsolete).
Declaration
[Obsolete("extensionDirectories is now obsolete. Please use Telerik.WebReportDesigner.Services.ResourceStorage(string)", false)]
public ResourceStorage(string baseDir, Dictionary<string, string> extensionDirectories)
Parameters
baseDir
string
The base directory path where report resources will be stored and managed.
extensionDirectories
Dictionary<string, string>
Legacy parameter for extension-to-directory mapping that is no longer used.
Remarks
This constructor is obsolete and provided for backward compatibility; use ResourceStorage(string) instead.
ResourceStorage(string, string[])
Initializes a new ResourceStorage instance with the specified base directory and folder exclusions.
Declaration
public ResourceStorage(string baseDir, string[] excludedFolders)
Parameters
baseDir
string
The base directory path where report resources will be stored and managed.
excludedFolders
string[]
Array of relative folder paths to exclude from folder content operations; wildcards are not supported.
Remarks
Creates storage with custom folder exclusions while using the standard default folder structure (Data, Images, Styles).
Fields
RootFolderName
Gets the standard name used for the root resources folder in the file system.
Declaration
public const string RootFolderName = "Resources"
Field Value
string
Remarks
This constant defines the default folder name "Resources" used across the application for storing report assets.
Properties
BaseDir
Gets the base directory used to access the report resources .
Declaration
public string BaseDir { get; }
Property Value
string
Methods
CreateDefaultFolder(CreateFolderModel)
Creates a default folder using the specified model without throwing exceptions if the folder already exists.
Declaration
protected override void CreateDefaultFolder(CreateFolderModel model)
Parameters
model
The folder creation model containing the folder name and parent URI information for the default folder to create.
Overrides
Remarks
This override implementation delegates to CreateFolder with throwIfExists set to false, allowing silent handling of existing folders during initialization. This behavior is essential for the default folder creation process where folders may already exist from previous runs.
CreateDirectory(string[])
Creates a directory structure using the provided array of relative path segments.
Declaration
protected void CreateDirectory(string[] relativePaths)
Parameters
relativePaths
string[]
Array of path segments that will be combined to create the directory structure relative to the base directory.
Remarks
Validates that the resulting path remains within the base directory to prevent directory traversal attacks. Creates the complete directory hierarchy if any intermediate directories don't exist.
CreateFolderAsync(CreateFolderModel)
Asynchronously creates a new folder in the specified parent location with the given name.
Declaration
public virtual Task<ResourceFolderModel> CreateFolderAsync(CreateFolderModel model)
Parameters
model
The folder creation model containing the folder name and parent URI where it should be created.
Returns
Task<ResourceFolderModel>
A task containing the ResourceFolderModel of the newly created folder.
Implements
Remarks
Always throws an exception if the folder already exists, providing strict creation semantics for public API usage.
DeleteAsync(string)
Deletes the given resource
Declaration
public virtual Task DeleteAsync(string uri)
Parameters
uri
string
The unique resource identifier (URI)
Returns
Task
Implements
DeleteFolderAsync(string)
Asynchronously deletes the specified folder and all its contents from the file system.
Declaration
public virtual Task DeleteFolderAsync(string uri)
Parameters
uri
string
The unique resource identifier of the folder to delete; cannot be null, empty, or represent the root directory.
Returns
Task
Implements
Remarks
Performs a recursive deletion that removes the folder and all contained files and subdirectories. The root folder cannot be deleted to maintain storage integrity.
EnsureDefaultFolders()
Ensures that both the root storage directory and all default folders are created in the file system.
Declaration
protected override void EnsureDefaultFolders()
Overrides
Remarks
First creates the root base directory if it doesn't exist, then delegates to the base class to create the standard default folders (Data, Images, Styles). This override ensures the storage directory structure is properly initialized before creating nested default folders.
FolderExists(string)
Determines whether a folder exists at the specified URI location within the resource storage.
Declaration
public virtual bool FolderExists(string uri)
Parameters
uri
string
The unique resource identifier of the folder to check; cannot be null or empty.
Returns
bool
True if the folder exists at the specified URI; otherwise, false.
Implements
Remarks
Validates the URI parameter and transforms it to an absolute file system path before checking directory existence. This method provides the core folder existence checking functionality used throughout the resource storage system.
FolderHasContents(string)
Determines whether the specified folder contains any files or subdirectories.
Declaration
public virtual bool FolderHasContents(string uri)
Parameters
uri
string
The unique resource identifier of the folder to check for contents.
Returns
bool
True if the folder contains any files or subdirectories; otherwise, false.
Implements
Remarks
Uses efficient enumeration to check for existence of any content without loading all items into memory.
FolderNameExists(string)
Determines whether a folder exists at the specified path using name-based identifiers.
Declaration
public virtual bool FolderNameExists(string folderName)
Parameters
folderName
string
The folder path using name identifiers rather than URI format.
Returns
bool
True if the folder exists at the specified path; otherwise, false.
Implements
Remarks
The default implementation delegates to FolderExists(string), treating the folderName as equivalent to a URI. This method provides an alternative interface for folder existence checking using name-based paths.
GetAllByExtension(string[])
Searches for and returns all report resources matching the specified file extensions throughout the entire directory tree.
Declaration
public virtual IEnumerable<ResourceFileModel> GetAllByExtension(string[] extensions)
Parameters
extensions
string[]
Array of file extension patterns to search for, supporting wildcards (* and ?) but not regular expressions.
Returns
IEnumerable<ResourceFileModel>
An enumerable collection of ResourceFileModel objects representing all matching files found in the base directory and subdirectories.
Implements
Remarks
Performs a recursive search starting from the base directory and includes all nested subdirectories in the search operation.
GetAsync(string)
Asynchronously retrieves the binary content of a report resource file by its filename.
Declaration
public virtual Task<byte[]> GetAsync(string resourceName)
Parameters
resourceName
string
The complete filename of the resource including its extension (e.g., "image.png", "style.css").
Returns
Task<byte[]>
A task containing a byte array with the complete file contents of the specified resource.
Implements
Remarks
The default implementation delegates to GetByUri(string) and treats the resourceName as a URI equivalent. This method provides asynchronous access to resource file contents for improved performance in web applications.
GetByUri(string)
Retrieves the binary content of a resource file by its URI and returns it as a byte array.
Declaration
public virtual byte[] GetByUri(string resourceUri)
Parameters
resourceUri
string
The unique resource identifier of the file to retrieve; cannot be null or empty.
Returns
byte[]
A byte array containing the complete file contents of the specified resource.
Implements
Remarks
Validates the URI parameter and transforms it to an absolute file system path before reading the file contents. This method provides synchronous access to resource file data for immediate use.
GetFile(string)
Retrieves a resource file by its URI and returns a complete data model for download operations.
Declaration
public virtual ResourceFileDataModel GetFile(string resourceUri)
Parameters
resourceUri
string
The unique resource identifier of the file to retrieve; cannot be null or empty.
Returns
A ResourceFileDataModel containing the file's binary data, name, and metadata for download operations.
Implements
Remarks
Validates the URI parameter, reads the complete file contents, and constructs a download-ready model with file metadata. MIME type detection is currently not implemented and will be added in future versions based on file extension analysis.
GetFolderAsync(string)
Asynchronously retrieves the folder model and metadata for the specified URI.
Declaration
public virtual Task<ResourceFolderModel> GetFolderAsync(string uri)
Parameters
uri
string
The unique resource identifier; null or empty string represents the root directory.
Returns
Task<ResourceFolderModel>
A task containing the ResourceFolderModel with folder information and parent relationships.
Implements
Remarks
Handles both root directory requests and nested folder requests with appropriate parent path resolution.
GetFolderByName(string)
Retrieves the folder model using a name-based identifier instead of URI.
Declaration
public virtual ResourceFolderModel GetFolderByName(string folderName)
Parameters
folderName
string
The folder path using name identifiers rather than URI format.
Returns
The ResourceFolderModel of the requested folder.
Implements
Remarks
The default implementation delegates to GetFolder(string) method, treating folderName as a URI equivalent.
GetFolderContents(string, string[])
Retrieves files and subfolders from the specified folder URI that match the provided search patterns.
Declaration
public virtual IEnumerable<ResourceModelBase> GetFolderContents(string uri, string[] searchPattern)
Parameters
uri
string
The unique resource identifier of the folder; null or empty string represents the root BaseDir directory.
searchPattern
string[]
Array of search patterns to filter files, supporting wildcards (* and ?) but not regular expressions.
Returns
IEnumerable<ResourceModelBase>
An enumerable collection of ResourceModelBase objects containing matching files and all first-level subfolders.
Remarks
Combines first-level subfolders with files matching the search patterns, providing comprehensive folder content enumeration.
GetFolderContentsAsync(string)
Asynchronously retrieves all files and subfolders contained within the specified folder URI.
Declaration
public virtual Task<IEnumerable<ResourceModelBase>> GetFolderContentsAsync(string uri)
Parameters
uri
string
The unique resource identifier of the folder; null or empty string represents the root BaseDir directory.
Returns
Task<IEnumerable<ResourceModelBase>>
A task containing an enumerable collection of ResourceModelBase objects representing all contents of the specified folder.
Implements
Remarks
Uses a wildcard search pattern to include all file types and delegates to the overloaded GetFolderContents method.
GetModelAsync(string)
Finds a resource by its uri and returns the information about it
Declaration
public virtual Task<ResourceFileModel> GetModelAsync(string resourceUri)
Parameters
resourceUri
string
The unique resource identifier (URI)
Returns
Task<ResourceFileModel>
Implements
GetModelByName(string)
Retrieves metadata and information about a resource using its name-based identifier. The default implementation returns the result of the .
Declaration
public virtual ResourceFileModel GetModelByName(string resourceName)
Parameters
resourceName
string
The full path to the resource using Name identifiers.
Returns
ResourceFileModel, containg the information about the resource.
Implements
GetModelCore<T>(string)
Reads the model of the given type T.
Declaration
protected T GetModelCore<T>(string resourceUri) where T : ResourceFileModel, new()
Parameters
resourceUri
string
Returns
T
Instance of T.
GetOrderedDefaultFoldersToCreate()
Orders the default folders by their absolute paths to ensure parent directories are created before child directories.
Declaration
protected override IEnumerable<CreateFolderModel> GetOrderedDefaultFoldersToCreate()
Returns
IEnumerable<CreateFolderModel>
An enumerable collection of CreateFolderModel objects ordered by their full absolute paths.
Overrides
Remarks
This ordering strategy guarantees that any non-existing parent folders are created before their children during initialization.
Move(MoveResourceModel)
Moves an existing resource file from its current location to a new parent directory.
Declaration
public virtual ResourceFileModel Move(MoveResourceModel model)
Parameters
model
The move operation model containing the source resource URI and destination parent URI.
Returns
ResourceFileModel, containg the information about the folder
Implements
Remarks
Delegates to MoveCore for the actual file system operation while preserving the resource's filename and contents. The resource is relocated to the specified parent directory without changing its name or file contents.
MoveCore<T>(MoveResourceModel)
Moves a resource of the given type T to a new parent.
Declaration
protected T MoveCore<T>(MoveResourceModel model) where T : ResourceFileModel, new()
Parameters
model
Returns
T
Instance of T.
MoveFolder(MoveFolderModel)
Moves an existing folder from its current location to a new parent directory, preserving all contents.
Declaration
public virtual ResourceFolderModel MoveFolder(MoveFolderModel model)
Parameters
model
The move operation model containing the source URI and destination parent URI.
Returns
A ResourceFolderModel representing the folder in its new location.
Implements
Remarks
Performs a complete directory move operation including all files and subdirectories within the source folder.
Overwrite(OverwriteResourceModel, byte[])
Overwrties the given resource contents with resource
Declaration
public virtual ResourceFileModel Overwrite(OverwriteResourceModel model, byte[] resource)
Parameters
model
The model containing the overwrite operation data
resource
byte[]
The new contents of the resource
Returns
ResourceFileModel, containg the information about the folder
Implements
OverwriteCore<T>(OverwriteResourceModel, byte[])
Overwrites the model of given type T using the provided bytes.
Declaration
public T OverwriteCore<T>(OverwriteResourceModel model, byte[] resource) where T : ResourceFileModel, new()
Parameters
model
resource
byte[]
Returns
T
Instance of T.
Exceptions
ArgumentNullException
RenameAsync(RenameResourceModel)
Asynchronously renames an existing resource file to a new name while preserving its contents and location.
Declaration
public virtual Task<ResourceFileModel> RenameAsync(RenameResourceModel model)
Parameters
model
The rename operation model containing the current resource URI and the new file name.
Returns
Task<ResourceFileModel>
ResourceFileModel, containg the information about the folder
Exceptions
Thrown when the model is null, the new resource name is null/empty, or the old URI is null/empty.
Implements
Remarks
Validates the rename operation parameters and delegates to RenameCore for the actual file system operation. The resource remains in the same directory location but with the updated filename.
RenameCore<T>(RenameResourceModel)
Renames a resource of the given type T.
Declaration
protected T RenameCore<T>(RenameResourceModel model) where T : ResourceFileModel, new()
Parameters
model
Returns
T
Instance of T.
RenameFolderAsync(RenameFolderModel)
Asynchronously renames an existing folder to a new name while preserving all contents and directory structure.
Declaration
public virtual Task<ResourceFolderModel> RenameFolderAsync(RenameFolderModel model)
Parameters
model
The rename operation model containing the current folder URI and the new folder name.
Returns
Task<ResourceFolderModel>
A task containing the ResourceFolderModel representing the renamed folder in its updated location.
Implements
Remarks
This operation is implemented as a directory move within the same parent directory, preserving all files and subdirectories. The folder remains in the same parent location but with the updated name.
ResourceExists(string)
Determines whether a resource exists at the specified URI location within the resource storage.
Declaration
public virtual bool ResourceExists(string resourceUri)
Parameters
resourceUri
string
The unique resource identifier of the resource to check; cannot be null or empty.
Returns
bool
True if the resource exists at the specified URI; otherwise, false.
Implements
Remarks
Validates the URI parameter and transforms it to an absolute file system path before checking file existence. Returns false if any exception occurs during path resolution or file system access, providing safe existence checking.
ResourceNameExists(string)
Determines whether a resource exists at the specified path using name-based identifiers.
Declaration
public virtual bool ResourceNameExists(string resourceName)
Parameters
resourceName
string
The full resource path using name identifiers rather than URI format.
Returns
bool
True if the resource exists at the specified path; otherwise, false.
Implements
Remarks
The default implementation delegates to ResourceExists(string), treating the resourceName as equivalent to a URI. This method provides an alternative interface for resource existence checking using name-based paths instead of URI format.
Save(string, byte[])
Creates new or overwrites an existing report resource file with the provided resource bytes.
Declaration
[Obsolete("The Telerik.WebReportDesigner.Services.ResourceStorage(string, byte[]) is now obsolete. Please use Telerik.WebReportDesigner.Services.ResourceStorage(SaveResourceModel, byte[])", false)]
public virtual string Save(string resourceName, byte[] resource)
Parameters
resourceName
string
The report resource filename including the file extension.
resource
byte[]
The new bytes of the report resource.
Returns
string
The location of the resource file.
Implements
SaveAsync(SaveResourceModel, byte[])
Saves the new bytes of a resource and returns the information about it.
Declaration
public virtual Task<ResourceFileModel> SaveAsync(SaveResourceModel model, byte[] resource)
Parameters
model
The model containing the save operation data
resource
byte[]
The contents of the resource
Returns
Task<ResourceFileModel>
Exceptions
Implements
SaveAsync(SaveResourceModel, byte[], bool)
Saves the new bytes of a resource and returns the information about it.
Declaration
public virtual Task<ResourceFileModel> SaveAsync(SaveResourceModel model, byte[] resource, bool forcePath)
Parameters
model
The model containing the save operation data
resource
byte[]
The contents of the resource
forcePath
bool
Determines whether the path to the resource will be created, if it does not exist, or an exception will be thrown.
Returns
Task<ResourceFileModel>
Exceptions
SaveCore<T>(SaveResourceModel, byte[], bool)
Saves the model of the given type T using the provided bytes.
Declaration
protected T SaveCore<T>(SaveResourceModel model, byte[] resource, bool forcePath) where T : ResourceFileModel, new()
Parameters
model
The model containing the save operation data
resource
byte[]
The contents of the resource
forcePath
bool
Determines whether the path to the resource will be created, if it does not exist, or an exception will be thrown.
Returns
T
Instance of T.
Exceptions
Search(SearchResourcesModel)
Searches for resource in the given ResourceFolderUri
Declaration
public virtual IEnumerable<ResourceModelBase> Search(SearchResourcesModel model)
Parameters
model
The model containing the search operation data. The SearchPattern can contain a combination of valid literal path and wildcard (* and ?) characters, but regular expressions are not supported.
Returns
IEnumerable<ResourceModelBase>
The search results, both files and folders, as an enumerable of ResourceModelBase
Implements