| 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 System.Globalization; |
|---|
| 10 | using Eraser.Manager; |
|---|
| 11 | |
|---|
| 12 | namespace Eraser |
|---|
| 13 | { |
|---|
| 14 | public partial class SchedulerPanel : Eraser.BasePanel |
|---|
| 15 | { |
|---|
| 16 | public SchedulerPanel() |
|---|
| 17 | { |
|---|
| 18 | InitializeComponent(); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | /// <summary> |
|---|
| 22 | /// Adds a task to the list of scheduled tasks |
|---|
| 23 | /// </summary> |
|---|
| 24 | /// <param name="task">The task object.</param> |
|---|
| 25 | public void AddTask(Task task) |
|---|
| 26 | { |
|---|
| 27 | ListViewItem item = scheduler.Items.Add(GenerateTaskName(task)); |
|---|
| 28 | if (task.Schedule is RecurringSchedule) |
|---|
| 29 | item.SubItems.Add((task.Schedule as RecurringSchedule).NextRun. |
|---|
| 30 | ToString(DateTimeFormatInfo.CurrentInfo.FullDateTimePattern)); |
|---|
| 31 | else |
|---|
| 32 | item.SubItems.Add(task.Schedule.UIText); |
|---|
| 33 | item.SubItems.Add(string.Empty); |
|---|
| 34 | |
|---|
| 35 | if (task.Schedule == Schedule.RunNow) |
|---|
| 36 | item.Group = scheduler.Groups["immediate"]; |
|---|
| 37 | else if (task.Schedule == Schedule.RunOnRestart) |
|---|
| 38 | item.Group = scheduler.Groups["restart"]; |
|---|
| 39 | else |
|---|
| 40 | item.Group = scheduler.Groups["recurring"]; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /// <summary> |
|---|
| 44 | /// Determines the task name to display, deciding on whether a task name is |
|---|
| 45 | /// provided by the user. |
|---|
| 46 | /// </summary> |
|---|
| 47 | /// <param name="task">The task object for which a name is to be generated</param> |
|---|
| 48 | /// <returns>A task name, may not be unique.</returns> |
|---|
| 49 | private string GenerateTaskName(Task task) |
|---|
| 50 | { |
|---|
| 51 | //Simple case, the task name was given by the user. |
|---|
| 52 | if (task.Name.Length != 0) |
|---|
| 53 | return task.Name; |
|---|
| 54 | |
|---|
| 55 | string result = string.Empty; |
|---|
| 56 | if (task.Entries.Count < 3) |
|---|
| 57 | //Simpler case, small set of data. |
|---|
| 58 | foreach (Task.EraseTarget tgt in task.Entries) |
|---|
| 59 | result += tgt.UIText + ", "; |
|---|
| 60 | else |
|---|
| 61 | //Ok, we've quite a few entries, get the first, the mid and the end. |
|---|
| 62 | for (int i = 0; i < task.Entries.Count; i += task.Entries.Count / 3) |
|---|
| 63 | result += task.Entries[i].UIText + ", "; |
|---|
| 64 | return result.Substring(0, result.Length - 2); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|