Overview
The Template Service provides functionality for renaming project templates by updating directory names, file names, and file contents throughout a project structure. Interface:ITemplateServiceImplementation:
ProjectTemplateServiceNamespace:
Chapi.Infrastructure.Services
Interface Definition
ITemplateService
Defines the contract for template operations.Methods
RenameTemplateAsync
Renames a project template by replacing all occurrences of the old name with the new name in directories, files, and file contents.The root directory path where the template is located
The current name to be replaced throughout the template
The new name that will replace the old name
Optional callback to receive progress updates during the renaming process
Returns a Result object indicating success or failure with error details
Implementation Details
TheProjectTemplateService implementation performs the following operations:
- Directory Renaming: Renames all directories containing the old name (bottom-up to preserve paths)
- Content Update: Replaces all occurrences of the old name in file contents
- File Renaming: Renames files that contain the old name in their filename
- Error Handling: Gracefully handles binary files and locked files by ignoring them
Usage Example
Progress Messages
The service reports the following progress updates:"Renombrando carpetas..."- When renaming directories"Renombrando archivos y actualizando contenido..."- When processing files"Contenido actualizado: {fileName}"- For each file that had content updated
Error Handling
The service returns a failed Result in the following cases:- Directory/File Access Errors: If the system cannot access or modify files
- Permission Issues: If the process lacks permissions to rename or modify
- General Exceptions: Any unexpected errors during the renaming process
"Error al renombrar plantilla: {message}"
Notes
- Binary and locked files are silently skipped during content updates
- Directory renaming is performed from deepest to shallowest to maintain path integrity
- File paths are re-scanned after directory renaming to account for path changes
- The operation runs asynchronously using
Task.Runto avoid blocking the UI thread