Private/TenantUtil.ps1
$global:NameDelimiter = " " function Get-ServiceNameFromTenant($Tenant) { return $TenantPrefix + $Tenant } function Get-ServiceDisplayNameFromTenant($Tenant) { return $TenantPrefix + $NameDelimiter + $Tenant } function Get-ServicePath { return "$env:ProgramFiles\$TenantPrefix" } function Get-WebAppNameFromTenant($Tenant) { return $TenantPrefix + $Tenant } function Get-SiteNameFromTenant($Tenant) { return $TenantPrefix + $NameDelimiter + $Tenant + " Site" } function Get-PoolNameFromTenant($Tenant) { return $TenantPrefix + $NameDelimiter + $Tenant + " Pool" } function Get-DatabaseNameFromTenant($Tenant) { return $TenantPrefix + $Tenant } function Get-ServerPathFromTenant($Tenant) { $servicePath = Get-ServicePath return "$servicePath\$Tenant" } function Get-LegacyRolePath { return "$env:ProgramData\$TenantPrefix\PlannerOneInstall.config" } function Get-LegacyDBConfigPath($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\database.config" } function Get-TenantsPath { return "$env:ProgramData\$TenantPrefix\Tenants\" } function Get-AdapterConfigPathFromTenant($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\Config\Adapter\" } function Get-UIParamPathFromTenant($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\Config\GUI\" } function Get-CriteriaPathFromTenant($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\Config\Criteria\" } function Get-LocalStorePathFromTenant($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\" } function Get-EnvironmentsPathFromTenant($Tenant) { return "$env:ProgramData\$TenantPrefix\$Tenant\Environments\" } function Register-Tenant($Tenant, $RemotingPort, $WebServicePort, $WebAppName, $SitePort, $Adapter) { $serverPath = ServerPathFromTenant $Tenant $serviceName = Get-ServiceNameFromTenant $Tenant if (!$WebAppName) { $WebAppName = Get-WebAppNameFromTenant $Tenant } $tenantInfo = @{ Role = $Tenant; Path = $serverPath; WebApplicationName = $WebAppName; SitePort = $SitePort; RemotingPort = $RemotingPort; WebServicePort = $WebServicePort; WindowsServiceName = $serviceName; WebHost = "localhost"; ServiceHost = "localhost"; Adapter = $Adapter; } Write-TenantInfo $Tenant $tenantInfo } function Write-TenantInfo($Tenant, $tenantInfo) { $data = $tenantInfo | ConvertTo-Json $storePath = Get-TenantsPath if (!(Test-Path $storePath)) { mkdir $storePath | Out-Null } $storePath = $storePath + $Tenant + ".json" [System.IO.File]::WriteAllText($storePath, $data) Write-Verbose "Tenant registered in $storePath" } function Remove-Tenant($Tenant, [switch]$RemoveData) { $storePath = Get-TenantsPath $storePath = $storePath + $Tenant + ".json" Write-Verbose "Removing tenant configuration $storePath" remove-item $storePath $dataPath = Get-LocalStorePathFromTenant $Tenant if ($RemoveData.IsPresent) { Write-Verbose "Removing data stored in $dataPath ..." Remove-Item $dataPath -Recurse -Force } else { Write-Verbose "Keeping data stored in $dataPath" } } function Get-TenantList() { $path = Get-TenantsPath Get-ChildItem $path -Filter *.json | format-table -property @{n="Tenant";e={$_.basename}} } function Get-TenantInfo($Tenant) { $storePath = Get-TenantsPath $path = $storePath + $Tenant + ".json" Write-Verbose "Reading $path" if ([System.IO.File]::Exists($path)) { $json = [system.IO.File]::ReadAllText($path) $tenant = $json | ConvertFrom-Json return $tenant } else { return "Tenant $Tenant does not exist" } } function Test-Tenant($Tenant) { $storePath = Get-TenantsPath $path = $storePath + $Tenant + ".json" return Test-Path $path } function Modify-TenantInfo([string] $Tenant, [int] $RemotingPort, [int] $WebServicePort, [int] $WebPort, [string] $WebAppName) { $tenantInfo = Get-TenantInfo $Tenant if ($RemotingPort -ne 0) { $tenantInfo.RemotingPort = $RemotingPort } if ($WebServicePort -ne 0) { $tenantInfo.WebServicePort = $WebServicePort } if ($WebPort -ne 0) { $tenantInfo.SitePort = $WebPort } if ($WebAppName -ne "") { $tenantInfo.WebApplicationName = $WebAppName } Write-TenantInfo $Tenant $tenantInfo } function Write-P1AdapterParametersList() { Write-Section "Adapter parameter list" foreach($parameter in $AdapterParameters) { Write-Output $parameter } } |