##Requires -Version 2.0
####################################################################################################
$PowerBootsPath = $PSScriptRoot
$ParameterHashCache = @{}
$DependencyProperties = @{}
if(Test-Path $PowerBootsPath\DependencyProperties.clixml) {
   $DependencyProperties = Import-CliXml $PowerBootsPath\DependencyProperties.clixml
}
$LoadedAssemblies = @(); 

$null = [Reflection.Assembly]::Load( "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" )

## Dot-Source all of these
. "$PowerBootsPath\UtilityFunctions.ps1"
. "$PowerBootsPath\ContentProperties.ps1"
. "$PowerBootsPath\Add-BootsFunction.ps1"
. "$PowerBootsPath\Set-DependencyProperty.ps1"
. "$PowerBootsPath\New-BootsImage.ps1"

# This is #Requires -STA
$IsSTA = [System.Threading.Thread]::CurrentThread.ApartmentState -eq "STA"
if( !$IsSTA ) { 
   Write-Warning "Out-BootsWindow disabled in MTA mode. (Must run PowerShell with -STA switch to enable)"
} else { # Requires -STA
   . "$PowerBootsPath\Out-BootsWindow.ps1"
}

## Put ths scripts into the path
[string[]]$path = ${Env:Path}.Split(";")
if($path -notcontains "$PowerBootsPath\Functions\") {
   $path += "$PowerBootsPath\Functions\"
   ${Env:Path} = [string]::Join(";", $path)
}

## Generate aliases for all the functions ....
$Scripts = Get-ChildItem "$PowerBootsPath\Functions\New-*.ps1" -ErrorAction 0

if($Scripts) {
   foreach($script in $Scripts) {
      $TypeName = $script.Name -replace 'New-(.*).ps1','$1'
      
      # Set-Alias -Name "New-$TypeName" $Script.FullName                     -EA "SilentlyContinue" -EV +ErrorList
      Set-Alias -Name "$($TypeName.Split('.')[-1])" "New-$TypeName"        -EA "SilentlyContinue" -EV +ErrorList
   }
} else {
   & "$PowerBootsPath\Reset-DefaultBoots.ps1"
   ## Generate aliases for all the functions ....
   foreach($script in Get-ChildItem "$PowerBootsPath\Functions\New-*.ps1" -ErrorAction 0) {
      $TypeName = $script.Name -replace 'New-(.*).ps1','$1'
      
      # Set-Alias -Name "New-$TypeName" $Script.FullName                     -EA "SilentlyContinue" -EV +ErrorList
      Set-Alias -Name "$($TypeName.Split('.')[-1])" "New-$TypeName"        -EA "SilentlyContinue" -EV +ErrorList
   }
}

## Extra aliases....
# A work around for the built-in "Grid" alias, call it GridPanel (which is what the class ought to be anyway?)
$errorList = @()
Set-Alias -Name GridPanel  -Value "New-System.Windows.Controls.Grid"   -EA "SilentlyContinue" -EV +ErrorList
if($ErrorList.Count) { Write-Warning """GridPanel"" alias not created, you must use New-System.Windows.Controls.Grid" }

$errorList = @()
Set-Alias -Name Boots      -Value "New-BootsWindow"         -EA "SilentlyContinue" -EV +ErrorList
if($ErrorList.Count) { Write-Warning "Boots alias not created, you must use the full New-BootsWindow function name!" }

$errorList = @()
Set-Alias -Name BootsImage -Value "Out-BootsImage"          -EA "SilentlyContinue" -EV +ErrorList
if($ErrorList.Count) { Write-Warning "BootsImage alias not created, you must use the full Out-BootsImage function name!" }

Set-Alias -Name obi    -Value "Out-BootsImage"          -EA "SilentlyContinue"
Set-Alias -Name sap    -Value "Set-DependencyProperty"  -EA "SilentlyContinue"
Set-Alias -Name gbw    -Value "Get-BootsWindow"         -EA "SilentlyContinue"
Set-Alias -Name rbw    -Value "Remove-BootsWindow"      -EA "SilentlyContinue"
                                                    
#  Write-Warning "======================================================================="
#  Write-Warning "== NOTICE: It is a known bug that the alias ""Grid"" will not be created."
#  Write-Warning "== We create ""GridPanel"" instead, but if there are other warnings above"
#  Write-Warning "== you should take note of them, as PowerBoots samples may not work."
#  Write-Warning "======================================================================="

$BootsFunctions = @("Add-BootsFunction", "Set-DependencyProperty", "New-*") +
                  @("Get-BootsModule", "Get-BootsAssemblies", "Get-Parameter", "Get-BootsParam" ) + 
                  @("Get-BootsContentProperty", "Add-BootsContentProperty", "Remove-BootsContentProperty") +
                  @("Get-BootsHelp", "Get-BootsCommand", "Out-BootsWindow", "New-BootsImage")
Export-ModuleMember -Function $BootsFunctions -Alias * -Variable IsSTA, PowerBootsPath
## Post CTP3 we have to export the submodule separately:
if($P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