public override int Read(byte[] buffer, int offset, int count) { int bytes = base.Read(buffer, offset, count); _progress.AddCount(bytes); return(bytes); }
public void AddCount(long count) { Interlocked.Add(ref _currentCount, count); _progress.AddCount(count); ThrowIfCancelled(); }
public virtual async Task RemoveRecentFiles(IEnumerable <IDataStore> encryptedPaths, IProgressContext progress) { if (encryptedPaths == null) { throw new ArgumentNullException("encryptedPaths"); } if (progress == null) { throw new ArgumentNullException("progress"); } progress.NotifyLevelStart(); try { progress.AddTotal(encryptedPaths.Count()); foreach (IDataStore encryptedPath in encryptedPaths) { ActiveFile activeFile = Resolve.FileSystemState.FindActiveFileFromEncryptedPath(encryptedPath.FullName); if (activeFile != null) { Resolve.FileSystemState.RemoveActiveFile(activeFile); } progress.AddCount(1); } await Resolve.FileSystemState.Save().Free(); } finally { progress.NotifyLevelFinished(); } }
/// <summary> /// Enumerate all files listed as active, checking for status changes and take appropriate actions such as updating status /// in the FileSystemState, re-encrypting or deleting temporary plaintext copies. /// </summary> /// <param name="_fileSystemState">The FileSystemState to enumerate and possibly update.</param> /// <param name="mode">Under what circumstances is the FileSystemState.Changed event raised.</param> /// <param name="progress">The ProgressContext to provide visual progress feedback via.</param> public virtual async Task CheckActiveFiles(IProgressContext progress) { if (progress == null) { throw new ArgumentNullException("progress"); } progress.NotifyLevelStart(); try { progress.AddTotal(Resolve.FileSystemState.ActiveFileCount); await Resolve.FileSystemState.ForEach(async (ActiveFile activeFile) => { try { activeFile = await CheckActiveFile(activeFile, progress).Free(); if (activeFile.Status == ActiveFileStatus.NotDecrypted && !activeFile.EncryptedFileInfo.IsAvailable) { activeFile = null; } return(activeFile); } finally { progress.AddCount(1); } }).Free(); } finally { progress.NotifyLevelFinished(); } }
public virtual async Task EncryptFoldersUniqueWithBackupAndWipeAsync(IEnumerable <IDataContainer> containers, EncryptionParameters encryptionParameters, IProgressContext progress) { if (containers == null) { throw new ArgumentNullException("containers"); } if (progress == null) { throw new ArgumentNullException("progress"); } progress.NotifyLevelStart(); try { List <IDataStore> files = new List <IDataStore>(); foreach (IDataContainer container in containers) { files.AddRange(await container.ListEncryptableWithWarningAsync(containers, New <UserSettings>().FolderOperationMode.Policy())); } progress.AddTotal(files.Count()); foreach (IDataStore file in files) { await EncryptFileUniqueWithBackupAndWipeAsync(file, encryptionParameters, progress); progress.AddCount(1); progress.Totals.AddFileCount(1); } } finally { progress.NotifyLevelFinished(); } }
public async Task ChangeEncryptionAsync(IEnumerable <IDataStore> files, LogOnIdentity identity, EncryptionParameters encryptionParameters, IProgressContext progress) { if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (files == null) { throw new ArgumentNullException(nameof(files)); } progress.AddTotal(files.Count()); foreach (IDataStore file in files) { await ChangeEncryptionAsync(file, identity, encryptionParameters, progress); progress.AddCount(1); } }
public virtual void Wipe(FileLock store, IProgressContext progress) { if (progress == null) { throw new ArgumentNullException("progress"); } if (store == null) { throw new ArgumentNullException("store"); } if (!store.DataStore.IsAvailable) { return; } if (Resolve.Log.IsInfoEnabled) { Resolve.Log.LogInfo("Wiping '{0}'.".InvariantFormat(store.DataStore.Name)); } progress.Cancel = false; bool cancelPending = false; progress.NotifyLevelStart(); try { string randomName; do { randomName = GenerateRandomFileName(store.DataStore.FullName); } while (New <IDataStore>(randomName).IsAvailable); IDataStore moveToFileInfo = New <IDataStore>(store.DataStore.FullName); moveToFileInfo.MoveTo(randomName); moveToFileInfo.IsWriteProtected = false; using (Stream stream = moveToFileInfo.OpenUpdate()) { long length = stream.Length + OS.Current.StreamBufferSize - stream.Length % OS.Current.StreamBufferSize; progress.AddTotal(length); for (long position = 0; position < length; position += OS.Current.StreamBufferSize) { byte[] random = Resolve.RandomGenerator.Generate(OS.Current.StreamBufferSize); stream.Write(random, 0, random.Length); stream.Flush(); try { progress.AddCount(random.Length); } catch (OperationCanceledException) { cancelPending = true; progress.AddCount(random.Length); } } } moveToFileInfo.Delete(); } finally { progress.NotifyLevelFinished(); } if (cancelPending) { throw new OperationCanceledException("Delayed cancel during wipe."); } }
public void AddCount(long count) { _progress.AddCount(count); }