-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAbstractCommand.cs
More file actions
125 lines (105 loc) · 3 KB
/
AbstractCommand.cs
File metadata and controls
125 lines (105 loc) · 3 KB
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
using System;
using System.Linq;
using InEngine.Core.IO;
using InEngine.Core.Scheduling;
using Konsole;
using Quartz;
namespace InEngine.Core
{
abstract public class AbstractCommand : ICommand, IFailed, IJob, IWrite
{
public Write Write { get; set; }
public ProgressBar ProgressBar { get; internal set; }
public string Name { get; set; }
public string SchedulerGroup { get; set; }
public string ScheduleId { get; set; }
protected AbstractCommand()
{
ScheduleId = Guid.NewGuid().ToString();
Name = GetType().FullName;
SchedulerGroup = GetType().AssemblyQualifiedName;
Write = new Write();;
}
public virtual void Run()
{
throw new NotImplementedException();
}
public virtual void Failed(Exception exception)
{}
#region ProgressBar
public void SetProgressBarMaxTicks(int maxTicks)
{
ProgressBar = new ProgressBar(maxTicks);
}
public void UpdateProgress(int tick)
{
ProgressBar.Refresh(tick, Name);
}
#endregion
#region Scheduling
public void Execute(IJobExecutionContext context)
{
var properties = GetType().GetProperties();
context.MergedJobDataMap.ToList().ForEach(x => {
var property = properties.FirstOrDefault(y => y.Name == x.Key);
if (property != null)
property.SetValue(this, x.Value);
});
try
{
Run();
}
catch (Exception exception)
{
Failed(exception);
}
}
#endregion
#region Console output
public IWrite Info(string val)
{
return Write.Info(val);
}
public IWrite Warning(string val)
{
return Write.Warning(val);
}
public IWrite Error(string val)
{
return Write.Error(val);
}
public IWrite Line(string val)
{
return Write.Line(val);
}
public IWrite ColoredLine(string val, ConsoleColor consoleColor)
{
return Write.ColoredLine(val, consoleColor);
}
public IWrite InfoText(string val)
{
return Write.InfoText(val);
}
public IWrite WarningText(string val)
{
return Write.WarningText(val);
}
public IWrite ErrorText(string val)
{
return Write.ErrorText(val);
}
public IWrite Text(string val)
{
return Write.Text(val);
}
public IWrite ColoredText(string val, ConsoleColor consoleColor)
{
return Write.ColoredText(val, consoleColor);
}
public IWrite Newline(int count = 1)
{
return Write.Newline(count);
}
#endregion
}
}