/
TaskRunTimesControl.cs
104 lines (92 loc) · 3.06 KB
/
TaskRunTimesControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Microsoft.Win32.TaskScheduler
{
/// <summary>Control that will display the run times for a provided task.</summary>
[System.Drawing.ToolboxBitmap(typeof(TaskEditDialog), "TaskControl")]
public partial class TaskRunTimesControl : UserControl, ISupportInitialize
{
private bool initializing = false;
private bool isTemp = false;
private Task task;
/// <summary>Initializes a new instance of the <see cref="TaskRunTimesControl"/> class.</summary>
public TaskRunTimesControl()
{
initializing = true;
InitializeComponent();
initializing = false;
}
/// <summary>Gets or sets the end date.</summary>
/// <value>The end date.</value>
[Category("Data")]
public DateTime EndDate
{
get => endDatePicker.Value;
set => endDatePicker.Value = value;
}
/// <summary>Gets or sets the start date.</summary>
/// <value>The start date.</value>
[Category("Data")]
public DateTime StartDate
{
get => startDatePicker.Value;
set => startDatePicker.Value = value;
}
/// <summary>Gets or sets the task.</summary>
/// <value>The task.</value>
[Browsable(false), DefaultValue((Task)null)]
public Task Task
{
get => task;
set
{
task = value;
Text = task == null ? null : string.Format(EditorProperties.Resources.TaskRunTimesDialogTitle, value.Name);
isTemp = task == null ? false : task.Name.StartsWith(TaskPropertiesControl.runTimesTempTaskPrefix) && task.Name.Length == (TaskPropertiesControl.runTimesTempTaskPrefix.Length + Guid.NewGuid().ToString().Length);
if (!initializing)
Fetch();
}
}
/// <summary>Signals the object that initialization is starting.</summary>
public void BeginInit() => initializing = true;
/// <summary>Signals the object that initialization is complete.</summary>
public void EndInit()
{
initializing = false;
Fetch();
}
/// <summary>Initializes an instance of the <see cref="TaskRunTimesDialog"/> class.</summary>
/// <param name="task">The task to display.</param>
/// <param name="startDate">The date to begin looking for run times.</param>
/// <param name="endDate">The date to end looking for run times.</param>
public void Initialize(Task task = null, DateTime? startDate = null, DateTime? endDate = null)
{
BeginInit();
if (startDate.HasValue)
StartDate = startDate.Value;
if (endDate.HasValue)
EndDate = endDate.Value;
Task = task;
EndInit();
}
internal bool ShouldSerializeEndDate() => endDatePicker.ShouldSerializeValue();
internal bool ShouldSerializeStartDate() => startDatePicker.ShouldSerializeValue();
private void dateValueChanged(object sender, EventArgs e)
{
if (!initializing)
Fetch();
}
private void Fetch()
{
if (task == null)
listBox1.DataSource = null;
else
{
if (isTemp) task.Enabled = true;
listBox1.DataSource = task.GetRunTimes(StartDate, EndDate);
if (isTemp) task.Enabled = false;
}
}
}
}