Class AdapterControlChannel
- Namespace
- MirrorPulse.Adapter.Sdk
- Assembly
- MirrorPulse.Adapter.Sdk.dll
Frames control and binary messages for one MirrorPulse Worker session.
public sealed class AdapterControlChannel : IAsyncDisposable
- Inheritance
-
AdapterControlChannel
- Implements
- Inherited Members
Remarks
The caller must serialize writes and keep a single reader. Validate the Host's Ready response before selecting its protocol.
Constructors
AdapterControlChannel(AdapterNamedPipeClient, Guid, Guid)
public AdapterControlChannel(AdapterNamedPipeClient pipe, Guid instanceId, Guid workerSessionId)
Parameters
pipeAdapterNamedPipeClientinstanceIdGuidworkerSessionIdGuid
Properties
ProtocolVersion
The current envelope version. A new channel starts at version 1 for Hello.
public int ProtocolVersion { get; }
Property Value
Methods
DisposeAsync()
public ValueTask DisposeAsync()
Returns
ReadAsync(CancellationToken)
Reads and validates one control frame when the next message is expected to be JSON.
public ValueTask<AdapterControlFrame> ReadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Remarks
Match the returned request ID and message type to the exchange. Use ReadNextAsync(CancellationToken) during v2 uploads.
ReadChunkAsync(CancellationToken)
Reads one binary chunk when the protocol exchange expects binary data next.
public ValueTask<AdapterBinaryChunk> ReadChunkAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
ReadNextAsync(CancellationToken)
Reads the next control message or upload chunk on a negotiated v2 channel.
public ValueTask<AdapterWorkerFrame> ReadNextAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Remarks
Use the same reader for both frame kinds so a Cancel command can be handled between upload chunks.
SelectProtocol(int)
Selects the protocol from the validated Ready response for this session.
public void SelectProtocol(int version)
Parameters
versionint
Exceptions
- InvalidDataException
The selected version is outside the supported set.
- InvalidOperationException
A different version has already been selected.
SendAsync(string, Guid, bool, object, CancellationToken)
Sends a JSON control envelope using the current version, instance and session identifiers.
public ValueTask SendAsync(string messageType, Guid requestId, bool isResponse, object payload, CancellationToken cancellationToken = default)
Parameters
messageTypestringrequestIdGuidisResponseboolpayloadobjectcancellationTokenCancellationToken
Returns
Remarks
Use the incoming request ID for its response and a fresh nonempty ID for an independent request or event.
SendChunkAsync(AdapterBinaryChunk, CancellationToken)
Sends a binary chunk with the encoding selected for the session.
public ValueTask SendChunkAsync(AdapterBinaryChunk chunk, CancellationToken cancellationToken = default)
Parameters
chunkAdapterBinaryChunkcancellationTokenCancellationToken