source: branches/eraser6/Eraser/SchedulerPanel.cs @ 172

Revision 172, 2.0 KB checked in by lowjoel, 7 years ago (diff)

Replaced all occurrences of Erase Method with Erasure Method.

Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8
9using System.Globalization;
10using Eraser.Manager;
11
12namespace 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.ErasureTarget 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
Note: See TracBrowser for help on using the repository browser.