IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

How do I tell Intent Architect to ignore a file if it already exists? #7

Closed leonAtRain closed 1 year ago

leonAtRain commented 1 year ago

Ask a question

I have a file that I need to add initially - but thereafter I don't want Intent to modify the file - the version file in the root folder. The problem is that there is only the version number in the file - how do I let Intent know to ignore the file if it exists already?

garethbaars commented 1 year ago

Hi @leonAtRain,

To instruct the Software Factory Execution to once-off create a file from a template, you can set the OverwriteBehaviour in the GetTemplateFileConfig method. By default this is set to OverwriteBehaviour.Always, which instructs Intent Architect to continuously manage the file, but there are two other options:

  1. OverwriteBehaviour.OnceOff - Will only generate the file once ever and only if the file doesn't already exist. If the file is deleted for any reason, it is not generated again.

  2. OverwriteBehaviour.OverwriteDisabled - If a file already exists at the output path for the template instance, then it is NOT overwritten. If the template's output path has changed since the previous software factory execution AND no file exists at the new output path AND a file exists at the previous output path, then it is renamed/moved. If there is no longer any template instance outputting to the file output path, then it is deleted.

For example, if we wanted a Web.config file to be created once-off:

public override ITemplateFileConfig GetTemplateFileConfig()
{
    return new TemplateFileConfig(
        overwriteBehaviour: OverwriteBehaviour.OnceOff,
        codeGenType: CodeGenType.UserControlledWeave,
        fileName: "Web",
        fileExtension: "config",
        );
}

Let us know if that doesn't solve your problem.

leonAtRain commented 1 year ago

Good moring,

This is what I was looking for, and seeing that the file has no name, I've also implemented it like this:

 public override ITemplateFileConfig GetTemplateFileConfig()
        {
            return new TemplateFileConfig(
                overwriteBehaviour: OverwriteBehaviour.OnceOff,
                fileName: $"",
                fileExtension: "version"
            );
        }