Class ServerFactory
- Namespace
- Microsoft.ServiceHub.Framework
- Assembly
- Microsoft.ServiceHub.Framework.dll
A static class for creating named pipe servers.
public static class ServerFactory
- Inheritance
-
ServerFactory
- Inherited Members
Methods
ConnectAsync(string, ClientOptions, CancellationToken)
Connects to an IPC pipe that was created with Create(Func<Stream, Task>, ServerOptions).
public static Task<Stream> ConnectAsync(string pipeName, ServerFactory.ClientOptions options, CancellationToken cancellationToken)
Parameters
pipeNamestringA fully-qualified pipe name, including the path. On Windows the prefixed path should be
\.\pipe</code>.optionsServerFactory.ClientOptionsOptions that can influence how the IPC pipe is connected to.
cancellationTokenCancellationTokenA cancellation token.
Returns
ConnectAsync(string, CancellationToken)
Connects to an IPC pipe that was created with Create(Func<Stream, Task>, ServerOptions).
public static Task<Stream> ConnectAsync(string pipeName, CancellationToken cancellationToken)
Parameters
pipeNamestringA fully-qualified pipe name, including the path. On Windows the prefixed path should be
\.\pipe</code>.cancellationTokenCancellationTokenA cancellation token.
Returns
Create(Func<Stream, Task>, ServerOptions)
Creates an IPC server.
public static IIpcServer Create(Func<Stream, Task> onConnectedCallback, ServerFactory.ServerOptions options = default)
Parameters
onConnectedCallbackFunc<Stream, Task>Callback function to be run whenever a client connects to the server. This may be called concurrently if multiple clients connect. The delegate may choose to return right away while still using the Stream or to complete only after finishing communication with the client.
optionsServerFactory.ServerOptionsIPC server options.
Returns
- IIpcServer
The server, which includes a means to obtain its pipe name and monitor for completion.
CreateAsync(string, TraceSource?, Func<Stream, Task>)
Creates a named pipe server.
[Obsolete("Use Create instead.")]
public static Task<(IDisposable Server, string ServerName)> CreateAsync(string pipeName, TraceSource? logger, Func<Stream, Task> onConnectedCallback)
Parameters
pipeNamestringThe name of the server. Typically just the result of calling ToString() on the result of NewGuid(). This should not include path separators.
loggerTraceSourceThe logger for the server.
onConnectedCallbackFunc<Stream, Task>- Callback function to be run whenever a client connects to the server. This may be called concurrently if multiple clients connect. The delegate may choose to return right away while still using the Stream or to complete only after finishing communication with the client.
Returns
- Task<(IDisposable Server, string ServerName)>
A tuple where
Serveris disposable to shut down the pipe, andServerNameis the pipe name as the client will need to access it. It implements IAsyncDisposable.ServerNamewill typically be the same aspipeNameon Windows, but on mac/linux it will have a path prepended to it.
PrependPipePrefix(string)
Prepends the OS-specific prefix to a simple pipe name.
public static string PrependPipePrefix(string leafPipeName)
Parameters
leafPipeNamestringThe simple pipe name. This should not include a path.
Returns
- string
The fully-qualified, OS-specific pipe name.