@@ -4,41 +4,41 @@ namespace $ServiceNameFull$
4
4
5
5
public class Worker : BackgroundService
6
6
{
7
- private readonly ILogger < Worker > logger ;
8
- private readonly IConfiguration configuration ;
9
- private readonly IFileSystem filesystem ;
7
+ private readonly ILogger < Worker > logger ;
8
+ private readonly IConfiguration configuration ;
9
+ private readonly IFileSystem filesystem ;
10
10
11
- public Worker ( ILogger < Worker > logger , IConfiguration configuration )
12
- {
13
- this . logger = logger ;
14
- this . configuration = configuration ;
15
- this . filesystem = FileSystem . Instance ;
16
- }
11
+ public Worker ( ILogger < Worker > logger , IConfiguration configuration )
12
+ {
13
+ this . logger = logger ;
14
+ this . configuration = configuration ;
15
+ this . filesystem = FileSystem . Instance ;
16
+ }
17
17
18
- protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
19
- {
20
- while ( ! stoppingToken . IsCancellationRequested )
18
+ protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
21
19
{
22
- #region ExampleCode
23
- // see appsettings.json "WritePath": "C:\\temp\\$DxmModuleName$\\example.txt"
24
- var path = configuration [ "File:WritePath" ] ;
25
- if ( String . IsNullOrWhiteSpace ( path ) )
20
+ while ( ! stoppingToken . IsCancellationRequested )
26
21
{
27
- throw new InvalidOperationException ( "Path for example file writes cannot be null or empty" ) ;
28
- }
22
+ #region ExampleCode
23
+ // see appsettings.json "WritePath": "C:\\temp\\$DxmModuleName$\\example.txt"
24
+ var path = configuration [ "File:WritePath" ] ;
25
+ if ( String . IsNullOrWhiteSpace ( path ) )
26
+ {
27
+ throw new InvalidOperationException ( "Path for example file writes cannot be null or empty" ) ;
28
+ }
29
29
30
- var directory = filesystem . Path . GetDirectoryName ( path ) ;
31
- if ( ! filesystem . Directory . Exists ( directory ) ) filesystem . Directory . CreateDirectory ( directory ) ;
30
+ var directory = filesystem . Path . GetDirectoryName ( path ) ;
31
+ if ( ! filesystem . Directory . Exists ( directory ) ) filesystem . Directory . CreateDirectory ( directory ) ;
32
32
33
- filesystem . File . AppendAllText ( path , $ "{ Environment . NewLine + DateTimeOffset . Now } : Worker is running.") ;
34
- #endregion
33
+ filesystem . File . AppendAllText ( path , $ "{ Environment . NewLine + DateTimeOffset . Now } : Worker is running.") ;
34
+ #endregion
35
35
36
- if ( logger . IsEnabled ( LogLevel . Information ) )
37
- {
38
- logger . LogInformation ( "Worker running at: {time}" , DateTimeOffset . Now ) ;
36
+ if ( logger . IsEnabled ( LogLevel . Information ) )
37
+ {
38
+ logger . LogInformation ( "Worker running at: {time}" , DateTimeOffset . Now ) ;
39
+ }
40
+ await Task . Delay ( 1000 , stoppingToken ) ;
39
41
}
40
- await Task . Delay ( 1000 , stoppingToken ) ;
41
42
}
42
43
}
43
- }
44
44
}
0 commit comments