@@ -24,11 +24,12 @@ public abstract class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle, IHas
2424 public int SecondsBeforeTimeout { get ; set ; } = 300 ;
2525
2626 private MailSettings mailSettings ;
27+
2728 public MailSettings MailSettings
2829 {
2930 get => mailSettings ;
3031 set => CommandLifeCycle . MailSettings = mailSettings = value ;
31- }
32+ }
3233
3334 protected AbstractCommand ( )
3435 {
@@ -38,21 +39,26 @@ protected AbstractCommand()
3839 SchedulerGroup = GetType ( ) . AssemblyQualifiedName ;
3940 }
4041
41- public abstract Task Run ( ) ;
42+ public virtual void Run ( )
43+ {
44+ }
45+
46+ public virtual async Task RunAsync ( ) => await Task . Run ( Run ) . ConfigureAwait ( false ) ;
4247
4348 public virtual async Task RunWithLifeCycle ( )
4449 {
4550 try
4651 {
4752 CommandLifeCycle . FirePreActions ( this ) ;
4853 if ( SecondsBeforeTimeout <= 0 )
49- await Run ( ) ;
54+ await RunAsync ( ) ;
5055 else
5156 {
52- var task = Task . Run ( Run ) ;
57+ var task = Task . Run ( RunAsync ) ;
5358 if ( ! task . Wait ( TimeSpan . FromSeconds ( SecondsBeforeTimeout ) ) )
5459 throw new Exception ( $ "Scheduled command timed out after { SecondsBeforeTimeout } second(s).") ;
5560 }
61+
5662 CommandLifeCycle . FirePostActions ( this ) ;
5763 }
5864 catch ( Exception exception )
@@ -65,32 +71,39 @@ public virtual async Task RunWithLifeCycle()
6571 }
6672
6773 public virtual void Failed ( Exception exception )
68- { }
74+ {
75+ }
6976
7077 #region ProgressBar
78+
7179 public void SetProgressBarMaxTicks ( int maxTicks ) => ProgressBar = new ProgressBar ( maxTicks ) ;
7280
7381 public void UpdateProgress ( int tick ) => ProgressBar . Refresh ( tick , Name ) ;
7482
7583 #endregion
7684
7785 #region Scheduling
86+
7887 public virtual async Task Execute ( IJobExecutionContext context )
7988 {
8089 if ( context != null )
8190 {
8291 var properties = GetType ( ) . GetProperties ( ) ;
83- context . MergedJobDataMap . ToList ( ) . ForEach ( x => {
92+ context . MergedJobDataMap . ToList ( ) . ForEach ( x =>
93+ {
8494 var property = properties . FirstOrDefault ( y => y . Name == x . Key ) ;
8595 if ( property != null )
8696 property . SetValue ( this , x . Value ) ;
8797 } ) ;
8898 }
99+
89100 await RunWithLifeCycle ( ) ;
90101 }
102+
91103 #endregion
92104
93105 #region Console output
106+
94107 public IWrite Info ( object val ) => Write . Info ( val ) ;
95108 public IWrite Warning ( object val ) => Write . Warning ( val ) ;
96109 public IWrite Error ( object val ) => Write . Error ( val ) ;
0 commit comments