src/T4Toolbox.VisualStudio/TransformationContextProvider.cs
/// <summary>
/// Writes generated content to output files and deletes the old files that were not regenerated.
/// </summary>
/// <param name="inputFile">
/// Full path to the template file.
/// </param>
/// <param name="outputFiles">
/// A collection of <see cref="OutputFile"/> objects produced by the template.
/// </param>
Writes generated content to output files and deletes the old files that were not regenerated.
Writes generated content to output files and deletes the old files that were not regenerated .
void ITransformationContextProvider.UpdateOutputFiles(string inputFile, OutputFile[] outputFiles)
        {
            if (inputFile == null)
            {
                throw new ArgumentNullException("inputFile");
            }
            if (!Path.IsPathRooted(inputFile))
            {
                throw new ArgumentException(Resources.InputFilePathMustBeAbsoluteMessage, "inputFile");
            }
            if (outputFiles == null)
            {
                throw new ArgumentNullException("outputFiles");
            }
            foreach (OutputFile newOutput in outputFiles)
            {
                if (newOutput == null)
                {
                    throw new ArgumentException(Resources.OutputFileIsNullMessage, "outputFiles");
                }
            }
            var manager = new OutputFileManager(this.serviceProvider, inputFile, outputFiles);
            manager.Validate();
            var watcher = new FileSystemWatcher();
            watcher.Path = Path.GetDirectoryName(inputFile);
            watcher.Filter = Path.GetFileNameWithoutExtension(inputFile) + "*." + this.GetTransformationOutputExtensionFromHost();
            FileSystemEventHandler runManager = (sender, args) =>
            {
                watcher.Dispose();
                OutputFile defaultOutput = outputFiles.FirstOrDefault(output => string.IsNullOrEmpty(output.File));
                if (defaultOutput != null)
                {
                    defaultOutput.File = Path.GetFileName(args.FullPath);
                }
                ThreadHelper.Generic.BeginInvoke(manager.DoWork);
            };
            watcher.Created += runManager;
            watcher.Changed += runManager;
            watcher.EnableRaisingEvents = true;
        }
void ITransformationContextProvider . UpdateOutputFiles ( string inputFile , OutputFile [ ] outputFiles ) { if ( inputFile == null ) { throw new ArgumentNullException ( " " ) ; } if ( ! Path . IsPathRooted ( inputFile ) ) { throw new ArgumentException ( Resources . InputFilePathMustBeAbsoluteMessage , " " ) ; } if ( outputFiles == null ) { throw new ArgumentNullException ( " " ) ; } foreach ( OutputFile newOutput in outputFiles ) { if ( newOutput == null ) { throw new ArgumentException ( Resources . OutputFileIsNullMessage , " " ) ; } } var manager = new OutputFileManager ( this . serviceProvider , inputFile , outputFiles ) ; manager . Validate ( ) ; var watcher = new FileSystemWatcher ( ) ; watcher . Path = Path . GetDirectoryName ( inputFile ) ; watcher . Filter = Path . GetFileNameWithoutExtension ( inputFile ) + " " + this . GetTransformationOutputExtensionFromHost ( ) ; FileSystemEventHandler runManager = ( sender , args ) => { watcher . Dispose ( ) ; OutputFile defaultOutput = outputFiles . FirstOrDefault ( output => string . IsNullOrEmpty ( output . File ) ) ; if ( defaultOutput != null ) { defaultOutput . File = Path . GetFileName ( args . FullPath ) ; } ThreadHelper . Generic . BeginInvoke ( manager . DoWork ) ; } ; watcher . Created += runManager ; watcher . Changed += runManager ; watcher . EnableRaisingEvents = true ; }
Writes generated content to output files and deletes the old files that were not regenerated.
Writes generated content to output files and deletes the old files that were not regenerated .
// Validate the output files immediately. Exceptions will be reported by the templating service. // Wait for the default output file to be generated // Store the actual output file name // Finish updating the output files on the UI thread
inputFile
string
Full path to the template file.
Full path to the template file .
outputFiles
OutputFile[]
A collection of  objects produced by the template.
A collection of objects produced by the template .