Esempio n. 1
0
        /// <summary>
        /// Returns the list of added files in other, removed files in other, etc. compared to this.
        /// </summary>
        /// <returns>A set of FolderDifferences. A folder difference of FileAdded means that Other has an added file compared to This, and vice-versa.</returns>
        public IEnumerable <FolderDifference> DiffAgainst(FolderEnumeration other)
        {
            var thisRoot  = this.FolderPath;
            var otherRoot = other.FolderPath;

            var thisFolderPaths  = RelativeFolderPaths.ToArray();
            var otherFolderPaths = other.RelativeFolderPaths.ToArray();

            //  TODO - Use hash map to avoid N^2 iteration via .Contains()
            var thisFilePaths  = RelativeFilePaths.ToArray();
            var otherFilePaths = other.RelativeFilePaths.ToArray();

            var missingFoldersInOther = thisFolderPaths.Where(tp => !otherFolderPaths.Contains(tp)).ToArray();
            var newFoldersInOther     = otherFolderPaths.Where(op => !thisFolderPaths.Contains(op)).ToArray();

            var missingFilesInOther = thisFilePaths.Where(tp => !otherFilePaths.Contains(tp)).ToArray();
            var newFilesInOther     = otherFilePaths.Where(op => !thisFilePaths.Contains(op)).ToArray();

            string FullOtherPath(string inputPath)
            {
                return(Path.GetFullPath(Path.Combine(other.FolderPath, inputPath)));
            }

            foreach (var missingFolder in missingFoldersInOther)
            {
                yield return new FolderDifference {
                           AbsolutePath = FullOtherPath(missingFolder), Type = FolderDifference.DifferenceType.FolderMissing
                }
            }
            ;

            foreach (var newFolder in newFoldersInOther)
            {
                yield return new FolderDifference {
                           AbsolutePath = FullOtherPath(newFolder), Type = FolderDifference.DifferenceType.FolderAdded
                }
            }
            ;

            foreach (var missingFile in missingFilesInOther)
            {
                yield return new FolderDifference {
                           AbsolutePath = FullOtherPath(missingFile), Type = FolderDifference.DifferenceType.FileMissing
                }
            }
            ;

            foreach (var newFile in newFilesInOther)
            {
                yield return new FolderDifference {
                           AbsolutePath = FullOtherPath(newFile), Type = FolderDifference.DifferenceType.FileAdded
                }
            }
            ;
        }
    }
}
        private void ProcessFile(string fileTempPath)
        {
            using (var image = Image.FromFile(fileTempPath))
                using (var newImage = image.ResizeImage(maxDimensions))
                {
                    var filePath = MakeDirPath(fileTempPath);
                    newImage.SaveJPeg(filePath, 90);
                    RelativeFilePaths.Add(filePath.Substring(_configuration.BasePath.Length + 1));
                    FullPaths.Add(filePath);
                }

            // remove the temp file.
            File.Delete(fileTempPath);
        }