コード例 #1
0
        public static void TestWipeWithConfirmAll()
        {
            ProgressContext          progress   = new ProgressContext();
            FileOperationsController controller = new FileOperationsController(_fileSystemState, progress);
            int confirmationCount = 0;

            controller.WipeQueryConfirmation += (object sender, FileOperationEventArgs e) =>
            {
                if (confirmationCount++ > 0)
                {
                    throw new InvalidOperationException("The event should not be raised a second time.");
                }
                e.ConfirmAll = true;
            };
            progress.NotifyLevelStart();
            FileOperationStatus status = controller.WipeFile(_helloWorldAxxPath);

            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The wipe should indicate success.");

            IRuntimeFileInfo fileInfo = OS.Current.FileInfo(_helloWorldAxxPath);

            Assert.That(!fileInfo.Exists, "The file should not exist after wiping.");

            Assert.DoesNotThrow(() => { status = controller.WipeFile(_davidCopperfieldTxtPath); });
            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The wipe should indicate success.");
            progress.NotifyLevelFinished();

            fileInfo = OS.Current.FileInfo(_davidCopperfieldTxtPath);
            Assert.That(!fileInfo.Exists, "The file should not exist after wiping.");
        }
コード例 #2
0
        public static void TestSimpleWipeOnThreadWorker()
        {
            FileOperationsController controller = new FileOperationsController(_fileSystemState);

            controller.WipeQueryConfirmation += (object sender, FileOperationEventArgs e) =>
            {
                e.Cancel     = false;
                e.Skip       = false;
                e.ConfirmAll = false;
            };

            string destinationPath     = String.Empty;
            FileOperationStatus status = FileOperationStatus.Unknown;

            controller.Completed += (object sender, FileOperationEventArgs e) =>
            {
                destinationPath = e.SaveFileFullName;
                status          = e.Status;
            };

            using (ThreadWorker worker = new ThreadWorker(new ProgressContext()))
            {
                controller.WipeFile(_davidCopperfieldTxtPath, worker);
            }
            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The status should indicate success.");

            IRuntimeFileInfo destinationInfo = OS.Current.FileInfo(destinationPath);

            Assert.That(!destinationInfo.Exists, "After wiping the destination file should not exist.");
        }
コード例 #3
0
        public static void TestWipeWithSkip()
        {
            FileOperationsController controller = new FileOperationsController(_fileSystemState);

            controller.WipeQueryConfirmation += (object sender, FileOperationEventArgs e) =>
            {
                e.Skip = true;
            };
            FileOperationStatus status = controller.WipeFile(_helloWorldAxxPath);

            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The wipe should indicate success even when skipping.");

            IRuntimeFileInfo fileInfo = OS.Current.FileInfo(_helloWorldAxxPath);

            Assert.That(fileInfo.Exists, "The file should still exist after wiping that was skipped during confirmation.");
        }
コード例 #4
0
        public static void TestSimpleWipe()
        {
            FileOperationsController controller = new FileOperationsController(_fileSystemState);

            controller.WipeQueryConfirmation += (object sender, FileOperationEventArgs e) =>
            {
                e.Cancel     = false;
                e.Skip       = false;
                e.ConfirmAll = false;
            };
            FileOperationStatus status = controller.WipeFile(_helloWorldAxxPath);

            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The wipe should indicate success.");

            IRuntimeFileInfo fileInfo = OS.Current.FileInfo(_helloWorldAxxPath);

            Assert.That(!fileInfo.Exists, "The file should not exist after wiping.");
        }
コード例 #5
0
        private void WipeFile(string file, IThreadWorker worker, ProgressContext progress)
        {
            FileOperationsController operationsController = new FileOperationsController(persistentState.Current, progress);

            operationsController.WipeQueryConfirmation += (object sender, FileOperationEventArgs e) =>
            {
                using (ConfirmWipeDialog cwd = new ConfirmWipeDialog())
                {
                    cwd.FileNameLabel.Text = Path.GetFileName(file);
                    DialogResult confirmResult = cwd.ShowDialog();
                    e.ConfirmAll = cwd.ConfirmAllCheckBox.Checked;
                    if (confirmResult == DialogResult.Yes)
                    {
                        e.Skip = false;
                    }
                    if (confirmResult == DialogResult.No)
                    {
                        e.Skip = true;
                    }
                    if (confirmResult == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                    }
                }
            };

            operationsController.Completed += (object sender, FileOperationEventArgs e) =>
            {
                if (CheckStatusAndShowMessage(e.Status, e.OpenFileFullName))
                {
                    if (!e.Skip)
                    {
                        persistentState.Current.RemoveRecentFiles(new string[] { e.SaveFileFullName }, progress);
                    }
                }
            };

            operationsController.WipeFile(file, worker);
        }