public static void RemoveRecentFiles(this FileSystemState fileSystemState, IEnumerable <string> encryptedPaths, ProgressContext progress) { progress.NotifyLevelStart(); progress.AddTotal(encryptedPaths.Count()); foreach (string encryptedPath in encryptedPaths) { ActiveFile activeFile = fileSystemState.FindEncryptedPath(encryptedPath); if (activeFile != null) { fileSystemState.Remove(activeFile); } progress.AddCount(1); } fileSystemState.Save(); progress.NotifyLevelFinished(); }
public static void TestWatchedFolders() { using (FileSystemState state = new FileSystemState()) { IRuntimeFileInfo stateInfo = OS.Current.FileInfo(_mystateXmlPath); state.Load(stateInfo); Assert.That(state.WatchedFolders, Is.Not.Null, "There should be a Watched Folders instance."); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders."); state.AddWatchedFolder(new WatchedFolder(_rootPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); state.AddWatchedFolder(new WatchedFolder(_rootPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still only be one Watched Folder."); state.Save(); } using (FileSystemState state = new FileSystemState()) { IRuntimeFileInfo stateInfo = OS.Current.FileInfo(_mystateXmlPath); state.Load(stateInfo); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); Assert.That(state.WatchedFolders.First(), Is.EqualTo(new WatchedFolder(_rootPath)), "The Watched Folder should be equal to this."); state.RemoveWatchedFolder(new WatchedFolder(_mystateXmlPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still be one Watched folders."); state.RemoveWatchedFolder(new WatchedFolder(_rootPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should still be no Watched folders now."); } }
public static void TestStatusMaskAtLoad() { using (FileSystemState state = new FileSystemState()) { state.Load(OS.Current.FileInfo(_mystateXmlPath)); ActiveFile activeFile = new ActiveFile(OS.Current.FileInfo(_encryptedAxxPath), OS.Current.FileInfo(_decryptedTxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, null); state.Add(activeFile); state.Save(); FileSystemState reloadedState = new FileSystemState(); reloadedState.Load(OS.Current.FileInfo(_mystateXmlPath)); Assert.That(reloadedState, Is.Not.Null, "An instance should always be instantiated."); Assert.That(reloadedState.ActiveFiles.Count(), Is.EqualTo(1), "The reloaded state should have one active file."); Assert.That(reloadedState.ActiveFiles.First().Status, Is.EqualTo(ActiveFileStatus.AssumedOpenAndDecrypted), "When reloading saved state, some statuses should be masked away."); } }
public static void TestLoadExisting() { ActiveFile activeFile; using (FileSystemState state = new FileSystemState()) { state.Load(OS.Current.FileInfo(_mystateXmlPath)); Assert.That(state, Is.Not.Null, "An instance should always be instantiated."); Assert.That(state.ActiveFiles.Count(), Is.EqualTo(0), "A new state should not have any active files."); activeFile = new ActiveFile(OS.Current.FileInfo(_encryptedAxxPath), OS.Current.FileInfo(_decryptedTxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted, null); state.Add(activeFile); state.Save(); } using (FileSystemState reloadedState = new FileSystemState()) { reloadedState.Load(OS.Current.FileInfo(_mystateXmlPath)); Assert.That(reloadedState, Is.Not.Null, "An instance should always be instantiated."); Assert.That(reloadedState.ActiveFiles.Count(), Is.EqualTo(1), "The reloaded state should have one active file."); Assert.That(reloadedState.ActiveFiles.First().ThumbprintMatch(activeFile.Key), Is.True, "The reloaded thumbprint should match the key."); } }
private static FileOperationStatus LaunchApplicationForDocument(FileSystemState fileSystemState, ActiveFile destinationActiveFile) { ILauncher process; try { if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Starting process for '{0}'".InvariantFormat(destinationActiveFile.DecryptedFileInfo.FullName)); } process = OS.Current.Launch(destinationActiveFile.DecryptedFileInfo.FullName); if (process.WasStarted) { process.Exited += new EventHandler(process_Exited); } else { if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Starting process for '{0}' did not start a process, assumed handled by the shell.".InvariantFormat(destinationActiveFile.DecryptedFileInfo.FullName)); } } } catch (Win32Exception w32ex) { if (OS.Log.IsErrorEnabled) { OS.Log.LogError("Could not launch application for '{0}', Win32Exception was '{1}'.".InvariantFormat(destinationActiveFile.DecryptedFileInfo.FullName, w32ex.Message)); } return FileOperationStatus.CannotStartApplication; } if (OS.Log.IsWarningEnabled) { if (process.HasExited) { OS.Log.LogWarning("The process seems to exit immediately for '{0}'".InvariantFormat(destinationActiveFile.DecryptedFileInfo.FullName)); } } if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Launched and opened '{0}'.".InvariantFormat(destinationActiveFile.DecryptedFileInfo.FullName)); } destinationActiveFile = new ActiveFile(destinationActiveFile, ActiveFileStatus.AssumedOpenAndDecrypted, process); fileSystemState.Add(destinationActiveFile); fileSystemState.Save(); return FileOperationStatus.Success; }