Amido.PreProcessor.Cmd.TokenisationRunner.ProcessSingleTemplate C# (CSharp) Method

ProcessSingleTemplate() public method

public ProcessSingleTemplate ( string>.IDictionary properties, string sourceFile, string destinationFile ) : void
properties string>.IDictionary
sourceFile string
destinationFile string
return void
        public void ProcessSingleTemplate(IDictionary<string, string> properties, string sourceFile, string destinationFile)
        {
            Args.NotNull(properties, "properties");
            Args.NotNullOrEmpty(sourceFile, "sourceFile");

            try
            {
                sourceFile = TryReplace(properties, sourceFile);
                destinationFile = TryReplace(properties, destinationFile);

                if (!this.fileSystem.FileExists(sourceFile)) throw new FileNotFoundException(string.Format("SourceFile not found at {0}.", sourceFile));

                if (null == destinationFile)
                {
                    if (!sourceFile.EndsWith(TemplateFileExtension))
                    {
                        throw new InvalidOperationException(string.Format("Unable to use convention to derive the Destination file path because the source path does not end in '{1}'.  Source file path is {0}.", sourceFile, TemplateFileExtension));
                    }

                    destinationFile = sourceFile.Substring(0, sourceFile.Length - TemplateFileExtension.Length);
                    log.DebugFormat("Derived destination file for source {0} is {1}.", sourceFile, destinationFile);
                }

                var template = this.fileSystem.ReadAllText(sourceFile);

                template = this.TryReplace(properties, template);

                var destinationDirectory = this.fileSystem.GetDirectoryFullPath(destinationFile);
                if (!this.fileSystem.DirectoryExists(destinationDirectory))
                {
                    log.DebugFormat("Creating directory{0}...", destinationDirectory);
                    this.fileSystem.CreateDirectory(destinationDirectory);
                }

                this.fileSystem.WriteAllText(destinationFile, template);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Error occurred while processing template {0} and destination file {1}.  Please refer to inner exception for details.",
                        sourceFile, destinationFile), ex);
            }
        }