<commit_before>Write-Host "Ensconce - scheduledTaskHelper Loading"

function ScheduledTask-CheckExists([string] $taskName, [string] $taskPath)
{
    $ErrorActionPreference = 'Stop'
    try 
    {
        Write-Host "Checking if scheduled task '\$taskPath\$taskName' exists"

        $response = & "schtasks" "/query" "/TN" "\$taskPath\$taskName"

        if($response -match ".*$taskName.*")
        {
            $true
        }
        else
        {
            $false
        }
    }
    catch
    {
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }
}

function ScheduledTask-Delete([string] $taskName, [string] $taskPath)
{
    if((ScheduledTask-CheckExists $taskName $taskPath) -eq $true)
    {
        $ErrorActionPreference = 'Stop'
        try 
        {
            Write-Host "Deleting scheduled task '\$taskPath\$taskName'"

            $response = & "schtasks" "/delete" "/TN" "\$taskPath\$taskName" "/f"

            if($response -match ".*SUCCESS.*")
            {
                Write-Host "Scheduled task '\$taskPath\$taskName' deleted"
                $true
            }
            else
            {
                Write-Error "Error deleting scheduled task '$taskPath\$taskName' - $response"
                $false

            }
        }
        catch
        {
            Write-Error "Error deleting scheduled task '$taskPath\$taskName'"
            $false
        }
        finally
        {
            $ErrorActionPreference = 'Continue'
        }       
    }
    else
    {
        Write-Host "Scheduled task '\$taskPath\$taskName' does not exist"
        $true
    }
}

function ScheduledTask-CreateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    $ErrorActionPreference = 'Continue'
    try 
    {
        Write-Host "Creating scheduled task '\$taskPath\$taskName'"
        $response = & "schtasks" "/create" "/XML" $taskXmlPath "/TN" "\$taskPath\$taskName" "/F"
        if($response -match ".*SUCCESS.*")
        {
            Write-Host "Scheduled task '\$taskPath\$taskName' created"
            $true
        }
        else
        {
            Write-Error "Error creating scheduled task '$taskPath\$taskName' - $response"
            $false
        }
    }
    catch
    {
        Write-Error "Error creating scheduled task '$taskPath\$taskName'"
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }    
}

function ScheduledTask-CreateOrUpdateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    if((ScheduledTask-Delete $taskName $taskPath) -eq $true)
    {
        ScheduledTask-CreateFromXml $taskName $taskPath $taskXmlPath
    }
    else
    {
        $false
    }
}

Write-Host "Ensconce - scheduledTaskHelper Loaded"
$scheduledTaskHelperLoaded = $true<commit_msg>Add scheduled task run<commit_after>Write-Host "Ensconce - scheduledTaskHelper Loading"

function ScheduledTask-CheckExists([string] $taskName, [string] $taskPath)
{
    $ErrorActionPreference = 'Stop'
    try 
    {
        Write-Host "Checking if scheduled task '\$taskPath\$taskName' exists"

        $response = & "schtasks" "/query" "/TN" "\$taskPath\$taskName"

        if($response -match ".*$taskName.*")
        {
            $true
        }
        else
        {
            $false
        }
    }
    catch
    {
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }
}

function ScheduledTask-Delete([string] $taskName, [string] $taskPath)
{
    if((ScheduledTask-CheckExists $taskName $taskPath) -eq $true)
    {
        $ErrorActionPreference = 'Stop'
        try 
        {
            Write-Host "Deleting scheduled task '\$taskPath\$taskName'"

            $response = & "schtasks" "/delete" "/TN" "\$taskPath\$taskName" "/f"

            if($response -match ".*SUCCESS.*")
            {
                Write-Host "Scheduled task '\$taskPath\$taskName' deleted"
                $true
            }
            else
            {
                Write-Error "Error deleting scheduled task '$taskPath\$taskName' - $response"
                $false
            }
        }
        catch
        {
            Write-Error "Error deleting scheduled task '$taskPath\$taskName'"
            $false
        }
        finally
        {
            $ErrorActionPreference = 'Continue'
        }       
    }
    else
    {
        Write-Host "Scheduled task '\$taskPath\$taskName' does not exist"
        $true
    }
}

