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