3/29/2017 1:20:29 PM [NORMAL] - Method "StartLogging" at line 124 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
PowerShell Editor Services Host v0.11.0.0 starting (pid 48932)...
Host application details:
Name: Visual Studio Code Host
ProfileId: Microsoft.VSCode
Version: 1.0.0
Arch: 64-bit
Operating system details:
Version: Microsoft Windows NT 10.0.14393.0
Arch: 64-bit
3/29/2017 1:20:29 PM [NORMAL] - Method "Initialize" at line 214 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
PowerShell runtime version: 5.1.14393.953, edition: Desktop
3/29/2017 1:20:29 PM [VERBOSE] - Method "SetExecutionPolicy" at line 1338 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Current execution policy: ExecutionPolicy.Unrestricted
3/29/2017 1:20:29 PM [VERBOSE] - Method "CheckForCapability" at line 154 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\Capabilities\DscBreakpointCapability.cs
Side-by-side DSC module was not found.
3/29/2017 1:20:29 PM [VERBOSE] - Method "SetProfileVariableInCurrentRunspace" at line 1456 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Setting $profile variable in runspace. Current user host profile path: C:\Users\christopher.mcgrath\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1
3/29/2017 1:20:29 PM [NORMAL] - Method "FindPSScriptAnalyzerModule" at line 261 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Analysis\AnalysisService.cs
PSScriptAnalyzer found at C:\Users\christopher.mcgrath\.vscode\extensions\ms-vscode.PowerShell-0.11.0\modules\PSScriptAnalyzer\PSScriptAnalyzer.psd1
3/29/2017 1:20:30 PM [VERBOSE] - Method "EnumeratePSScriptAnalyzerRules" at line 289 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Analysis\AnalysisService.cs
Available PSScriptAnalyzer Rules:
PSAvoidUsingCmdletAliases
PSAvoidDefaultValueSwitchParameter
PSAvoidDefaultValueForMandatoryParameter
PSAvoidUsingEmptyCatchBlock
PSAvoidGlobalAliases
PSAvoidGlobalFunctions
PSAvoidGlobalVars
PSAvoidInvokingEmptyMembers
PSAvoidNullOrEmptyHelpMessageAttribute
PSAvoidUsingPositionalParameters
PSReservedCmdletChar
PSReservedParams
PSAvoidShouldContinueWithoutForce
PSAvoidUsingUserNameAndPassWordParams
PSAvoidUsingComputerNameHardcoded
PSAvoidUsingConvertToSecureStringWithPlainText
PSAvoidUsingDeprecatedManifestFields
PSAvoidUsingInvokeExpression
PSAvoidUsingPlainTextForPassword
PSAvoidUsingWMICmdlet
PSAvoidUsingWriteHost
PSMisleadingBacktick
PSMissingModuleManifestField
PSPlaceCloseBrace
PSPlaceOpenBrace
PSPossibleIncorrectComparisonWithNull
PSProvideCommentHelp
PSUseApprovedVerbs
PSUseBOMForUnicodeEncodedFile
PSUseCmdletCorrectly
PSUseCompatibleCmdlets
PSUseConsistentIndentation
PSUseConsistentWhitespace
PSUseDeclaredVarsMoreThanAssignments
PSUseLiteralInitializerForHashtable
PSUseOutputTypeCorrectly
PSUsePSCredentialType
PSShouldProcess
PSUseShouldProcessForStateChangingFunctions
PSUseSingularNouns
PSUseToExportFieldsInManifest
PSUseUTF8EncodingForHelpFile
PSDSCDscExamplesPresent
PSDSCDscTestsPresent
PSDSCReturnCorrectTypesForDSCFunctions
PSDSCUseIdenticalMandatoryParametersForDSC
PSDSCUseIdenticalParametersForDSC
PSDSCStandardDSCFunctionsInResource
PSDSCUseVerboseMessageInDSCResource
3/29/2017 1:20:30 PM [VERBOSE] - Method "Initialize" at line 103 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Extensions\ExtensionService.cs
Executing extension API cmdlet script at path: C:\Users\christopher.mcgrath\AppData\Local\Temp\PSES_ExtensionCmdlets_kjgfkjnd.ps1
3/29/2017 1:20:30 PM [VERBOSE] - Method "ExecuteCommand" at line 430 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Attempting to execute command(s):
. C:\Users\christopher.mcgrath\AppData\Local\Temp\PSES_ExtensionCmdlets_kjgfkjnd.ps1
3/29/2017 1:20:30 PM [VERBOSE] - Method "OnSessionStateChanged" at line 1051 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Session state changed --
Old state: Ready
New state: Running
Result: NotFinished
3/29/2017 1:20:30 PM [VERBOSE] - Method "OnSessionStateChanged" at line 1051 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Session state changed --
Old state: Running
New state: Ready
Result: Completed
3/29/2017 1:20:30 PM [VERBOSE] - Method "ExecuteCommand" at line 488 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Execution completed successfully.
3/29/2017 1:20:30 PM [NORMAL] - Method "StartLanguageService" at line 158 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
Language service started, listening on port 18072
3/29/2017 1:20:30 PM [NORMAL] - Method "StartDebugService" at line 213 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
Debug service started, listening on port 10665
3/29/2017 1:20:30 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"processId": 42480,
"rootPath": "d:\\Repos\\svn\\FM3\\trunk\\BuildScripts",
"capabilities": {}
}
}
3/29/2017 1:20:30 PM [VERBOSE] - Method "WriteMessage" at line 59 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs
WRITE MESSAGE:
{
"jsonrpc": "2.0",
"id": "0",
"result": {
"capabilities": {
"textDocumentSync": 2,
"hoverProvider": true,
"completionProvider": {
"resolveProvider": true,
"triggerCharacters": [
".",
"-",
":",
"\\"
]
},
"signatureHelpProvider": {
"triggerCharacters": [
" "
]
},
"definitionProvider": true,
"referencesProvider": true,
"documentHighlightProvider": true,
"documentSymbolProvider": true,
"workspaceSymbolProvider": true,
"codeActionProvider": true
}
}
}
3/29/2017 1:20:30 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"method": "workspace/didChangeConfiguration",
"params": {
"settings": {
"powershell": {
"codeFormatting": {
"ignoreOneLineBlock": true,
"newLineAfterCloseBrace": true,
"newLineAfterOpenBrace": true,
"openBraceOnSameLine": true,
"whitespaceAfterSeparator": true,
"whitespaceAroundOperator": true,
"whitespaceBeforeOpenBrace": true,
"whitespaceBeforeOpenParen": true
},
"developer": {
"bundledModulesPath": "",
"editorServicesLogLevel": "Verbose",
"editorServicesWaitForDebugger": false,
"featureFlags": [],
"powerShellExeIsWindowsDevBuild": false,
"powerShellExePath": ""
},
"enableProfileLoading": true,
"integratedConsole": {
"focusConsoleOnExecute": true,
"showOnStartup": true
},
"scriptAnalysis": {
"enable": true,
"settingsPath": ""
},
"startAutomatically": true,
"useX86Host": false
}
}
}
}
3/29/2017 1:20:30 PM [VERBOSE] - Method "ExecuteCommand" at line 430 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Attempting to execute command(s):
C:\Users\christopher.mcgrath\Documents\WindowsPowerShell\profile.ps1
3/29/2017 1:20:30 PM [VERBOSE] - Method "OnSessionStateChanged" at line 1051 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Session state changed --
Old state: Ready
New state: Running
Result: NotFinished
3/29/2017 1:20:33 PM [VERBOSE] - Method "OnSessionStateChanged" at line 1051 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Session state changed --
Old state: Running
New state: Ready
Result: Completed
3/29/2017 1:20:33 PM [VERBOSE] - Method "ExecuteCommand" at line 488 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
Execution completed successfully.
3/29/2017 1:20:33 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"uri": "file:///d%3A/Repos/svn/FM3/trunk/build.ps1",
"text": "param\r\n(\r\n [Parameter(Mandatory = $true)] $targets,\r\n $EnvPath = $env:FM_ENVIRONMENT_CONFIG,\r\n $Package = $env:FM_PACKAGE_DIRECTORY,\r\n $DBServer,\r\n $Server,\r\n $Website,\r\n [switch]\r\n $CreateIISWebSite,\r\n [switch]\r\n $Force,\r\n $Id, \r\n [switch] $Thin,\r\n [switch] $EnableDetailedLogging\r\n \r\n)\r\n\r\n#.\\build.ps1 -envPath C:\\Repos\\svn\\FM3\\trunk\\BuildScripts\\Configs\\JPM\\JPM.fmenv.xml -targets new -package \"C:\\Users\\christopher.mcgrath\\Desktop\\New folder\"\r\nif (Get-Module -name 'fm')\r\n{\r\n Remove-Module -name 'fm'\r\n}\r\n\r\nImport-Module .\\BuildScripts\\fm.psm1 \r\n\r\nAssert-HasValue -Value $envPath -ErrorMessage '-EnvPath is required, please provide -EnvPath or set FM_ENVIRONMENT_CONFIG environment variable' -ThrowOnError\r\nAssert-HasValue -Value $package -ErrorMessage '-Package is required, please provide -Package or set FM_PACKAGE_DIRECTORY environment variable' -ThrowOnError\r\n\r\nSet-FMEnvPath -Environment $envPath -Package $package\r\n\r\n$UseVerbose = Test-ActionPreference $VerbosePreference Continue\r\n\r\nif ($UseVerbose -and $EnableDetailedLogging)\r\n{\r\n Enable-SuperVerboseLogging\r\n}\r\n\r\nWrite-Verbose \"Using Verbose Logging... \"\r\nWrite-Verbose \"Selected Targets $targets \"\r\n\r\n#todo: refactor packageRoot out of this as we are now settinging this as part of Set-FMEnvPath \r\n$targets | ForEach-Object {\r\n switch ($_) {\r\n #package\r\n 'new' { New-FMPackage -Thin:$Thin }\r\n 'newwebapp' { New-FMWebPackages }\r\n 'clean'{ Clean-PackageDirectory $package }\r\n 'client' {\r\n $fmenv = Get-FMEnv \r\n Deploy-FMClient -clickOnce $fmenv.clickonce\r\n }\r\n 'services' {Install-FMServices -Website $Website -Server $Server -Id $Id -Force:$Force -CreateIISWebSite:$CreateIISWebSite }\r\n #deploy\r\n 'db' { Update-FMDatabases $DBServer }\r\n 'reports' { Update-FMReports -Server $Server -Id $Id -Verbose:$UseVerbose } \r\n 'reporturls' { Initialize-FMReportUrls } \r\n 'services' { Update-FMServices -Server $Server -Website $Website -Id $id -Verbose:$UseVerbose }\r\n 'all' { Deploy-FMPackage -DBServer $DBServer -Server $Server -Website $Website -Verbose:$UseVerbose }\r\n 'deployNoDB' { Update-AllNoDb -Server $Server -Website $Website -Verbose:$UseVerbose }\t\t\r\n 'batch' { Update-FMBatchQueues -Server $Server -Verbose:$UseVerbose }\r\n 'dealsetupservices' { Update-DealSetupServices -Server $Server -Website $Website -Verbose:$UseVerbose }\r\n 'webapp' { Deploy-FMWebPackages }\r\n 'test' { HelperTests -Server $Server -Website $Website -Verbose:$UseVerbose }\r\n }\r\n}\r\n"
}
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "ResolveFilePath" at line 294 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs
Resolved path: d:\Repos\svn\FM3\trunk\build.ps1
3/29/2017 1:20:33 PM [VERBOSE] - Method "GetFileBuffer" at line 135 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs
Opened file as in-memory buffer: d:\Repos\svn\FM3\trunk\build.ps1
3/29/2017 1:20:33 PM [VERBOSE] - Method "HandleDidOpenTextDocumentNotification" at line 500 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\LanguageServer.cs
Finished opening document.
3/29/2017 1:20:33 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"uri": "file:///d%3A/Repos/svn/FM3/trunk/BuildScripts/fm.psm1",
"text": "param(\r\n\t[Parameter(Position = 0, Mandatory = $false)][boolean]$SkipWebAdministrationModule = $false\r\n)\r\n\r\n\r\n\r\n$DefaultBuildConfig = \"Release\"\r\n\r\n$script:packageRoot = $env:FM_PACKAGE_DIRECTORY\r\n$script:envDefinition = $env:FM_ENVIRONMENT_CONFIG\r\n$script:SuperVerboseLogging = $false\r\n\r\n#Packager Tools\r\n function New-FMPackage($config = $DefaultBuildConfig, $buildFMDeploy = $true, [switch] $Thin){\r\n $fmenv = Get-FMEnv\r\n Write-Output \"Creating new FM Package at $script:packageRoot\"\r\n $script:packageRoot | Assert-HasValue -ThrowOnError -ErrorMessage 'FATAL: $packageRoot not initialized'\r\n \r\n if (Test-Path $script:packageRoot)\r\n {\r\n CleanPackageDirectory -ErrorAction SilentlyContinue\r\n }\r\n \r\n Initialize-Package\r\n if (-not $Thin) {\r\n\r\n if ($buildFMDeploy -eq $true) { Update-FMDeploy $config }\r\n #Build And Package WinUi\r\n Add-WinUIToPackage $config\r\n # Application files\r\n Add-ApplicationFilesToPackage $config\r\n # DB Files \r\n Add-DatabaseFilesToPackage \r\n # Reconciliation\r\n if (-not $fmenv.excludeRT){ Add-ReconciliationToolToPackage $config }\r\n # Reports\r\n Add-FMReportsToPackage\r\n # FMTaskHost\r\n if ($fmenv.taskHost ){ Add-TaskHostToPackage $config }\r\n # TradeWeb\r\n if ($fmenv.tradeWeb ){ Add-TradeWebToPackage $config }\r\n # ClickOnce\r\n if ($fmenv.clickOnce ){ Add-ClickOnceToPackage }\r\n # BatchQueue\r\n if ($fmenv.batchQueueServer){ Add-BatchQueueToPackage $config }\r\n # DealSetup Services\r\n if ((Get-FMEnvSection dealSetupServices)){ Add-DealSetupToPackage $config }\r\n \r\n if ((Get-FMEnvSection webService | Where-Object { $_.type -eq \"RTAutomation\"} )){ Add-RTAutomationToPackage $config }\r\n \r\n # MarketData\r\n if (-not $fmenv.excludeMD){ Add-MarketDataToPackage $config }\r\n }\r\n # Copy scripts and configs \r\n Add-BuildScriptsToPackage\r\n \r\n }\r\n \r\n function CleanPackageDirectory(){\r\n [CmdletBinding()]\r\n param(\r\n\r\n )\r\n\r\n \"Cleaning Directory {0}\" -f $script:packageRoot | Write-Output\r\n\r\n Remove-ChildItems -rootfolder $script:packageRoot -excluded \".git\"\r\n\r\n }\r\n\r\n function Remove-ChildItems\r\n {\r\n [cmdletbinding()]\r\n param(\r\n [string]$rootfolder,\r\n [string[]]$excluded\r\n )\r\n $rootfolder = resolve-path $rootfolder\r\n Push-Location $rootFolder\r\n if($excluded -notmatch \"^\\s*$\")\r\n {\r\n $excluded = Resolve-Path $excluded\r\n }\r\n $filesToDel = Get-ChildItem $rootFolder -Recurse\r\n # Excluding files in the excluded folder\r\n foreach($exclusion in $excluded)\r\n {\r\n $filesToDel = $filesToDel |?{$_.fullname -notlike (\"{0}\\*\" -f $exclusion)}\r\n # Excluding parent folders of the excluded folder\r\n while($exclusion -notmatch \"^\\s*$\")\r\n {\r\n $filesToDel = $filesToDel |?{$_.fullname -ne $exclusion}\r\n $exclusion = Split-Path -parent $exclusion\r\n }\r\n }\r\n $filesToDel | Remove-Item -Recurse -ErrorAction SilentlyContinue\r\n Pop-Location\r\n }\r\n\r\n function Copy-DatabaseFiles($DatabaseDir, $DestinationRoot){\r\n if (-not (Test-Path $DestinationRoot\\$DatabaseDir))\r\n {\r\n New-Item -Path $DestinationRoot\\$DatabaseDir -ItemType directory\r\n }\r\n\r\n # Exclude the following files:\r\n \"/xf\" | Set-Content job.rcj\r\n Get-ChildItem $DatabaseDir CreateAll*sql | ForEach-Object {$_.FullName} | Add-Content job.rcj\r\n Get-ChildItem $DatabaseDir Create*sql | ForEach-Object {$_.FullName} | Add-Content job.rcj\r\n Get-ChildItem $DatabaseDir *dbp | ForEach-Object {$_.FullName} | Add-Content job.rcj\r\n\r\n # Exclude the following directories:\r\n \"/xd\" | Add-Content job.rcj\r\n Get-ChildItem $DatabaseDir Scripts | ForEach-Object {$_.FullName} | Add-Content job.rcj\r\n Get-ChildItem $DatabaseDir \"Admin User\" | ForEach-Object {$_.FullName} | Add-Content job.rcj\r\n \r\n robocopy.exe $DatabaseDir $DestinationRoot\\$DatabaseDir /e /ns /nc /nfl /ndl /np /njh /njs /job:job.rcj\r\n\r\n if (Test-Path job.rcj)\r\n {\r\n Remove-Item job.rcj\r\n }\r\n }\r\n\r\n function New-FMWebPackages(){\r\n\r\n $fmenv = Get-FMEnv\r\n $version = Get-BuildVersion\r\n\r\n if (-Not (Test-Path $packageRoot))\r\n {\r\n\t\t\tNew-Item -Path $packageRoot -ItemType directory\r\n\t\t}\r\n\r\n if (-Not (Test-Path $packageRoot\\$version))\r\n {\r\n New-Item -Path $packageRoot\\$version -ItemType directory \r\n }\r\n \r\n $outputRoot = \"$packageRoot\\$version\\FMWeb\"\r\n\r\n if (-Not (Test-Path $outputRoot))\r\n {\r\n\r\n New-Item -Path $outputRoot -ItemType directory \r\n }\r\n \r\n #Run Bower / Gulp for Web Auth project\r\n Push-Location -Path \"WebAuth\"\r\n Write-Output \"Running npm install for WebAuth project\" \r\n & npm install -q\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: npm install failed with exit code $LastExitCode.\"\r\n throw \"ERROR: npm install failed with exit code $LastExitCode.\" \r\n Exit $LastExitCode \r\n }\r\n\r\n $env:NODE_ENV = \"production\"\r\n Write-Output \"Running bower install for WebAuth project\"\r\n Remove-Item .\\bower_components\\* -recurse\r\n\r\n & .\\node_modules\\.bin\\bower install --config.interactive=false\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: bower install failed with exit code $LastExitCode.\" \r\n throw \"ERROR: bower install failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Write-Output \"Running gulp vendor for WebAuth project\"\r\n & .\\node_modules\\.bin\\gulp vendor\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: bower vendor failed with exit code $LastExitCode.\" \r\n throw \"ERROR: bower vendor failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Pop-Location\r\n\r\n $proj = \"./WebAuth/WebAuth.csproj\"\r\n $msbuild = Get-MSBuild \r\n $msdeploy = Get-MSDeploy \r\n \r\n\r\n #Build Web Auth Project\r\n $outputPath = (Get-Item -Path $outputRoot -Verbose).FullName\r\n if(Test-Path $outputPath) {\r\n Remove-Item -Path $outputPath -Recurse -Verbose\r\n }\r\n\r\n & $msbuild /p:Configuration=Release /p:Platform=AnyCPU $proj /p:OutputPath=$outputPath\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: msbuild failed with exit code $LastExitCode.\" \r\n throw \"ERROR: msbuild failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n \r\n #Copy environment specific web.config\r\n $configFile = $packageRoot + \"\\WebAuth\\Configs\\Web.$($fmenv.id).config\"\r\n\r\n if(Test-Path $configFile) {\r\n Copy-Item $configFile \"$outputPath\\_PublishedWebsites\\WebAuth\\Web.config\" -Force\r\n }\r\n\r\n #Update config file\r\n Update-FMAppConfig -configPath \"$outputPath\\_PublishedWebsites\\WebAuth\\Web.config\"\r\n\r\n #Create the WebAuth package\r\n \r\n $webDeploySource = $outputPath + \"\\_PublishedWebsites\\WebAuth\"\r\n $webDeployDest = $outputPath + \"\\WebAuthPackage.zip\"\r\n \r\n $md = $(\"`\"{0}`\" -verb:sync -source:iisApp=`\"{1}`\" -dest:package=`\"{2}`\" -declareParam:name=AppPath,type=ProviderPath,scope=iisApp\" -f $msdeploy, $webDeploySource, $webDeployDest )\r\n Write-Output Executing $md\r\n cmd.exe /C \"`\"$md`\"\"\r\n\r\n \r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: msdeploy failed with exit code $LastExitCode.\" \r\n throw \"ERROR: msdeploy failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n \r\n\r\n #Run Bower / Gulp for Web UI project \r\n Push-Location -Path \"WebUI\"\r\n Write-Output \"Running npm install for WebUI project\"\r\n $env:NODE_ENV = \"development\"\r\n & npm install -q\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: npm install failed with exit code $LastExitCode.\" \r\n throw \"npm install failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n $env:NODE_ENV = \"production\"\r\n Write-Output \"Running bower install for WebUI project\"\r\n Remove-Item .\\bower_components\\* -recurse\r\n & .\\node_modules\\.bin\\bower install --config.interactive=false \r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: bower install failed with exit code $LastExitCode.\" \r\n throw \"bower install failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Write-Output \"Running gulp vendor for WebUI project\"\r\n & .\\node_modules\\.bin\\gulp vendor\r\n if ($LastExitCode -ne 0) {\r\n\r\n Write-Error \"ERROR: gulp vendor failed with exit code $LastExitCode.\" \r\n throw \"gulp vendor failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Write-Output \"Running gulp default for WebUI project\"\r\n & .\\node_modules\\.bin\\gulp default\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: gulp default failed with exit code $LastExitCode.\" \r\n throw \"gulp default failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Pop-Location\r\n\r\n #Build Web UI Project\r\n $proj = \"./WebUI/WebUI.csproj\"\r\n & $msbuild /p:Configuration=Release /p:Platform=AnyCPU $proj /p:OutputPath=$outputPath\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: msbuild failed with exit code $LastExitCode.\" \r\n throw \"msbuild failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n\r\n #Test the Web UI Project\r\n Push-Location -Path \"WebUI\"\r\n Write-Output \"Running karma unit test runner for WebUI project\"\r\n & .\\node_modules\\.bin\\karma start --reporters teamcity --single-run --browsers PhantomJS\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: karma unit test runner failed with exit code $LastExitCode.\" \r\n throw \"karma unit test runner failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n Pop-Location\r\n\r\n #Copy environment specific web.config\r\n $configFile = $packageRoot + \"\\WebUI\\Configs\\Web.$($fmenv.id).config\"\r\n if(Test-Path $configFile) {\r\n Copy-Item $configFile \"$outputPath\\_PublishedWebsites\\WebUI\\Web.config\" -Force\r\n }\r\n\r\n #Update config file\r\n Update-FMAppConfig -configPath \"$outputPath\\_PublishedWebsites\\WebUI\\Web.config\"\r\n \r\n #Create WebUI Package\r\n $webDeploySource = $outputPath + \"\\_PublishedWebsites\\WebUI\"\r\n $webDeployDest = $outputPath + \"\\WebUIPackage.zip\"\r\n \r\n $md = $(\"`\"{0}`\" -verb:sync -source:iisApp=`\"{1}`\" -dest:package=`\"{2}`\" -declareParam:name=AppPath,type=ProviderPath,scope=iisApp\" -f $msdeploy, $webDeploySource, $webDeployDest )\r\n Write-Output Executing $md\r\n cmd.exe /C \"`\"$md`\"\"\r\n\r\n \r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: msdeploy failed with exit code $LastExitCode.\" \r\n throw \"ERROR: msdeploy failed with exit code $LastExitCode.\"\r\n Exit $LastExitCode\r\n }\r\n\r\n #Clean up all other files\r\n Get-ChildItem \"$outputPath\" -Exclude \"*.zip\" | Remove-Item -Recurse -Force \r\n\r\n \r\n }\r\n\r\n function Initialize-Package {\r\n New-Item -Path $packageRoot -ItemType directory -Force\r\n \r\n }\r\n\r\n function Add-RTAutomationToPackage($config, [switch] $BuildWebDeployPackage){\r\n \r\n Write-Output \"Building RTAutomation\"\r\n $proj = (Get-ChildItem .\\RTWebservices\\RTAutomationWebservice.sln).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config \r\n Write-Output \"Packaging RTAutomation\"\r\n New-Item -Path $packageRoot\\RTWebservices\\RTAutomationWebService -ItemType directory -ErrorAction SilentlyContinue\r\n New-Item -Path $packageRoot\\RTWebservices\\RTAutomationTestClient -ItemType directory -ErrorAction SilentlyContinue\r\n Copy-Item .\\RTWebservices\\RTAutomationWebService\\bin\\* $packageRoot\\RTWebServices\\RTAutomationWebService -Recurse\r\n Copy-Item .\\RTWebservices\\RTAutomationTestClient\\bin\\$config\\* $packageRoot\\RTWebServices\\RTAutomationTestClient -Recurse\r\n\r\n #Add WebDeploy Package \r\n if ($BuildWebDeployPackage){\r\n Invoke-PackageBuild -PackagePath \"$packageRoot\\WebDeploy\\RTWebServices\\RTAutomationWebService.zip\" -ProjectPath $proj \r\n }\r\n\r\n }\r\n\r\n function Add-InstallerScriptToPackage ($MainScriptName) {\r\n Write-Output \"Copying build scripts\"\r\n New-Item -Path $packageRoot\\BuildScripts -ItemType directory -ErrorAction SilentlyContinue\r\n Copy-Item .\\BuildScripts\\fm.psm1 $packageRoot\\BuildScripts -Verbose -Force\r\n Copy-Item .\\BuildScripts\\Tools\\ $packageRoot\\BuildScripts -Verbose -Force\r\n \r\n\r\n Copy-Item .\\$MainScriptName.ps1 $packageRoot -Force -Verbose\r\n \r\n # Everything else that might be in the Configs folder for this FMEnv\r\n if (Test-Path .\\BuildScripts\\Configs\\$($fmenv.id)\\)\r\n {\r\n New-Item -Path $packageRoot\\BuildScripts\\Configs -ItemType directory -ErrorAction SilentlyContinue\r\n Copy-Item .\\BuildScripts\\Configs\\$($fmenv.id)\\* $packageRoot\\BuildScripts\\Configs -Recurse -Force -Exclude \"package.filters.xml\"\r\n\r\n }\r\n\r\n }\r\n\r\n function Add-BuildScriptsToPackage () {\r\n Write-Output \"Copying build scripts\"\r\n New-Item -Path $packageRoot\\BuildScripts -ItemType directory -ErrorAction SilentlyContinue\r\n Copy-Item .\\BuildScripts\\fm.psm1 $packageRoot\\BuildScripts -Force\r\n Copy-Item .\\BuildScripts\\Tools\\ $packageRoot\\BuildScripts -Force\r\n Copy-Item .\\BuildScripts\\version.txt $packageRoot -Force\r\n\r\n Copy-Item .\\build.ps1 $packageRoot -Force\r\n \r\n \r\n \r\n # Everything else that might be in the Configs folder for this FMEnv\r\n if (Test-Path .\\BuildScripts\\Configs\\$($fmenv.id)\\)\r\n {\r\n New-Item -Path $packageRoot\\BuildScripts\\Configs -ItemType directory -ErrorAction SilentlyContinue\r\n Copy-Item .\\BuildScripts\\Configs\\$($fmenv.id)\\* $packageRoot\\BuildScripts\\Configs -Recurse -Force\r\n }\r\n\r\n }\r\n\r\n function Add-WinUIToPackage{\r\n \r\n Write-Output \"Building and packaging WinUI\"\r\n if (Test-Path \".\\WinUI\\App.config.$($fmenv.id).remote.template\" -PathType Leaf)\r\n {\r\n Write-Output \"Found .\\WinUI\\App.config.$($fmenv.id).remote.template, using as app.config\"\r\n $configFile = \".\\WinUI\\App.config.$($fmenv.id).remote.template\"\r\n }\r\n elseif (Test-Path \".\\WinUI\\$($fmenv.clickOnce.configFile)\" -PathType Leaf)\r\n {\r\n Write-Output \"Found .\\WinUI\\$($fmenv.clickOnce.configFile), using as app.config\"\r\n $configFile = \".\\WinUI\\$($fmenv.clickOnce.configFile)\"\r\n }\r\n else\r\n {\r\n Write-Output \"Using .\\WinUI\\App.config.remote.template as app.config\"\r\n $configFile = \".\\WinUI\\App.config.remote.template\"\r\n }\r\n\r\n if (Test-Path .\\WinUI\\App.config)\r\n {\r\n Write-Output \"App.config exists, creating a backup\" \r\n Copy-Item .\\WinUI\\App.config .\\WinUI\\App.config.bak -Force\r\n }\r\n\r\n Copy-Item $configFile .\\WinUI\\App.config -Force\r\n\r\n # Need to make sure we have an app.config for WaveLength.PMSObjects.Tests. \r\n # Don't care which one to use (it is not part of the package anyway) so just copy a .template one if the .config is not there\r\n if (-not (Test-Path .\\WaveLength.PMSObjects.Tests\\app.config))\r\n {\r\n Copy-Item .\\WaveLength.PMSObjects.Tests\\app.config.template .\\WaveLength.PMSObjects.Tests\\app.config\r\n }\r\n\r\n Write-Output \"Building main solution\" \r\n $proj = (Get-ChildItem .\\\"FM3 Base.sln\").FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config\r\n \r\n if (Test-Path .\\WinUI\\App.config.bak)\r\n {\r\n Write-Output \"Restoring App.config from backup\"\r\n Move-Item .\\WinUI\\App.config.bak .\\WinUI\\App.config -Force\r\n }\r\n }\r\n\r\n function Update-FMDeploy ($config) {\r\n Write-Output \"Building FMDeploy...\"\r\n $proj = (Get-ChildItem .\\FMDeploy\\FMDeploy.sln).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config\r\n\r\n New-Item -Path $packageRoot\\FMDeploy -ItemType directory -Force\r\n Copy-Item .\\FMDeploy\\bin\\$config\\* $packageRoot\\FMDeploy -Force\r\n }\r\n\r\n function Add-ApplicationFilesToPackage () {\r\n Write-Output \"Packaging application files\"\r\n New-Item -Path $packageRoot\\Application -ItemType directory\r\n Copy-Item .\\WinUI\\bin\\$config\\* $packageRoot\\Application -Recurse\r\n Copy-Item .\\WinUI\\cubes.ico $packageRoot\\Application\r\n }\r\n\r\n function Add-DatabaseFilesToPackage{\r\n Write-Output \"Packaging database files\"\r\n Copy-DatabaseFiles -DatabaseDir GlobalSecurityDatabase -DestinationRoot $packageRoot\r\n Copy-DatabaseFiles -DatabaseDir Database -DestinationRoot $packageRoot\r\n }\r\n\r\n function Add-ReconciliationToolToPackage($config = $DefaultBuildConfig){\r\n Write-Output \"Packaging Reconciliation Module\"\r\n Copy-DatabaseFiles -DatabaseDir ReconciliationDatabase -DestinationRoot $packageRoot\r\n New-Item $packageRoot\\ReconciliationService -ItemType directory\r\n Copy-Item .\\WaveLength.RT.BLL\\bin\\$config\\* $packageRoot\\ReconciliationService\r\n }\r\n\r\n function Add-TaskHostToPackage($config = $DefaultBuildConfig){\r\n Write-Output \"Building FMTaskHost\"\r\n $proj = (Get-ChildItem .\\FMTaskHost\\FMTaskHost.csproj).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config -noPlatform\r\n\r\n Write-Output \"Packaging FMTaskHost\"\r\n New-Item -Path $packageRoot\\FMTaskHost -ItemType directory\r\n Copy-Item .\\FMTaskHost\\bin\\$config\\* $packageRoot\\FMTaskHost -Recurse\r\n \r\n if (Test-Path \".\\FMTaskHost\\Configs\\$($fmenv.taskHost.configFile)\" -PathType Leaf)\r\n {\r\n Copy-Item \".\\FMTaskHost\\Configs\\$($fmenv.taskHost.configFile)\" $packageRoot\\FMTaskHost\\FMTaskHost.exe.config -Force\r\n }\r\n elseif (Test-Path \".\\FMTaskHost\\Configs\\App.$($fmenv.id).config\" -PathType Leaf)\r\n {\r\n Copy-Item \".\\FMTaskHost\\Configs\\App.$($fmenv.id).config\" $packageRoot\\FMTaskHost\\FMTaskHost.exe.config -Force\r\n }\r\n }\r\n\r\n function Add-ClickOnceToPackage {\r\n Write-Output \"Packaging deployment website\"\r\n New-Item -Path $packageRoot\\WebSite -ItemType directory\r\n Copy-Item .\\BuildScripts\\WebSite\\* $packageRoot\\WebSite -Recurse\r\n }\r\n\r\n function Add-BatchQueueToPackage($config = $DefaultBuildConfig){\r\n Write-Output \"Packaging BatchQueue\"\r\n New-Item -Path $packageRoot\\FMBatchQueue -ItemType directory\r\n New-Item -Path $packageRoot\\FMBatchQueue\\Service -ItemType directory\r\n Copy-Item .\\BatchQueue2\\BatchQueue2Service\\bin\\$config\\* $packageRoot\\FMBatchQueue\\Service -Recurse\r\n Copy-Item .\\BatchProcesses\\bin\\$config\\* $packageRoot\\FMBatchQueue\\Service -Recurse -Force\r\n\r\n New-Item -Path $packageRoot\\FMBatchQueue\\Executor -ItemType directory\r\n Copy-Item .\\BatchQueue2\\BatchQueue2JobExecutor\\bin\\$config\\* $packageRoot\\FMBatchQueue\\Executor -Recurse -Force\r\n Copy-Item .\\BatchProcesses\\bin\\$config\\* $packageRoot\\FMBatchQueue\\Executor -Recurse -Force\r\n }\r\n\r\n function Add-TradeWebToPackage ($config = $DefaultBuildConfig) {\r\n Write-Output \"Building TradeWeb\"\r\n $proj = (Get-ChildItem .\\WaveLength.Integration.TradeWeb.Server.sln).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config\r\n\r\n Write-Output \"Packaging TradeWeb\"\r\n New-Item -Path $packageRoot\\TradeWeb -ItemType directory\r\n Copy-Item .\\WaveLength.Integration.TradeWeb.Server\\bin\\$config\\* $packageRoot\\TradeWeb\r\n\r\n if (Test-Path \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.configFile)\" -PathType Leaf)\r\n {\r\n Write-Output (\"Including config: {0}\" -f \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.configFile)\") \r\n Copy-Item \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.configFile)\" $packageRoot\\TradeWeb\\WaveLength.Integration.TradeWeb.Server.exe.config -Force\r\n }\r\n\r\n if (Test-Path \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.quickFixConfigFile)\" -PathType Leaf)\r\n {\r\n Write-Output (\"Including config: {0}\" -f \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.quickFixConfigFile)\")\r\n Copy-Item \".\\WaveLength.Integration.TradeWeb.Server\\Configs\\$($fmenv.tradeWeb.quickFixConfigFile)\" $packageRoot\\TradeWeb\\QuickFixN.cfg -Force\r\n }\r\n }\r\n\r\n function Add-MarketDataToPackage($config = $DefaultBuildConfig, [switch] $WindowsServiceOnly ){\r\n\r\n Write-Output \"Packaging MarketData Module\"\r\n\r\n Copy-DatabaseFiles -DatabaseDir MarketDataDatabase -DestinationRoot $packageRoot\r\n Copy-DatabaseFiles -DatabaseDir IDCDatabase -DestinationRoot $packageRoot\r\n \r\n New-Item $packageRoot\\MarketDataService -ItemType directory\r\n Copy-Item .\\WaveLength.MarketData.BLL\\bin\\$config\\* $packageRoot\\MarketDataService -Recurse\r\n\r\n Write-Output \"Building ETL\"\r\n $proj = (Get-ChildItem .\\\"Market Data ETL.sln\").FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config\r\n\r\n New-Item $packageRoot\\ETL\\FileImportTool -ItemType directory\r\n New-Item $packageRoot\\ETL\\FtpSyncTool -ItemType directory\r\n New-Item $packageRoot\\ETL\\SSIS -ItemType directory\r\n\r\n Copy-Item .\\WaveLength.MarketData.Integration.IDC.Parser\\bin\\$config\\* $packageRoot\\ETL\\FileImportTool -Recurse\r\n $importToolConfig = (Get-FMEnvSection marketdata).etlFileImportToolConfig\r\n \r\n Copy-Item .\\WaveLength.MarketData.Integration.IDC.Parser\\$importToolConfig $packageRoot\\ETL\\FileImportTool\\log4net.config -Force\r\n\r\n Copy-Item .\\WaveLength.MarketData.Integration.FolderSync\\bin\\$config\\* $packageRoot\\ETL\\FtpSyncTool -Recurse\r\n $ftpToolConfig = $fmenv.marketdata.etlFtpSyncToolConfig\r\n Copy-Item .\\WaveLength.MarketData.Integration.FolderSync\\$ftpToolConfig $packageRoot\\ETL\\FtpSyncTool\\log4netFtp.config -Force\r\n\r\n Copy-Item WaveLength.MarketData.Integration.IDC.SSIS\\*.dtsx $packageRoot\\ETL\\SSIS\r\n }\r\n\r\n function Add-DealSetupToPackage($config = $DefaultBuildConfig, [switch] $WindowsServiceOnly, [switch] $BuildWebDeployPackage){\r\n \r\n Write-Output \"Building DealSetupService\"\r\n $proj = (Get-ChildItem .\\JPMDealSetupService\\JPMDealSetupService.sln).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config\r\n \r\n Write-Output \"Packaging DealSetupService\"\r\n New-Item -Path $packageRoot\\JPMDealSetupService -ItemType directory\r\n Copy-Item .\\JPMDealSetupService\\bin\\$config\\* $packageRoot\\JPMDealSetupService -Recurse\r\n \r\n if (-not $WindowsServiceOnly){\r\n Write-Output \"Building DealSetupWebService\"\r\n $proj = (Get-ChildItem .\\JPMWebServices\\JPMWebServices.sln).FullName\r\n Start-Build -proj $proj -target \"Build\" -config $config \r\n Write-Output \"Packaging DealSetupWebService\"\r\n New-Item -Path $packageRoot\\JPMDealSetupWebService\\JPMDealSetupWebService -ItemType directory\r\n New-Item -Path $packageRoot\\JPMDealSetupWebService\\JPMDealSetupWSTestClient -ItemType directory\r\n Copy-Item .\\JPMWebServices\\JPMDealSetupWebService\\bin\\* $packageRoot\\JPMDealSetupWebService\\JPMDealSetupWebService -Recurse\r\n Copy-Item .\\JPMWebServices\\JPMDealSetupTestClient\\bin\\$config\\* $packageRoot\\JPMDealSetupWebService\\JPMDealSetupWSTestClient -Recurse\r\n if ($BuildWebDeployPackage){\r\n Invoke-PackageBuild -PackagePath \"$packageRoot\\WebDeploy\\JPMDealSetupService\\JPMDealSetupWebService.zip\" -ProjectPath $proj \r\n }\r\n }\r\n }\r\n\r\n function Add-FMReportsToPackage ([switch]$CleanOutputDirectory) {\r\n \r\n if ($CleanOutputDirectory)\r\n {\r\n CleanPackageDirectory \\FMReports\r\n }\r\n \r\n $fmenv = Get-FMEnv\r\n Write-Output \"Packaging FMReports\"\r\n New-Item -Path $packageRoot\\FMReports -ItemType directory -Force\r\n $fileList =[System.Array] (Get-ReportFiles -isPackage $true)\r\n \r\n foreach($file in $fileList){\r\n $type = \r\n if($file.Extension -eq \".rdl\"){\"report\"}\r\n elseif($file.Extension -eq \".rsd\"){\"dataset\"}\r\n else{\"resource\"}\r\n \r\n if (($type -eq \"report\") -and (-not (IsExcluded -type $type -Name $file.Name -IsPackage $true))){\r\n #if is report use report filter settings \r\n \"Copying $($type) $($file.Name) to Package Directory\" | Write-Output\r\n Copy-Item $file.FullName $packageRoot\\FMReports -Exclude *rptproj*, *sln\r\n }\r\n elseif ($type -eq \"dataset\") {\r\n #if is dataset copy always \r\n \"Copying $($type) $($file.Name) to Package Directory\" | Write-Output\r\n Copy-Item $file.FullName $packageRoot\\FMReports -Exclude *rptproj*, *sln\r\n }\r\n elseif (-not (IsExcluded -type $type -Name $file.Name -IsPackage $true)){\r\n #if is report use report filter settings \r\n \"Copying $($type) $($file.Name) to Package Directory\" | Write-Output\r\n Copy-Item $file.FullName $packageRoot\\FMReports -Exclude *rptproj*, *sln\r\n }\r\n else\r\n {\r\n \"Skipping $($type) $($file.Name) | Reason: Exclusion Rule\" | Write-Output\r\n }\r\n }\r\n \r\n\r\n # Copy-Item .\\FMReports\\* $packageRoot\\FMReports -Exclude *rptproj*, *sln\r\n }\r\n\r\n function New-ClickOncePackage{\r\n [CmdletBinding()]\r\n param(\r\n [Parameter(Mandatory = $true)]\r\n $clickOnce\r\n )\r\n\r\n $fmenv = Get-FMEnv\r\n\r\n $version = Get-Content $packageRoot\\version.txt\r\n \r\n $clickOncePath = Join-Path $packageRoot \"ClickOnce\"\r\n New-Item -Path $clickOncePath -ItemType directory | Out-Null\r\n \r\n $clickOnceBin = Join-Path $clickOncePath $version\r\n New-Item -Path $clickOnceBin -ItemType directory | Out-Null\r\n \r\n $appManifest = Join-Path $clickOnceBin \"WinUI.exe.manifest\"\r\n $deploymentManifest = Join-Path $clickOncePath \"WinUI.application\" \r\n \r\n Copy-Item -Path $packageRoot\\Application\\* $clickOnceBin -Recurse \r\n Remove-Item $clickOnceBin\\*pdb\r\n Remove-Item $clickOnceBin\\*xml\r\n Remove-Item $clickOnceBin\\*WinUI.vshost.exe*\r\n \r\n $mage = Get-Mage \r\n \r\n & $mage `\r\n -New Application -ToFile $appManifest -Name $clickOnce.appName `\r\n -Version $version -FromDirectory $clickOnceBin -IconFile cubes.ico\r\n\r\n # Manually update the entry point in the manifest, because mage.exe does some bad things:\r\n # 1) uses heuristics to guess the entry point but guesses it wrong in this case\r\n # 2) appends .exe to the application which becomes \"FundManager.NET Geneva.exe\" which we don't need\r\n $path = (Get-ChildItem $clickOnceBin\\WinUI.exe.manifest).FullName\r\n $xml = [xml] (Get-Content $clickOnceBin\\WinUI.exe.manifest)\r\n $xml.assembly.assemblyIdentity.name = $clickOnce.appName\r\n $xml.assembly.entryPoint.assemblyIdentity.name = \"WinUI\"\r\n $xml.assembly.entryPoint.assemblyIdentity.version = $xml.assembly.assemblyIdentity.version\r\n $xml.assembly.entryPoint.commandLine.file = \"WinUI.exe\"\r\n $xml.Save(\"$path\")\r\n\r\n # Sign manifest if certFile is available\r\n if ($clickOnce.certFile)\r\n {\r\n $certPwd = $clickOnce.certPassword\r\n if (($certPwd -ne $null) -and ($certPwd.ToLower().StartsWith(\"env:\")))\r\n {\r\n # If contains environment variable name then resolve the value of that environment variable\r\n $varname = $certPwd.Substring(4)\r\n $certPwd = (Get-Item env:$varname).Value\r\n }\r\n\r\n if ($certPwd -ne $null)\r\n {\r\n & $mage -Sign $clickOnceBin\\WinUI.exe.manifest -CertFile $clickOnce.certFile -Password $certPwd\r\n }\r\n else\r\n {\r\n & $mage -Sign $clickOnceBin\\WinUI.exe.manifest -CertFile $clickOnce.certFile\r\n }\r\n }\r\n \r\n & $mage `\r\n -New Deployment -Install true -Publisher $clickOnce.publisher `\r\n -Name $clickOnce.appName -Version $version `\r\n -ProviderUrl $clickOnce.providerUrl `\r\n -AppManifest $appManifest -ToFile $deploymentManifest\r\n & $mage -Update $deploymentManifest -MinVersion $version -Publisher $clickOnce.publisher\r\n\r\n Get-ChildItem $clickOnceBin -Recurse | ForEach-Object { \r\n if ((-not $_.FullName.EndsWith(\".manifest\")) -and (-not $_.PSIsContainer)) \r\n { \r\n Rename-Item $_.FullName \"$($_.FullName).deploy\"\r\n } \r\n }\r\n \r\n # Manually update deployment manifest:\r\n # Mage.exe sets in but we need instead \r\n $path = (Get-ChildItem $deploymentManifest).FullName\r\n $xml = [xml] (Get-Content $deploymentManifest)\r\n $node = $xml.SelectSingleNode(\"//*[local-name() = 'deployment']\")\r\n $node.SetAttribute(\"mapFileExtensions\", \"true\")\r\n $xml.assembly.deployment.subscription.update.InnerXml = ''\r\n\r\n # Mage will set \r\n # but we need \r\n if ($clickOnce.forceAppName -eq \"true\")\r\n {\r\n $xml.assembly.assemblyIdentity.name = $clickOnce.appName\r\n }\r\n \r\n $xml.Save(\"$path\")\r\n\r\n if ($clickOnce.certFile)\r\n {\r\n if ($certPwd -ne $null)\r\n {\r\n & $mage -Sign $deploymentManifest -CertFile $clickOnce.certFile -Password $certPwd \r\n }\r\n else\r\n {\r\n & $mage -Sign $deploymentManifest -CertFile $clickOnce.certFile\r\n }\r\n }\r\n\r\n Write-Output \"Preparing website...\"\r\n $date = (Get-Date).ToString(\"MMMM, dd\", [System.Globalization.CultureInfo]::InvariantCulture)\r\n $indexPage = Get-ChildItem $packageRoot\\WebSite\\index.html\r\n $temp = [System.IO.Path]::GetTempFileName()\r\n Get-Content $indexPage | ForEach-Object { $_ -replace '@version@', $version -replace '@date@', $date -replace '@appname@', $clickOnce.appName } | Out-File $temp -Encoding ascii\r\n Move-Item $temp $indexPage -Force\r\n Copy-Item -Path $packageRoot\\WebSite\\* $clickOncePath -Force -Recurse\r\n }\r\n\r\n#Batch Deploy \r\n function Deploy-FMPackage( $Website, $Server, $DBServer){\r\n Deploy-FMPackageNoDB -Website $Website -Server $Server\r\n Update-FMDatabases -DBServer $DBServer\r\n }\r\n\r\n function Update-AllNoDB {\r\n [CmdletBinding()]\r\n param(\r\n [Parameter()]\r\n [string]\r\n $Website,\r\n\r\n [Parameter()]\r\n [string] \r\n $Server\r\n )\r\n \r\n $fmenv = Get-FMEnv\r\n\r\n Deploy-FMClient -clickOnce $fmenv.clickOnce\r\n \r\n Update-FMServices -Server $Server -Website $Website\r\n Update-FMReports -Server $Server\r\n Update-BatchQueues -Server $Server\r\n Update-DealSetupServices -Server $Server\r\n\r\n }\r\n\r\n\r\n#Install Tools\r\n function Install-FMWebSite([Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName) ] $id, [switch] $Force, [switch] $IncludeApplications){\r\n if($SkipWebAdministrationModule)\r\n {\r\n return \r\n }\r\n\r\n $config = Get-FMEnvSection website $id\r\n \r\n Assert-HasValue -Value $config -ErrorMessage \"WebSite $id not found\" \r\n \r\n $website = Get-Website -Name $config.name -ErrorAction SilentlyContinue\r\n\r\n @(\"name\", \"path\") | ForEach-Object {\r\n $key = $_\r\n Assert-HasValue -Value $config.$key -ErrorMessage \"Website $key attribute is required\"\r\n }\r\n \r\n $credentialId = Get-CredentialId -id $config.id -type website\r\n\r\n $credentials = Get-FMCredentials $credentialId\r\n\r\n $appPoolName = if($config.applicationPool){\r\n $config.applicationPool\r\n }else{\r\n $config.name\r\n }\r\n\r\n $appPool = Get-ChildItem \"IIS:\\AppPools\\$appPoolName\" -ErrorAction SilentlyContinue\r\n\r\n if ((-not $appPool) -or $Force)\r\n {\r\n $apppool = New-AppPool -Name $appPoolName -Credentials $credentials -Force:$Force\r\n }\r\n\r\n $arg = \"-Name $($config.name) -PhysicalPath '$($config.path)' -ApplicationPool $appPoolName\"\r\n\r\n @(\"IpAddress\", \"Port\", \"HostHeader\", \"SslFlags\") | ForEach-Object {\r\n \r\n if ($config.$_){\r\n $arg += \" -$_ $($config.$_) \"\r\n }\r\n }\r\n\r\n \r\n if ($config.ssl)\r\n {\r\n $arg += \" -Ssl\"\r\n }\r\n\r\n if ($Force -and $website)\r\n {\r\n Write-Host -ForegroundColor Magenta \"Force Specified, Removing Website $($config.name)\"\r\n Remove-Website -Name $config.name -Confirm:$false \r\n $website = Get-Website -Name $config.name -ErrorAction SilentlyContinue \r\n }\r\n \r\n if($website){\r\n Write-Host \"Website $($config.name) exists skipping...\"\r\n }else{\r\n \r\n $pathExists = Test-Path $config.path -PathType Container\r\n \r\n if (-not $pathExists ){\r\n Write-Host \"$($config.path)does not yet exist creating target directory...\"\r\n New-Item -ItemType Directory -Path $config.path -Force\r\n }\r\n\r\n Write-Host \"Creating website $($config.name) at $($config.path) with App Pool $($appPool.name)\"\r\n \r\n $cmd = (\"New-Website $arg\")\r\n $website = Invoke-Expression $cmd\r\n \r\n }\r\n \r\n if ($website -and $IncludeApplications ){\r\n $services = Get-FMEnvSection webservice | Where-Object { $_.website -eq $config.id }\r\n $services | ForEach-Object{\r\n $type = $_.type\r\n $id = $_.id\r\n $credentialid = $_.credentials\r\n\r\n $credentialid = Get-CredentialId -type $_.type -id $_.id -IsWebService \r\n \r\n $credentials = Get-FMCredentials -id $credentialid \r\n Write-Host \"Creating $($_.type) Webservice Application $($_.iisAppName)\"\r\n New-WebService -Name $_.iisAppName `\r\n -AppPool $_.appPool `\r\n -SiteName $config.name `\r\n -Credentials $credentials `\r\n -Path $_.path `\r\n -Force:$Force\r\n }\r\n }\r\n\r\n Get-Website -Name $config.name \r\n \r\n }\r\n\r\n function Install-FMServices {\r\n [CmdletBinding()]\r\n param(\r\n $updateConfigs = $true,\r\n [switch] $CreateIISWebSite, \r\n [switch] $Force,\r\n $Server,\r\n $Website,\r\n $Id\r\n )\r\n \r\n if ($CreateIISWebSite)\r\n {\r\n Install-FMWebSite -id $Website -Force:$Force -IncludeApplications\r\n }\r\n\r\n Get-FMEnvSection webService -Server $Server -Website $Website | Update-WebService -CreateIISApp -Force:$Force -updateConfigs $updateConfigs\r\n\r\n Get-FMEnvSection taskhost -Server $Server -Id $Id | Update-TaskHost \r\n \r\n }\r\n\r\n function Update-FMServices\r\n {\r\n\r\n [CmdletBinding()]\r\n param(\r\n [bool] \r\n $updateConfigs = $true, \r\n [string]\r\n $Website, \r\n [string]\r\n $Server, \r\n [string]\r\n $Type, \r\n [string]\r\n $Id, \r\n [switch] $SkipTaskhost, \r\n [switch] $SkipWebservices, \r\n [switch] $Force\r\n )\r\n\r\n process {\r\n if(-not $SkipWebservices){\r\n $services = Get-FMEnvSection webService -Website $Website -Server $Server -id $Id\r\n # if website specified filter services to update \r\n if ($type)\r\n {\r\n $services = $services | Where-Object { $_.type -eq $type }\r\n } \r\n \r\n foreach ($svc in $services) {\r\n if (-not (IsDisabled $svc))\r\n {\r\n Update-WebService -id $svc.Id \r\n }\r\n }\r\n\r\n }\r\n\r\n if(-not $SkipTaskhost){\r\n $taskhosts = Get-FMEnvSection taskHost -Server $Server \r\n foreach ($taskhost in $taskhosts) {\r\n Update-TaskHost $taskhost.id \r\n }\r\n }\r\n }\r\n }\r\n\r\n function New-AppPool([Parameter(Mandatory)]$Name, $Credentials, [switch]$Force)\r\n {\r\n $path = \"IIS:\\AppPools\\$Name\"\r\n \r\n $appPool = Get-ChildItem $path -ErrorAction SilentlyContinue\r\n \r\n \r\n if ($appPool -and $Force){\r\n \r\n Write-Host \"New-AppPool: -Force Specified Removing Existing AppPool $Name\"\r\n $appPool = Remove-WebAppPool $Name\r\n\r\n }elseif($appPool){\r\n \r\n Write-Host \"AppPool $Name exists, Skipping...\"\r\n return $appPool\r\n }\r\n \r\n\r\n $appPool = New-WebAppPool $Name \r\n \r\n $appPool | Set-ItemProperty -Name \"managedRuntimeVersion\" -Value \"v4.0\" -Force\r\n $appPool | Set-ItemProperty -Name \"processmodel.identityType\" -Value 3\r\n $appPool | Set-ItemProperty -Name \"managedPipelineMode\" -Value 0\r\n\r\n\r\n $username = $Credentials.UserName\r\n $password = $Credentials.Password\r\n\r\n\r\n $appPool | Set-ItemProperty -Name \"processmodel.userName\" -Value $username\r\n $appPool | Set-ItemProperty -Name \"processmodel.password\" -Value $password\r\n\r\n Write-Host (\"New appPool $Name created\")\r\n\r\n\r\n return $appPool\r\n }\r\n\r\n function New-WebService([Parameter(Mandatory)]$Name, $AppPool, [Parameter(Mandatory)]$Path, $SiteName = \"Default Website\", $Credentials, [switch] $Force, $webDeployUrl){\r\n\r\n $AppPoolName = if (-not $AppPool) { $Name }else { $AppPool }\r\n\r\n $website = Get-Website -Name $SiteName \r\n\r\n if (-not $website){\r\n Write-Error \"WebSite $SiteName does not exist\"\r\n return\r\n }\r\n \r\n $application = Get-WebApplication -Site $SiteName -Name $Name -ErrorAction SilentlyContinue\r\n\r\n if ($application -and $Force){\r\n \r\n Write-Host \"New-WebService: -Force Specified Removing and Recreating WebService Application $SiteName\\$Name\"\r\n Remove-Item \"IIS:\\Sites\\$SiteName\\$Name\" -Recurse -Force \r\n\r\n }elseif($application){\r\n\r\n Write-Host \"Application $SiteName\\$Name Exists, Skipping...\"\r\n return $application\r\n }\r\n\r\n\r\n $applicationPool = New-AppPool $AppPoolName -Credentials $Credentials -Force:$Force\r\n \r\n Write-Host \"Creating Web Appplication $SiteName\\$Name\"\r\n\r\n $appPath = Get-ChildItem $Path -ErrorAction SilentlyContinue\r\n if (-not $appPath)\r\n {\r\n $appPath = New-Item $Path -Force -ItemType Container\r\n }\r\n\r\n $application = New-WebApplication -Site $SiteName -ApplicationPool $AppPool -PhysicalPath $Path -Name $Name \r\n\r\n return $application\r\n }\r\n\r\n #Polyfill to remove a Windows Service since powershell doesn't support this natively \r\n function Remove-Service {\r\n [CmdletBinding()]\r\n param(\r\n [parameter(ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Name, \r\n\r\n [parameter()]\r\n [pscredential] \r\n $Credentials,\r\n\r\n [parameter()]\r\n [string] \r\n $ComputerName = 'localhost'\r\n )\r\n\r\n process{\r\n\r\n $serviceObj = Get-Service -Name $Name\r\n if($serviceObj -and $serviceObj.CanStop)\r\n {\r\n $serviceObj.Stop();\r\n $serviceObj.WaitForStatus(\"Stopped\", \"00:00:30\") \r\n }\r\n\r\n $service = Get-WmiObject -Class Win32_Service -Filter \"Name='$Name'\" -ComputerName $ComputerName -Credential $Credentials\r\n if ($service){\r\n $service.delete() | Out-Null\r\n }\r\n\r\n # sc.exe delete $Name\r\n }\r\n }\r\n\r\n\r\n#Credentials\r\n function Get-DefaultCredentialID($type)\r\n {\r\n\r\n $credentialType = @{}\r\n\r\n $credentialType.FM = 'FMAccess'\r\n $credentialType.FMReport = 'FMReportUser'\r\n $credentialType.RT = 'RTUser'\r\n $credentialType.RTAutomation = 'RTAutomationUser'\r\n $credentialType.website = \"FMWebsiteUser\"\r\n $credentialType.dealSetupServices = 'DealSetupUser'\r\n $credentialType.taskHost = 'TaskHostUser'\r\n $credentialType.batchQueueServer = 'BatchQueueUser'\r\n \r\n $credentialType.FMAccess = 'FMAccess'\r\n \r\n $credentialType.SSRSManagement = 'SSRSManagement'\r\n $credentialType.SSRSExecution = 'SSRSExecution'\r\n \r\n return $credentialType.$type \r\n }\r\n\r\n function Get-CredentialId([Parameter(Mandatory)]$type, [Parameter(Mandatory)] $id, $AttributeName = \"credentials\", [switch] $IsWebService, [switch] $IsSSRS ){\r\n \r\n $service = $null\r\n\r\n if($IsWebService) {\r\n $service = Get-FMEnvSection webService $id \r\n }elseif($IsSSRS) {\r\n $service = Get-FMEnvSection reportServer $id\r\n }else{\r\n $service = Get-FMEnvSection $type $id\r\n }\r\n \r\n $credentialId = if($service.$AttributeName){\r\n $service.$AttributeName \r\n }else{\r\n Get-DefaultCredentialID $type\r\n }\r\n\r\n return $credentialId\r\n }\r\n \r\n function Get-FMCredentials ($id, [switch] $GetPsCredential) {\r\n if (-not (Test-FMCredential -id $id)) {\r\n throw \"Unable to find credential definition with id '$id'\"\r\n }\r\n\r\n $fmenv = Get-FMEnv\r\n\r\n $credEntry = $fmenv.credentials | Where-Object { $_.id -eq $id }\r\n\r\n $username = $credEntry.login\r\n $password = $credEntry.password\r\n\r\n if ($password.ToLower().StartsWith(\"env:\")) {\r\n # If contains environment variable name then resolve the value of that environment variable\r\n $varname = $password.Substring(4)\r\n $password = (Get-Item env:$varname).Value\r\n } elseif ($password.ToLower() -eq \"prompt\") {\r\n $c = Get-Credential -Credential $username\r\n $password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($c.Password))\r\n }\r\n \r\n $result = @{ UserName = $username; Password = $password }\r\n\r\n # Return result\r\n if ($GetPsCredential)\r\n {\r\n $secpass = $result.password | ConvertTo-SecureString -AsPlainText -Force\r\n $pscred = New-Object System.Management.Automation.PsCredential($result.username, $secpass)\r\n return $pscred\r\n }\r\n $result\r\n }\r\n\r\n function Test-FMCredential($id){\r\n $fmenv = Get-FMEnv \r\n\r\n ($fmenv.credentials | Select-Object -ExpandProperty id) -contains $id\r\n }\r\n\r\n\r\n#Database Deployment\r\n function Update-FMDatabases\r\n {\r\n [CmdletBinding()]\r\n param(\r\n # DbServer Id To Update\r\n [string]\r\n $DBServer\r\n )\r\n\r\n Write-Header -ForegroundColor Green -HeaderText \"Updating FM Database Servers\"\r\n $databaseServers = Get-FMEnvSection dbserver -Server $DBServer \r\n $databaseServers | Update-FMDatabaseServer \r\n }\r\n\r\n\r\n function Update-FMDatabaseServer{\r\n [CmdletBinding()]\r\n param(\r\n # DbServer Id\r\n [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]\r\n [string]\r\n $Id\r\n )\r\n process{\r\n \r\n $server = Get-FMEnvSection dbserver $id\r\n \r\n\r\n $server | Assert-HasValue -ErrorMessage \"dbserver id $id not found in envorinment file\" \r\n \r\n $excludeDBs = \"MD\", \"IDC\", \"WebDashboard\"\r\n $databases = Get-FMEnvSection db $id -keyProperty 'server' | Where-Object {$excludeDBs -notcontains $_.type }\r\n \r\n Write-Header \"Updating DbServer $($server.instance) ($id)\" -ForegroundColor Blue\r\n \r\n # Update all DBs except MD-related ones, they will be updated separately in Publish-MarketDataETL\r\n # Also exclude WebDashboard DB, it will be updated separately as part of WebDashboard publish\r\n \r\n $databases | Update-FMDatabase \r\n \r\n } \r\n }\r\n\r\n function Update-FMDatabase {\r\n [CmdletBinding()]\r\n param (\r\n # Parameter help description\r\n [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]\r\n [string]\r\n $Id\r\n )\r\n \r\n process {\r\n $fmdeploy = Get-FMDeploy \r\n $db = Get-FMEnvSection db $id \r\n $dbserver = Get-FMEnvSection dbserver $db.server\r\n\r\n Write-Header \"Updating DB $($db.name) ($id) on server $($dbserver.instance) ($($dbserver.id))\"\r\n Write-Verbose \"Update Command: $fmDeploy up --db $id -e $script:envDefinition $packageRoot\"\r\n & $fmDeploy up --db $id -e $script:envDefinition $packageRoot \r\n\r\n if ($db.type -eq \"FM\")\r\n {\r\n Write-Verbose \"Database is FM database type Initialing Report URLs\"\r\n $db | Initialize-FMReportUrls \r\n }\r\n }\r\n }\r\n\r\n function Initialize-FMReportUrls{\r\n [CmdletBinding()]\r\n param(\r\n # Db id to update\r\n [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]\r\n [string]\r\n $Id\r\n )\r\n\r\n $database = Get-FMEnvSection db $id\r\n Write-Output \"Inializing Report Urls on Database Id $id\"\r\n if (-not ($database.type -eq \"FM\"))\r\n {\r\n Write-Warning \"Invalid Database Type for update, skipping..\"\r\n return \r\n }\r\n\r\n $fmDeploy = Get-FMDeploy \r\n Write-Verbose \"Executing FMDeploy Command $fmDeploy initreports --db $id -e $script:envDefinition $packageRoot\"\r\n [string] $result = & $fmDeploy initreports --db $id -e $script:envDefinition $packageRoot\r\n \r\n if ($LastExitCode -ne 0)\r\n {\r\n Write-Error $Result\r\n }\r\n }\r\n\r\n\r\n\r\n\r\n#Deployment Tools\r\n function Get-AZCopy{\r\n\r\n $azcopylocation = 'C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\AzCopy\\AzCopy.exe'\r\n if (Test-Path $azcopylocation)\r\n {\r\n return $azcopylocation\r\n }\r\n\r\n Write-Error 'Could not find AzCopy.exe, quitting'\r\n exit 1\r\n }\r\n\r\n function Deploy-FMWebPackages{\r\n\r\n $fmenv = Get-FMEnv\r\n $version = Get-BuildVersion\r\n \r\n $outputRoot = \".\\Package\\$version\\FMWeb\"\r\n $outputPath = (Get-Item -Path $outputRoot -Verbose).FullName\r\n \r\n $msdeploy = Get-MSDeploy \r\n\r\n Publish-FMWeb -siteName $fmenv.WebDeploy.WebAuthAppName -package \"$outputPath\\WebAuthPackage.zip\" -serverName $fmenv.WebDeploy.WebServerName\r\n Publish-FMWeb -siteName $fmenv.WebDeploy.WebUIAppName -package \"$outputPath\\WebUIPackage.zip\" -serverName $fmenv.WebDeploy.WebServerName \r\n }\r\n\r\n function Publish-FMWeb($siteName, $package, $serverName){ \r\n $md = $(\"`\"{0}`\" -source:package=`\"{1}`\" -dest:iisApp=`\"{2}`\",computerName='{3}',authtype='NTLM', -verb:sync -setParam:AppPath=`\"{2}`\" -disableLink:ContentExtension\" -f $msdeploy, $package, $siteName, $serverName )\r\n Write-Output Executing $md\r\n cmd.exe /C \"`\"$md`\"\"\r\n if ($LastExitCode -ne 0) {\r\n Write-Error \"ERROR: msdeploy.exe failed with exit code $LastExitCode.\"\r\n throw \"ERROR: msdeploy.exe failed with exit code $LastExitCode.\" \r\n Exit $LastExitCode \r\n }\r\n }\r\n\r\n filter FilterByType {\r\n [CmdletBinding()]\r\n param(\r\n [parameter(Mandatory)] \r\n $Type,\r\n \r\n [parameter(Mandatory, ValueFromPipeline)] \r\n $InputObject \r\n )\r\n\r\n Process{\r\n if ($InputObject.type -eq $Type)\r\n {\r\n return $InputObject\r\n }\r\n }\r\n }\r\n #Deletes all deployed components (web service binaries, clickonce files)\r\n #todo: refactor if possible \r\n function Remove-FMDeployment{\r\n $fmenv = Get-FMEnv\r\n\r\n Write-Output (\"Removing {0}\" -f $fmenv.clickOnce.path)\r\n Remove-Item -Path $fmenv.clickOnce.path -Recurse\r\n \r\n $dest = \"$((Get-FMEnvServices)['FM'].path)\\bin\"\r\n Write-Output (\"Removing {0}\" -f $dest)\r\n Remove-Item -Path $dest -Recurse\r\n\r\n $dest = \"$((Get-FMEnvServices)['RT'].path)\\bin\"\r\n Write-Output (\"Removing {0}\" -f $dest)\r\n Remove-Item -Path $dest -Recurse\r\n\r\n $dest = \"$((Get-FMEnvServices)['FMReport'].path)\\bin\"\r\n Write-Output (\"Removing {0}\" -f $dest)\r\n Remove-Item -Path $dest -Recurse\r\n\r\n $dest = $fmenv.tradeWeb.path\r\n Write-Output (\"Removing {0}\" -f $dest)\r\n Remove-Item -Path $dest -Recurse\r\n\r\n $dest = $fmenv.taskHost.path\r\n Write-Output (\"Removing {0}\" -f $dest)\r\n Remove-Item -Path $dest -Recurse\r\n }\r\n\r\n function Get-MSDeploy{\r\n $folder = (Get-ChildItem \"HKLM:\\SOFTWARE\\Microsoft\\IIS Extensions\\MSDeploy\" | Select-Object -last 1).GetValue(\"InstallPath\") \r\n Join-Path $folder \"msdeploy.exe\"\r\n }\r\n\r\n function Get-Mage(){\r\n # mage.exe may be provided as part of the package\r\n $maybeMage = Join-Path $packageRoot \"BuildScripts\\Configs\\Tools\\Mage\\mage.exe\"\r\n if (Test-Path $maybeMage)\r\n {\r\n Write-Host \"Using mage.exe from $maybeMage\"\r\n\r\n return $maybeMage\r\n }\r\n\r\n #This seems to end up in a different place on Windows Server 2012\r\n if (Test-Path 'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.1A')\r\n {\r\n $root = (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.1A' -Name 'InstallationFolder').InstallationFolder \r\n }\r\n elseif (Test-Path 'HKLM:\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows')\r\n {\r\n $root = (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows' -Name 'CurrentInstallFolder').CurrentInstallFolder\r\n }\r\n else\r\n {\r\n Write-Error 'Could not find mage.exe, quitting'\r\n exit 1\r\n } \r\n\r\n $bin = Join-Path $root 'bin'\r\n $mage = Join-Path $bin 'mage.exe'\r\n\r\n Write-Host \"Looking for mage.exe at $mage\"\r\n if (Test-Path $mage)\r\n {\r\n return $mage\r\n }\r\n \r\n $bin = Join-Path $bin 'NETFX 4.5.1 Tools'\r\n $mage = Join-Path $bin 'mage.exe'\r\n Write-Host \"Looking for mage.exe at $mage\"\r\n if (Test-Path $mage)\r\n {\r\n return $mage\r\n }\r\n\r\n Write-Error 'Could not find mage.exe, quitting'\r\n exit 1\r\n }\r\n#FMReports\r\n function Get-SSRSServiceProxy($id){\r\n\r\n $reportServer = Get-FMEnvSection reportServer $id\r\n\r\n if(-not (Test-Path variable:script:ssrsProxy))\r\n {\r\n $mgmtCredentialId = Get-CredentialId -AttributeName \"ssrsManagementCredentials\" -type SSRSManagement -id $id -IsSSRS\r\n \r\n Write-Verbose \"Using Credential ID $mgmtCredentialId as SSRS login\"\r\n # Use SSRSManagement credentials if specified in the config file\r\n if (Test-FMCredential -id $mgmtCredentialId )\r\n {\r\n [PsCredential] $credential = Get-FMCredentials -id $mgmtCredentialId -GetPsCredential\r\n $uri = \"$($reportServer.url)/ReportService2010.asmx?wsdl\"\r\n Write-Verbose \"Creating new Web Service Proxy for $uri with username $($credential.UserName)\"\r\n\r\n $script:ssrsProxy = New-WebServiceProxy -Uri $uri -Credential $credential\r\n }\r\n else # Otherwise use Windows Integrated authentication\r\n {\r\n $uri = \"$($reportServer.url)/ReportService2010.asmx?wsdl\"\r\n Write-Verbose \"Creating new Web Service Proxy for $uri Using Windows Authentication\"\r\n\r\n $script:ssrsProxy = New-WebServiceProxy -Uri $uri -UseDefaultCredential\r\n }\r\n\r\n $script:ssrsNamespace = ($script:ssrsProxy).GetType().Namespace\r\n\r\n Write-Verbose \"Setting SSRS Namespace to $($script:ssrsNamespace)\" \r\n \r\n $script:browserRole = ($script:ssrsProxy).ListRoles('All', $null)[0]\r\n Write-Verbose \"Setting SSRS BrowserRole to $($script:browserRole.Name) ($($script:browserRole.Description))\"\r\n \r\n \r\n $script:ssrsProxy.Timeout = 600 * 1000 # 600 sec timeout for ReportService operations\r\n Write-Verbose \"Setting SSRS Timeout to $($script:ssrsProxy.Timeout / 1000) seconds ($($script:ssrsProxy.Timeout) ms)\"\r\n }\r\n \r\n $script:ssrsProxy\r\n }\r\n\r\n function Get-FMReportService ($id){\r\n $reportServer = Get-FMEnvSection reportServer $id\r\n # use fmReportWebService if defined on reportServer\r\n $webServiceID = 'FMReport'\r\n if ($reportServer.fmReportWebService)\r\n {\r\n $webServiceID = $reportServer.fmReportWebService\r\n }\r\n\r\n Get-FMEnvSection webService $webServiceID\r\n }\r\n\r\n function Publish-SSRSHelper($reportServerId){\r\n $server = Get-FMEnvSection reportServer $reportServerId\r\n \r\n Assert-HasValue -Value $server.gacutil -ErrorMessage \"required gacutil attribute missing from reportServer id $reportServerId in environment file\"\r\n Assert-HasValue -Value $server.tempLocal -ErrorMessage \"required tempLocal attribute missing from reportServer id $reportServerId in environment file\"\r\n Assert-HasValue -Value $server.machineName -ErrorMessage \"required machineName attribute missing from reportServer id $reportServerId in environment file\"\r\n \r\n $gacutil = $server.gacutil\r\n $localPath = \"$($server.tempLocal)\\SSRSHelper.dll\" \r\n Copy-Item $packageRoot\\Common\\Assemblies\\SSRSHelper.dll $server.tempShare\r\n \r\n Invoke-Command -ComputerName $server.machineName {\r\n & $args[0] /i $args[1]\r\n } -Args $gacutil, $localPath\r\n }\r\n\r\n function Update-FMReports {\r\n [cmdletbinding()]\r\n param(\r\n #ID Filter\r\n [Parameter()]\r\n [string]\r\n $Id, \r\n\r\n #Server Filter \r\n [Parameter()]\r\n [string]\r\n $Server, \r\n \r\n # Website Id Filter\r\n [Parameter()]\r\n [string]\r\n $Website\r\n )\r\n\r\n $reportServers = Get-FMEnvSection reportServer -Website $Website -Server $Server -Id $Id\r\n if ($reportServers)\r\n {\r\n Write-Header -ForegroundColor Green -HeaderText \"Updating Report Servers\"\r\n }\r\n\r\n $reportServers | Update-FMReportServer\r\n }\r\n\r\n function Update-FMReportServer{\r\n [CmdletBinding()]\r\n param(\r\n \r\n [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\r\n $Id, \r\n \r\n [Parameter(ValueFromPipelineByPropertyName)]\r\n [switch] \r\n $DeploySSRSHelper\r\n )\r\n process{\r\n\r\n Write-Header \"Updating Report Server $Id \"\r\n\r\n $reportServer = Get-FMEnvSection reportServer $id\r\n \r\n \r\n\r\n Write-Verbose \"Retrieving SSRSServiceProxy...\"\r\n $ssrs = Get-SSRSServiceProxy -id $id\r\n \r\n \r\n\r\n $reportsFolder = $reportServer.contentFolder\r\n Write-Verbose \"Setting Report Content location to $reportsFolder\"\r\n\r\n if ($ssrs.GetItemType($reportsFolder) -eq 'Folder')\r\n {\r\n Write-Verbose \"Deleting Report Folder $reportsFolder\"\r\n $ssrs.DeleteItem($reportsFolder)\r\n }\r\n\r\n Write-Verbose \"Creating reports folder $reportsFolder\"\r\n\r\n $ssrs.CreateFolder($reportsFolder.Substring(1, $reportsFolder.Length - 1), \"/\", @()) | Out-Null\r\n \r\n if (-not ($reportServer.browseGroup -eq $null))\r\n {\r\n #Remove-BrowsePolicy -reportServer $reportServer -folderPath $reportsFolder\r\n Write-Verbose \"Adding Browse Policy for $reportsFolder in groupName $($reportServer.browseGroup)\"\r\n Add-BrowsePolicy -id $id -folderPath $reportsFolder -groupName $reportServer.browseGroup\r\n }\r\n\r\n Create-DataSources -id $id\r\n\r\n # Shared DataSet\r\n $dsFile = Get-ChildItem $packageRoot\\FMReports\\CompanyLogoDataSet.rsd\r\n Write-Output \"Creating dataset $($dsFile.Name)\"\r\n [byte[]] $dsDef = [System.IO.File]::ReadAllBytes($dsFile.FullName)\r\n $ssrs.CreateCatalogItem('DataSet', 'CompanyLogoDataSet', $reportsFolder, $true, $dsDef, @(), [ref] @()) | Out-Null\r\n \r\n # Deploy resources\r\n $mimeTypes = @{'.jpg' = 'image/jpeg'; '.png' = 'image/x-png'; '.gif' = 'image/gif' }\r\n $resourceFiles = Get-ChildItem $packageRoot\\FMReports | Where-Object {$mimeTypes.Keys -contains $_.Extension }\r\n $resourceFiles | ForEach-Object { \r\n\r\n Write-Output \"Deploying resource $($_.Name)\"\r\n [byte[]] $resDef = [System.IO.File]::ReadAllBytes($_.FullName)\r\n $prop = New-Object ($script:ssrsNamespace + '.Property')\r\n $prop.Name = 'MimeType'\r\n $prop.Value = $mimeTypes[$_.Extension]\r\n $ssrs.CreateCatalogItem('Resource', $_.Name, $reportsFolder, $true, $resDef, @($prop), [ref] @()) | Out-Null\r\n\r\n }\r\n\r\n #Deploy-SSRSHelper\r\n if ($DeploySSRSHelper){\r\n Publish-SSRSHelper -reportServerId $id\r\n }\r\n \r\n\r\n if ($reportServer.installRenderingExtensions -eq $true)\r\n {\r\n Write-Verbose \"InstallRenderingExtensions Specified, Installing Report Rendering Extensions\"\r\n Set-RDCE -id $id -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n # Deploy reports\r\n $reportFiles = Get-ReportList\r\n \r\n $reportFiles | ForEach-Object {\r\n \r\n $reportName = $_.Name.Replace('.rdl', '')\r\n $filter = $reportServer.filter\r\n if (-not (IsExcluded -Name $_.Name -Id $reportServer.filter) ){\r\n\r\n Write-Output \"Deploying report $($_.Name)\"\r\n [byte[]] $rdlDef = [System.IO.File]::ReadAllBytes($_.FullName)\r\n \r\n Write-Verbose \"Creating Report Catalog Item $reportName, in $reportsFolder on $($script:ssrsProxy.Url)\"\r\n $ssrs.CreateCatalogItem('Report', $reportName, $reportsFolder, $true, $rdlDef, @(), [ref] @()) | Out-Null\r\n }\r\n else\r\n {\r\n Write-Output \"Skipping Report $($_.Name) : Reason : Exclusion Rule\"\r\n } \r\n }\r\n\r\n # Set rendering extension for the MonthlyPerformanceReport\r\n\r\n }\r\n }\r\n\r\n function Create-DataSources($id){\r\n $reportServer = Get-FMEnvSection reportServer $id\r\n $fmenv = Get-FMEnv\r\n Write-Verbose \"Retrieving SSRSServiceProxy\"\r\n $ssrs = Get-SSRSServiceProxy -id $id\r\n \r\n \r\n Write-Verbose \"Server Url: $($ssrs.Url)\"\r\n Write-Verbose \"Server Version: $($ssrs.ServerInfoHeaderValue.ReportServerVersion)\"\r\n \r\n \r\n $ssrsExecutionCredentialId = Get-CredentialId -id $id -type \"SSRSManagement\" -AttributeName \"ssrsExecutionCredentials\" -IsSSRS \r\n\r\n $fmCredentialId = Get-CredentialId -type FM -AttributeName \"fmCredentials\" -id $id -IsSSRS\r\n \r\n $reportsFolder = $reportServer.contentFolder\r\n\r\n $def = New-Object ($script:ssrsNamespace + '.DataSourceDefinition')\r\n $def.CredentialRetrieval = 'Store'\r\n $def.ConnectString = Get-FMDataSourceConnectionString $reportServer.id\r\n\r\n $tmpSSRSLogin = $null\r\n $tmpSSRSPassword = $null\r\n\r\n # Use sql server auth if FMAccess account exist\r\n if (Test-FMCredential -id $fmCredentialId)\r\n {\r\n $credentials = Get-FMCredentials -id $fmCredentialId\r\n $def.UserName = $credentials.UserName\r\n $def.Password = $credentials.Password\r\n }\r\n else # Use windows auth otherwise\r\n {\r\n $def.CredentialRetrieval = 'Store'\r\n $credentials = Get-FMCredentials -id $ssrsExecutionCredentialId\r\n $def.UserName = $credentials.UserName\r\n $def.Password = $credentials.Password\r\n $def.WindowsCredentials = $true\r\n\r\n $tmpSSRSLogin = $def.UserName\r\n $tmpSSRSPassword = $def.Password\r\n }\r\n\r\n $def.Enabled = $true\r\n $def.EnabledSpecified = $true\r\n $def.Extension = 'SQL'\r\n Write-Output \"Creating data source FMDataSource\"\r\n $ssrs.CreateDataSource('FMDataSource', $reportsFolder, $true, $def, @()) | Out-Null\r\n \r\n Write-Verbose $ssrs\r\n\r\n $def = New-Object ($script:ssrsNamespace + '.DataSourceDefinition')\r\n $def.ConnectString = (Get-FMReportService $id).url\r\n \r\n $def.CredentialRetrieval = 'Store'\r\n\r\n if ($tmpSSRSLogin -eq $null)\r\n {\r\n $credentials = Get-FMCredentials -id $ssrsExecutionCredentialId\r\n $def.UserName = $credentials.UserName\r\n $def.Password = $credentials.Password\r\n }\r\n else\r\n {\r\n $def.UserName = $tmpSSRSLogin\r\n $def.Password = $tmpSSRSPassword\r\n }\r\n $def.WindowsCredentials = $true\r\n\r\n $def.Enabled = $true\r\n $def.EnabledSpecified = $true\r\n $def.Extension = 'XML'\r\n Write-Output \"Creating data source FMReportService\"\r\n $ssrs.CreateDataSource('FMReportService', $reportsFolder, $true, $def, @()) | Write-Verbose\r\n }\r\n\r\n function Set-RDCE($id)\r\n {\r\n \r\n $reportServer = Get-FMEnvSection reportServer $id\r\n\r\n $ssrs = Get-SSRSServiceProxy $id\r\n\r\n $reportsFolder = $reportServer.contentFolder\r\n $prop = New-Object ($script:ssrsNamespace + '.Property')\r\n $prop.Name = 'RDCE'\r\n $prop.Value = 'MonthlyPerformanceRDCE'\r\n \r\n $ssrs.SetProperties(\"$reportsFolder/MonthlyPerformanceReport\", @($prop))\r\n $ssrs.SetProperties(\"$reportsFolder/MonthlyPerformanceReportFI\", @($prop))\r\n $ssrs.SetProperties(\"$reportsFolder/QuarterlyPerformance\", @($prop))\r\n $ssrs.SetProperties(\"$reportsFolder/QuarterlyPerformanceFI\", @($prop))\r\n \r\n }\r\n\r\n#Filter Tools\r\n function Get-Filters($type, $isPackage = $false){\r\n \r\n if (-not (Test-Path variable:script:filtersHT) )\r\n {\r\n $script:filtersHT = @{}\r\n }\r\n\r\n if (-not (Test-Path variable:script:filtersHT:$type))\r\n {\r\n\r\n $script:filtersHT.$type = @{}\r\n \r\n $fmenv = Get-FMEnv\r\n $id = $fmenv.id\r\n\r\n $envPath = Split-Path $script:envDefinition\r\n if ($isPackage){\r\n $id = 'package' \r\n }\r\n\r\n $path = \"$($envPath)\\$($id).filters.xml\"\r\n \r\n \r\n if (-not (Test-Path $path)){\r\n Write-Output \"Filter File $($path) not found \"\r\n return $script:filtersHT.$type\r\n }\r\n\r\n $filters = [System.Array](([xml] (Get-Content $path )).filters.$type)\r\n\r\n #lazy load filters on first call \r\n foreach ($f in $filters) {\r\n if(-not (IsDisabled $f)){\r\n $script:filtersHT.$type.$($f.id) = $f\r\n }\r\n }\r\n \r\n }\r\n\r\n $ht = $script:filtersHT.$type\r\n return $ht\r\n }\r\n\r\n function Get-ReportFiles($isPackage){\r\n if ($isPackage){\r\n return Get-ChildItem .\\FMReports\\* -Exclude *rptproj*, *sln\r\n }\r\n\r\n return (Get-ChildItem $packageRoot\\FMReports\\*.rdl -Exclude *HFLeague*) \r\n # Exclude HFLeague for now (can't deploy SSRSHelper)\r\n \r\n $execute = {Invoke-Expression -Command \"\"}\r\n Invoke-Command -ComputerName \"\" -Credential (Get-FMCredentials \"\" -GetPsCredential ) -ScriptBlock $execute \r\n }\r\n\r\n function Get-ReportList{\r\n $reportslist = Get-ReportFiles\r\n #todo refactor into Get-ReportFiles\r\n return $reportslist\r\n }\r\n\r\n#Tools \r\n function Enable-SuperVerboseLogging(){\r\n $script:SuperVerboseLogging = $true\r\n Write-Host \"Super Verbose Logging set to $SuperVerboseLogging\"\r\n }\r\n\r\n #Enables Extra verbosity on calls to copy, new item etc \r\n function Disable-SuperVerboseLogging(){\r\n $script:SuperVerboseLogging = $false\r\n Write-Host \"Super Verbose Logging set to $SuperVerboseLogging\"\r\n }\r\n\r\n function Test-VerbosePreference {\r\n [CmdletBinding()]\r\n param (\r\n # Force Verbosity to true to override logging when $SuperVerboseLogging set to false\r\n [Parameter()]\r\n [switch]\r\n $Force\r\n )\r\n\r\n process {\r\n $isVerbose = Test-ActionPreference $VerbosePreference Continue\r\n if ($script:SuperVerboseLogging -or $Force) \r\n { \r\n return $isVerbose \r\n } \r\n else \r\n {\r\n return $false\r\n }\r\n }\r\n\r\n\r\n }\r\n\r\n function IsDisabled($element){\r\n \r\n if ($null -eq $element -or -not ($element -is [System.Xml.XmlElement]) )\r\n { \r\n return $false \r\n }\r\n $result = ($element.disabled -eq \"true\")\r\n \r\n if ($result -eq $true){\r\n Write-Verbose \"Skipping Disabled Element $($element.id)\"\r\n }\r\n \r\n \r\n return $result\r\n }\r\n\r\n function Set-FMEnvPath\r\n {\r\n [CmdletBinding()]\r\n param(\r\n [Parameter()]\r\n [string]\r\n $Environment,\r\n \r\n [Parameter()]\r\n [string] \r\n $Package\r\n )\r\n\r\n if ($Environment)\r\n {\r\n $script:envDefinition = $Environment\r\n\r\n Write-Verbose \"Setting Environment File Path To $envPath\"\r\n }\r\n if ($Package)\r\n {\r\n $script:packageRoot = $package\r\n Write-Verbose \"Setting Package root path To $Package\"\r\n \r\n }\r\n if (Test-Path variable:script:fmenv)\r\n {\r\n Remove-Variable fmenv -Scope script\r\n \r\n Write-Verbose \"Cached enviroment settings have been reset\"\r\n }\r\n }\r\n\r\n function Test-FileLock {\r\n [CmdletBinding()]\r\n param (\r\n [parameter(Mandatory=$true)][string]$Path\r\n )\r\n\r\n try \r\n {\r\n [IO.File]::OpenWrite($Path).close();\r\n $locked = $false\r\n }\r\n catch [System.IO.IOException]\r\n {\r\n $locked = $true;\r\n }\r\n\r\n return $locked\r\n }\r\n\r\n function Wait-FileLock {\r\n [CmdletBinding()]\r\n param (\r\n # File Path To Wait For Lock To Release\r\n [Parameter(ValueFromPipeline, Mandatory)]\r\n [string]\r\n $Path,\r\n [parameter()]\r\n [timespan]\r\n $Timeout = ([timespan] \"24:00:00\"),\r\n [long] $Refresh = 500\r\n )\r\n\r\n Write-Verbose \"Waiting up to $Timeout for File Lock on $Path\"\r\n\r\n [System.Diagnostics.Stopwatch] $timer = New-Object System.Diagnostics.Stopwatch\r\n Write-Verbose \"Timeout set to $Timeout, Starting Timer\"\r\n $timer.Start()\r\n \r\n if(-not (Test-Path $path)){\r\n throw [System.IO.FileNotFoundException] \"File $path not found\"\r\n }\r\n\r\n while (Test-FileLock -Path $Path) {\r\n \r\n if ($timer.ElapsedTicks -ge $Timeout.Ticks)\r\n {\r\n throw [System.ServiceProcess.TimeoutException] \"Operation timed out while waiting for file lock to clear\"\r\n }\r\n \r\n Start-Sleep -Milliseconds $Refresh \r\n Write-Verbose \"$Path Still Locked Waiting...\"\r\n }\r\n\r\n Write-Verbose \"File Lock Released Continuing...\"\r\n }\r\n\r\n #Check if value is set, displays error if null continues without incident otherwise \r\n function Assert-HasValue{\r\n [CmdletBinding(DefaultParameterSetName='ByUserName')]\r\n param (\r\n [parameter(Position=0, ValueFromPipeline)]\r\n $Value,\r\n [Parameter(Mandatory = $true, ParameterSetName = 'ByErrorMessage')]\r\n [string]\r\n $ErrorMessage,\r\n [Parameter(Mandatory = $true, ParameterSetName = 'ByName')]\r\n [string]\r\n $Name, \r\n [switch]\r\n $ThrowOnError\r\n \r\n )\r\n process{\r\n # if( (-not $ErrorMessage)-and (-not $Name))\r\n # {\r\n # throw [System.ArgumentException] \"-Name or -Errormessage is required\"\r\n # }\r\n \r\n if ($Value){\r\n return \r\n } \r\n if (-not $ErrorMessage )\r\n {\r\n $ErrorMessage = \"$Name is required\" \r\n return \r\n }\r\n if ($ThrowOnError)\r\n {\r\n throw [System.Configuration.ConfigurationException] $ErrorMessage\r\n return $ex\r\n }\r\n\r\n $ex = [System.Configuration.ConfigurationException] $ErrorMessage\r\n \r\n Write-Error -Message $ErrorMessage -Exception $ex\r\n $ex\r\n }\r\n }\r\n\r\n #TODO: Change to use -match/like syntax\r\n function IsExcluded([Parameter(Mandatory)] $name, $type = \"report\", $id, $isPackage = $false){\r\n $fmenv = Get-FMEnv\r\n $filters = Get-Filters -type $type -isPackage $isPackage\r\n\r\n if ($id)\r\n {\r\n $filterstoUse = @{}\r\n $filterstoUse.Add($id, $filters[$id])\r\n $filters = $filterstoUse\r\n }\r\n \r\n foreach ($f in $filters.Values ) {\r\n \r\n $shouldExclude = $false\r\n #in this case inclusion is more important than exclusion and will override an excluded report \r\n foreach ($exp in $f.exclude){\r\n if ($exp.name -eq $name -or $exp.name -eq \"*\"){\r\n $shouldExclude = $true\r\n break\r\n }\r\n \r\n }\r\n\r\n foreach ($exp in $f.include){\r\n if ($exp.name -eq $name -or $exp.name -eq \"*\"){\r\n $shouldExclude = $false\r\n break\r\n }\r\n }\r\n return $shouldExclude\r\n }\r\n\r\n #if filters not found return false \r\n return $false\r\n }\r\n\r\n # execute an external .exe and throw an error if it fails\r\n function Exec {\r\n [CmdletBinding()]\r\n param (\r\n [Parameter(Position=0, Mandatory=1, ValueFromPipeline)]\r\n $Command,\r\n [Parameter(Position=1, Mandatory=0)]\r\n [string]$ErrorMessage = \"Execution of command failed.`n$Command\"\r\n )\r\n process{\r\n\r\n \r\n Write-Output \"Execute Command $Command\"\r\n Invoke-Expression $Command\r\n \r\n Write-Output \"Last exit code: $LastExitCode\"\r\n \r\n if ($LastExitCode -ne 0) {\r\n throw \"Exec: $ErrorMessage\"\r\n }\r\n }\r\n }\r\n\r\n function Get-PackageSource([Parameter(Mandatory)] [ValidateSet(\"FM\", \"FMReport\", \"RT\", \"TaskHost\", \"RTAutomation\", \"DealSetup\", \"DealSetupService\", \"BatchQueueExecutor\", \"BatchQueueService\")] [string] $type, [switch] $WebDeploy){\r\n $subPath = if($WebDeploy) {\"WebDeploy\\\"}\r\n $pathExt = if($WebDeploy) {\".zip\"} else {\"\\\"}\r\n\r\n $folders = @{}\r\n $Folders.FM = (Join-Path \"$packageRoot\" \"$($subPath)Application$pathExt\")\r\n $folders.FMReport = (Join-Path \"$packageRoot\" \"$($subPath)Application$pathExt\")\r\n $folders.RT = (Join-Path \"$packageRoot\" \"$($subPath)ReconciliationService$pathExt\")\r\n $folders.RTAutomation = (Join-Path \"$packageRoot\" \"$($subPath)RTWebServices\\RTAutomationWebservice$pathExt\")\r\n $folders.DealSetup = (Join-Path \"$packageRoot\" \"$($subPath)JPMDealSetupWebService$pathExt\")\r\n $folders.DealSetupService = (Join-Path \"$packageRoot\" \"$($subPath)JPMDealSetupService$pathExt\")\r\n $folders.BatchQueueExecutor = (Join-Path \"$packageRoot\" \"FMBatchQueue\\Executor\")\r\n $folders.BatchQueueService = (Join-Path \"$packageRoot\" \"FMBatchQueue\\Service\")\r\n $folders.TaskHost = (Join-Path \"$packageRoot\" \"\\FMTaskHost\")\r\n $return = $folders.$type\r\n \r\n Write-Verbose \"Package Source $type Selected\"\r\n Write-Verbose \"Package Source Path: $return\"\r\n \r\n return $return\r\n }\r\n\r\n function Get-ConfigSource{ \r\n [CmdletBinding()]\r\n param(\r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [ValidateSet(\"FM\", \"FMReport\", \"RT\", \"RTAutomation\", \"DealSetup\", \"DealSetupService\", \"BatchQueueExecutor\", \"BatchQueueService\", \"TaskHost\")] \r\n [string] \r\n $type)\r\n \r\n process {\r\n $configRoot = \"$packageRoot\\BuildScripts\\Configs\\\"\r\n $folders = @{}\r\n $Folders.FM = Join-Path \"$configRoot\" \"\\Web\\FundManager\\web.config\"\r\n $folders.FMReport = Join-Path \"$configRoot\" \"\\Web\\FMReportService\\web.config\"\r\n $folders.RT = Join-Path \"$configRoot\" \"\\Web\\RT\\web.config\"\r\n $folders.RTAutomation = Join-Path \"$configRoot\" \"\\Web\\RTAutomationWebservice\\web.config\"\r\n $folders.DealSetup = Join-Path \"$configRoot\" \"Web\\JPMDealSetupWebService\\web.config\"\r\n $folders.DealSetupService = Join-Path \"$configRoot\" \"\\JPMDealSetupService\\JPMDealSetupService.exe.config\"\r\n $folders.BatchQueueExecutor = Join-Path \"$configRoot\" \"\\FMBatchQueue\\Executor\\BatchQueue2JobExecutor.exe.config\"\r\n $folders.BatchQueueService = Join-Path \"$configRoot\" \"\\FMBatchQueue\\Service\\BatchQueue2Service.exe.config\"\r\n $folders.TaskHost = Join-Path $configRoot \"\\FMTaskHost\"\r\n\r\n $return = $folders.$type\r\n \r\n Write-Verbose \"Configuration Source $type Selected\"\r\n Write-Verbose \"Configuration Source Path: $return\"\r\n \r\n return $return\r\n }\r\n }\r\n\r\n function Get-FMDeploy(){\r\n # If have FMDeploy.exe in the PATH then use it\r\n if (Get-Command \"FMDeploy.exe\" -CommandType Application -ErrorAction SilentlyContinue)\r\n {\r\n 'FMDeploy.exe'\r\n }\r\n else # Otherwise use one from the package\r\n { \r\n $p = Join-Path $packageRoot 'FMDeploy'\r\n Join-Path $p 'FMDeploy.exe'\r\n }\r\n }\r\n\r\n function Get-FMConnectionString {\r\n [CmdletBinding()]\r\n param (\r\n # DB Id \r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id,\r\n\r\n [switch] \r\n $Encrypt\r\n )\r\n \r\n process {\r\n $db = Get-FMEnvSection db $Id \r\n\r\n Assert-HasValue $db -ErrorMessage \"DB Section Id $Id Not found in environment file\"\r\n\r\n $fmdeploy = Get-FMDeploy\r\n \r\n $x = $null\r\n if ($Encrypt)\r\n {\r\n $x = \"-x\"\r\n }\r\n \r\n [string] $result = & $fmDeploy getconnectionstring --db $Id -e $script:envDefinition $packageRoot $x ` | select -Last 1\r\n $result \r\n }\r\n \r\n }\r\n\r\n #todo: can this be revamped to something better ??\r\n function Get-FMDataSourceConnectionString {\r\n\r\n [CmdletBinding()]\r\n param(\r\n # Id\r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id\r\n )\r\n process{\r\n \r\n $fmenv = Get-FMEnv\r\n $reportServer = Get-FMEnvSection reportServer $id\r\n # If available - use server and db name as directly specified on the \r\n $dbServerKey = $reportServer.dataSourceServer\r\n $reportDbKey = $reportServer.fmDataSourceDbOverride \r\n\r\n # If report DB name is not specified - use \"SSO\" \r\n if ($reportDbKey -eq $null) \r\n {\r\n $reportDbKey = \"SSO\"\r\n }\r\n\r\n # Find DB definition given the key if possible \r\n $reportDb = $fmenv.db | Where-Object { $_.id -eq $reportDbKey }\r\n\r\n # Couldn't find DB by key? Use key as DB name.\r\n if ($reportDb -eq $null)\r\n {\r\n $reportDBSqlName = $reportDbKey \r\n }\r\n else \r\n {\r\n # Otherwise use name of the DB found by key\r\n $reportDBSqlName = $reportDb.name \r\n }\r\n\r\n # If db server key is not specified on take it from the db\r\n if ($dbServerKey -eq $null)\r\n {\r\n # Can't take the server key from the DB definition because couldn't find the db\r\n # Fail with an error in this case\r\n if ($reportDb -eq $null)\r\n {\r\n throw \"Couldn't determine dbServerKey. Reason: no 'dataSourceServer' defined on '$($id)', and couldn't find db definition using '$reportDbKey'\" \r\n }\r\n else \r\n {\r\n $dbServerKey = $reportDb.server\r\n }\r\n }\r\n\r\n $server = Get-FMEnvSection dbserver $dbServerKey\r\n\r\n \"Data Source=$($server.instance);Initial Catalog=$reportDBSqlName\"\r\n }\r\n }\r\n\r\n #Outputs formatted header to host \r\n function Write-Header {\r\n [CmdletBinding()]\r\n param(\r\n # Text to display in header output \r\n [Parameter(Mandatory, Position=0)]\r\n [string]\r\n $HeaderText,\r\n # Text Color of header \r\n [Parameter()]\r\n [System.ConsoleColor]\r\n $ForegroundColor = [System.ConsoleColor]::Cyan\r\n )\r\n process{\r\n\r\n Write-Host -ForegroundColor $ForegroundColor \"========================================================================\"\r\n Write-Host -ForegroundColor $ForegroundColor \"$HeaderText\"\r\n Write-Host -ForegroundColor $ForegroundColor \"========================================================================\"\r\n \r\n }\r\n }\r\n\r\n function Convert-ToHashTable {\r\n param(\r\n [Parameter(Mandatory, ParameterSetName=\"DirectCall\")]\r\n [System.Array]\r\n $Array,\r\n \r\n # Process Pipeline Input\r\n [Parameter(Mandatory, ParameterSetName=\"Pipeline\", ValueFromPipeline, DontShow )]\r\n \r\n $ArrayItem,\r\n\r\n [Parameter()]\r\n [string]\r\n $key = 'id',\r\n\r\n $Property\r\n )\r\n begin{\r\n\r\n \r\n $ht = @{}\r\n\r\n function ProcessItem ([parameter(ValueFromPipeline)] $V) {\r\n \r\n process{\r\n $value = if($Property){\r\n $V.$Property\r\n }else{ \r\n $V \r\n }\r\n \r\n $keyValue = $V.$key\r\n\r\n if (-not $keyValue) {\r\n Write-Error \"Key property $key does not exist on source object\"\r\n }\r\n\r\n $ht.$keyValue = $value\r\n }\r\n\r\n }\r\n\r\n }\r\n \r\n process{\r\n if ($Array)\r\n {\r\n $Array | ProcessItem \r\n }\r\n elseif($ArrayItem)\r\n {\r\n ProcessItem $ArrayItem \r\n }\r\n }\r\n\r\n end {\r\n return $ht \r\n }\r\n\r\n\r\n }\r\n\r\n\r\n#Configuration Tools \r\n function Get-FMEnv{\r\n if (-not (Test-Path variable:script:fmenv))\r\n {\r\n $script:fmenv = ([xml] (Get-Content $script:envDefinition)).fmenv\r\n }\r\n \r\n $script:fmenv\r\n }\r\n\r\n function Get-FMEnvServices {\r\n\r\n $services = Get-FMEnvSection webService \r\n return Convert-ToHashTable $services\r\n }\r\n\r\n function Get-FMEnvAppSettings {\r\n $appSettingsConfig = Get-FMEnvSection appSetting\r\n\r\n if ($appSettingsConfig) {\r\n $appSettings = $appSettingsConfig | Convert-ToHashTable -key 'key'\r\n }\r\n\r\n $appSettings\r\n }\r\n\r\n function Get-FMEnvSection($type, $id, $includeDisabled = $false, $keyProperty = 'id', $Website, $Server, $ThrowOnError ){\r\n $fmenv = Get-FMEnv\r\n $sections = [System.Array]$fmenv.$type \r\n\r\n if ($Website)\r\n {\r\n $temp = ($sections | Where-Object { $_.website -eq $Website } )\r\n $sections = $temp\r\n }\r\n \r\n $ServerId = $null\r\n\r\n #autodetect server from env:COMPUTERNAME id autodetect specified \r\n if($Server -eq \"autodetect\"){\r\n $Servers = $fmenv.server\r\n \r\n $name = $env:COMPUTERNAME\r\n $instance = ($Servers | Where-Object {$_.instance -eq $name })\r\n\r\n $ServerId = $instance.id\r\n \r\n $ex = Assert-HasValue -Value $ServerId -ThrowOnError -ErrorMessage \"AutoDetected Server $($env:COMPUTERNAME) not found in environment file\"\r\n if ($ex)\r\n {\r\n throw $ex\r\n return $null\r\n }\r\n\r\n Write-Output \"AutoDetected Server as '$($instance.id)' ($($instance.instance))\"\r\n \r\n \r\n }else{\r\n $ServerId = $Server\r\n }\r\n \r\n\r\n if ($ServerId -and $type -in \"server\", \"dbserver\")\r\n {\r\n $temp = $sections | Where-Object { $_.id -eq $ServerId } \r\n $sections = $temp\r\n }\r\n elseif ($ServerId )\r\n {\r\n $temp = $sections | Where-Object { $_.server -eq $ServerId } \r\n $sections = $temp\r\n }\r\n\r\n #include config items marked disabled \r\n if (-not $includeDisabled)\r\n {\r\n $temp = $sections | Where-Object {-not (IsDisabled $_) }\r\n $sections = $temp\r\n }\r\n \r\n #if -id specified return section by id \r\n if ($id){\r\n $section = $sections | Where-Object {$_.$keyProperty -eq $id}\r\n # Assert-HasValue -Value $section -ThrowOnError:$ThrowOnError -ErrorMessage \"No Environment $type Section with id '$id' found in environment file\"\r\n \r\n return $section \r\n }\r\n else\r\n {\r\n if($ThrowOnError){\r\n # Assert-HasValue -Value $sections -ThrowOnError:$ThrowOnError -ErrorMessage \"No Environment $type Sections found in environment file\"\r\n }\r\n return $sections\r\n \r\n }\r\n\r\n }\r\n\r\n function Update-FMAppConfig {\r\n [CmdletBinding()] \r\n param(\r\n [Parameter(Mandatory)] $configPath, \r\n [string]\r\n $savePath,\r\n\r\n [string]\r\n $type, \r\n \r\n [Parameter(ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id,\r\n\r\n [Parameter(ValueFromPipeline)]\r\n $envSection \r\n )\r\n\r\n process{\r\n \r\n if(!$envSection)\r\n {\r\n $envSection = Get-FMEnvSection $type $id\r\n }\r\n\r\n $envAppSettings = $envSection | Get-AppSettings | Convert-ToHashTable -key 'key' -Property 'value'\r\n\r\n $appConfig = (Get-ChildItem $configPath)\r\n $xml = [xml] (Get-Content $appConfig)\r\n\r\n $fmAppSettings = Get-FMEnvAppSettings \r\n \r\n $xml.configuration.appSettings.add | ForEach-Object {\r\n\r\n if ($envAppSettings.Keys -contains $_.key)\r\n {\r\n $_.value = $envAppSettings[$_.key]\r\n Write-Verbose \"Updated AppSetting $($_.key) To $($_.value)\"\r\n\r\n }\r\n\r\n }\r\n\r\n $connStrings = $xml.configuration.connectionStrings.add \r\n\r\n $connStrings | ForEach-Object {\r\n if ($_.name -eq \"DB:SingleSignOn\" -and $envSection.SSO )\r\n {\r\n try {\r\n\r\n Write-Verbose \"SSO attribute found on $($envSection.name) element $id\"\r\n [string] $connectionString = (Get-FMConnectionString -Id $envSection.SSO -ErrorAction Stop)\r\n $_.connectionString = Get-FMConnectionString -Id $envSection.SSO -ErrorAction Stop\r\n \r\n Write-Verbose \"Updated Connection String $($_.name) To $($_.connectionString)\" \r\n }\r\n catch [System.Management.Automation.SetValueException]{\r\n Write-Error (Get-FMConnectionString -Id $envSection.SSO)\r\n }\r\n }\r\n if ($_.name -eq \"ReconciliationTool\" -and $envSection.RT )\r\n {\r\n try {\r\n Write-Verbose \"RT attribute found on $($envSection.name) element $id\"\r\n [string] $connectionString = (Get-FMConnectionString -Id $envSection.SSO -ErrorAction Stop)\r\n $_.connectionString = Get-FMConnectionString -Id $envSection.SSO -ErrorAction Stop\r\n Write-Verbose \"Updated Connection String $($_.name) To $($_.connectionString)\" \r\n }\r\n catch [System.Management.Automation.SetValueException]{\r\n Write-Error (Get-FMConnectionString -Id $envSection.SSO)\r\n }\r\n }\r\n \r\n }\r\n\r\n # Substitute entries in element if fmenv file has them.\r\n if ($fmenv.connectionString -ne $null)\r\n {\r\n \r\n #HACK to support old and new connection string resolution \r\n #TODO: Find better way to do this \r\n\r\n $RT = if($envSection.RT){ $envSection.RT }else{ 'ReconciliationTool' }\r\n $SSO = if($envSection.SSO){ $envSection.SSO }else{ 'DB:SingleSignOn' }\r\n \r\n \r\n $dbMapSrc = Get-FMEnvSection connectionString | Select-Object id,type | Convert-ToHashTable -Property 'type' \r\n\r\n \r\n\r\n $dbMap = @{\r\n 'DB:SingleSignOn' = $SSO;\r\n 'ReconciliationTool' = $RT;\r\n }\r\n\r\n $connStrings | ForEach-Object {\r\n \r\n if ($dbMap.Keys -contains $_.name)\r\n {\r\n $temp = (Get-FMEnvSection connectionString -id $dbMap[$_.name])\r\n if ($temp -eq $null)\r\n {\r\n Write-Warning \"$($_.name) not found in the XML settings file so no value set\"\r\n }\r\n else\r\n {\r\n $_.connectionString = $temp.value \r\n $_.providerName = $temp.provider\r\n Write-Verbose \"Updated Connection String for $($_.name)\"\r\n }\r\n } \r\n }\r\n }\r\n\r\n if ($savePath){\r\n $xml.Save($savePath)\r\n return\r\n }\r\n \r\n $xml.Save($appConfig.FullName)\r\n }\r\n }\r\n\r\n#Build Tools \r\n function Get-MSBuild($WebDeployPackage, $Configuration=\"Release\", $OutputDirectory){\r\n\r\n $folder = (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0' -Name 'MSBuildToolsPath').MSBuildToolsPath\r\n\r\n Join-Path $folder 'msbuild.exe'\r\n\r\n $args = \"\"\r\n\r\n if ($WebDeployPackage){\r\n\r\n $args = $args + \"/T Package /P:Configuration=$Configuration\"\r\n\r\n }\r\n\r\n if ($OutputDirectory){\r\n\r\n $args = $args + \"/P OutDir $OutputDirectory\"\r\n\r\n }\r\n\r\n } \r\n\r\n function Set-AssemblyInfo{\r\n Copy-Item .\\Common\\AssemblyInfo.cs .\\Common\\AssemblyInfo.cs.bak\r\n $assemblyVersionPattern = 'AssemblyVersionAttribute\\(\"([0-9]+(\\.([0-9]+|\\*)){1,3})\"\\)'\r\n \r\n $ver = Get-BuildVersion\r\n $newVersion = \"AssemblyVersionAttribute(`\"$ver`\")\"\r\n $newVersion\r\n Get-Content .\\Common\\AssemblyInfo.cs | ForEach-Object {$_ -replace $assemblyVersionPattern, $newVersion} | Set-Content .\\Common\\AssemblyInfo.cs.temp\r\n Move-Item .\\Common\\AssemblyInfo.cs.temp .\\Common\\AssemblyInfo.cs -Force\r\n }\r\n\r\n function Reset-AssemblyInfo{\r\n Copy-Item .\\Common\\AssemblyInfo.cs.bak .\\Common\\AssemblyInfo.cs\r\n }\r\n\r\n function Get-BuildVersion{ \r\n if (Test-Path env:build_version)\r\n {\r\n return ${env:build_version}\r\n }\r\n else\r\n {\r\n $versionPrefix = Get-Content .\\BuildScripts\\version.txt\r\n\r\n & svn info --xml > .\\svn_version.tmp\r\n $xml = [xml] (Get-Content .\\svn_version.tmp)\r\n $revision = $xml.info.entry.revision\r\n Remove-Item .\\svn_version.tmp\r\n \r\n # Revision number can't be >= 65535\r\n $revision = $revision - 65535\r\n\r\n return \"$versionPrefix.$revision\"\r\n }\r\n }\r\n\r\n #TODO: replace with new MsBuild Module \r\n function Start-Build(\r\n [Parameter(Mandatory = $true)]\r\n $proj, \r\n\r\n $target = \"Build\", \r\n $config = \"Debug\",\r\n \r\n [switch] $noPlatform){\r\n $vsversion = \"10.0\"\r\n if (Test-Path env:vs_version)\r\n {\r\n $vsversion = $env:vs_version\r\n }\r\n\r\n $msbuild = Get-MSBuild \r\n \r\n Set-AssemblyInfo\r\n \r\n if ($noPlatform -eq $true)\r\n {\r\n & $msbuild /target:$target /p:Configuration=$config /p:NoWin32Manifest=true /p:VisualStudioVersion=$vsversion $proj\r\n }\r\n else\r\n {\r\n & $msbuild /target:$target /p:Configuration=$config /p:Platform=`\"Any CPU`\" /p:VisualStudioVersion=$vsversion /p:NoWin32Manifest=true $proj\r\n }\r\n \r\n if ($LastExitCode -ne 0)\r\n {\r\n throw \"MSBuild failed\"\r\n }\r\n \r\n Reset-AssemblyInfo\r\n }\r\n\r\n function Write-RoboCopyResult{\r\n [CmdletBinding()]\r\n param(\r\n [parameter(ValueFromPipeline)]\r\n $Result\r\n\r\n )\r\n begin{\r\n \r\n $exitcodes = @{}\r\n $exitcodes.0\t= \"No errors occurred and no files were copied.\"\r\n $exitcodes.1\t= \"One of more files were copied successfully.\"\r\n $exitcodes.2\t= \"Extra files or directories were detected. Examine the log file for more information.\"\r\n $exitcodes.4\t= \"Mismatched files or directories were detected. Examine the log file for more information.\"\r\n $exitcodes.8\t= \"Some files or directories could not be copied and the retry limit was exceeded.\"\r\n $exitcodes.16\t= \"Robocopy did not copy any files. Check the command line parameters and verify that Robocopy has enough rights to write to the destination folder.\"\r\n \r\n if ($LASTEXITCODE -in 2, 4)\r\n {\r\n \r\n $exitcodes.$LASTEXITCODE | Write-Warning \r\n }\r\n elseif($LASTEXITCODE -in 0, 1 )\r\n {\r\n $exitcodes.$LASTEXITCODE | Write-Verbose\r\n }\r\n else {\r\n Write-Error \"Robocopy failed with exitcode $LASTEXITCODE\"\r\n $exitcodes.$LASTEXITCODE | Write-Error \r\n }\r\n \r\n }\r\n\r\n process {\r\n \r\n\r\n if ($LASTEXITCODE -in 0, 2, 4)\r\n {\r\n \r\n $Result | Write-Warning \r\n }\r\n elseif($LASTEXITCODE -eq 1 )\r\n {\r\n $result | Write-Verbose\r\n }\r\n else {\r\n \r\n $result | Write-Host -ForegroundColor Red -BackgroundColor Black\r\n }\r\n }\r\n\r\n }\r\n\r\n function Invoke-Robocopy {\r\n [CmdletBinding()]\r\n param (\r\n # Source Path\r\n [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Source,\r\n\r\n # Destination Path\r\n [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Destination,\r\n \r\n [string]\r\n $Arguments = \"/e /ns /nc /nfl /ndl /np /njh /njs\"\r\n )\r\n \r\n process {\r\n\r\n $dest = Get-ChildItem $Destination \r\n $src = Get-ChildItem $Source \r\n \r\n Write-Verbose \"Executing Robocopy Command robocopy.exe $Source $Destination $Arguments\"\r\n\r\n $result = robocopy.exe $Source $Destination $Arguments | Write-RoboCopyResult\r\n \r\n \r\n }\r\n \r\n }\r\n\r\n#FM Updater Tools\r\n function Update-TaskHost{\r\n\r\n [CmdletBinding()]\r\n param(\r\n # TaskHost Config id \r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id\r\n )\r\n\r\n process{\r\n \r\n $taskhost = Get-FMEnvSection taskhost $id\r\n\r\n if ($taskhost){\r\n Write-Header \"Deploying TaskHost Service $($service.id)\"\r\n # TaskHost\r\n $dest = $taskhost.path\r\n Write-Output (\"Copying TaskHost binaries to {0}\" -f $dest)\r\n $sourcePath = Get-PackageSource -type taskhost \r\n #Copy-WithProgress $packageRoot\\FMTaskHost\\ $dest -Args \"/e /ns /nc /nfl /ndl /np /njh /njs\"\r\n Copy-Item -Recurse -Path $sourcePath -Destination $dest -Container -Force \r\n }\r\n else{\r\n Write-Error \"TaskHost $id was not found in environment file\" \r\n }\r\n }\r\n }\r\n\r\n function Deploy-FMClient($clickOnce){\r\n $fmenv = Get-FMEnv\r\n \r\n if ($clickOnce)\r\n {\r\n Write-Output \"Creating ClickOnce package...\"\r\n \r\n if (Test-Path \"$packageRoot\\Application\\$($clickOnce.configFile)\" -PathType Leaf)\r\n {\r\n Write-Output (\"Using config: {0}\" -f \"$packageRoot\\Application\\$($clickOnce.configFile)\")\r\n Copy-Item \"$packageRoot\\Application\\$($clickOnce.configFile)\" $packageRoot\\Application\\WinUI.exe.config\r\n }\r\n else\r\n {\r\n Write-Output \"Using existing config file, will update with environment settings\"\r\n $clickOnce | Update-FMAppConfig -configPath $packageRoot\\Application\\WinUI.exe.config\r\n }\r\n \r\n New-ClickOncePackage -clickOnce $clickOnce\r\n Deploy-ClickOncePackage -clickOnce $clickOnce\r\n }\r\n else \r\n {\r\n $configPath = \"$packageRoot\\Application\\WinUI.exe.config\"\r\n Write-Verbose \"ClickOnce not specified, only updating config at '$configPath'\"\r\n Update-FMAppConfig -configPath $configPath -envSection @{}\r\n }\r\n }\r\n\r\n function Publish-MarketDataETL(){\r\n $fmenv = Get-FMEnv\r\n $fmDeploy = Get-FMDeploy \r\n\r\n Write-Output \"Updating Market Data databases...\"\r\n Exec { & $fmDeploy up --db MD -e $script:envDefinition $packageRoot }\r\n Exec { & $fmDeploy up --db IDC -e $script:envDefinition $packageRoot }\r\n\r\n $dest = \"$((Get-FMEnvServices)['MD'].path)\\Bin\"\r\n Write-Output (\"Copying MD app server binaries to {0}\" -f $dest)\r\n robocopy.exe $packageRoot\\MarketDataService\\ $dest /ns /nc /nfl /ndl /np\r\n if (Test-Path $packageRoot\\BuildScripts\\Configs\\Web\\MarketData\\) \r\n { \r\n if ((Test-Path $packageRoot\\BuildScripts\\Configs\\Web\\MarketData\\web.config) -and $updateConfigs) \r\n {\r\n Update-FMAppConfig -configPath $packageRoot\\BuildScripts\\Configs\\Web\\MarketData\\web.config\r\n }\r\n Copy-Item $packageRoot\\BuildScripts\\Configs\\Web\\MarketData\\* \"$((Get-FMEnvServices)['MD'].path)\\\" -Recurse -Force \r\n }\r\n\r\n $etlRoot = $fmenv.marketdata.etlRoot\r\n\r\n $dest = Join-Path $etlRoot $fmenv.marketdata.etlFileImportToolDir\r\n Write-Output (\"Copying FileImportTool to {0}\" -f \"$dest\")\r\n robocopy.exe $packageRoot\\ETL\\FileImportTool \"$dest\" /ns /nc /nfl /ndl /np\r\n\r\n $dest = Join-Path $etlRoot FtpSyncTool\r\n Write-Output (\"Copying FTPSyncTool to {0}\" -f \"$dest\")\r\n robocopy.exe $packageRoot\\ETL\\FtpSyncTool \"$dest\" /ns /nc /nfl /ndl /np\r\n\r\n $dest = Join-Path $etlRoot Package\r\n Write-Output (\"Copying SSIS packages to {0}\" -f \"$dest\")\r\n robocopy.exe $packageRoot\\ETL\\SSIS \"$dest\" /ns /nc /nfl /ndl /np\r\n }\r\n\r\n function Deploy-ClickOncePackage([Parameter(Mandatory = $true)] $clickOnce){\r\n Write-Output (\"Copying ClickOnce package to {0}\" -f $clickOnce.path)\r\n if ($clickOnce.azureDeployment) {\r\n $azcopy = Get-AZCopy\r\n $azstoragepath = $clickOnce.path\r\n $azstoragekey = $clickOnce.azureStorageKey\r\n\r\n & $azcopy /Source:\"$packageRoot\\ClickOnce\\\" /S /DestKey:$azstoragekey /Dest:$azstoragepath /Y\r\n }\r\n else {\r\n robocopy.exe $packageRoot\\ClickOnce\\ $clickOnce.path /e /ns /nc /nfl /ndl /np /njh /njs\r\n }\r\n \r\n }\r\n\r\n function Publish-TradeWeb(){\r\n $fmenv = Get-FMEnv\r\n\r\n $serviceName = $fmenv.tradeWeb.serviceName\r\n $computerName = $fmenv.tradeWeb.computerName\r\n\r\n Write-Output (\"Looking for TradeWeb serviceName = '{0}' on computerName = '{1}'\" -f $serviceName, $computerName)\r\n\r\n $twService = Get-Service -Name $serviceName -ComputerName $computerName -ErrorAction SilentlyContinue\r\n if ($twService -ne $null)\r\n {\r\n Write-Output \"Stopping the service...\"\r\n $twService.Stop()\r\n Write-Output \"Stopped successfully\"\r\n\r\n $dest = $fmenv.tradeWeb.path\r\n Write-Output (\"Copying TradeWeb binaries to {0}\" -f $dest)\r\n robocopy.exe $packageRoot\\TradeWeb\\ \"$dest\" /ns /nc /nfl /ndl /np\r\n\r\n Write-Output \"Starting the service...\"\r\n $twService.Start()\r\n Write-Output \"Started successfully\"\r\n }\r\n else \r\n {\r\n Write-Output \"Service not found, doing nothing\" \r\n }\r\n }\r\n\r\n function Update-DealSetupServices{\r\n\r\n [CmdletBinding()]\r\n param(\r\n [bool] $updateConfigs = $true, \r\n [string] $Website, \r\n [string] $Server, \r\n [switch] $CreateIISApp, \r\n [switch] $Force \r\n )\r\n\r\n #change to windows services only \r\n $dealSetupServices = Get-FMEnvSection dealSetupServices -Website $Website -Server $Server\r\n \r\n $dealsetupWebSvcs = Get-FMEnvSection webService -Server $Server -Website $Website | Where-Object { $_.type -eq \"DealSetup\" } \r\n \r\n if($dealsetupWebSvcs) {\r\n Write-Header -ForegroundColor Green -HeaderText \"Updating Deal Setup Web Services\" \r\n }\r\n\r\n $dealsetupWebSvcs | Update-WebService -updateConfigs $updateConfigs\r\n\r\n $dealSetupServices | Update-DealSetupService \r\n }\r\n\r\n\r\n \r\n function Update-WebService(){\r\n [CmdletBinding()]\r\n param(\r\n [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)]\r\n [string] \r\n $Id, \r\n [bool]\r\n $UpdateConfigs = $true, \r\n \r\n [switch] \r\n $CreateIISApp, \r\n \r\n [switch] \r\n $Force\r\n )\r\n process{\r\n\r\n \r\n $service = (Get-FMEnvSection webService $Id) \r\n \r\n\r\n Assert-HasValue -Value $service -ErrorMessage \"Web Service $id not found in Environment File $envPath\" \r\n\r\n\r\n\r\n $ServiceType = $service.type\r\n \r\n Write-Header \"Deploying $ServiceType Webservice $($service.id)\"\r\n\r\n $iisSiteName = if ($service.website)\r\n {\r\n $website = Get-FMEnvSection website $service.website\r\n Assert-HasValue -Value $website -ErrorMessage \"Website Id $($service.website) not found\" \r\n $website.name \r\n }\r\n elseif($service.iisSitename)\r\n {\r\n $service.iisSiteName\r\n }\r\n else\r\n {\r\n \"Default Website\"\r\n }\r\n\r\n Write-Verbose \"Deploying Service to IIS Site $IISSiteName on $computer\"\r\n $credentialId = Get-CredentialId $ServiceType $id -IsWebService\r\n\r\n Write-Verbose \"Using Credential ID $credentialid\"\r\n\r\n if($CreateIISApp){\r\n\r\n Write-Verbose \"-CreateIISApp Specified Attempting to Create IIS Website \"\r\n\r\n $credentials = Get-FMCredentials $credentialId \r\n\r\n Write-Verbose \"Using credential username $($credentials.username)\"\r\n\r\n $application = New-WebService -SiteName $iisSiteName `\r\n -Name $service.iisAppName `\r\n -Credentials $credentials `\r\n -AppPool $service.appPool `\r\n -Path $service.Path `\r\n -Force:$Force \r\n }\r\n\r\n if($service.webdeployUrl){\r\n Write-Verbose \"Webdeploy url $($service.webdeployUrl) detected using webdeploy to publish to website\"\r\n\r\n $packagePath = Get-PackageSource -type $service.type -WebDeploy\r\n \r\n if(-not (Test-Path $packagePath -PathType Leaf))\r\n {\r\n Write-Error \"Web Deploy Package not found at $packagePath\"\r\n }\r\n \r\n $pscredentials = Get-FMCredentials $credentialId -GetPsCredential\r\n\r\n Write-Verbose \"Initializing Web Deploy with username $($pscredentials.username)\"\r\n \r\n Initialize-WebDeploy -Credential $pscredentials\r\n\r\n\r\n $ServerHost = $service.computerName \r\n Write-Verbose \"Server Host = $ServerHost\" \r\n \r\n $IISSiteName = $service.IISSiteName \r\n Write-Verbose \"IIS Site Name = $IISSiteName \"\r\n \r\n $IISApp = $service.IISAppName\r\n Write-Verbose \"IIS Application Name = $IISAppName \"\r\n \r\n #todo: fix webdeploy by url \r\n Invoke-WebDeployment -PackagePath $packagePath `\r\n -ServerHost $ServerHost `\r\n -SiteName $IISSiteName `\r\n -Application $IISApp\r\n\r\n }\r\n elseif ($service.webdeploy)\r\n {\r\n Write-Verbose \"Web Deploy Enabled With automatic url generation \"\r\n\r\n $packagePath = Get-PackageSource -type $service.type -WebDeploy\r\n \r\n Write-Verbose \"Package Path : $packagePath\"\r\n`\r\n if(-not (Test-Path $packagePath -PathType Leaf))\r\n {\r\n Write-Error \"Web Deploy Package not found at $packagePath\"\r\n throw\r\n }\r\n\r\n $pscredentials = Get-FMCredentials $credentialId -GetPsCredential\r\n\r\n Initialize-WebDeploy -Credential $pscredentials\r\n \r\n $ServerHost = $service.computerName \r\n Write-Verbose \"Server Host = $ServerHost\" \r\n \r\n $IISSiteName = $service.IISSiteName \r\n Write-Verbose \"IIS Site Name = $IISSiteName \"\r\n \r\n $IISApp = $service.IISAppName\r\n Write-Verbose \"IIS Application Name = $IISAppName \"\r\n \r\n\r\n Invoke-WebDeployment -PackagePath $packagePath `\r\n -ServerHost $ServerHost `\r\n -SiteName $IISSiteName `\r\n -Application $IISApp\r\n \r\n }\r\n else\r\n {\r\n\r\n $sourcePkg = Get-PackageSource -type $service.type\r\n Write-Verbose \"Package Source $packageSource\"\r\n \r\n $configPath = Get-ConfigSource -type $service.type\r\n Write-Verbose \"Configuration Source $packageSource\"\r\n \r\n $ServerHost = $service.computerName \r\n Write-Verbose \"Server Host = $ServerHost\" \r\n \r\n $IISSiteName = $service.IISSiteName \r\n Write-Verbose \"IIS Site Name = $IISSiteName \"\r\n \r\n $IISApp = $service.IISAppName\r\n Write-Verbose \"IIS Application Name = $IISAppName \"\r\n\r\n Assert-HasValue -Value $configPath -ErrorMessage \"Configuration Path for $($service.type) not found.\"\r\n\r\n # Update web.config with env settings\r\n $config = Get-ChildItem \"$configPath\" -ErrorAction SilentlyContinue -Verbose:(Test-VerbosePreference)\r\n\r\n\r\n $webServicePath = $service.Path\r\n Write-Verbose \"Web Service Path = $IISAppName \"\r\n\r\n if (-not (Test-Path $webServicePath -PathType Container))\r\n {\r\n New-Item -Path \"$webServicePath\\bin\" -ItemType Directory -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n $destPath = \"$webServicePath\\bin\"\r\n Write-Output (\"Copying web service binaries to '{0}'\" -f $destPath)\r\n \r\n \r\n Copy-Item -Recurse $sourcePkg $destPath -Force -Verbose:(Test-VerbosePreference)\r\n #robocopy.exe $sourcePkg $destPath /ns /nc /nfl /ndl /np\r\n #use Invoke-RoboCopy once command is fixed \r\n #Invoke-Robocopy -Source $sourcePkg -Destination $destPath \r\n\r\n if ($config -and (Test-Path $config.FullName -PathType Leaf) -and $updateConfigs)\r\n {\r\n #if appconfg exists in Configs folder update and copy to destination directory \r\n Write-Output (\"Updating web.config '{0}'\" -f $configPath)\r\n $service | Update-FMAppConfig -configPath $configPath -savePath $configPath \r\n\r\n $configParent = (Get-ChildItem $configPath).Directory.FullName\r\n\r\n Write-Output (\"Copying support files to '{0}'\" -f $webServicePath)\r\n #robocopy.exe $configPath $webServicePath /ns /nc /nfl /ndl /np\r\n Copy-Item \"$configParent\\*.*\" $webServicePath -Force -Verbose:(Test-VerbosePreference)\r\n \r\n }\r\n else {\r\n Write-Warning \"No Config Exists at $configPath , Skipping Update...\"\r\n }\r\n\r\n }\r\n }\r\n }\r\n\r\n function Test-ActionPreference {\r\n [CmdletBinding()]\r\n param (\r\n \r\n [System.Management.Automation.ActionPreference] $TestValue,\r\n [System.Management.Automation.ActionPreference] $Preference,\r\n [switch] $Force \r\n )\r\n\r\n process {\r\n\r\n return ($TestValue -eq $Preference)\r\n \r\n }\r\n \r\n }\r\n\r\n function Install-DealSetupService {\r\n [CmdletBinding()]\r\n param (\r\n [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)]\r\n [string]\r\n $Id,\r\n # \r\n [Parameter()]\r\n [bool]\r\n $updateConfigs = $true, \r\n \r\n [Parameter()]\r\n [switch]\r\n $Force\r\n )\r\n \r\n process {\r\n\r\n $service = Get-FMEnvSection dealSetupServices $id \r\n $service | Assert-HasValue -ErrorMessage \"DealSetupService id $Id not found in environment file $envPath\" \r\n\r\n $ServiceName = $service.ServiceName\r\n\r\n $win_service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue\r\n \r\n $service.ServiceName | Assert-HasValue -ErrorMessage \"DisplayName attribute missing from dealSetupServices id $($service.Id)\"\r\n\r\n Write-Header \"Installing $ServiceName ($($service.Id))\"\r\n\r\n if ($Force){\r\n\r\n if ($win_service)\r\n {\r\n Write-Host \"-Force specified reinstalling service $Id\"\r\n Write-Host \"Removing Existing Service $Id\"\r\n $win_service | Remove-Service -Verbose:(Test-VerbosePreference) \r\n $win_service = $null\r\n }\r\n }\r\n elseif($win_service)\r\n {\r\n Write-Warning \"Service Name $Id Already Exists on this machine to reinstall specify -Force \"\r\n Write-Warning \"Continuing with Service Update\" \r\n $service | Update-DealSetupService -updateConfigs $updateConfigs \r\n return \r\n }\r\n\r\n $service | Update-DealSetupService -updateConfigs $updateConfigs -CopyOnly\r\n $credentialId = Get-CredentialId -id $id -type dealSetupServices \r\n Write-Verbose \"Using crededential id $credentialid \"\r\n $credentials = Get-FMCredentials -id $credentialId -GetPsCredential\r\n \r\n if (-not $win_service)\r\n {\r\n\r\n $svc = New-Service -Name $ServiceName `\r\n -Credential $credentials `\r\n -Verbose:(Test-VerbosePreference) `\r\n -BinaryPathName \"$($service.path)\\JPMDealSetupService.exe\" `\r\n -DisplayName $ServiceName `\r\n -StartupType Automatic \r\n \r\n\r\n $win_service = Get-Service -Name $ServiceName \r\n Write-Host \"\"\r\n Write-Verbose \"Starting $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n try {\r\n Write-Host \"Starting $ServiceName Service...\"\r\n Write-Host \"Waiting for $ServiceName service to start...\"\r\n $win_service | Start-Service -ErrorAction Stop -Verbose:(Test-VerbosePreference)\r\n \r\n }\r\n catch {\r\n [System.Exception] $exception = $_.Exception\r\n if ($exception.InnerException)\r\n {\r\n [System.Exception] $exception = $exception.InnerException\r\n }\r\n \r\n $eventLog = Get-EventLog -Source \"Service1\" -LogName \"Application\" -Newest 1 -EntryType \"Error\"\r\n\r\n Write-Error -Message $exception.Message -Exception $exception\r\n $eventLog.Message | Write-Verbose\r\n\r\n $service.Attributes | ForEach-Object { Write-Verbose \"$($_.Name) : $($_.Value) \" }\r\n \r\n }\r\n\r\n\r\n $win_service \r\n \r\n }\r\n\r\n }\r\n \r\n }\r\n\r\n function Update-BatchQueues {\r\n [CmdletBinding()]\r\n param (\r\n # Server Id Filter \r\n [Parameter()]\r\n [string]\r\n $Server\r\n )\r\n \r\n $services = Get-FMEnvSection batchQueueServer -Server $Server\r\n $services | Update-BatchQueueService \r\n \r\n }\r\n #todo:seperate automatic service installation from update code \r\n function Update-DealSetupService{\r\n [CmdletBinding()]\r\n param(\r\n [Parameter()]\r\n [bool]\r\n $updateConfigs = $true, \r\n \r\n [Parameter(ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id, \r\n\r\n [Parameter()]\r\n [switch]\r\n $CopyOnly,\r\n\r\n #override or set computer name for update \r\n [Parameter()]\r\n [string]\r\n $ComputerName\r\n )\r\n process {\r\n $service = Get-FMEnvSection dealSetupServices $Id\r\n $ServiceName = $service.ServiceName \r\n $service | Assert-HasValue -ErrorMessage \"DealSetupService id $Id not found in environment file\" \r\n $ServiceName | Assert-HasValue -ErrorMessage \"Required DealSetupService attribute ServiceName not found on dealSetupServices id $id\" \r\n $service.Path | Assert-HasValue -ErrorMessage \"Required DealSetupService attribute Path not found on dealSetupServices id $id\"\r\n\r\n $computer = if ($ComputerName) { $ComputerName } elseif ($service.ComputerName) { $service.ComputerName } else { 'localhost' }\r\n \r\n if (-not $CopyOnly)\r\n {\r\n\r\n Write-Header \"Updating Deal Setup Service $Id on $computer\"\r\n\r\n #Stop Service If Running To Prep for update \r\n $serviceParams = @{}\r\n $serviceParams.Add(\"ServiceName\", $ServiceName)\r\n if ($computer -ne 'localhost')\r\n {\r\n $serviceParams.Add(\"ComputerName\", $computer)\r\n }\r\n\r\n [System.ServiceProcess.ServiceController] $win_service = Get-Service -Verbose:(Test-VerbosePreference) @serviceParams\r\n \r\n \r\n $win_service | Assert-HasValue -ErrorMessage \"Service $($service.ServiceName) Does not Exists run Install-DealSetupService locally on server to install service\" -ThrowOnError -ErrorAction Stop\r\n \r\n\r\n if ($win_service.CanStop){\r\n \r\n Write-Host \"Stopping Service $ServiceName\"\r\n Write-Host \"Stopping Service $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n\r\n $win_service | Stop-Service -NoWait:$false -Verbose:(Test-VerbosePreference) \r\n $win_service.WaitForStatus(\"Stopped\", \"00:00:20\" )\r\n \r\n ##WTF? why does service shutdown not release file lock for 2 more seconds ?\r\n #TODO: Find a way around File lock issue with out sleeping script \r\n Join-Path $service.Path \"BusinessObjects.dll\" | Wait-FileLock -Timeout \"00:00:15\" \r\n\r\n if($win_service.Status -eq 'Stopped')\r\n {\r\n Write-Host \"Service Stopped Successfully, Continuing With Update\"\r\n }\r\n }\r\n else {\r\n Write-Host \"Service $ServiceName Found, But Already Stopped... Continuing with update..\" \r\n }\r\n \r\n }\r\n\r\n Write-Host \"Copying Windows Service Files ...\" \r\n # Copy Service Files From Package \r\n $packageSource = Get-PackageSource DealSetupService\r\n \r\n #workaround to deal with file locking issues from script moving faster then resources can be released \r\n if(Test-Path (Join-Path $service.Path \"BusinessObjects.dll\") ){\r\n Join-Path $service.Path \"BusinessObjects.dll\" | Wait-FileLock -Timeout \"00:00:15\" \r\n }\r\n\r\n Copy-Item -Recurse -Container:$false -Path $packageSource -Destination $service.Path -Force # -Verbose:(Test-VerbosePreference)\r\n \r\n\r\n $configSource = Get-ConfigSource -type \"DealSetupService\"\r\n \r\n if (Test-Path $configSource){\r\n Write-Verbose \"Configuration Files found updating and copying to Service Directory\"\r\n\r\n\r\n $service | Update-FMAppConfig -configPath $configSource -savePath $configSource\r\n $supportPath = ((Get-ChildItem $configSource).Directory.FullName)\r\n \r\n Copy-Item -Path $supportPath `\r\n -Destination $service.Path `\r\n -Force `\r\n -Recurse `\r\n -Container:$false `\r\n -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n # restart service to complete update process \r\n if (-not $CopyOnly)\r\n {\r\n try {\r\n Write-Verbose \"Starting Service $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n Write-Host \"Starting $ServiceName Service...\"\r\n Write-Host \"Waiting for $ServiceName service to start...\"\r\n $win_service | Start-Service -ErrorAction Stop\r\n Write-Host \"Service $ServiceName Started Successfully...\"\r\n \r\n }\r\n catch {\r\n [System.Exception] $exception = $_.Exception\r\n if ($exception.InnerException)\r\n {\r\n [System.Exception] $exception = $exception.InnerException\r\n }\r\n \r\n $eventLog = Get-EventLog -Source \"Service1\" -LogName \"Application\" -Newest 1 -EntryType \"Error\"\r\n\r\n Write-Error -Message $exception.Message -Exception $exception\r\n Write-Verbose \"Most Recent Event Log Message\" \r\n Write-Verbose \"Note: This may not pertain to this startup failure\"\r\n $eventLog.Message | Write-Verbose\r\n\r\n $service.Attributes | ForEach-Object { Write-Verbose \"$($_.Name) : $($_.Value) \" }\r\n \r\n }\r\n\r\n }\r\n\r\n }\r\n\r\n } \r\n \r\n function Get-AppSettings {\r\n [CmdletBinding()]\r\n param (\r\n # Input Object\r\n [Parameter(DontShow, ValueFromPipeline, ParameterSetName=\"Pipeline\")]\r\n $InputObject,\r\n\r\n # Config Id\r\n [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName=\"Query\")]\r\n [string]\r\n $Id,\r\n\r\n # Element Type\r\n [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName=\"Query\")]\r\n [string]\r\n $Type,\r\n\r\n # Parameter help description\r\n [Parameter()]\r\n [switch]\r\n $IsWebService\r\n\r\n )\r\n \r\n process {\r\n $config = if ($InputObject){\r\n $InputObject\r\n }elseif ($IsWebService){\r\n Get-FMEnvSection webservice $Id\r\n }else{\r\n Get-FMEnvSection $Type $Id\r\n }\r\n\r\n $config | Assert-HasValue -Errormessage \"$Type configuration $id was not found in environment file\"\r\n\r\n $appSettings = Get-FMEnvSection appSetting \r\n\r\n\r\n Write-Verbose \"Loading AppSettings For $($config.type) $($config.name) $($config.id)\"\r\n $appSettings | Select-Object key | Get-Unique -AsString | Get-AppSetting -Config $config\r\n\r\n }\r\n \r\n }\r\n\r\n filter Get-AppSetting {\r\n [CmdletBinding()]\r\n param (\r\n # App Setting Name\r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Key,\r\n [parameter(Mandatory)]\r\n $Config\r\n )\r\n process\r\n { \r\n \r\n [System.Array] $appSettings = Get-FMEnvSection appSetting | Where-Object { $_.key -eq $key } \r\n \r\n if (-not $appSettings)\r\n {\r\n return\r\n }\r\n else\r\n {\r\n \r\n Write-Verbose \"Getting AppSetting $Key\"\r\n\r\n if ($Config.server -and $appSettings.server){\r\n $appSettings = $appSettings | Where-Object { $_.server -eq $Config.server } \r\n Write-Verbose \"Server Filter $($Config.server) detected on $($Config.name) $($Config.id) and found a matching setting in appsettings config\" \r\n }\r\n \r\n if ($Config.website -and $appSettings.website){\r\n $appSettings = $appSettings | Where-Object { $_.website -eq $Config.website }\r\n Write-Verbose \"Website Filter $($Config.website) detected on $($Config.name) $($Config.id) and found a matching setting in appsettings config\" \r\n }\r\n\r\n # if ($appSettings.id){\r\n # $appSettings = $appSettings | Where-Object { $_.id -eq $Config.id }\r\n # Write-Verbose \"Id Filter $($Config.id) detected on $($Config.name) $($Config.id) and found a matching setting in appsettings config\" \r\n # }\r\n\r\n if ($appSettings.Length -gt 1)\r\n {\r\n Write-Warning \"Ambiguous App Setting Key $Key Found In Environment File Using Default\"\r\n $appSettings | ForEach-Object { \r\n Write-Verbose \"AppSettings $($_.key) with value\" \r\n Write-Verbose \"Filters: $($_.value) $($_.server) $($_.website) \"\r\n }\r\n return $appSettings | Select-Object -First 1\r\n\r\n }\r\n\r\n if ($appSettings)\r\n {\r\n $appSettings\r\n } \r\n\r\n } \r\n \r\n }\r\n\r\n } \r\n \r\n function Install-BatchQueueService {\r\n [CmdletBinding()]\r\n param (\r\n [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)]\r\n [string]\r\n $Id,\r\n # \r\n [Parameter()]\r\n [bool]\r\n $updateConfigs = $true, \r\n \r\n [Parameter()]\r\n [switch]\r\n $Force\r\n )\r\n \r\n process {\r\n\r\n $service = Get-FMEnvSection batchQueueServer $Id\r\n $service | Assert-HasValue -ErrorMessage \"BatchQueueServer id $Id not found in environment file $envPath\" \r\n\r\n $ServiceName = $service.ServiceName\r\n\r\n $win_service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue\r\n \r\n $service.ServiceName | Assert-HasValue -ErrorMessage \"DisplayName attribute missing from dealSetupServices id $($service.Id)\"\r\n\r\n Write-Header \"Installing $ServiceName ($($service.Id))\"\r\n\r\n if ($Force){\r\n\r\n if ($win_service)\r\n {\r\n Write-Host \"-Force specified reinstalling service $Id\"\r\n Write-Host \"Removing Existing Service $Id\"\r\n $win_service | Remove-Service -Verbose:(Test-VerbosePreference) \r\n $win_service = $null\r\n }\r\n }\r\n elseif($win_service)\r\n {\r\n Write-Warning \"Service Name $Id Already Exists on this machine to reinstall specify -Force \"\r\n Write-Warning \"Continuing with Service Update\" \r\n $service | Update-BatchQueueService -updateConfigs $updateConfigs \r\n return \r\n }\r\n\r\n $service | Update-BatchQueueService -updateConfigs $updateConfigs -CopyOnly -Force:$Force\r\n $credentialId = Get-CredentialId -id $id -type batchQueueServer \r\n Write-Verbose \"Using crededential id $credentialid \"\r\n $credentials = Get-FMCredentials -id $credentialId -GetPsCredential\r\n \r\n if (-not $win_service)\r\n {\r\n\r\n $svc = New-Service -Name $ServiceName `\r\n -Credential $credentials `\r\n -Verbose:(Test-VerbosePreference) `\r\n -BinaryPathName \"$($service.path)\\Service\\BatchQueue2Service.exe\" `\r\n -DisplayName $ServiceName `\r\n -StartupType Automatic \r\n \r\n $win_service = Get-Service -Name $ServiceName \r\n Write-Host \"\"\r\n Write-Verbose \"Starting $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n \r\n try {\r\n Write-Host \"Starting $ServiceName Service...\"\r\n Write-Host \"Waiting for $ServiceName service to start...\"\r\n $win_service | Start-Service -ErrorAction Stop -Verbose:(Test-VerbosePreference)\r\n }\r\n catch {\r\n [System.Exception] $exception = $_.Exception\r\n if ($exception.InnerException)\r\n {\r\n [System.Exception] $exception = $exception.InnerException\r\n }\r\n \r\n $eventLog = Get-EventLog -Source \"FMBatch2\" -LogName \"Application\" -Newest 1 -EntryType \"Error\" -ErrorAction SilentlyContinue\r\n\r\n Write-Error -Message $exception.Message -Exception $exception\r\n Write-Verbose \"Last Generated Service Event Log\"\r\n $eventLog.Message | Write-Verbose\r\n \r\n Write-Verbose \"Last Generated Service Controller Log\"\r\n $eventLog = Get-EventLog -Source \"Service Control Manager\" -LogName \"System\" -Newest 1 -EntryType \"Error\" -ErrorAction SilentlyContinue\r\n $eventLog.Message | Write-Verbose\r\n\r\n $service.Attributes | ForEach-Object { Write-Verbose \"$($_.Name) : $($_.Value) \" }\r\n \r\n }\r\n\r\n\r\n $win_service \r\n \r\n }\r\n\r\n }\r\n \r\n }\r\n\r\n function Write-ForceMessage {\r\n [CmdletBinding()]\r\n param (\r\n # Message to display with force message \r\n [Parameter(Mandatory, ValueFromPipeline)]\r\n [string]\r\n $Message\r\n )\r\n \r\n process {\r\n Write-Host -ForegroundColor Magenta \"-Force Specified, \"$Message\r\n }\r\n \r\n }\r\n\r\n #todo:seperate automatic service installation from update code \r\n function Update-BatchQueueService{\r\n [CmdletBinding()]\r\n param(\r\n [Parameter()]\r\n [bool]\r\n $updateConfigs = $true, \r\n \r\n [Parameter(ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id, \r\n\r\n [Parameter()]\r\n [switch]\r\n $CopyOnly,\r\n\r\n #override or set computer name for update \r\n [Parameter()]\r\n [string]\r\n $ComputerName, \r\n\r\n # Wipes out target directory and clean updates service to do a full clean install use Install-BatchQueueService -Force \r\n [Parameter()]\r\n [switch]\r\n $Force\r\n )\r\n process {\r\n $service = Get-FMEnvSection BatchQueueServer $Id\r\n $ServiceName = $service.ServiceName \r\n $service | Assert-HasValue -ErrorMessage \"DealSetupService id $Id not found in environment file\" \r\n $ServiceName | Assert-HasValue -ErrorMessage \"Required DealSetupService attribute ServiceName not found on dealSetupServices id $id\" \r\n $service.Path | Assert-HasValue -ErrorMessage \"Required DealSetupService attribute Path not found on dealSetupServices id $id\"\r\n\r\n $computer = if ($ComputerName) { $ComputerName } elseif ($service.ComputerName) { $service.ComputerName } else { 'localhost' }\r\n\r\n if (-not $CopyOnly)\r\n {\r\n\r\n Write-Header \"Updating Batch Queue Service $Id on $computer\"\r\n\r\n #Stop Service If Running To Prep for update \r\n $serviceParams = @{}\r\n $serviceParams.Add(\"ServiceName\", $ServiceName)\r\n if ($computer -ne 'localhost')\r\n {\r\n $serviceParams.Add(\"ComputerName\", $computer)\r\n }\r\n\r\n [System.ServiceProcess.ServiceController] $win_service = Get-Service -Verbose:(Test-VerbosePreference) @serviceParams\r\n \r\n \r\n $win_service | Assert-HasValue -ErrorMessage \"Service $($service.ServiceName) Does not Exists run Install-DealSetupService locally on server to install service\" -ThrowOnError -ErrorAction Stop\r\n \r\n\r\n if ($win_service.CanStop){\r\n \r\n Write-Host \"Stopping Service $ServiceName\"\r\n Write-Host \"Stopping Service $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n\r\n $win_service | Stop-Service -NoWait:$false -Verbose:(Test-VerbosePreference) \r\n $win_service.WaitForStatus(\"Stopped\", \"00:00:20\" )\r\n \r\n #check if resources have been released after service shutdown and wait till they are released if still locked \r\n #Join-Path $service.Path \"BusinessObjects.dll\" | Wait-FileLock -Timeout \"00:00:15\" \r\n\r\n if($win_service.Status -eq 'Stopped')\r\n {\r\n Write-Host \"Service Stopped Successfully, Continuing With Update\"\r\n }\r\n }\r\n else {\r\n Write-Host \"Service $ServiceName Found, But Already Stopped... Continuing with update..\" \r\n }\r\n \r\n }\r\n\r\n Write-Host \"Copying Windows Service Files ...\" \r\n # Copy Service Files From Package \r\n $packageSource = Get-PackageSource BatchQueueService\r\n \r\n\r\n #copy BatchQueue Executor Files \r\n $service | Copy-ExecutorFiles -Force:$Force\r\n $configSource = Get-ConfigSource -type \"BatchQueueExecutor\"\r\n if (Test-Path $configSource){\r\n Write-Verbose \"Configuration Files found updating and copying to Service Directory\"\r\n\r\n\r\n $service | Update-FMAppConfig -configPath $configSource -savePath $configSource\r\n $supportPath = ((Get-ChildItem $configSource).Directory.FullName)\r\n $supportTarget = Join-Path $service.Path \"\\Service\"\r\n\r\n Copy-Item -Path $supportPath `\r\n -Destination $supportTarget `\r\n -Force `\r\n -Recurse `\r\n -Container:$false `\r\n -Verbose:(Test-VerbosePreference)\r\n \r\n }\r\n\r\n \r\n #copy BatchQueue Service Files \r\n $service | Copy-BatchQueueFiles -Force:$Force \r\n $configSource = Get-ConfigSource -type \"BatchQueueService\"\r\n if (Test-Path $configSource){\r\n Write-Verbose \"Configuration Files found updating and copying to Service Directory\"\r\n\r\n\r\n $service | Update-FMAppConfig -configPath $configSource -savePath $configSource\r\n $supportPath = ((Get-ChildItem $configSource).Directory.FullName)\r\n $supportTarget = Join-Path $service.Path \"\\Service\"\r\n\r\n Write-Verbose \"Copying BatchQueueService Support Files From $supportPath to $supportTarget\"\r\n Copy-Item -Path $supportPath `\r\n -Destination $supportTarget `\r\n -Force `\r\n -Recurse `\r\n -Container:$false `\r\n -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n\r\n # restart service to complete update process \r\n if (-not $CopyOnly)\r\n {\r\n try {\r\n Write-Verbose \"Starting Service $($win_service.DisplayName) on $($win_service.MachineName)\"\r\n Write-Host \"Starting $ServiceName Service...\"\r\n Write-Host \"Waiting for $ServiceName service to start...\"\r\n $win_service | Start-Service -ErrorAction Stop\r\n Write-Host \"Service $ServiceName Started Successfully...\"\r\n \r\n }\r\n catch {\r\n [System.Exception] $exception = $_.Exception\r\n if ($exception.InnerException)\r\n {\r\n [System.Exception] $exception = $exception.InnerException\r\n }\r\n \r\n $eventLog = Get-EventLog -Source \"FMBatch\" -LogName \"Application\" -Newest 1 -EntryType \"Error\" -ErrorAction SilentlyContinue\r\n\r\n Write-Error -Message $exception.Message -Exception $exception\r\n \r\n if($eventLog){\r\n Write-Verbose \"Most Recent Event Log Message\" \r\n Write-Verbose \"Note: This may not pertain to this startup failure\"\r\n $eventLog.Message | Write-Verbose\r\n }\r\n \r\n $service.Attributes | ForEach-Object { Write-Verbose \"$($_.Name) : $($_.Value) \" }\r\n \r\n }\r\n\r\n }\r\n\r\n }\r\n\r\n } \r\n\r\n function Copy-ExecutorFiles {\r\n [CmdletBinding()]\r\n param(\r\n # Batch Queue Id\r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id,\r\n # Force\r\n [Parameter()]\r\n [switch] \r\n $Force\r\n )\r\n process{\r\n \r\n \r\n $computerName = 'localhost'\r\n \r\n $batchQueueServer = Get-FMEnvSection batchQueueServer $id \r\n\r\n Assert-HasValue -Value $batchQueueServer -ErrorMessage \"Batch Queue Server $id not found in environment file.\"\r\n\r\n if ($batchQueueServer.computerName)\r\n {\r\n $computerName = $batchQueueServer.computerName\r\n }\r\n\r\n $dest = Join-Path $batchQueueServer.path \"\\Executor\"\r\n\r\n if ($Force.IsPresent -and (Test-Path -Path $batchQueueServer.path) ){\r\n Write-ForceMessage \"Removing Existing Files...\"\r\n Remove-Item -Path $dest -Recurse -Force -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n Write-Verbose \"Checking folder '$dest'...\"\r\n if (Test-Path $dest -PathType Container) {\r\n Write-Verbose \"'$dest' exists\"\r\n }\r\n else {\r\n Write-Verbose \"'$dest' doesn't exist. Creating folder\"\r\n New-Item -Path $dest -ItemType Directory -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n\r\n $source = Get-PackageSource -type \"BatchQueueExecutor\"\r\n\r\n Write-Output \"Copying Batch Job Executor Files to $dest...\" \r\n\r\n Copy-Item $source $dest -Force -Container:$false -Recurse -Verbose:(Test-VerbosePreference)\r\n\r\n\r\n Write-Output \"File Copy Completed..\"\r\n }\r\n }\r\n \r\n\r\n\r\n function Copy-BatchQueueFiles{\r\n \r\n [CmdletBinding()]\r\n param(\r\n # Batch Queue Id\r\n [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n [string]\r\n $Id,\r\n # Force\r\n [Parameter()]\r\n [switch] \r\n $Force\r\n )\r\n process {\r\n \r\n \r\n \r\n $computerName = 'localhost'\r\n \r\n $batchQueueServer = Get-FMEnvSection batchQueueServer $id \r\n\r\n Assert-HasValue -Value $batchQueueServer -ErrorMessage \"Batch Queue Server $id not found in environment file.\"\r\n\r\n if ($batchQueueServer.computerName)\r\n {\r\n $computerName = $batchQueueServer.computerName\r\n }\r\n\r\n $dest = Join-Path $batchQueueServer.path \"\\Service\"\r\n\r\n \r\n \r\n if ($Force.IsPresent -and (Test-Path -Path $batchQueueServer.path) ){\r\n Write-ForceMessage \"Removing Existing Files...\"\r\n Remove-Item -Path $dest -Recurse -Force -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n \r\n Write-Verbose \"Checking folder '$dest'...\"\r\n \r\n if (Test-Path $dest -PathType Container) {\r\n Write-Verbose \"'$dest' exists\"\r\n }\r\n else {\r\n Write-Verbose \"'$dest' doesn't exist. Creating folder\"\r\n New-Item -Path $dest -ItemType Directory -Verbose:(Test-VerbosePreference)\r\n }\r\n\r\n $source = Get-PackageSource -type \"BatchQueueService\"\r\n\r\n Write-Output \"Copying Batch Queue Service Files to $dest...\" \r\n\r\n Copy-Item $source $dest -Force -Container:$false -Recurse -Verbose:(Test-VerbosePreference)\r\n\r\n\r\n Write-Output \"File Copy Completed..\"\r\n }\r\n }\r\n\r\n#Test Code \r\n function HelperTests(){\r\n Get-FMEnvSection batchQueueServer \"BatchQueue.SiteA\" | Install-BatchQueueService \r\n }\r\n\r\n#Module Importer\r\n #import all ps1m files in tools folder \r\n function Import-CommonModules ($BasePath = \"$PSScriptRoot\\tools\") {\r\n $common = Get-ChildItem -Path $BasePath -File -Recurse \r\n\r\n $modules = $common | Where-Object {$_.Extension -match \".psm1\"}\r\n $modules | ForEach-Object {\r\n Write-Verbose \"Importing Module $($_.Name)\"\r\n Import-Module $_.FullName -Force\r\n }\r\n\r\n if ($SkipWebAdministrationModule -eq $false)\r\n {\r\n Import-Module WebAdministration\r\n }\r\n\r\n\r\n }\r\n\r\n Import-CommonModules\r\n"
}
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "ResolveFilePath" at line 294 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs
Resolved path: d:\Repos\svn\FM3\trunk\BuildScripts\fm.psm1
3/29/2017 1:20:33 PM [VERBOSE] - Method "GetFileBuffer" at line 135 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs
Opened file as in-memory buffer: d:\Repos\svn\FM3\trunk\BuildScripts\fm.psm1
3/29/2017 1:20:33 PM [VERBOSE] - Method "HandleDidOpenTextDocumentNotification" at line 500 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\LanguageServer.cs
Finished opening document.
3/29/2017 1:20:33 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"id": 1,
"method": "powerShell/getVersion"
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "WriteMessage" at line 59 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs
WRITE MESSAGE:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"version": "5.1.14393.953",
"displayVersion": "5.1",
"edition": "Desktop",
"architecture": "x64"
}
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs
READ MESSAGE:
{
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/codeAction",
"params": {
"textDocument": {
"uri": "file:///d%3A/Repos/svn/FM3/trunk/BuildScripts/fm.psm1"
},
"range": {
"start": {
"line": 1626,
"character": 8
},
"end": {
"line": 1626,
"character": 8
}
},
"context": {
"diagnostics": []
}
}
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "WriteMessage" at line 59 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs
WRITE MESSAGE:
{
"jsonrpc": "2.0",
"id": "2",
"result": []
}
3/29/2017 1:20:33 PM [VERBOSE] - Method "DelayThenInvokeDiagnostics" at line 1348 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\LanguageServer.cs
Analyzing script file: d:\Repos\svn\FM3\trunk\BuildScripts\fm.psm1
3/29/2017 1:20:38 PM [VERBOSE] - Method "GetDiagnosticRecordsAsync" at line 327 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Analysis\AnalysisService.cs
Found 10 violations
3/29/2017 1:20:38 PM [VERBOSE] - Method "DelayThenInvokeDiagnostics" at line 1352 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\LanguageServer.cs
Analysis complete.
3/29/2017 1:20:38 PM [VERBOSE] - Method "WriteMessage" at line 59 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs
WRITE MESSAGE:
{
"jsonrpc": "2.0",
"method": "textDocument/publishDiagnostics",
"params": {
"uri": "file:///d%3A/Repos/svn/FM3/trunk/BuildScripts/fm.psm1",
"diagnostics": [
{
"range": {
"start": {
"line": 716,
"character": 13
},
"end": {
"line": 716,
"character": 29
}
},
"severity": 2,
"code": "51ffad6f-4470-401c-99e2-796c9ae03b09",
"message": "The cmdlet 'Deploy-FMPackage' uses an unapproved verb.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 1225,
"character": 13
},
"end": {
"line": 1225,
"character": 33
}
},
"severity": 2,
"code": "f819cc2e-2f1c-498d-bb25-1509d421ad93",
"message": "The cmdlet 'Deploy-FMWebPackages' uses an unapproved verb.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 1548,
"character": 13
},
"end": {
"line": 1548,
"character": 31
}
},
"severity": 2,
"code": "002c8340-0049-4546-9ad8-087de70208ff",
"message": "The cmdlet 'Create-DataSources' uses an unapproved verb.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 2619,
"character": 13
},
"end": {
"line": 2619,
"character": 28
}
},
"severity": 2,
"code": "9a28e93c-e28c-45d7-814c-6632d08cdc2a",
"message": "The cmdlet 'Deploy-FMClient' uses an unapproved verb.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 2683,
"character": 13
},
"end": {
"line": 2683,
"character": 36
}
},
"severity": 2,
"code": "8da4c924-1b52-49a4-85b7-5557359fa893",
"message": "The cmdlet 'Deploy-ClickOncePackage' uses an unapproved verb.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 913,
"character": 54
},
"end": {
"line": 913,
"character": 66
}
},
"severity": 2,
"code": "1b3a5608-c957-4947-b3da-7ce557d26e03",
"message": "Parameter '$Credentials' should use SecureString, otherwise this will expose sensitive information. See ConvertTo-SecureString for more information.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 952,
"character": 127
},
"end": {
"line": 952,
"character": 139
}
},
"severity": 2,
"code": "fa6af59f-c515-4880-b6b2-edd03d1054d8",
"message": "Parameter '$Credentials' should use SecureString, otherwise this will expose sensitive information. See ConvertTo-SecureString for more information.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 87,
"character": 39
},
"end": {
"line": 87,
"character": 40
}
},
"severity": 2,
"code": "f71cf3e9-6be6-4bb6-b098-38ed85076c8c",
"message": "'?' is an alias of 'Where-Object'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 91,
"character": 43
},
"end": {
"line": 91,
"character": 44
}
},
"severity": 2,
"code": "9a4b8a14-7148-4223-8ca0-5812d33e5c59",
"message": "'?' is an alias of 'Where-Object'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.",
"source": "PowerShellEditorServices"
},
{
"range": {
"start": {
"line": 2039,
"character": 120
},
"end": {
"line": 2039,
"character": 126
}
},
"severity": 2,
"code": "afd84d5c-5757-423f-a863-0b24e67e6565",
"message": "'select' is an alias of 'Select-Object'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.",
"source": "PowerShellEditorServices"
}
]
}
}