ResourceStorage
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
Initializes a new ResourceStorage instance with full configuration control over default folders and exclusions.
public ResourceStorage(string baseDir, CreateFolderModel[] defaultFolders, string[] excludedFolders)
The base directory path where report resources will be stored and managed.
defaultFoldersCreateFolderModel[]Array of folder models that define which default folders will be created during initialization.
excludedFoldersstring[]Array of relative folder paths to exclude from folder content operations; wildcards are not supported.
Exceptions:ArgumentNullException
Thrown when defaultFolders parameter is null.
This is the primary constructor that provides complete control over storage configuration and folder management behavior.
Initializes a new ResourceStorage instance with the specified base directory and extension mapping (obsolete).
[Obsolete("extensionDirectories is now obsolete. Please use Telerik.WebReportDesigner.Services.ResourceStorage(string)", false)]
public ResourceStorage(string baseDir, Dictionary<string, string> extensionDirectories)
The base directory path where report resources will be stored and managed.
extensionDirectoriesDictionary<string, string>Legacy parameter for extension-to-directory mapping that is no longer used.
This constructor is obsolete and provided for backward compatibility; use ResourceStorage(string) instead.
Initializes a new ResourceStorage instance with the specified base directory and folder exclusions.
public ResourceStorage(string baseDir, string[] excludedFolders)
The base directory path where report resources will be stored and managed.
excludedFoldersstring[]Array of relative folder paths to exclude from folder content operations; wildcards are not supported.
Creates storage with custom folder exclusions while using the standard default folder structure (Data, Images, Styles).
Initializes a new ResourceStorage instance with the specified base directory and default folder configuration.
public ResourceStorage(string baseDir)
The base directory path where report resources will be stored and managed.
Creates storage with no excluded folders and uses the standard default folder structure (Data, Images, Styles).
Fields
RootFolderName
string
Gets the standard name used for the root resources folder in the file system.
public const string RootFolderName = "Resources"
This constant defines the default folder name "Resources" used across the application for storing report assets.
Properties
BaseDir
string
Gets the base directory used to access the report resources .
public string BaseDir { get; }
Methods
Creates a default folder using the specified model without throwing exceptions if the folder already exists.
protected override void CreateDefaultFolder(CreateFolderModel model)
The folder creation model containing the folder name and parent URI information for the default folder to create.
Overrides:
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.
Creates a directory structure using the provided array of relative path segments.
protected void CreateDirectory(string[] relativePaths)
Array of path segments that will be combined to create the directory structure relative to the base directory.
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.
Asynchronously creates a new folder in the specified parent location with the given name.
public virtual Task<ResourceFolderModel> CreateFolderAsync(CreateFolderModel 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:
Always throws an exception if the folder already exists, providing strict creation semantics for public API usage.
Deletes the given resource
public virtual Task DeleteAsync(string uri)
The unique resource identifier (URI)
Returns:Task
Implements:
Asynchronously deletes the specified folder and all its contents from the file system.
public virtual Task DeleteFolderAsync(string uri)
The unique resource identifier of the folder to delete; cannot be null, empty, or represent the root directory.
Returns:Task
Implements:
Performs a recursive deletion that removes the folder and all contained files and subdirectories. The root folder cannot be deleted to maintain storage integrity.
Ensures that both the root storage directory and all default folders are created in the file system.
protected override void EnsureDefaultFolders()
Overrides:
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.
Determines whether a folder exists at the specified URI location within the resource storage.
public virtual bool FolderExists(string uri)
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:
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.
Determines whether the specified folder contains any files or subdirectories.
public virtual bool FolderHasContents(string uri)
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:
Uses efficient enumeration to check for existence of any content without loading all items into memory.
Determines whether a folder exists at the specified path using name-based identifiers.
public virtual bool FolderNameExists(string folderName)
The folder path using name identifiers rather than URI format.
Returns:bool
True if the folder exists at the specified path; otherwise, false.
Implements:
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[])
IEnumerable<ResourceFileModel>
Searches for and returns all report resources matching the specified file extensions throughout the entire directory tree.
public virtual IEnumerable<ResourceFileModel> GetAllByExtension(string[] extensions)
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:
Performs a recursive search starting from the base directory and includes all nested subdirectories in the search operation.
GetAsync(string)
Task<byte[]>
Asynchronously retrieves the binary content of a report resource file by its filename.
public virtual Task<byte[]> GetAsync(string resourceName)
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:
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)
byte[]
Retrieves the binary content of a resource file by its URI and returns it as a byte array.
public virtual byte[] GetByUri(string resourceUri)
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:
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.
Retrieves a resource file by its URI and returns a complete data model for download operations.
public virtual ResourceFileDataModel GetFile(string resourceUri)
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:
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.
Asynchronously retrieves the folder model and metadata for the specified URI.
public virtual Task<ResourceFolderModel> GetFolderAsync(string uri)
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:
Handles both root directory requests and nested folder requests with appropriate parent path resolution.
Retrieves the folder model using a name-based identifier instead of URI.
public virtual ResourceFolderModel GetFolderByName(string folderName)
The folder path using name identifiers rather than URI format.
Returns:The ResourceFolderModel of the requested folder.
Implements:
The default implementation delegates to GetFolder(string) method, treating folderName as a URI equivalent.
GetFolderContents(string, string[])
IEnumerable<ResourceModelBase>
Retrieves files and subfolders from the specified folder URI that match the provided search patterns.
public virtual IEnumerable<ResourceModelBase> GetFolderContents(string uri, string[] searchPattern)
The unique resource identifier of the folder; null or empty string represents the root BaseDir directory.
searchPatternstring[]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.
Combines first-level subfolders with files matching the search patterns, providing comprehensive folder content enumeration.
GetFolderContentsAsync(string)
Task<IEnumerable<ResourceModelBase>>
Asynchronously retrieves all files and subfolders contained within the specified folder URI.
public virtual Task<IEnumerable<ResourceModelBase>> GetFolderContentsAsync(string uri)
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:
Uses a wildcard search pattern to include all file types and delegates to the overloaded GetFolderContents method.
Finds a resource by its uri and returns the information about it
public virtual Task<ResourceFileModel> GetModelAsync(string resourceUri)
The unique resource identifier (URI)
Returns:Task<ResourceFileModel>
Implements:
Retrieves metadata and information about a resource using its name-based identifier. The default implementation returns the result of the .
public virtual ResourceFileModel GetModelByName(string resourceName)
The full path to the resource using Name identifiers.
Returns:ResourceFileModel, containg the information about the resource.
Implements:
Reads the model of the given type T.
protected T GetModelCore<T>(string resourceUri) where T : ResourceFileModel, new()
T
Instance of T.
GetOrderedDefaultFoldersToCreate()
IEnumerable<CreateFolderModel>
Orders the default folders by their absolute paths to ensure parent directories are created before child directories.
protected override IEnumerable<CreateFolderModel> GetOrderedDefaultFoldersToCreate()
IEnumerable<CreateFolderModel>
An enumerable collection of CreateFolderModel objects ordered by their full absolute paths.
Overrides:
This ordering strategy guarantees that any non-existing parent folders are created before their children during initialization.
Moves an existing resource file from its current location to a new parent directory.
public virtual ResourceFileModel Move(MoveResourceModel model)
The move operation model containing the source resource URI and destination parent URI.
Returns:ResourceFileModel, containg the information about the folder
Implements:
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.
Moves a resource of the given type T to a new parent.
protected T MoveCore<T>(MoveResourceModel model) where T : ResourceFileModel, new()
T
Instance of T.
Moves an existing folder from its current location to a new parent directory, preserving all contents.
public virtual ResourceFolderModel MoveFolder(MoveFolderModel model)
The move operation model containing the source URI and destination parent URI.
Returns:A ResourceFolderModel representing the folder in its new location.
Implements:
Performs a complete directory move operation including all files and subdirectories within the source folder.
Overwrties the given resource contents with resource
public virtual ResourceFileModel Overwrite(OverwriteResourceModel model, byte[] resource)
The model containing the overwrite operation data
resourcebyte[]The new contents of the resource
Returns:ResourceFileModel, containg the information about the folder
Implements:
Overwrites the model of given type T using the provided bytes.
public T OverwriteCore<T>(OverwriteResourceModel model, byte[] resource) where T : ResourceFileModel, new()
T
Instance of T.
ArgumentNullException
Asynchronously renames an existing resource file to a new name while preserving its contents and location.
public virtual Task<ResourceFileModel> RenameAsync(RenameResourceModel 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:
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.
Renames a resource of the given type T.
protected T RenameCore<T>(RenameResourceModel model) where T : ResourceFileModel, new()
T
Instance of T.
Asynchronously renames an existing folder to a new name while preserving all contents and directory structure.
public virtual Task<ResourceFolderModel> RenameFolderAsync(RenameFolderModel 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:
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.
Determines whether a resource exists at the specified URI location within the resource storage.
public virtual bool ResourceExists(string resourceUri)
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:
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.
Determines whether a resource exists at the specified path using name-based identifiers.
public virtual bool ResourceNameExists(string resourceName)
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:
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[])
string
Creates new or overwrites an existing report resource file with the provided resource bytes.
[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)
The report resource filename including the file extension.
resourcebyte[]The new bytes of the report resource.
Returns:string
The location of the resource file.
Implements:
Saves the new bytes of a resource and returns the information about it.
public virtual Task<ResourceFileModel> SaveAsync(SaveResourceModel model, byte[] resource, bool forcePath)
The model containing the save operation data
resourcebyte[]The contents of the resource
forcePathboolDetermines whether the path to the resource will be created, if it does not exist, or an exception will be thrown.
Returns:Task<ResourceFileModel>
Exceptions:Saves the new bytes of a resource and returns the information about it.
public virtual Task<ResourceFileModel> SaveAsync(SaveResourceModel model, byte[] resource)
The model containing the save operation data
resourcebyte[]The contents of the resource
Returns:Task<ResourceFileModel>
Exceptions:Implements:
Saves the model of the given type T using the provided bytes.
protected T SaveCore<T>(SaveResourceModel model, byte[] resource, bool forcePath) where T : ResourceFileModel, new()
The model containing the save operation data
resourcebyte[]The contents of the resource
forcePathboolDetermines 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.
Search(SearchResourcesModel)
IEnumerable<ResourceModelBase>
Searches for resource in the given ResourceFolderUri
public virtual IEnumerable<ResourceModelBase> Search(SearchResourcesModel 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: