/// <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>
        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");
                }
            }

            // Validate the output files immediately. Exceptions will be reported by the templating service.
            var manager = new OutputFileManager(this.serviceProvider, inputFile, outputFiles);

            manager.Validate();

            // Wait for the default output file to be generated
            var watcher = new FileSystemWatcher();

            watcher.Path   = Path.GetDirectoryName(inputFile);
            watcher.Filter = Path.GetFileNameWithoutExtension(inputFile) + "*." + this.GetTransformationOutputExtensionFromHost();

            FileSystemEventHandler runManager = (sender, args) =>
            {
                watcher.Dispose();

                // Store the actual output file name
                OutputFile defaultOutput = outputFiles.FirstOrDefault(output => string.IsNullOrEmpty(output.File));
                if (defaultOutput != null)
                {
                    defaultOutput.File = Path.GetFileName(args.FullPath);
                }

                // Finish updating the output files on the UI thread
                ThreadHelper.Generic.BeginInvoke(manager.DoWork);
            };

            watcher.Created            += runManager;
            watcher.Changed            += runManager;
            watcher.EnableRaisingEvents = true;
        }
        /// <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>
        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");
                }
            }

            // Validate the output files immediately. Exceptions will be reported by the templating service.
            var manager = new OutputFileManager(this.serviceProvider, inputFile, outputFiles);
            manager.Validate();

            // Wait for the default output file to be generated
            var watcher = new FileSystemWatcher();
            watcher.Path = Path.GetDirectoryName(inputFile);
            watcher.Filter = Path.GetFileNameWithoutExtension(inputFile) + "*." + this.GetTransformationOutputExtensionFromHost();

            FileSystemEventHandler runManager = (sender, args) =>
            {
                watcher.Dispose();

                // Store the actual output file name
                OutputFile defaultOutput = outputFiles.FirstOrDefault(output => string.IsNullOrEmpty(output.File));
                if (defaultOutput != null)
                {
                    defaultOutput.File = Path.GetFileName(args.FullPath);
                }

                // Finish updating the output files on the UI thread
                ThreadHelper.Generic.BeginInvoke(manager.DoWork);
            };

            watcher.Created += runManager;
            watcher.Changed += runManager;
            watcher.EnableRaisingEvents = true;
        }