예제 #1
0
        /// <summary>
        /// Copies a source file to a target location, but only if it does not exist yet, with the same MD5 checksum
        /// as the source
        /// </summary>
        /// <param name="sourceDirectory">Source root directory</param>
        /// <param name="sourceFileName">Source file's relative path</param>
        /// <param name="targetRoot">Target root directory</param>
        /// <param name="targetRelativePath">Target file's relative path</param>
        private void CopyIfDifferent(IFileSystemDirectory sourceDirectory, string sourceFileName, IFileSystemDirectory targetRoot, string targetRelativePath)
        {
            bool copy       = true;
            long sourceSize = sourceDirectory.GetFileSize(sourceFileName);

            if (targetRoot.Exists(targetRelativePath))
            {
                long targetSize = targetRoot.GetFileSize(targetRelativePath);
                if (sourceSize == targetSize)
                {
                    byte[] sourceChecksum = ComputeChecksum(sourceDirectory, sourceFileName);
                    byte[] targetChecksum = ComputeChecksum(targetRoot, targetRelativePath);

                    copy = !sourceChecksum.SequenceEqual(targetChecksum);
                }
            }

            if (copy)
            {
                using (var source = sourceDirectory.ReadBinaryFile(sourceFileName))
                    using (var target = targetRoot.CreateBinaryFileWithDirectories(targetRelativePath))
                        StreamOperations.Copy(source, target);
            }
            else
            {
                log.DebugFormat("File {0} is the same as the cached one", targetRelativePath);
            }
        }
예제 #2
0
        /// <summary>
        /// Copy a file to a target directory
        /// </summary>
        /// <param name="name">Name of the file</param>
        /// <param name="target">Target file system directory</param>
        /// <param name="targetName">Name (relative path) in the target directory</param>
        public void CopyFile(string name, IFileSystemDirectory target, string targetName)
        {
            var localTarget = target as LocalFileSystemDirectory;

            if (localTarget != null)
            {
                var targetSubdir = Path.GetDirectoryName(targetName);

                if (!String.IsNullOrWhiteSpace(targetSubdir))
                {
                    var absoluteTargetDir = Path.Combine(localTarget.AbsolutePath, targetSubdir);
                    if (!Directory.Exists(absoluteTargetDir))
                    {
                        Directory.CreateDirectory(absoluteTargetDir);
                    }
                }

                File.Copy(Path.Combine(path, name), Path.Combine(localTarget.AbsolutePath, targetName), overwrite: true);
            }
            else
            {
                using (var sourceStream = ReadBinaryFile(name))
                    using (var targetStream = target.CreateBinaryFileWithDirectories(targetName))
                        StreamOperations.Copy(sourceStream, targetStream);
            }
        }
예제 #3
0
        /// <summary>
        /// Copy a file to a target directory
        /// </summary>
        /// <param name="name">Name of the file</param>
        /// <param name="target">Target file system directory</param>
        /// <param name="targetName">Name (relative path) in the target directory</param>
        public void CopyFile(string name, IFileSystemDirectory target, string targetName)
        {
            var localTarget = target as LocalFileSystemDirectory;

            if (localTarget != null)
            {
                var targetSubdir = Path.GetDirectoryName(targetName);

                if (!String.IsNullOrWhiteSpace(targetSubdir))
                {
                    var absoluteTargetDir = Path.Combine(localTarget.AbsolutePath, targetSubdir);
                    if (!Directory.Exists(absoluteTargetDir))
                    {
                        Directory.CreateDirectory(absoluteTargetDir);
                    }
                }

                var copy = true;
                if (target.Exists(targetName))
                {
                    var sourceSize = GetFileSize(name);
                    var targetSize = target.GetFileSize(targetName);
                    var sourceDate = GetLastModifiedDate(name);
                    var targetDate = target.GetLastModifiedDate(targetName);

                    copy = sourceSize != targetSize || !sourceDate.Equals(targetDate);
                }

                if (copy)
                {
                    File.Copy(Path.Combine(path, name), Path.Combine(localTarget.AbsolutePath, targetName), overwrite: true);
                }
            }
            else
            {
                using (var sourceStream = ReadBinaryFile(name))
                    using (var targetStream = target.CreateBinaryFileWithDirectories(targetName))
                        StreamOperations.Copy(sourceStream, targetStream);
            }
        }
예제 #4
0
 private void Copy(TargetRelativePath sourcePath, string relativePath)
 {
     using (var source = targetRoot.ReadBinaryFile(sourcePath))
         using (var target = targetDirectory.CreateBinaryFileWithDirectories(relativePath))
             StreamOperations.Copy(source, target);
 }
예제 #5
0
        /// <summary>
        /// Copies a source file to a target location, but only if it does not exist yet, with the same MD5 checksum
        /// as the source
        /// </summary>
        /// <param name="sourceDirectory">Source root directory</param>
        /// <param name="sourceFileName">Source file's relative path</param>
        /// <param name="targetRoot">Target root directory</param>
        /// <param name="targetRelativePath">Target file's relative path</param>
        private void CopyIfDifferent(IFileSystemDirectory sourceDirectory, string sourceFileName, IFileSystemDirectory targetRoot, string targetRelativePath)
        {
            bool copy = true;
            long sourceSize = sourceDirectory.GetFileSize(sourceFileName);
            if (targetRoot.Exists(targetRelativePath))
            {
                long targetSize = targetRoot.GetFileSize(targetRelativePath);
                if (sourceSize == targetSize)
                {
                    byte[] sourceChecksum = ComputeChecksum(sourceDirectory, sourceFileName);
                    byte[] targetChecksum = ComputeChecksum(targetRoot, targetRelativePath);

                    copy = !sourceChecksum.SequenceEqual(targetChecksum);
                }
            }

            if (copy)
            {
                using (var source = sourceDirectory.ReadBinaryFile(sourceFileName))
                using (var target = targetRoot.CreateBinaryFileWithDirectories(targetRelativePath))
                    StreamOperations.Copy(source, target);
            }
            else
            {
                log.DebugFormat("File {0} is the same as the cached one", targetRelativePath);
            }
        }