Class ResourceStorage
Provides file system-based resource storage for managing report assets in a local directory structure.
Inherited Members
Namespace: Telerik.WebReportDesigner.Services
Assembly: Telerik.WebReportDesigner.Services.dll
Syntax
public class ResourceStorage : ResourceStorageBase, IResourceStorage, IAssetsStorage, IHasBaseDir
Remarks
Implements comprehensive resource management including folder operations, file operations, and security validation with support for excluded directories.
Constructors
ResourceStorage(String)
Initializes a new ResourceStorage instance with the specified base directory and default folder configuration.
Declaration
public ResourceStorage(string baseDir)
Parameters
|
System.String
baseDir
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, 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
|
System.String
baseDir
The base directory path where report resources will be stored and managed. |
|
System.Collections.Generic.Dictionary<System.String, System.String>
extensionDirectories
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
|
System.String
baseDir
The base directory path where report resources will be stored and managed. |
|
System.String[]
excludedFolders
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).
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
|
System.String
baseDir
The base directory path where report resources will be stored and managed. |
|
CreateFolderModel[]
defaultFolders
Array of folder models that define which default folders will be created during initialization. |
|
System.String[]
excludedFolders
Array of relative folder paths to exclude from folder content operations; wildcards are not supported. |
Remarks
This is the primary constructor that provides complete control over storage configuration and folder management behavior.
Exceptions
|
System.ArgumentNullException
Thrown when defaultFolders parameter is null. |
Fields
RootFolderName
Gets the standard name used for the root resources folder in the file system.
Declaration
public const string RootFolderName = "Resources"
Field Value
|
System.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
|
System.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
|
CreateFolderModel
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
|
System.String[]
relativePaths
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
|
CreateFolderModel
model
The folder creation model containing the folder name and parent URI where it should be created. |
Returns
|
System.Threading.Tasks.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
|
System.String
uri
The unique resource identifier (URI) |
Returns
|
System.Threading.Tasks.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
|
System.String
uri
The unique resource identifier of the folder to delete; cannot be null, empty, or represent the root directory. |
Returns
|
System.Threading.Tasks.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
|
System.String
uri
The unique resource identifier of the folder to check; cannot be null or empty. |
Returns
|
System.Boolean
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
|
System.String
uri
The unique resource identifier of the folder to check for contents. |
Returns
|
System.Boolean
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
|
System.String
folderName
The folder path using name identifiers rather than URI format. |
Returns
|
System.Boolean
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
|
System.String[]
extensions
Array of file extension patterns to search for, supporting wildcards (* and ?) but not regular expressions. |
Returns
|
System.Collections.Generic.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
|
System.String
resourceName
The complete filename of the resource including its extension (e.g., "image.png", "style.css"). |
Returns
|
System.Threading.Tasks.Task<System.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
|
System.String
resourceUri
The unique resource identifier of the file to retrieve; cannot be null or empty. |
Returns
|
System.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
|
System.String
resourceUri
The unique resource identifier of the file to retrieve; cannot be null or empty. |
Returns
|
ResourceFileDataModel
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
|
System.String
uri
The unique resource identifier; null or empty string represents the root directory. |
Returns
|
System.Threading.Tasks.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
|
System.String
folderName
The folder path using name identifiers rather than URI format. |
Returns
|
ResourceFolderModel
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
|
System.String
uri
The unique resource identifier of the folder; null or empty string represents the root BaseDir directory. |
|
System.String[]
searchPattern
Array of search patterns to filter files, supporting wildcards (* and ?) but not regular expressions. |
Returns
|
System.Collections.Generic.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
|
System.String
uri
The unique resource identifier of the folder; null or empty string represents the root BaseDir directory. |
Returns
|
System.Threading.Tasks.Task<System.Collections.Generic.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
|
System.String
resourceUri
The unique resource identifier (URI) |
Returns
|
System.Threading.Tasks.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 Telerik.WebReportDesigner.Services.ResourceStorage.GetModel(System.String).
Declaration
public virtual ResourceFileModel GetModelByName(string resourceName)
Parameters
|
System.String
resourceName
The full path to the resource using Name identifiers. |
Returns
|
ResourceFileModel
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
|
System.String
resourceUri
|
Returns
|
T
Instance of |
Type Parameters
|
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
|
System.Collections.Generic.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
|
MoveResourceModel
model
The move operation model containing the source resource URI and destination parent URI. |
Returns
|
ResourceFileModel
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
|
MoveResourceModel
model
|
Returns
|
T
Instance of |
Type Parameters
|
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
|
MoveFolderModel
model
The move operation model containing the source URI and destination parent URI. |
Returns
|
ResourceFolderModel
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
|
OverwriteResourceModel
model
The model containing the overwrite operation data |
|
System.Byte[]
resource
The new contents of the resource |
Returns
|
ResourceFileModel
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
|
OverwriteResourceModel
model
|
|
System.Byte[]
resource
|
Returns
|
T
Instance of |
Type Parameters
|
T
|
Exceptions
|
System.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
|
RenameResourceModel
model
The rename operation model containing the current resource URI and the new file name. |
Returns
|
System.Threading.Tasks.Task<ResourceFileModel>
ResourceFileModel, containg the information about the folder |
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.
Exceptions
|
InvalidResourceNameException
Thrown when the model is null, the new resource name is null/empty, or the old URI is null/empty. |
RenameCore<T>(RenameResourceModel)
Renames a resource of the given type T.
Declaration
protected T RenameCore<T>(RenameResourceModel model)
where T : ResourceFileModel, new()
Parameters
|
RenameResourceModel
model
|
Returns
|
T
Instance of |
Type Parameters
|
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
|
RenameFolderModel
model
The rename operation model containing the current folder URI and the new folder name. |
Returns
|
System.Threading.Tasks.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
|
System.String
resourceUri
The unique resource identifier of the resource to check; cannot be null or empty. |
Returns
|
System.Boolean
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
|
System.String
resourceName
The full resource path using name identifiers rather than URI format. |
Returns
|
System.Boolean
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
|
System.String
resourceName
The report resource filename including the file extension. |
|
System.Byte[]
resource
The new bytes of the report resource. |
Returns
|
System.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
|
SaveResourceModel
model
The model containing the save operation data |
|
System.Byte[]
resource
The contents of the resource |
Returns
|
System.Threading.Tasks.Task<ResourceFileModel>
|
Implements
Exceptions
|
InvalidResourceNameException
|
SaveAsync(SaveResourceModel, Byte[], Boolean)
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
|
SaveResourceModel
model
The model containing the save operation data |
|
System.Byte[]
resource
The contents of the resource |
|
System.Boolean
forcePath
Determines whether the path to the resource will be created, if it does not exist, or an exception will be thrown. |
Returns
|
System.Threading.Tasks.Task<ResourceFileModel>
|
Exceptions
|
InvalidResourceNameException
|
SaveCore<T>(SaveResourceModel, Byte[], Boolean)
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
|
SaveResourceModel
model
The model containing the save operation data |
|
System.Byte[]
resource
The contents of the resource |
|
System.Boolean
forcePath
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 |
Type Parameters
|
T
|
Exceptions
|
ResourceAlreadyExistsException
|
Search(SearchResourcesModel)
Searches for resource in the given ResourceFolderUri
Declaration
public virtual IEnumerable<ResourceModelBase> Search(SearchResourcesModel model)
Parameters
|
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
|
System.Collections.Generic.IEnumerable<ResourceModelBase>
The search results, both files and folders, as an enumerable of ResourceModelBase |