NamedPipeRequestEventArgs
Namespace: TagBites.Pipes
Assembly: TagBites.Pipes.dll
Product: TagBites.Pipes v. 1.2.0
Provides data for the NamedPipeServer.Request event.
public class NamedPipeRequestEventArgs : System.EventArgsInheritance: EventArgs → NamedPipeRequestEventArgs
Constructors
Section titled “Constructors”NamedPipeRequestEventArgs(NamedPipeConnectionContext, string, string)
Section titled “NamedPipeRequestEventArgs(NamedPipeConnectionContext, string, string)”Initializes a new instance of the NamedPipeRequestEventArgs class.
public NamedPipeRequestEventArgs(NamedPipeConnectionContext context, string address, string message)Parameters
Section titled “Parameters”contextNamedPipeConnectionContext
The context of the connection the request arrived on.addressstring
The address of the request.messagestring
The message of the request.
Properties
Section titled “Properties”Address
Section titled “Address”Gets the address of the request, which names the operation the client asks for.
public string Address { get; }Property Value
Section titled “Property Value”Context
Section titled “Context”Gets the context of the connection the request arrived on.
public NamedPipeConnectionContext Context { get; }Property Value
Section titled “Property Value”Message
Section titled “Message”Gets the message of the request.
public string Message { get; }Property Value
Section titled “Property Value”Exceptions
Section titled “Exceptions”- InvalidOperationException - NamedPipeServer.UseMessageStream is on, so the message arrives as MessageStream and is never held as a string.
MessageStream
Section titled “MessageStream”Gets the message of the request as a stream.
public Stream MessageStream { get; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”Valid while the handler runs. Whatever the handler leaves unread is skipped, so the next request still starts at a message boundary.
Response
Section titled “Response”Gets or sets the text sent back to the client.
public string Response { get; set; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”null reaches the client as an empty string.
ResultTask
Section titled “ResultTask”Gets or sets the task the server waits for before it reads the response.
public Task ResultTask { get; set; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”Set this to handle a request asynchronously. The handler assigns the task and returns, and the server reads the response once the task completes. An exception from the task reaches the client the same way as one thrown by the handler itself.
Methods
Section titled “Methods”SetResponse(Func<Stream, Task>)
Section titled “SetResponse(Func<Stream, Task>)”Answers with whatever the callback writes into the stream, without holding the whole response in memory.
public void SetResponse(Func<Stream, Task> writeResponse)Parameters
Section titled “Parameters”Remarks
Section titled “Remarks”The connection has to be on encoding version 3, because earlier versions carry text only. A failure after the callback started writing breaks the connection, since the answer is already on its way. Read MessageStream in the handler, not in this callback: the request is consumed to the end before the answer starts, so by then it is empty.