| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Adds a named pipe listener to a Kestrun server instance. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function adds a named pipe listener to the specified Kestrun server instance, allowing it to listen for incomin |
| | 6 | | .PARAMETER Server |
| | 7 | | The Kestrun server instance to which the named pipe listener will be added. This parameter is optional and can be pr |
| | 8 | | .PARAMETER NamedPipeName |
| | 9 | | The name of the named pipe on which the server will listen for incoming requests. This parameter is mandatory. |
| | 10 | | .PARAMETER PassThru |
| | 11 | | If specified, the cmdlet will return the modified server instance after adding the named pipe listener |
| | 12 | | .EXAMPLE |
| | 13 | | Add-KrNamedPipeListener -Server $server -NamedPipeName "MyNamedPipe" |
| | 14 | | Adds a named pipe listener with the specified name to the given Kestrun server instance. |
| | 15 | | .NOTES |
| | 16 | | This function is designed to be used in the context of a Kestrun server setup and allows for flexible configuration |
| | 17 | | The named pipe listener will be added to the server's options and will be used when the server is started to listen |
| | 18 | | #> |
| | 19 | | function Add-KrNamedPipeListener { |
| | 20 | | [KestrunRuntimeApi('Definition')] |
| | 21 | | [CmdletBinding(defaultParameterSetName = 'NoCert')] |
| | 22 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | 23 | | param( |
| | 24 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | 25 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | 26 | |
|
| | 27 | | [Parameter(Mandatory = $true)] |
| | 28 | | [string]$NamedPipeName, |
| | 29 | |
|
| | 30 | | [Parameter()] |
| | 31 | | [switch]$PassThru |
| | 32 | | ) |
| | 33 | | begin { |
| | 34 | | # Ensure the server instance is resolved |
| 0 | 35 | | $Server = Resolve-KestrunServer -Server $Server |
| 0 | 36 | | if ($null -eq $Server) { |
| 0 | 37 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 38 | | } |
| | 39 | | } |
| | 40 | | process { |
| | 41 | |
|
| | 42 | | # Add the named pipe listener to the server options |
| 0 | 43 | | $Server.Options.NamedPipeNames.Add($NamedPipeName) |
| | 44 | |
|
| 0 | 45 | | if ($PassThru.IsPresent) { |
| | 46 | | # Return the modified server instance |
| 0 | 47 | | return $Server |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |
| | 51 | |
|