< Summary - Kestrun — Combined Coverage

Information
Class: Public.Service.Add-KrSignalRHub
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Add-KrSignalRHub.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 87
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Add-KrSignalRHub.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Maps a SignalR hub class to the given URL path.
 4    .DESCRIPTION
 5        This function allows you to map a SignalR hub class to a specific URL path on the Kestrun server.
 6    .PARAMETER Server
 7        The Kestrun server instance to which the SignalR hub will be added.
 8    .PARAMETER HubType
 9        The type of the SignalR hub class to be mapped.
 10    .PARAMETER Path
 11        The URL path where the SignalR hub will be accessible.
 12    .PARAMETER PassThru
 13        If specified, the cmdlet will return the modified server instance after adding the SignalR hub.
 14    .EXAMPLE
 15        $server | Add-KrSignalRHub -HubType ([ChatHub]) -Path "/chat"
 16        This example maps the ChatHub class to the "/chat" URL path on the specified Kestrun server.
 17    .EXAMPLE
 18        Get-KrServer | Add-KrSignalRHub -HubType ([ChatHub]) -Path "/chat"
 19        This example retrieves the current Kestrun server and maps the ChatHub class to the "/chat" URL path.
 20    .NOTES
 21        This function is part of the Kestrun PowerShell module and is used to manage SignalR hubs on the Kestrun server.
 22        The HubType parameter must be a valid SignalR hub class type.
 23        The Path parameter specifies the URL path where the SignalR hub will be accessible.
 24        The function uses reflection to find and invoke the generic AddSignalR<T>(string) method on the KestrunHost inst
 25        This allows for dynamic mapping of SignalR hubs to specific URL paths at runtime.
 26        The function returns the modified server instance for further chaining if needed.
 27        The function ensures that the server instance is resolved before proceeding with the mapping.
 28        The function is designed to be used in a pipeline, allowing for easy integration with other Kestrun commands.
 29        The function is part of the Kestrun.Hosting namespace and is used to extend the functionality of the Kestrun ser
 30        The function is designed to be used in a modular way, allowing for easy addition of SignalR hubs to the Kestrun 
 31        The function is intended for use in scenarios where SignalR hubs need to be dynamically mapped to specific URL p
 32        The function is part of the Kestrun.Hosting library and is used to manage SignalR hubs on the Kestrun server.
 33        The function is designed to be used in a modular way, allowing for easy addition of SignalR hubs to the Kestrun 
 34        The function is intended for use in scenarios where SignalR hubs need to be dynamically mapped to specific URL p
 35#>
 36function Add-KrSignalRHub {
 37    [KestrunRuntimeApi('Definition')]
 38    [CmdletBinding()]
 39    param(
 40        [Parameter(Mandatory = $true, ValueFromPipeline)]
 41        [Kestrun.Hosting.KestrunHost]$Server,
 42
 43        [Parameter(Mandatory)]
 44        [Type]$HubType,
 45
 46        [Parameter(Mandatory)]
 47        [string]$Path,
 48
 49        [Parameter()]
 50        [switch]$PassThru
 51    )
 52    begin {
 53        # Ensure the server instance is resolved
 054        $Server = Resolve-KestrunServer -Server $Server
 055        if ($null -eq $Server) {
 056            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 57        }
 58    }
 59    process {
 060        Write-KrLog -Level Warning 'Add-KrSignalRHub is an experimental feature and may not work as expected.'
 61
 62        # 1.  Find the generic method definition on KestrunHost
 063        $method = $Server.GetType().GetMethods() |
 064            Where-Object {
 065                $_.Name -eq 'AddSignalR' -and
 66                $_.IsGenericMethod -and
 67                $_.GetParameters().Count -eq 1        # (string path)
 68            }
 69
 070        if (-not $method) {
 071            throw 'Could not locate the generic AddSignalR<T>(string) method.'
 72        }
 73
 74        # 2.  Close the generic with the hub type from the parameter
 075        $closed = $method.MakeGenericMethod(@($HubType))
 76
 77        # 3.  Invoke it, passing the path; return the resulting server for chaining
 078        $closed.Invoke($Server, @($Path)) | Out-Null
 79
 080        if ($PassThru.IsPresent) {
 81            # if the PassThru switch is specified, return the server instance
 82            # Return the modified server instance
 083            return $Server
 84        }
 85    }
 86}
 87

Methods/Properties

Add-KrSignalRHub()