File tree Expand file tree Collapse file tree 2 files changed +36
-100
lines changed
src/NTorSpectator.Observer/Services Expand file tree Collapse file tree 2 files changed +36
-100
lines changed Original file line number Diff line number Diff line change
1
+ using Microsoft . Extensions . Options ;
2
+ using NTorSpectator . Services ;
3
+
4
+ namespace NTorSpectator . Observer . Services ;
5
+
6
+ public class SitesUpdater : BackgroundService
7
+ {
8
+ private readonly ILogger < SitesUpdater > _logger ;
9
+ private readonly string _torSitesFile ;
10
+ private readonly ISitesCatalogue _sitesCatalogue ;
11
+
12
+ public SitesUpdater ( ILogger < SitesUpdater > logger , IOptions < SpectatorSettings > opts , ISitesCatalogue sitesCatalogue )
13
+ {
14
+ _logger = logger ;
15
+ _sitesCatalogue = sitesCatalogue ;
16
+ _torSitesFile = opts . Value . SiteList ;
17
+ }
18
+
19
+ protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
20
+ {
21
+ if ( ! File . Exists ( _torSitesFile ) )
22
+ {
23
+ _logger . LogWarning ( "Tor sites file is not found at path {TorSitesFilePath}. Exiting" , _torSitesFile ) ;
24
+ return ;
25
+ }
26
+
27
+ var sites = await File . ReadAllLinesAsync ( _torSitesFile ) ;
28
+ foreach ( var site in sites )
29
+ {
30
+ if ( string . IsNullOrWhiteSpace ( site ) )
31
+ continue ;
32
+ await _sitesCatalogue . AddIfNotExists ( site ) ;
33
+ }
34
+ _logger . LogDebug ( "Finished adding sites" ) ;
35
+ }
36
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments