public async Task <Stats> Encrypt(Action <int> reporter) { try { using (var sourceStream = File.OpenRead(_sourceFilePath)) using (var destinationStream = File.OpenWrite(EncryptedFilePath)) { _cryptor.EncryptDestination = destinationStream; return(await CypherEngine.Encrypt(_cryptor, sourceStream, BUFFER_SIZE, new Progress <int>(reporter))); } } catch (Exception exception) { UIEx.ShowNotice("Exception", exception.Message); } return(new Stats()); }
private async void actionButton_Click(object sender, EventArgs e) { progressBar.Value = 0; //actionButton.Enabled = false; Action <int> reporter = progress => { progressBar.Value = progress; }; var stats = _decryptActivated ? await _model.Decrypt(reporter).ConfigureAwait(false) : await _model.Encrypt(reporter).ConfigureAwait(false); var seconds = stats.duration / 1000; var message = (_decryptActivated ? "Encryption" : "Decryption") + " Complete!"; UIEx.ShowNotice(message, "Duration: " + seconds.ToString() + " seconds."); //actionButton.Enabled = true; }