Exemple #1
0
        private IEnumerable <FileStream> AddFiles(ModuleBuilder moduleBuilder, FileSearchTemplate template, bool compareLatest, DirectoryInfo lastVersionDirectoryPath)
        {
            var files             = new List <FileStream>();
            var excludedFileNames = GetExcludedFileNames(ExcludedFiles);

            if (template.Directory.Exists)
            {
                foreach (var fileInfo in template.Directory.GetFiles(template.Pattern, template.SearchOption))
                {
                    if (!ExcludedContains(fileInfo, excludedFileNames))
                    {
                        var file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);
                        if (compareLatest)
                        {
                            FileInfo latestFilePath = new FileInfo(Path.Combine(lastVersionDirectoryPath.FullName, fileInfo.Name));
                            if (latestFilePath.Exists)
                            {
                                using (var latestFile = new FileStream(latestFilePath.FullName, FileMode.Open, FileAccess.Read))
                                {
                                    if (!file.AreEqual(latestFile))
                                    {
                                        AddFile(moduleBuilder, fileInfo, file, files);
                                    }
                                    else
                                    {
                                        file.Close();
                                    }
                                }
                            }
                            else
                            {
                                AddFile(moduleBuilder, fileInfo, file, files);
                            }
                        }
                        else
                        {
                            AddFile(moduleBuilder, fileInfo, file, files);
                        }
                    }
                }
            }

            return(files);
        }
        private IEnumerable<FileStream> AddFiles(ModuleBuilder moduleBuilder, FileSearchTemplate template, bool compareLatest, DirectoryInfo lastVersionDirectoryPath)
        {
            var files = new List<FileStream>();
            var excludedFileNames = GetExcludedFileNames(ExcludedFiles);
            if (template.Directory.Exists)
            {
                foreach (var fileInfo in template.Directory.GetFiles(template.Pattern, template.SearchOption))
                {
                    if (!ExcludedContains(fileInfo, excludedFileNames))
                    {
                        var file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);
                        if (compareLatest)
                        {
                            FileInfo latestFilePath = new FileInfo(Path.Combine(lastVersionDirectoryPath.FullName, fileInfo.Name));
                            if (latestFilePath.Exists)
                            {
                                using (var latestFile = new FileStream(latestFilePath.FullName, FileMode.Open, FileAccess.Read))
                                {
                                    if (!file.AreEqual(latestFile))
                                    {
                                        AddFile(moduleBuilder, fileInfo, file, files);
                                    }
                                    else
                                    {
                                        file.Close();
                                    }
                                }
                            }
                            else
                            {
                                AddFile(moduleBuilder, fileInfo, file, files);
                            }
                        }
                        else
                        {
                            AddFile(moduleBuilder, fileInfo, file, files);
                        }
                    }
                }
            }

            return files;
        }