Public/Start-P1TenantManager.ps1
function Start-P1TenantManager { [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') [xml]$mainXaml = Get-Content "$PSScriptRoot\UI\MainWindow.xaml" [xml]$tenantXaml = Get-Content "$PSScriptRoot\UI\Tenant.xaml" $reader=(New-Object System.Xml.XmlNodeReader $mainXaml) try { $mainForm=[Windows.Markup.XamlReader]::Load( $reader ) } catch { Write-Warning "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." } $reader=(New-Object System.Xml.XmlNodeReader $tenantXaml) try { $tenantForm=[Windows.Markup.XamlReader]::Load( $reader ) } catch { Write-Warning "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." } # Store Form Objects In PowerShell $mainXaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $mainForm.FindName($_.Name)} $tenantXaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $tenantForm.FindName($_.Name)} # Close event $btnExit.Add_Click({$mainForm.Close()}) # Test click event $btnTest.Add_Click({ $features = Test-P1Prerequisites $prereqDataGrid.ItemsSource = @($features) }) # Add missing click event $btnAddMissing.Add_Click({ $prereqDataGrid.ItemsSource = $null $features = Test-P1Prerequisites -Install $prereqDataGrid.ItemsSource = @($features) }) # Test click event $btnLoad.Add_Click({ $packages = Get-P1Packages $itemsSource = @() foreach ($package in $packages) { $installedPackage = Get-Package $package.Name if ($installedPackage -ne $null) { $installedVersion = $installedPackage.Version } else { $installedVersion = $null } [PSCustomObject]$item = @{ Name = $package.Name; Version = $package.Version; InstalledVersion = $installedVersion; Install = $false; } $itemsSource += $item } $packagesDataGrid.ItemsSource = $itemsSource }) # Install click event $btnInstall.Add_Click({ $itemsSource = $packagesDataGrid.ItemsSource foreach ($package in ($itemsSource | Where-Object Install -eq $true)) { Install-P1Package $package.Name } }) $btnLoadTenants.Add_Click({ $tenants = Get-P1Tenant $tenantsDataGrid.ItemsSource = $tenants }) # New tenant $btnNewTenant.Add_Click({ $NameTxt.Text = "Demo" $AdapterTxt.Text = "NAV" $InstanceTxt.Text = "NAV" $DomainTxt.Text = $env:USERDOMAIN $LoginTxt.Text = $env:USERNAME $PasswordTxt.Text = "<YourPassword>" $tenantForm.ShowDialog() | Out-Null }) $CancelBtn.Add_Click({ $tenantForm.Hide() }) $CreateBtn.Add_Click({ New-P1Tenant -Tenant $NameTxt.Text -Adapter $AdapterTxt.Text Set-P1Adapter -Tenant $NameTxt.Text -InstanceName $InstanceTxt.Text -AutoPort -ServiceDomain $DomainTxt.Text -ServiceLogin $LoginTxt.Text -ServicePassword $PasswordTxt.Text $tenantForm.Hide() }) $mainForm.ShowDialog() | Out-Null } |