44
55using Microsoft . Extensions . Hosting ;
66using Microsoft . Extensions . Logging ;
7+ using Westwind . AspNetCore . LiveReload ;
78
89namespace Documentation . Builder . Http ;
910
10- public sealed class ReloadGeneratorService (
11- ReloadableGeneratorState reloadableGenerator ,
12- ILogger < ReloadGeneratorService > logger ) : IHostedService ,
13- IDisposable
11+ public sealed class ReloadGeneratorService ( ReloadableGeneratorState reloadableGenerator , ILogger < ReloadGeneratorService > logger ) : IHostedService , IDisposable
1412{
1513 private FileSystemWatcher ? _watcher ;
1614 private ReloadableGeneratorState ReloadableGenerator { get ; } = reloadableGenerator ;
@@ -23,7 +21,9 @@ public async Task StartAsync(Cancel cancellationToken)
2321 {
2422 await ReloadableGenerator . ReloadAsync ( cancellationToken ) ;
2523
26- var watcher = new FileSystemWatcher ( ReloadableGenerator . Generator . DocumentationSet . SourceDirectory . FullName )
24+ var directory = ReloadableGenerator . Generator . DocumentationSet . SourceDirectory . FullName ;
25+ Logger . LogInformation ( "Start file watch on: {Directory}" , directory ) ;
26+ var watcher = new FileSystemWatcher ( directory )
2727 {
2828 NotifyFilter = NotifyFilters . Attributes
2929 | NotifyFilters . CreationTime
@@ -50,10 +50,11 @@ public async Task StartAsync(Cancel cancellationToken)
5050 private void Reload ( ) =>
5151 _ = _debouncer . ExecuteAsync ( async ctx =>
5252 {
53- Logger . LogInformation ( "Reload due to changes!" ) ;
5453 await ReloadableGenerator . ReloadAsync ( ctx ) ;
5554 Logger . LogInformation ( "Reload complete!" ) ;
56- } , default ) ;
55+
56+ _ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
57+ } , Cancel . None ) ;
5758
5859 public Task StopAsync ( Cancel cancellationToken )
5960 {
@@ -66,26 +67,27 @@ private void OnChanged(object sender, FileSystemEventArgs e)
6667 if ( e . ChangeType != WatcherChangeTypes . Changed )
6768 return ;
6869
70+ Logger . LogInformation ( "Changed: {FullPath}" , e . FullPath ) ;
71+
6972 if ( e . FullPath . EndsWith ( "docset.yml" ) )
7073 Reload ( ) ;
7174 if ( e . FullPath . EndsWith ( ".md" ) )
7275 Reload ( ) ;
7376
74- Logger . LogInformation ( "Changed: {FullPath}" , e . FullPath ) ;
7577 }
7678
7779 private void OnCreated ( object sender , FileSystemEventArgs e )
7880 {
81+ Logger . LogInformation ( "Created: {FullPath}" , e . FullPath ) ;
7982 if ( e . FullPath . EndsWith ( ".md" ) )
8083 Reload ( ) ;
81- Logger . LogInformation ( "Created: {FullPath}" , e . FullPath ) ;
8284 }
8385
8486 private void OnDeleted ( object sender , FileSystemEventArgs e )
8587 {
88+ Logger . LogInformation ( "Deleted: {FullPath}" , e . FullPath ) ;
8689 if ( e . FullPath . EndsWith ( ".md" ) )
8790 Reload ( ) ;
88- Logger . LogInformation ( "Deleted: {FullPath}" , e . FullPath ) ;
8991 }
9092
9193 private void OnRenamed ( object sender , RenamedEventArgs e )
0 commit comments