6
6
using Microsoft . Extensions . Logging ;
7
7
using Westwind . AspNetCore . LiveReload ;
8
8
9
+ [ assembly: System . Reflection . Metadata . MetadataUpdateHandler ( typeof ( Documentation . Builder . Http . HotReloadManager ) ) ]
10
+
9
11
namespace Documentation . Builder . Http ;
10
12
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
+
11
27
public sealed class ReloadGeneratorService ( ReloadableGeneratorState reloadableGenerator , ILogger < ReloadGeneratorService > logger ) : IHostedService , IDisposable
12
28
{
13
29
private FileSystemWatcher ? _watcher ;
@@ -22,6 +38,9 @@ public async Task StartAsync(Cancel cancellationToken)
22
38
await ReloadableGenerator . ReloadAsync ( cancellationToken ) ;
23
39
24
40
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
25
44
Logger . LogInformation ( "Start file watch on: {Directory}" , directory ) ;
26
45
var watcher = new FileSystemWatcher ( directory )
27
46
{
@@ -40,6 +59,9 @@ public async Task StartAsync(Cancel cancellationToken)
40
59
watcher . Renamed += OnRenamed ;
41
60
watcher . Error += OnError ;
42
61
62
+ #if DEBUG
63
+ watcher . Filters . Add ( "*.cshtml" ) ;
64
+ #endif
43
65
watcher . Filters . Add ( "*.md" ) ;
44
66
watcher . Filters . Add ( "docset.yml" ) ;
45
67
watcher . IncludeSubdirectories = true ;
@@ -73,6 +95,10 @@ private void OnChanged(object sender, FileSystemEventArgs e)
73
95
Reload ( ) ;
74
96
if ( e . FullPath . EndsWith ( ".md" ) )
75
97
Reload ( ) ;
98
+ #if DEBUG
99
+ if ( e . FullPath . EndsWith ( ".cshtml" ) )
100
+ _ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
101
+ #endif
76
102
77
103
}
78
104
@@ -97,6 +123,10 @@ private void OnRenamed(object sender, RenamedEventArgs e)
97
123
Logger . LogInformation ( " New: {NewFullPath}" , e . FullPath ) ;
98
124
if ( e . FullPath . EndsWith ( ".md" ) )
99
125
Reload ( ) ;
126
+ #if DEBUG
127
+ if ( e . FullPath . EndsWith ( ".cshtml" ) )
128
+ _ = LiveReloadMiddleware . RefreshWebSocketRequest ( ) ;
129
+ #endif
100
130
}
101
131
102
132
private void OnError ( object sender , ErrorEventArgs e ) =>
0 commit comments