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); }
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); }