| 1 | using System; |
|---|
| 2 | using System.Collections.Generic; |
|---|
| 3 | using System.ComponentModel; |
|---|
| 4 | using System.Data; |
|---|
| 5 | using System.Drawing; |
|---|
| 6 | using System.Text; |
|---|
| 7 | using System.Windows.Forms; |
|---|
| 8 | |
|---|
| 9 | using Eraser.Manager; |
|---|
| 10 | using Eraser.Util; |
|---|
| 11 | |
|---|
| 12 | namespace Eraser |
|---|
| 13 | { |
|---|
| 14 | public partial class ProgressForm : Form |
|---|
| 15 | { |
|---|
| 16 | private Task task; |
|---|
| 17 | |
|---|
| 18 | public ProgressForm(Task task) |
|---|
| 19 | { |
|---|
| 20 | InitializeComponent(); |
|---|
| 21 | this.task = task; |
|---|
| 22 | |
|---|
| 23 | //Register the event handlers |
|---|
| 24 | jobTitle.Text = task.UIText; |
|---|
| 25 | task.ProgressChanged += new Task.ProgressEventFunction(task_ProgressChanged); |
|---|
| 26 | task.TaskFinished += new Task.TaskEventFunction(task_TaskFinished); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | ~ProgressForm() |
|---|
| 30 | { |
|---|
| 31 | task.ProgressChanged -= new Task.ProgressEventFunction(task_ProgressChanged); |
|---|
| 32 | task.TaskFinished -= new Task.TaskEventFunction(task_TaskFinished); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void task_ProgressChanged(TaskProgressEventArgs e) |
|---|
| 36 | { |
|---|
| 37 | if (InvokeRequired) |
|---|
| 38 | { |
|---|
| 39 | Task.ProgressEventFunction func = |
|---|
| 40 | new Task.ProgressEventFunction(task_ProgressChanged); |
|---|
| 41 | Invoke(func, new object[] {e}); |
|---|
| 42 | return; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | item.Text = File.GetCompactPath(e.CurrentItemName, item.Width, item.Font); |
|---|
| 46 | pass.Text = string.Format("{0} out of {1}", e.CurrentPass, e.TotalPasses); |
|---|
| 47 | timeLeft.Text = string.Format("{0} left", new TimeSpan(0, 0, e.TimeLeft).ToString()); |
|---|
| 48 | |
|---|
| 49 | itemProgress.Value = e.CurrentItemProgress; |
|---|
| 50 | itemProgressLbl.Text = string.Format("{0}%", e.CurrentItemProgress); |
|---|
| 51 | overallProgress.Value = e.OverallProgress; |
|---|
| 52 | overallProgressLbl.Text = string.Format("Total: {0}%", e.OverallProgress); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void task_TaskFinished(TaskEventArgs e) |
|---|
| 56 | { |
|---|
| 57 | if (InvokeRequired) |
|---|
| 58 | { |
|---|
| 59 | Task.TaskEventFunction func = |
|---|
| 60 | new Task.TaskEventFunction(task_TaskFinished); |
|---|
| 61 | Invoke(func, new object[] { e }); |
|---|
| 62 | return; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | //Inform the user on the status of the task. |
|---|
| 66 | status.Text = "Completed"; |
|---|
| 67 | LogLevel highestLevel = LogLevel.INFORMATION; |
|---|
| 68 | foreach (LogEntry log in e.Task.Log) |
|---|
| 69 | if (log.Level > highestLevel) |
|---|
| 70 | highestLevel = log.Level; |
|---|
| 71 | |
|---|
| 72 | switch (highestLevel) |
|---|
| 73 | { |
|---|
| 74 | case LogLevel.WARNING: |
|---|
| 75 | status.Text += " with warnings"; |
|---|
| 76 | break; |
|---|
| 77 | case LogLevel.ERROR: |
|---|
| 78 | status.Text += " with errors"; |
|---|
| 79 | break; |
|---|
| 80 | case LogLevel.FATAL: |
|---|
| 81 | status.Text = "Not completed"; |
|---|
| 82 | break; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | //Change the Stop button to be a Close button. |
|---|
| 86 | stop.Text = "Close"; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | private void stop_Click(object sender, EventArgs e) |
|---|
| 90 | { |
|---|
| 91 | if (task.Executing) |
|---|
| 92 | task.Executor.CancelTask(task); |
|---|
| 93 | Close(); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | } |
|---|