23 using System.Collections.Generic;
24 using System.Globalization;
29 namespace Ntp.Analyzer.Monitor.Server
33 public static string Jobs(IEnumerable<Job> jobs)
35 var builder =
new StringBuilder();
37 builder.Append(
"ID".PadRight(3));
38 builder.Append(
"Act".PadRight(4));
39 builder.Append(
"Job".PadRight(15));
40 builder.Append(
"Que".PadLeft(5));
41 builder.Append(
"Ini".PadLeft(5));
42 builder.Append(
"Fix".PadLeft(5));
43 builder.Append(
"Freq".PadLeft(6));
44 builder.Append(
"Prio".PadLeft(5));
45 builder.Append(
"Runs".PadLeft(6));
47 builder.Append(
"Description");
50 const int size = 3 + 4 + 15 + 5 + 5 + 5 + 6 + 5 + 6 + 3 + 25;
52 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
54 IEnumerable<Job> orderedJobs = jobs.OrderBy(j => j.Description.Priority);
56 foreach (
Job job
in orderedJobs)
58 builder.Append(job.
JobId.ToString(
"00").PadRight(3));
59 builder.Append(job.
Running ?
" * " :
" ");
62 ?
"Unnamed".PadRight(15)
67 builder.Append((job.
Queued ?
" 1" :
" 0").PadLeft(5));
70 builder.Append(job.
Schedule.
Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(6));
72 builder.Append(job.
RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
78 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
80 return builder.ToString();
83 public static string Proc(IEnumerable<Job> jobs)
85 var builder =
new StringBuilder();
87 builder.Append(
"ID".PadRight(4));
88 builder.Append(
"Job".PadRight(16));
89 builder.Append(
"Ini".PadLeft(5));
90 builder.Append(
"Fix".PadLeft(5));
91 builder.Append(
"Freq".PadLeft(7));
92 builder.Append(
"Prio".PadLeft(6));
93 builder.Append(
"Runs".PadLeft(5));
95 builder.Append(
"State".PadRight(12));
96 builder.Append(
"Time".PadRight(15));
99 const int size = 4 + 16 + 5 + 5 + 7 + 6 + 5 + 3 + 12 + 15 + 2;
101 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
103 IEnumerable<Job> orderedJobs = jobs.OrderBy(j => j.JobId);
105 foreach (
Job job
in orderedJobs)
107 builder.Append(job.
JobId.ToString(
"00").PadRight(4));
113 builder.Append(job.
Schedule.
Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(7));
114 builder.Append(job.
Description.
Priority.ToString(CultureInfo.InvariantCulture).PadLeft(6));
115 builder.Append(job.
RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
117 builder.Append(job.
State.PadRight(12));
118 builder.Append(job.
TotalRuntime.PadLeft(15).Substring(0, 15));
119 builder.AppendLine();
122 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
124 return builder.ToString();
127 public static string Running(IEnumerable<Job> jobs)
129 var list = jobs.ToList();
130 if (list.Count(j => j.Running) == 0)
132 return "No jobs are currently running.";
135 var builder =
new StringBuilder();
137 builder.Append(
"ID".PadRight(4));
138 builder.Append(
"Job".PadRight(16));
139 builder.Append(
"Ini".PadLeft(5));
140 builder.Append(
"Fix".PadLeft(5));
141 builder.Append(
"Freq".PadLeft(7));
142 builder.Append(
"Prio".PadLeft(6));
143 builder.Append(
"Runs".PadLeft(5));
145 builder.Append(
"State".PadRight(12));
146 builder.Append(
"Time".PadRight(15));
147 builder.AppendLine();
149 const int size = 4 + 16 + 5 + 5 + 7 + 6 + 5 + 3 + 12 + 15 + 2;
151 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
153 IEnumerable<Job> orderedJobs = list.Where(j => j.Running).OrderBy(j => j.JobId);
155 foreach (
Job job
in orderedJobs)
157 builder.Append(job.
JobId.ToString(
"00").PadRight(4));
163 builder.Append(job.
Schedule.
Frequency.ToString(CultureInfo.InvariantCulture).PadLeft(7));
164 builder.Append(job.
Description.
Priority.ToString(CultureInfo.InvariantCulture).PadLeft(6));
165 builder.Append(job.
RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
167 builder.Append(job.
State.PadRight(12));
168 builder.Append(job.
Runtime.PadLeft(15).Substring(0, 15));
169 builder.AppendLine();
172 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
174 return builder.ToString();
177 public static string Schedule(IEnumerable<ScheduledJob> jobs)
179 var builder =
new StringBuilder();
181 builder.AppendLine(
"Server time: " + DateTime.Now.ToLongTimeString());
182 builder.AppendLine();
184 builder.Append(
"ID".PadRight(4));
185 builder.Append(
"Job".PadRight(15));
186 builder.Append(
"Ini".PadLeft(4));
187 builder.Append(
"Fix".PadLeft(5));
188 builder.Append(
"Freq".PadLeft(6));
189 builder.Append(
"Prio".PadLeft(5));
190 builder.Append(
"Runs".PadLeft(6));
192 builder.Append(
"Next".PadRight(8));
193 builder.AppendLine();
195 const int size = 4 + 15 + 4 + 5 + 6 + 5 + 6 + 3 + 8 + 2;
197 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
199 IEnumerable<ScheduledJob> orderedJobs = jobs.OrderBy(j => j.Run);
203 builder.Append(job.
Job.
JobId.ToString(
"00").PadRight(4));
211 builder.Append(job.
Job.
RunCount.ToString(CultureInfo.InvariantCulture).PadLeft(6));
213 builder.Append(job.
Run.ToLongTimeString().PadLeft(8));
214 builder.AppendLine();
217 builder.AppendLine(
string.Empty.PadLeft(size,
'-'));
219 return builder.ToString();
bool Queued
Gets or sets a value indicating whether this Job is queued for run.
abstract int Priority
Gets the priority to use when scheduling jobs.
static string Proc(IEnumerable< Job > jobs)
DateTime Run
Gets the time of planned execution.
Job Job
Gets the job to execute.
string State
Gets the current state of this Job.
bool InitialRun
Gets a value indicating whether this JobScheduleDescription should do an initial run upon first call...
static string Schedule(IEnumerable< ScheduledJob > jobs)
JobScheduleDescription Schedule
Gets the schedule.
static string Jobs(IEnumerable< Job > jobs)
abstract string JobType
Gets the type of the job as text.
int RunCount
Gets the number of times this Job have been executed.
A job which have been scheduled for execution.
string Runtime
Gets the time this Job have currently been running.
int Frequency
Gets the schedule frequency in minutes.
bool Running
Gets or sets a value indicating whether this Job is running.
string Name
Gets the name.
string TotalRuntime
Gets the total time this Job have been running.
bool FixedRun
Gets a value indicating whether this JobScheduleDescription has a fixed schedule frequency, eg. cannot be moved.
static string Running(IEnumerable< Job > jobs)
int JobId
Gets the job identifier.
JobDescription Description
Gets the description.