Public/Debugging/Send-ASDSignal.ps1


function Send-ASDSignal
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter(Mandatory, Position=0)][string]$Type,
        [Parameter()][hashtable] $Fields
        )

        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $object = New-Object –TypeName PSObject
        foreach ($boundParam in $PSBoundParameters.GetEnumerator())
        {
            $object | Add-Member –MemberType NoteProperty –Name $boundParam.Key –Value $boundParam.Value
        }
        
        $body = $object | ConvertTo-Json -Depth 8

        $uri = "http://$($shellLocal):4444/api/debugging/SendSignal" 
        $result = Invoke-RestMethod -Body $body -Uri $uri -Method POST -ContentType 'application/json'

        if($result.success) {
            if ($result.message) {
                $result.message
            }
        }
        else {
            Write-Error $result.error -ErrorAction Stop
        }
}