Class FileService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
Provides a concrete implementation of the IFileService contract for performing file-related operations.
public class FileService : IFileService
- Inheritance
-
FileService
- Implements
- Inherited Members
- Extension Methods
Constructors
FileService(IOptions<ApiSettings>, ILogger<FileService>)
public FileService(IOptions<ApiSettings> apiSettings, ILogger<FileService> logger)
Parameters
apiSettingsIOptions<ApiSettings>loggerILogger<FileService>
Methods
CopyUpdateFiles(ICollection<IFormFile>)
Copies the provided uploaded files into the configured update directory, creating each file on disk. Returns false if the update directory is not configured (null, empty, or whitespace); otherwise returns true after all files have been copied.
public Task<bool> CopyUpdateFiles(ICollection<IFormFile> files)
Parameters
filesICollection<IFormFile>The collection of uploaded form files to be written to the update directory.
Returns
- Task<bool>
A task that resolves to true when every file is successfully copied, or false when the update directory is not configured.
GetAllAssetFile(AssetTheme)
Retrieves all asset files from the subdirectory that matches the specified theme, creating the subdirectory if it does not exist. Returns an empty list when the assets directory is not configured or when an error occurs while reading the files.
public List<AssetDto> GetAllAssetFile(FileEnum.AssetTheme themeParse)
Parameters
themeParseFileEnum.AssetThemeThe theme used to locate the corresponding subdirectory within the assets directory.
Returns
- List<AssetDto>
A list of AssetDto objects containing the name, extension, and full path of each file found; an empty list if the assets directory is not configured or an error occurs.
GetFilesInDirectory(string)
Retrieves the list of file paths contained in the specified directory. If the directory does not exist, a warning is logged and an empty list is returned; if an error occurs during retrieval, it is logged and an empty list is returned.
public List<string> GetFilesInDirectory(string directoryPath)
Parameters
directoryPathstringThe path of the directory to search for files.
Returns
- List<string>
A list of file paths found in the directory, or an empty list if the directory does not exist or an error occurs.
UploadAssetFiles(ICollection<IFormFile>, AssetTheme)
Asynchronously uploads a collection of asset files into a directory organized by the specified theme. If the assets directory is not configured, the method returns false; otherwise, it ensures the target directory exists, writes each file to disk, and returns true.
public Task<bool> UploadAssetFiles(ICollection<IFormFile> files, FileEnum.AssetTheme themeParse)
Parameters
filesICollection<IFormFile>The collection of uploaded form files to persist to the assets directory.
themeParseFileEnum.AssetThemeThe asset theme used to determine the subdirectory in which the files will be stored.