Logeto.psm1

$ScriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

. ($ScriptDir + "./Global.ps1")
. ($ScriptDir + "./Terminal.ps1")
. ($ScriptDir + "./TerminalService.ps1")

<#
    Install any Logeto product
#>

function Install-LogetoProduct
{
    Param(

        [parameter(Mandatory=$true)]
        [ValidateSet('Terminal', 'TerminalService')]
        $ProductName,
        [parameter(Mandatory=$false)]
        $UpdateInfo,
        [parameter(Mandatory=$false)]
        $IgnoreActiveHoursSettings
    )

    try
    {
        Write-LogetoProgress "Installing Logeto product $ProductName." "Install-LogetoProduct"

        if ($ProductName -eq 'Terminal')
        {
            if (!($UpdateInfo))
            {
                $UpdateInfo = Get-LogetoTerminalUpdateInfo
            }
        
            if ($UpdateInfo)
            {
                $followActiveHours =  $json | Select -ExpandProperty FollowActiveHours

                if (($IgnoreActiveHoursSettings) -Or (($followActiveHours) -And (Get-IsLogetoActiveHours)))
                {
                    Install-LogetoTerminal $UpdateInfo
                }
            }
        }
        elseif ($ProductName -eq 'TerminalService')
        {
            if (!($UpdateInfo))
            {
                $UpdateInfo = Get-LogetoTerminalServiceUpdateInfo
            }

            if ($UpdateInfo)
            {
                $followActiveHours =  $json | Select -ExpandProperty FollowActiveHours

                if (($IgnoreActiveHoursSettings) -Or (($followActiveHours) -And (Get-IsLogetoActiveHours)))
                {
                    Install-LogetoTerminalService $UpdateInfo
                }
            }
        }
    }
    catch 
    { 
        if ($_.Exception.Data.Contains("i18n"))
        {
            throw $_
        }
        else
        {
            throw Get-LogetoCustomException "Install-LogetoProduct with error $_.Exception.Message" "" $ResultExceptionThrown 0
        }
    }
}

<#
    Uninstall any Logeto product
#>

function Uninstall-LogetoProduct
{
    Param(
        [parameter(Mandatory=$true)]
        [ValidateSet('Terminal', 'TerminalService')]
        $ProductName
    )
    try
    {
        Write-LogetoProgress "Uninstalling Logeto product $ProductName." "Uninstall-LogetoProduct"

        if ($ProductName -eq 'Terminal')
        {
            Uninstall-LogetoTerminal 
        }
        elseif ($ProductName -eq 'TerminalService')
        {
            Uninstall-LogetoTerminalService 
        }
    }
    catch 
    { 
        if ($_.Exception.Data.Contains("i18n"))
        {
            throw $_
        }
        else
        {
            throw Get-LogetoCustomException "Uninstall-LogetoProduct with error $_.Exception.Message" "" $ResultExceptionThrown 0
        }
    }
}

<#
    Prepare any Logeto product environment (e.g. install drivers, update system pre or post installation etc.)
#>

function Set-LogetoProductEnvironment
{
    Param(
        [parameter(Mandatory=$true)]
        [ValidateSet('Terminal', 'TerminalService')]
        $ProductName,
        [parameter(Mandatory=$true)]        
        $Components
    )

    try
    {
        Write-LogetoProgress "Setting Logeto product environment $Components for $ProductName." "Set-LogetoProductEnvironment"

        if ($ProductName -eq 'Terminal')
        {
            Set-LogetoTerminalEnvironment $Components
        }
        elseif ($ProductName -eq 'TerminalService')
        {
            Set-LogetoTerminalServiceEnvironment $Components
        }
    }
    catch 
    { 
        if ($_.Exception.Data.Contains("i18n"))
        {
            throw $_
        }
        else
        {
            throw Get-LogetoCustomException "Set-LogetoProductEnvironment with error $_.Exception.Message" "" $ResultExceptionThrown 0
        }
    }
}

<#
    Remove any Logeto product environment (e.g. install drivers, update system pre or post installation etc.)
#>

function Clear-LogetoProductEnvironment
{
        Param(
        [parameter(Mandatory=$true)]
        [ValidateSet('Terminal', 'TerminalService')]
        $ProductName,
        [parameter(Mandatory=$true)]        
        $Components
    )

    try
    {
        Write-LogetoProgress "Removing Logeto product environment $Components for $ProductName." "Clear-LogetoProductEnvironment"

        if ($ProductName -eq 'Terminal')
        {
            Clear-LogetoTerminalEnvironment $Components
        }
        elseif ($ProductName -eq 'TerminalService')
        {
            Clear-LogetoTerminalServiceEnvironment $Components
        }
    }
    catch 
    { 
        if ($_.Exception.Data.Contains("i18n"))
        {
            throw $_
        }
        else
        {
            throw Get-LogetoCustomException "Clear-LogetoProductEnvironment with error $_.Exception.Message" "" $ResultExceptionThrown 0
        }
    }
}