66using Microsoft . Extensions . Logging ;
77using Westwind . AspNetCore . LiveReload ;
88
9+ [ assembly: System . Reflection . Metadata . MetadataUpdateHandler ( typeof ( Documentation . Builder . Http . HotReloadManager ) ) ]
10+
911namespace Documentation . Builder . Http ;
1012
13+ public static class HotReloadManager
14+ {
15+ public static void ClearCache ( Type [ ] ? _ ) => LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
16+
17+ public static void UpdateApplication ( Type [ ] ? _ ) => Task . Run ( async ( ) =>
18+ {
19+ await Task . Delay ( 1000 ) ;
20+ var __ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
21+ Console . WriteLine ( "UpdateApplication" ) ;
22+ } ) ;
23+
24+ }
25+
26+
1127public sealed class ReloadGeneratorService ( ReloadableGeneratorState reloadableGenerator , ILogger < ReloadGeneratorService > logger ) : IHostedService , IDisposable
1228{
1329 private FileSystemWatcher ? _watcher ;
@@ -22,6 +38,9 @@ public async Task StartAsync(Cancel cancellationToken)
2238 await ReloadableGenerator . ReloadAsync ( cancellationToken ) ;
2339
2440 var directory = ReloadableGenerator . Generator . DocumentationSet . SourceDirectory . FullName ;
41+ #if DEBUG
42+ directory = ReloadableGenerator . Generator . Context . DocumentationCheckoutDirectory ? . FullName ?? throw new InvalidOperationException ( "No checkout directory" ) ;
43+ #endif
2544 Logger . LogInformation ( "Start file watch on: {Directory}" , directory ) ;
2645 var watcher = new FileSystemWatcher ( directory )
2746 {
@@ -40,6 +59,9 @@ public async Task StartAsync(Cancel cancellationToken)
4059 watcher . Renamed += OnRenamed ;
4160 watcher . Error += OnError ;
4261
62+ #if DEBUG
63+ watcher . Filters . Add ( "*.cshtml" ) ;
64+ #endif
4365 watcher . Filters . Add ( "*.md" ) ;
4466 watcher . Filters . Add ( "docset.yml" ) ;
4567 watcher . IncludeSubdirectories = true ;
@@ -73,6 +95,10 @@ private void OnChanged(object sender, FileSystemEventArgs e)
7395 Reload ( ) ;
7496 if ( e . FullPath . EndsWith ( ".md" ) )
7597 Reload ( ) ;
98+ #if DEBUG
99+ if ( e . FullPath . EndsWith ( ".cshtml" ) )
100+ _ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
101+ #endif
76102
77103 }
78104
@@ -97,6 +123,10 @@ private void OnRenamed(object sender, RenamedEventArgs e)
97123 Logger . LogInformation ( " New: {NewFullPath}" , e . FullPath ) ;
98124 if ( e . FullPath . EndsWith ( ".md" ) )
99125 Reload ( ) ;
126+ #if DEBUG
127+ if ( e . FullPath . EndsWith ( ".cshtml" ) )
128+ _ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
129+ #endif
100130 }
101131
102132 private void OnError ( object sender , ErrorEventArgs e ) =>
0 commit comments