Exemplo n.º 1
0
 public void WriteTargetFile(ITargetFile file, string filePath)
 {
     if (file is TextFile textFile)
     {
         File.WriteAllText(filePath, textFile.Contents);
     }
     else
     {
         throw new Exception("Bad file writer.");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Copies the source file to destination file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="destination">The destination.</param>
        private static void CopySourceFileToDestinationFile(ITargetFile file, string destination)
        {
            //We assume that for most we will not have an existing file, and we will want to copy the target
            //to the destination.  We also need to ensure that if the directory that we want to copy into is
            //not there that we create it.
            FileInfo fileInfo = new FileInfo(destination);

            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }
            File.Copy(Path.Combine(Directory.GetCurrentDirectory(), file.source), destination);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Substitutes the specified target, basically a simple copy operation.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="directory">The directory.</param>
 public static void Substitute(ITargetFile target, string directory)
 {
     try
     {
         FileInfo file = new FileInfo(ResolveAndCopyDestinationFilename(target, directory, false));
         if (!Directory.Exists(file.DirectoryName))
         {
             Directory.CreateDirectory(file.DirectoryName);
         }
         File.Copy(target.source, file.FullName, true);
     }
     catch (Exception i)
     {
         throw new Exception("Failed to copy " + target.source + " to " + target.destination, i);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Check and modify source and destination file based on input and output directory existence, and a set of configuration values
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="file">The file.</param>
        private void CheckAndModifySourceAndDestination(RenderConfigConfig config, ITargetFile file)
        {
            //Check to see if we want to preserve the directory structure....
            file.source = CleansePlatformSpecificDirectoryMarkers(file.source);
            FileInfo t = new FileInfo(file.source);

            if (config.PreserveSourceStructure)
            {
                if (file.destination == null)
                {
                    file.destination = file.source;
                }
                else
                {
                    //TODO This is broken
                    if (file.source.IndexOf(t.Name) != Path.DirectorySeparatorChar)
                    {
                        char badSep = file.source[file.source.IndexOf(t.Name)];
                        file.source.Replace(badSep, Path.DirectorySeparatorChar);
                    }
                    file.destination = Path.Combine(file.source.Replace(t.Name, string.Empty), file.destination);
                }
            }

            //Now check to see if the input directory has been provided, and modify the file object to represent the change of relative path if so
            if (config.InputDirectory != null)
            {
                file.source = Path.Combine(config.InputDirectory, file.source);
            }
            else
            {
                file.source = t.FullName;
            }

            LogUtilities.LogTargetFileHeader(file.source, file.destination, config.InputDirectory, config.OutputDirectory, log);

            //Check if it exists now...
            if (!File.Exists(file.source))
            {
                throw new Exception("Could not find source file " + file.source);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the target file based on the source file and the target output directory. Takes into account InputDirectory and PreserveStructure flags.
        /// </summary>
        /// <param name="file">The TargetFile object we are using.</param>
        /// <param name="configDirectory">The config directory.</param>
        /// <param name="copyFile">if set to <c>true</c> [copy file], otherwise if the file is not in place it will not be copied.</param>
        /// <returns></returns>
        public static string ResolveAndCopyDestinationFilename(ITargetFile file, string configDirectory, Boolean copyFile)
        {
            string destination;

            //First, are we just dropping the file into the target root directory with the same name?
            //We need to sort out what the target filename is if we are not passing one in.
            if (String.IsNullOrEmpty(file.destination))
            {
                FileInfo fileInfo = new FileInfo(file.source);
                destination = Path.Combine(configDirectory, fileInfo.Name);
            }
            else
            {
                destination = Path.Combine(configDirectory, file.destination);
            }

            //Copy over the file if it does not already exist.  If it exists, odds on a configuration has already run...
            if (!File.Exists(destination) && copyFile)
            {
                CopySourceFileToDestinationFile(file, destination);
            }

            return(destination);
        }
Exemplo n.º 6
0
 public void AddFile(ITargetFile file)
 {
     Files.Add(file);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Check and modify source and destination file based on input and output directory existence, and a set of configuration values
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="file">The file.</param>
        private void CheckAndModifySourceAndDestination(RenderConfigConfig config, ITargetFile file)
        {
            //Check to see if we want to preserve the directory structure....
            file.source = CleansePlatformSpecificDirectoryMarkers(file.source);
			FileInfo t = new FileInfo(file.source);
            if (config.PreserveSourceStructure)
            {
                 if (file.destination == null)
                {
                    file.destination = file.source;
                }
                else
                {
					//TODO This is broken
					if (file.source.IndexOf(t.Name) != Path.DirectorySeparatorChar)
					{
						char badSep = file.source[file.source.IndexOf(t.Name)];
						file.source.Replace(badSep,Path.DirectorySeparatorChar);
					}
                    file.destination = Path.Combine(file.source.Replace(t.Name, string.Empty), file.destination);
                }
            }

            //Now check to see if the input directory has been provided, and modify the file object to represent the change of relative path if so
            if (config.InputDirectory != null)
            {
                file.source = Path.Combine(config.InputDirectory, file.source);
            }
			else
			{
				file.source = t.FullName;
			}

            LogUtilities.LogTargetFileHeader(file.source, file.destination, config.InputDirectory,config.OutputDirectory, log);

            //Check if it exists now...
            if (!File.Exists(file.source))
            {
                throw new Exception("Could not find source file " + file.source);
            }
        }
        /// <summary>
        /// Gets the target file based on the source file and the target output directory. Takes into account InputDirectory and PreserveStructure flags.
        /// </summary>
        /// <param name="file">The TargetFile object we are using.</param>
        /// <param name="configDirectory">The config directory.</param>
        /// <param name="copyFile">if set to <c>true</c> [copy file], otherwise if the file is not in place it will not be copied.</param>
        /// <returns></returns>
        public static string ResolveAndCopyDestinationFilename(ITargetFile file, string configDirectory, Boolean copyFile)
        {
            string destination;

            //First, are we just dropping the file into the target root directory with the same name?
            //We need to sort out what the target filename is if we are not passing one in.
            if (String.IsNullOrEmpty(file.destination))
            {
                FileInfo fileInfo = new FileInfo(file.source);
                destination = Path.Combine(configDirectory, fileInfo.Name);
            }
            else
            {
                destination = Path.Combine(configDirectory, file.destination);
            }

            //Copy over the file if it does not already exist.  If it exists, odds on a configuration has already run...
            if (!File.Exists(destination) && copyFile)
            {
                CopySourceFileToDestinationFile(file, destination);
            }

            return destination;
        }
 /// <summary>
 /// Copies the source file to destination file.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="destination">The destination.</param>
 private static void CopySourceFileToDestinationFile(ITargetFile file, string destination)
 {
     //We assume that for most we will not have an existing file, and we will want to copy the target
     //to the destination.  We also need to ensure that if the directory that we want to copy into is 
     //not there that we create it.
     FileInfo fileInfo = new FileInfo(destination);
     if (!Directory.Exists(fileInfo.DirectoryName))
     {
         Directory.CreateDirectory(fileInfo.DirectoryName);
     }
     File.Copy(Path.Combine(Directory.GetCurrentDirectory(), file.source), destination);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Substitutes the specified target, basically a simple copy operation.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="directory">The directory.</param>
 public static void Substitute(ITargetFile target, string directory)
 {
     try
     {
         FileInfo file = new FileInfo(ResolveAndCopyDestinationFilename(target, directory, false));
         if (!Directory.Exists(file.DirectoryName))
         {
             Directory.CreateDirectory(file.DirectoryName);
         }
         File.Copy(target.source, file.FullName, true);
     }
     catch (Exception i)
     {
         throw new Exception("Failed to copy " + target.source + " to " + target.destination, i);
     }
 }