Пример #1
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);
            }
        }
Пример #2
0
        public SourceSetFingerprint([SuiteRoot] IFileSystemDirectory root, IEnumerable <SuiteRelativePath> files, Func <string, bool> exclusions, bool fullDependency)
        {
            Contract.Requires(root != null);
            Contract.Requires(files != null);

            this.fullDependency = fullDependency;
            fileNames           = new SortedSet <SuiteRelativePath>();
            lastModifiedDates   = new Dictionary <SuiteRelativePath, DateTime>();
            lastSizes           = new Dictionary <SuiteRelativePath, long>();

            foreach (var file in files)
            {
                if (exclusions == null || !exclusions(file))
                {
                    fileNames.Add(file);

                    if (fullDependency)
                    {
                        lastModifiedDates.Add(file, root.GetLastModifiedDate(file));
                        lastSizes.Add(file, root.GetFileSize(file));
                    }
                }
            }
        }