private async Task extractImageFilesAsync(IArchive archive, string extractDir) { await Task.Run(() => { foreach (var entry in archive.Entries) { if (SourceItem.IsTargetFile(entry)) { var dirPath = this.createParentDirectory(Path.GetDirectoryName(entry.Key), extractDir); Debug.WriteLine("extractImageFilesAsync" + entry.Key); entry.WriteToDirectory(dirPath); } } }).ConfigureAwait(false); }
internal async Task <bool> HasExtractError(ZipFileSettings zipSettings) { long total = 0; var sumBlock = new ActionBlock <IArchiveEntry>(async e => await Task.Run(() => total += e.Size), new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded }); var extractTasks = new List <Task>(); foreach (var imageSource in zipSettings.ImageSources) { if (imageSource.SourceKind.Value != ImageSourceType.File) { continue; } extractTasks.Add(Task.Run(() => { using (var archive = ArchiveFactory.Open(imageSource.Path.Value)) { imageSource.ArchiveEntryTotalCount = archive.Entries.Where(e => !e.IsDirectory).Count(); foreach (var entry in archive.Entries) { if (SourceItem.IsTargetFile(entry)) { imageSource.ArchiveEntryTargetCount++; sumBlock.Post(entry); } } } })); } await Task.WhenAll(extractTasks); sumBlock.Complete(); await sumBlock.Completion; var freeSpace = zipSettings.GetExtractPathFreeSpace(); return(total < freeSpace); }
private async Task <long> getArchiveEntrySourceSizeAsync(IArchive archive) { long totalSize = 0; await Task.Run(() => { foreach (var entry in archive.Entries) { if (SourceItem.IsTargetFile(entry)) { //Debug.WriteLine("getArchiveEntrySourceSizeAsync" + entry.Key); totalSize += entry.Size; } } }).ConfigureAwait(false); return(totalSize); }
internal bool HasExtractError(ZipFileSettings zipSettings) { long totalSize = 0; var watch = Stopwatch.StartNew(); Parallel.ForEach <ImageSource>(zipSettings.ImageSources, src => { Debug.WriteLine($"容量取得:{src.Path.Value}"); using (var archive = ArchiveFactory.Open(src.Path.Value)) { src.ArchiveEntryTotalCount = archive.Entries.Where(e => !e.IsDirectory).Count(); var entries = archive.Entries.Where(e => SourceItem.IsTargetFile(e)); src.ArchiveEntryTargetCount = entries.Count(); Parallel.ForEach <IArchiveEntry, long> ( entries, () => 0, (entry, state, local) => { local += entry.Size; //Debug.WriteLine($"容量取得(entry):{entry.Key}"); return(local); }, local => Interlocked.Add(ref totalSize, local) ); } }); var freeSpace = zipSettings.GetExtractPathFreeSpace(); watch.Stop(); // 圧縮ファイル内トータルサイズ取得:215[ms] // 圧縮ファイル内トータルサイズ取得(Debug.WriteLineあり):6828[ms] // 圧縮ファイル内トータルサイズ取得(Debug.WriteLineなし):221[ms] return(totalSize < freeSpace); }
//private async Task extractImageSourceAsync(ImageSource source, ImageAgent agent) private void extractImageSourceAsync(ImageSource source, ImageAgent agent) { //await Task.Run(async () => //{ using (var archive = ArchiveFactory.Open(source.Path.Value)) { var entries = archive.Entries.Where(e => SourceItem.IsTargetFile(e)); foreach (var e in entries) { var targetFolder = source.GetExtractedFolder(e.Key); e.WriteToDirectory(targetFolder.ItemPath); var extractedPath = this.getExtractedFilePath(e, targetFolder); targetFolder.Children.Add(new SourceItem(ImageFile.GetImageSpecification(extractedPath))); //targetFolder.Children.Add(new SourceItem(agent.GetImageSpecification(extractedPath))); //targetFolder.Children.Add(new SourceItem(await agent.GetImageSpecificationAsync(extractedPath))); } } //}); }
private void getExtractedFiles(string targetFolderPath) { if (!Directory.Exists(targetFolderPath)) { return; } var folder = new SourceItem(ImageSourceType.Folder, targetFolderPath); Directory.EnumerateDirectories(targetFolderPath).ToList().ForEach(d => { this.getExtractedFiles(d); }); foreach (var filePath in Directory.EnumerateFiles(targetFolderPath)) { if (SourceItem.IsTargetFile(filePath)) { continue; } } }