1616
1717namespace Microsoft . DotNet . HotReload ;
1818
19- internal sealed class DefaultHotReloadClient ( ILogger logger , ILogger agentLogger , string startupHookPath , bool handlesStaticAssetUpdates , ClientTransport transport )
19+ /// <summary>
20+ /// Default Hot Reload client. Used for local app or an app running on a device.
21+ /// </summary>
22+ /// <param name="logger">Logger for client messages.</param>
23+ /// <param name="agentLogger">Logger for messages received from the agent.</param>
24+ /// <param name="startupHookPath">Path to the startup hook to be loaded to the target process.</param>
25+ /// <param name="transport">Transport layer (e.g. named pipe or web socket)</param>
26+ /// <param name="handlesStaticAssetUpdates">True if the agent handles static asset updates. False if static assets are updated via browser refresh server.</param>
27+ /// <param name="hasRemoteAgent">True if the agent runs on a remote machine (device).</param>
28+ internal sealed class DefaultHotReloadClient (
29+ ILogger logger ,
30+ ILogger agentLogger ,
31+ string startupHookPath ,
32+ ClientTransport transport ,
33+ bool handlesStaticAssetUpdates ,
34+ bool hasRemoteAgent )
2035 : HotReloadClient ( logger , agentLogger )
2136{
22- private Task < ImmutableArray < string > > ? _capabilitiesTask ;
37+ private Task < HotReloadAgentInfo > ? _connectedAgentTask ;
2338 private bool _managedCodeUpdateFailedOrCancelled ;
2439
2540 // The status of the last update response.
@@ -40,9 +55,9 @@ public override void InitiateConnection(IReadOnlyCollection<(string name, string
4055 // It is important to establish the connection (WaitForConnectionAsync) before we return,
4156 // otherwise the client wouldn't be able to connect.
4257 // However, we don't want to wait for the task to complete, so that we can start the client process.
43- _capabilitiesTask = ConnectAsync ( ) ;
58+ _connectedAgentTask = ConnectAsync ( ) ;
4459
45- async Task < ImmutableArray < string > > ConnectAsync ( )
60+ async Task < HotReloadAgentInfo > ConnectAsync ( )
4661 {
4762 try
4863 {
@@ -52,34 +67,49 @@ async Task<ImmutableArray<string>> ConnectAsync()
5267 var initResponse = await transport . ReadAsync ( cancellationToken ) ;
5368 if ( initResponse == null )
5469 {
55- return [ ] ;
70+ // connection dropped before we could read the initialization response.
71+ return HotReloadAgentInfo . Unavailable ;
5672 }
5773
5874 using var r = initResponse . Value ;
5975 if ( r . Type != ResponseType . InitializationResponse )
6076 {
6177 Logger . LogError ( "Expected initialization response, got: {ResponseType}" , r . Type ) ;
62- return [ ] ;
78+ return HotReloadAgentInfo . Unavailable ;
6379 }
6480
65- var capabilities = ( await ClientInitializationResponse . ReadAsync ( r . Data , cancellationToken ) ) . Capabilities ;
81+ var response = await ClientInitializationResponse . ReadAsync ( r . Data , cancellationToken ) ;
6682
67- if ( string . IsNullOrEmpty ( capabilities ) )
83+ // Remote process id has no meaning on the client's machine:
84+ var localProcessId = hasRemoteAgent ? ( int ? ) null : response . ProcessId ;
85+
86+ if ( response . Capabilities is "" )
6887 {
69- return [ ] ;
88+ // Hot Reload not supported by the runtime:
89+ Logger . Log ( LogEvents . Capabilities , "" ) ;
90+
91+ return new HotReloadAgentInfo
92+ {
93+ ManagedCodeUpdateCapabilities = [ ] ,
94+ LocalProcessId = localProcessId
95+ } ;
7096 }
7197
72- var result = AddImplicitCapabilities ( capabilities . Split ( ' ' ) ) ;
98+ var effectiveCapabilities = AddImplicitCapabilities ( response . Capabilities . Split ( ' ' ) ) ;
7399
74- Logger . Log ( LogEvents . Capabilities , string . Join ( " " , result ) ) ;
100+ Logger . Log ( LogEvents . Capabilities , string . Join ( " " , effectiveCapabilities ) ) ;
75101
76102 // Initialize process:
77103 await SetEnvironmentVariablesAsync ( environmentVariables , cancellationToken ) ;
78104
79105 // fire and forget:
80106 _ = ListenForResponsesAsync ( cancellationToken ) ;
81107
82- return result ;
108+ return new HotReloadAgentInfo
109+ {
110+ ManagedCodeUpdateCapabilities = effectiveCapabilities ,
111+ LocalProcessId = localProcessId
112+ } ;
83113 }
84114 catch ( Exception e ) when ( e is not OperationCanceledException )
85115 {
@@ -90,7 +120,7 @@ async Task<ImmutableArray<string>> ConnectAsync()
90120 Logger . LogError ( "Failed to read capabilities: {Message}" , e . Message ) ;
91121 }
92122
93- return [ ] ;
123+ return HotReloadAgentInfo . Unavailable ;
94124 }
95125 }
96126 }
@@ -137,15 +167,15 @@ private async Task ListenForResponsesAsync(CancellationToken cancellationToken)
137167 }
138168 }
139169
140- [ MemberNotNull ( nameof ( _capabilitiesTask ) ) ]
141- private Task < ImmutableArray < string > > GetCapabilitiesTask ( )
142- => _capabilitiesTask ?? throw new InvalidOperationException ( ) ;
170+ [ MemberNotNull ( nameof ( _connectedAgentTask ) ) ]
171+ private Task < HotReloadAgentInfo > GetAgentConnectedTask ( )
172+ => _connectedAgentTask ?? throw new InvalidOperationException ( ) ;
143173
144- [ MemberNotNull ( nameof ( _capabilitiesTask ) ) ]
174+ [ MemberNotNull ( nameof ( _connectedAgentTask ) ) ]
145175 private void RequireReadyForUpdates ( )
146176 {
147177 // should only be called after connection has been created:
148- _ = GetCapabilitiesTask ( ) ;
178+ _ = GetAgentConnectedTask ( ) ;
149179 }
150180
151181 public override void ConfigureLaunchEnvironment ( IDictionary < string , string > environmentBuilder )
@@ -159,10 +189,10 @@ public override void ConfigureLaunchEnvironment(IDictionary<string, string> envi
159189 }
160190
161191 public override Task WaitForConnectionEstablishedAsync ( CancellationToken cancellationToken )
162- => GetCapabilitiesTask ( ) ;
192+ => GetAgentConnectedTask ( ) ;
163193
164- public override Task < ImmutableArray < string > > GetUpdateCapabilitiesAsync ( CancellationToken cancellationToken )
165- => GetCapabilitiesTask ( ) ;
194+ public override Task < HotReloadAgentInfo > GetConnectedAgentInfoAsync ( CancellationToken cancellationToken )
195+ => GetAgentConnectedTask ( ) ;
166196
167197 private ResponseLoggingLevel ResponseLoggingLevel
168198 => Logger . IsEnabled ( LogLevel . Debug ) ? ResponseLoggingLevel . Verbose : ResponseLoggingLevel . WarningsAndErrors ;
0 commit comments