@@ -21,15 +21,13 @@ async Task<SenderStateMachine> PrepareTransferInternalAsync(EndpointInfo endpoin
2121
2222 Guid operationId = Guid . NewGuid ( ) ;
2323
24- using var handShakeChannel = await session . StartClientChannelAsync < HandshakeHandler > ( cancellationToken ) . ConfigureAwait ( false ) ;
25- HandshakeHandler handshake = new ( handShakeChannel ) ;
24+ var handshake = await session . StartClientChannelAsync < HandshakeHandler > ( cancellationToken ) . ConfigureAwait ( false ) ;
2625 await handshake . Execute ( operationId ) . ConfigureAwait ( false ) ;
2726
2827 // ToDo: CorrelationVector
2928 // var cv = handshakeResultMsg.Header.TryGetCorrelationVector() ?? throw new InvalidDataException("No Correlation Vector");
3029
31- var channel = await session . StartClientChannelAsync ( operationId . ToString ( "D" ) . ToUpper ( ) , NearShareApp . Name , cancellationToken ) . ConfigureAwait ( false ) ;
32- SenderStateMachine senderStateMachine = new ( channel ) ;
30+ var senderStateMachine = await session . StartClientChannelAsync < SenderStateMachine > ( operationId . ToString ( "D" ) . ToUpper ( ) , NearShareApp . Name , cancellationToken ) . ConfigureAwait ( false ) ;
3331 return senderStateMachine ;
3432 }
3533
@@ -48,7 +46,7 @@ public async Task SendFilesAsync(CdpDevice device, IReadOnlyList<CdpFileProvider
4846 await senderStateMachine . SendFilesAsync ( files , progress , cancellationToken ) . ConfigureAwait ( false ) ;
4947 }
5048
51- sealed class HandshakeHandler ( CdpChannel channel ) : CdpBondApp ( channel ) , ICdpAppId
49+ sealed class HandshakeHandler ( CdpChannel channel ) : CdpBondApp ( channel ) , ICdpAppFactory < HandshakeHandler > , ICdpAppId
5250 {
5351 public static string Id { get ; } = NearShareHandshakeApp . Id ;
5452 public static string Name { get ; } = NearShareHandshakeApp . Name ;
@@ -76,9 +74,11 @@ protected override void HandleMessage(in BinaryMsgHeader header, ValueSet payloa
7674
7775 _promise . SetResult ( ) ;
7876 }
77+
78+ static HandshakeHandler ICdpAppFactory < HandshakeHandler > . Create ( CdpChannel channel ) => new ( channel ) ;
7979 }
8080
81- sealed class SenderStateMachine ( CdpChannel channel ) : CdpBondApp ( channel )
81+ sealed class SenderStateMachine ( CdpChannel channel ) : CdpBondApp ( channel ) , ICdpAppFactory < SenderStateMachine >
8282 {
8383 readonly TaskCompletionSource _promise = new ( ) ;
8484 public async Task SendUriAsync ( Uri uri )
@@ -199,6 +199,8 @@ void HandleDataRequest(BinaryMsgHeader header, ValueSet payload)
199199 } ) ;
200200 }
201201
202+ static SenderStateMachine ICdpAppFactory < SenderStateMachine > . Create ( CdpChannel channel ) => new ( channel ) ;
203+
202204 private readonly struct DataResponseMessage : IBinaryWritable < DataResponseMessage >
203205 {
204206 public required CdpFileProvider FileProvider { get ; init ; }
0 commit comments