protected override void ProcessRecordCore()
{
if ((!string.IsNullOrEmpty(OutputPath)) && Path.IsPathRooted(OutputPath)) {
WriteError(string.Format("Invalid OutputPath '{0}' - must be a relative path, e.g., Models\\Person.cs", OutputPath ?? ""));
return;
}
var project = SolutionManager.GetProject(string.IsNullOrEmpty(Project) ? SolutionManager.DefaultProjectName : Project);
if (project == null) {
WriteError(string.Format("Could not find project '{0}'", Project ?? string.Empty));
return;
}
TemplateRenderingResult result = GetTemplateOutput(project, _fileSystem, Template, OutputPath, Model, Force);
if (result.SkipBecauseFileExists) {
WriteWarning(string.Format("{0} already exists! Pass -Force to overwrite. Skipping...", result.ProjectRelativeOutputPathWithExtension));
} else if ((result.Errors != null) && result.Errors.HasErrors) {
WriteObject(result.Errors.Cast<CompilerError>().OrderBy(x => x.Line));
WriteError("Failed to render template");
} else if (string.IsNullOrEmpty(result.Content)) {
WriteWarning(string.Format("Template '{0}' produced no output. Skipping...", Template));
} else {
if (result.ExistingProjectItemToOverwrite != null) {
// Overwrite existing item and report its path
OverwriteProjectItemTextContent(result.ExistingProjectItemToOverwrite, result.Content);
WriteObject(result.ProjectRelativeOutputPathWithExtension);
} else if (!string.IsNullOrEmpty(result.ProjectRelativeOutputPathWithExtension)) {
// Create new item and report its path
AddTextFileToProject(project, _fileSystem, result.ProjectRelativeOutputPathWithExtension, result.Content);
WriteObject(result.ProjectRelativeOutputPathWithExtension);
} else {
// Just return the template's text output
WriteObject(result.Content);
}
}
}