function ScheduledTask-CreateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    $ErrorActionPreference = 'Continue'
    try 
    {
        Write-Host "Creating scheduled task '\$taskPath\$taskName'"
        $response = & "schtasks" "/create" "/XML" $taskXmlPath "/TN" "\$taskPath\$taskName" "/F"
        if($response -match ".*SUCCESS.*")
        {
            Write-Host "Scheduled task '\$taskPath\$taskName' created"
            $true
        }
        else
        {
            Write-Error "Error creating scheduled task '$taskPath\$taskName' - $response"
            $false
        }
    }
    catch
    {
        Write-Error "Error creating scheduled task '$taskPath\$taskName'"
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }    
}

function ScheduledTask-CreateOrUpdateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    if((ScheduledTask-Delete $taskName $taskPath) -eq $true)
    {
        ScheduledTask-CreateFromXml $taskName $taskPath $taskXmlPath
    }
    else
    {
        $false
    }
}

function ScheduledTask-Run([string] $taskName, [string] $taskPath)
{
    if((ScheduledTask-CheckExists $taskName $taskPath) -eq $true)
    {
        $ErrorActionPreference = 'Stop'
        try 
        {
            Write-Host "Running scheduled task '\$taskPath\$taskName'"

            $response = & "schtasks" "/run" "/TN" "\$taskPath\$taskName"

            if($response -match ".*SUCCESS.*")
            {
                Write-Host "Scheduled task '\$taskPath\$taskName' ran"
                $true
            }
            else
            {
                Write-Error "Error running scheduled task '$taskPath\$taskName' - $response"
                $false
            }
        }
        catch
        {
            Write-Error "Error running scheduled task '$taskPath\$taskName'"
            $false
        }
        finally
        {
            $ErrorActionPreference = 'Continue'
        }       
    }
    else
    {
        Write-Error "Scheduled task '\$taskPath\$taskName' does not exist"
        $false
    }
}
        Write-Host "Scheduled task '\$taskPath\$taskName' does not exist"
        $true
    }
}

function ScheduledTask-CreateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    $ErrorActionPreference = 'Continue'
    try 
    {
        Write-Host "Creating scheduled task '\$taskPath\$taskName'"
        $response = & "schtasks" "/create" "/XML" $taskXmlPath "/TN" "\$taskPath\$taskName" "/F"
        if($response -match ".*SUCCESS.*")
        {
            Write-Host "Scheduled task '\$taskPath\$taskName' created"
            $true
        }
        else
        {
            Write-Error "Error creating scheduled task '$taskPath\$taskName' - $response"
            $false
        }
    }
    catch
    {
        Write-Error "Error creating scheduled task '$taskPath\$taskName'"
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }    
}

function ScheduledTask-CreateOrUpdateFromXml([string] $taskName, [string] $taskPath, [string] $taskXmlPath)
{
    if((ScheduledTask-Delete $taskName $taskPath) -eq $true)
    {
        ScheduledTask-CreateFromXml $taskName $taskPath $taskXmlPath
    }
    else
    {
        $false
    }
}

function ScheduledTask-Run([string] $taskName, [string] $taskPath)
{
    $ErrorActionPreference = 'Stop'
    try 
    {
        #TODO write this function
        Write-Host "Checking if scheduled task '\$taskPath\$taskName' exists"

        $response = & "schtasks" "/query" "/TN" "\$taskPath\$taskName"

        if($response -match ".*$taskName.*")
        {
            $true
        }
        else
        {
            $false
        }
    }
    catch
    {
        $false
    }
    finally
    {
        $ErrorActionPreference = 'Continue'
    }
}

Write-Host "Ensconce - scheduledTaskHelper Loaded"
$scheduledTaskHelperLoaded = $true
{'fraction_non_alphanumeric': 0.12250443000590668, 'fraction_numerical': 0.0, 'mean_word_length': 1.795904887714663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5983420', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2458, 'n_words': 522}