| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Gets the current Kestrun server instance. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function retrieves the current Kestrun server instance. If a server instance is not provided, |
| | | 6 | | it attempts to resolve the server from the current context. |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance to retrieve. If not specified, the function will attempt to resolve the current server c |
| | | 9 | | .PARAMETER StartTime |
| | | 10 | | If specified, returns the server's start time as a DateTime object. |
| | | 11 | | .PARAMETER StopTime |
| | | 12 | | If specified, returns the server's stop time as a DateTime object. |
| | | 13 | | .PARAMETER Uptime |
| | | 14 | | If specified, returns the server's uptime as a TimeSpan object. |
| | | 15 | | .EXAMPLE |
| | | 16 | | Get-KrServer |
| | | 17 | | This command retrieves the current Kestrun server instance. |
| | | 18 | | .EXAMPLE |
| | | 19 | | Get-KrServer -StartTime |
| | | 20 | | This command retrieves the start time of the current Kestrun server instance. |
| | | 21 | | .EXAMPLE |
| | | 22 | | Get-KrServer -StopTime |
| | | 23 | | This command retrieves the stop time of the current Kestrun server instance. |
| | | 24 | | .EXAMPLE |
| | | 25 | | Get-KrServer -Uptime |
| | | 26 | | This command retrieves the uptime of the current Kestrun server instance. |
| | | 27 | | .OUTPUTS |
| | | 28 | | [Kestrun.Hosting.KestrunHost] |
| | | 29 | | The current Kestrun server instance. |
| | | 30 | | [DateTime] |
| | | 31 | | The server's start time or stop time if the corresponding switch is used. |
| | | 32 | | [TimeSpan] |
| | | 33 | | The server's uptime if the Uptime switch is used. |
| | | 34 | | .NOTES |
| | | 35 | | This function is part of the Kestrun PowerShell module and is used to manage Kestrun server instances. |
| | | 36 | | If the server instance is not found in the context, it attempts to resolve it using the Resolve-KestrunServer functi |
| | | 37 | | #> |
| | | 38 | | function Get-KrServer { |
| | | 39 | | [KestrunRuntimeApi('Everywhere')] |
| | | 40 | | [CmdletBinding(defaultParameterSetName = 'Default')] |
| | | 41 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | | 42 | | [OutputType([DateTime])] |
| | | 43 | | [OutputType([TimeSpan])] |
| | | 44 | | param( |
| | | 45 | | [Parameter(ValueFromPipeline)] |
| | | 46 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 47 | | [Parameter(ParameterSetName = 'StartTime')] |
| | | 48 | | [switch]$StartTime, |
| | | 49 | | [Parameter(ParameterSetName = 'StopTime')] |
| | | 50 | | [switch]$StopTime, |
| | | 51 | | [Parameter(ParameterSetName = 'Uptime')] |
| | | 52 | | [switch]$Uptime |
| | | 53 | | ) |
| | | 54 | | process { |
| | 0 | 55 | | if ($null -eq $Context -or $null -eq $Context.Response) { |
| | 0 | 56 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 57 | | } else { |
| | 0 | 58 | | $Server = $Context.Host |
| | | 59 | | } |
| | | 60 | | |
| | 0 | 61 | | if ($StartTime.IsPresent) { |
| | 0 | 62 | | return $Server.StartTime |
| | 0 | 63 | | } elseif ($StopTime.IsPresent) { |
| | 0 | 64 | | return $Server.StopTime |
| | 0 | 65 | | } elseif ($Uptime.IsPresent) { |
| | 0 | 66 | | return $Server.Uptime |
| | | 67 | | } else { |
| | 0 | 68 | | return $Server |
| | | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |