protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken token) { var entriesCount = 0; var foldersCount = 0; var filesCount = 0; var filePath = ZipFilePath.Get(context); if (!File.Exists(filePath)) { throw new FileNotFoundException(filePath); } await Task.Run(() => { using (var zip = ZipFile.Open(filePath, ZipArchiveMode.Read)) { entriesCount = zip.Entries.Count; foldersCount = zip.Entries.Count(entry => string.IsNullOrEmpty(entry.Name)); filesCount = entriesCount - foldersCount; } }).ConfigureAwait(false); return(ctx => { EntriesCount.Set(ctx, entriesCount); FilesCount.Set(ctx, filesCount); FoldersCount.Set(ctx, foldersCount); }); }
private void ReceiveFilesCount(FilesCount filesCount) { Application.Current.Dispatcher.BeginInvoke((ThreadStart)(() => { Sh2Count = filesCount.Sh2Count; Wh3Count = filesCount.Wh3Count; })); }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken token) { var zipFilePath = Path.GetFullPath(ZipFilePath.Get(context)); var toCompress = ToCompress.Get(context); var encoding = TextEncoding.Get(context); var counter = 0; if (toCompress is string) { toCompress = new string[] { toCompress.ToString() } } ; await Task.Run(() => { var paths = (IEnumerable <string>)toCompress; var directories = paths.Where(Directory.Exists); var files = paths.Except(directories) .Concat(directories.SelectMany(path => Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))) .Select(Path.GetFullPath) .Where(path => path != zipFilePath); var emptyFolders = directories.SelectMany(dir => Directory.EnumerateDirectories(dir, "*", SearchOption.AllDirectories)) .Select(Path.GetFullPath) .Where(path => !Directory.EnumerateFileSystemEntries(path).Any()); var entries = files.Concat(emptyFolders).OrderBy(path => path).ToArray(); var mode = File.Exists(zipFilePath) ? ZipArchiveMode.Update : ZipArchiveMode.Create; using (var zip = ZipFile.Open(zipFilePath, mode, encoding)) counter = CompressTo(zip, entries, mode, token, null); }, token).ConfigureAwait(false); return(ctx => FilesCount.Set(ctx, counter)); }
public void Update(FileObject file, float pourcentage, long bytesReceived, long totalBytes) { if (file == null) { return; } if (Updating) { return; } if (DateTime.Now.Subtract(LastUpdate).TotalMilliseconds > 1000) { Updating = true; LastUpdate = DateTime.Now; int y = Console.CursorTop; SetText("Downloading : " + AlignText(file.Path, 50, false), ConsoleColor.Yellow, 0, y + 1); SetText( "File : " + AlignText( CurrentFileIndex.ToString(CultureInfo.InvariantCulture) + "/" + FilesCount.ToString(CultureInfo.InvariantCulture), 50, false), ConsoleColor.Yellow, 0, y + 2); SetText("File Size : " + AlignText(HumanReadableByteCount(totalBytes), 50, false), ConsoleColor.Yellow, 0, y + 3); SetText("Downloaded : " + AlignText(HumanReadableByteCount(bytesReceived), 50, false), ConsoleColor.Yellow, 0, y + 4); SetText( "Pourcent : " + AlignText(pourcentage.ToString(CultureInfo.InvariantCulture) + "%", 50, false), ConsoleColor.Yellow, 0, y + 5); Console.CursorTop = y; Updating = false; } }