11using System ;
2+ using System . Linq ;
23using InEngine . Core . IO ;
4+ using InEngine . Core . Scheduling ;
35using Konsole ;
4- using NLog ;
56using Quartz ;
67
78namespace InEngine . Core
89{
910 abstract public class AbstractCommand : ICommand , IFailed , IJob , IWrite
1011 {
11- public IJobExecutionContext JobExecutionContext { get ; set ; }
12- public ILogger Logger { get ; internal set ; }
12+ public Write Write { get ; set ; }
1313 public ProgressBar ProgressBar { get ; internal set ; }
14- string _name ;
15- public string Name
16- {
17- get { return _name ; }
18- set
19- {
20- _name = value ;
21- Logger = LogManager . GetLogger ( _name ) ;
22- }
23- }
14+ public string Name { get ; set ; }
2415 public string SchedulerGroup { get ; set ; }
2516 public string ScheduleId { get ; set ; }
26- public Write Write { get ; set ; }
2717
2818 protected AbstractCommand ( )
2919 {
@@ -56,7 +46,13 @@ public void UpdateProgress(int tick)
5646 #region Scheduling
5747 public void Execute ( IJobExecutionContext context )
5848 {
59- JobExecutionContext = context ;
49+ var properties = GetType ( ) . GetProperties ( ) ;
50+ context . MergedJobDataMap . ToList ( ) . ForEach ( x => {
51+ var property = properties . FirstOrDefault ( y => y . Name == x . Key ) ;
52+ if ( property != null )
53+ property . SetValue ( this , x . Value ) ;
54+ } ) ;
55+
6056 try
6157 {
6258 Run ( ) ;
@@ -67,33 +63,6 @@ public void Execute(IJobExecutionContext context)
6763 }
6864 }
6965
70- public JobBuilder MakeJobBuilder ( )
71- {
72- return JobBuilder
73- . Create ( GetType ( ) )
74- . WithIdentity ( $ "{ Name } :job:{ ScheduleId } ", SchedulerGroup ) ;
75- }
76-
77- public TriggerBuilder MakeTriggerBuilder ( )
78- {
79- return TriggerBuilder
80- . Create ( )
81- . WithIdentity ( $ "{ Name } :trigger:{ ScheduleId } ", SchedulerGroup ) ;
82- }
83-
84- public T GetJobContextData < T > ( string key )
85- {
86- if ( JobExecutionContext == null || JobExecutionContext . MergedJobDataMap == null )
87- return default ( T ) ;
88- var objectVal = JobExecutionContext . MergedJobDataMap . Get ( key ) ;
89- return objectVal == null ? default ( T ) : ( T ) objectVal ;
90- }
91-
92- public void AddJobContextData < T > ( string key , T val )
93- {
94- JobExecutionContext . MergedJobDataMap . Add ( key , val ) ;
95- }
96-
9766 #endregion
9867
9968 #region Console output
0 commit comments