-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSchedulerJobResultsForm.cs
159 lines (142 loc) · 7.59 KB
/
SchedulerJobResultsForm.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using DevExpress.ReportServer.ServiceModel.ConnectionProviders;
using DevExpress.ReportServer.ServiceModel.DataContracts;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScheduledTasksAPIClientDemo {
public partial class SchedulerJobResultsForm : Form {
#region inner classes
class Info {
public string Name { get; set; }
public object Value { get; set; }
}
#endregion
readonly ConnectionProvider serverConnection;
readonly int scheduledJobId;
public SchedulerJobResultsForm(int scheduledJobId, string scheduledJobName, ConnectionProvider serverConnection) {
InitializeComponent();
this.serverConnection = serverConnection;
this.scheduledJobId = scheduledJobId;
this.id.Text = string.Format("{0}", scheduledJobId);
this.scheduledJobName.Text = scheduledJobName;
}
// The following code obtains the logs corresponding to a selected scheduled job from the server
// for the period of 100 days prior to the current date
// and displays the total number of obtained logs.
private void SchedulerJobResults_Load(object sender, EventArgs e) {
splashScreenManager1.ShowWaitForm();
serverConnection.DoWithScheduledJobAsync(x => x.GetScheduledJobLogsAsync(scheduledJobId,
new DataPaginationByDate() {
From = DateTime.Now - TimeSpan.FromDays(100),
Interval = TimeSpan.FromDays(100)
}, null))
.ContinueWith(taskFunc => {
splashScreenManager1.CloseWaitForm();
if (taskFunc.IsFaulted) {
MessageBox.Show(taskFunc.Exception.GetBaseException().Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
FillScheduledJobLogs(taskFunc.Result);
}
}, TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith((taskFunc) => {
return serverConnection.DoWithScheduledJobAsync(x => x.GetScheduledJobLogsCountAsync(scheduledJobId, null));
})
.Unwrap()
.ContinueWith(taskFunc => {
logsLabel.Text = string.Format("Logs count: {0}", taskFunc.Result);
}, TaskScheduler.FromCurrentSynchronizationContext());
}
// The following method populates a grid control with a list
// of job executions and the dates on which they were started.
void FillScheduledJobLogs(IEnumerable<ScheduledJobLogDto> scheduledJobLogs) {
jobLogsView.GridControl.DataSource = scheduledJobLogs;
}
// The following code displays information about the last 100 results of a job's execution.
// This information includes the date and time when the result was obtained,
// as well as the status or result of its execution and the total number of results.
private void jobLogsView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
jobResultsGrid.DataSource = null;
resultInfoGrid.DataSource = null;
var selectedId = jobLogsView.GetFocusedRowCellValue("Id") as int?;
if (!selectedId.HasValue) {
return;
}
splashScreenManager1.ShowWaitForm();
serverConnection.DoWithScheduledJobAsync(x => x.GetScheduledJobResultsAsync(selectedId.Value,
new DataPaginationByCount() {
Offset = 0,
Count = 100
}, null))
.ContinueWith(taskFunc => {
splashScreenManager1.CloseWaitForm();
if (taskFunc.IsFaulted) {
MessageBox.Show(taskFunc.Exception.GetBaseException().Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
FillScheduledJobResults(taskFunc.Result, selectedId.Value);
}
}, TaskScheduler.FromCurrentSynchronizationContext())
.ContinueWith((taskFunc) => {
return serverConnection.DoWithScheduledJobAsync(x => x.GetScheduledJobResultsCountAsync(selectedId.Value, null));
})
.Unwrap()
.ContinueWith(taskFunc => {
resultsLabel.Text = string.Format("Results count: {0}", taskFunc.Result);
}, TaskScheduler.FromCurrentSynchronizationContext());
}
void FillScheduledJobResults(IEnumerable<ScheduledJobResultCatalogItemDto> scheduledJobResults, int scheduledJobLogId) {
jobResultsView.GridControl.DataSource = scheduledJobResults;
}
// The following code displays information about the selected job execution result.
// This information includes a list of email subscribers,
// parameter values at the moment of execution, and (when applicable)
// the reason why the task execution failed.
private void jobResultsView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
previewDocumentButton.Enabled = false;
resultInfoGrid.DataSource = null;
if (jobResultsView.SelectedRowsCount == 0) {
return;
}
var selectedId = jobResultsView.GetFocusedRowCellValue("Id") as int?;
if (!selectedId.HasValue) {
return;
}
var status = jobResultsView.GetFocusedRowCellValue("Status") as JobResultStatus?;
previewDocumentButton.Enabled = status.HasValue && status.Value == JobResultStatus.Success;
splashScreenManager1.ShowWaitForm();
serverConnection.DoWithScheduledJobAsync(x => x.GetScheduledJobResultAsync(selectedId.Value, null))
.ContinueWith(taskFunc => {
splashScreenManager1.CloseWaitForm();
if (taskFunc.IsFaulted) {
MessageBox.Show(taskFunc.Exception.GetBaseException().Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
FillScheduledJobResultInfo(taskFunc.Result);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
void FillScheduledJobResultInfo(ScheduledJobResultDto scheduledJobResult) {
var infos = new List<Info>();
infos.Add(new Info { Name = "Recipients", Value = scheduledJobResult.Recipients });
infos.Add(new Info { Name = "Reason", Value = scheduledJobResult.Message });
infos.Add(new Info { Name = "Parameters", Value = scheduledJobResult.ExecutionParameters });
resultInfoGrid.DataSource = infos;
resultInfoView.BestFitColumns();
}
// The following code invokes a Print Preview form displaying
// the report document created by a selected task.
private void previewDocumentButton_Click(object sender, EventArgs e) {
if (jobResultsView.SelectedRowsCount == 0) {
return;
}
var selectedId = jobResultsView.GetFocusedRowCellValue("Id") as int?;
if (!selectedId.HasValue) {
return;
}
ReportViewerForm form = new ReportViewerForm(selectedId.Value) { Owner = this };
form.ShowDialog();
}
}
}