fix: resolve WPF event handler variable scope null exception and dialog itemsource casting

This commit is contained in:
2026-10-21 19:57:38 +09:00
parent 0ebe04234e
commit 5da8bb951e
2 changed files with 21 additions and 17 deletions
+17 -17
View File
@@ -296,11 +296,11 @@ function Show-UserResolverDialog {
$txtInput.Text = $InitialText
}
$runResolution = {
$script:runResolutionDialog = {
$raw = if ($txtInput) { $txtInput.Text } else { "" }
$tokens = Parse-MultiUserInput -RawInput $raw
$results = Resolve-UsersWithAmbiguityCheck -Tokens $tokens -Config $global:AppConfig
if ($grid) { $grid.ItemsSource = $results }
if ($grid) { $grid.ItemsSource = @($results) }
$ambCount = @($results | Where-Object { $_.IsAmbiguous }).Count
$normCount = @($results | Where-Object { $_.IsResolved -and (-not $_.IsAmbiguous) }).Count
@@ -320,14 +320,14 @@ function Show-UserResolverDialog {
}
}
if ($btnResolve) { $btnResolve.add_Click({ & $runResolution }) }
if ($btnResolve) { $btnResolve.add_Click({ & $script:runResolutionDialog }) }
if ($btnPaste) {
$btnPaste.add_Click({
try {
$clip = [System.Windows.Clipboard]::GetText()
if (-not [string]::IsNullOrWhiteSpace($clip)) {
$txtInput.Text = $clip
& $runResolution
& $script:runResolutionDialog
}
} catch {}
})
@@ -390,7 +390,7 @@ function Show-UserResolverDialog {
}
# Initial Run
& $runResolution
& $script:runResolutionDialog
$ret = $dialog.ShowDialog()
if ($ret -eq $true) {
@@ -592,7 +592,7 @@ function Navigate-ToPage {
$btnClearLog = $view.FindName("BtnClearLog")
# Helper to append logs
$appendShareLog = {
$script:appendShareLog = {
param([string]$msg)
$v = $ViewCache["ShareAccess"]
if ($v) {
@@ -663,7 +663,7 @@ function Navigate-ToPage {
$sams = @($checkedUsers | ForEach-Object { $_.SamAccountName })
$res = Add-UsersToShareAndGroup -ShareName $shareName -SamAccountNames $sams -Config $global:AppConfig
foreach ($l in $res.Logs) { & $appendShareLog $l }
foreach ($l in $res.Logs) { & $script:appendShareLog $l }
[System.Windows.MessageBox]::Show($res.Message, "그룹 추가 완료", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
& $script:reloadShareData
@@ -689,7 +689,7 @@ function Navigate-ToPage {
$sams = @($checkedUsers | ForEach-Object { $_.SamAccountName })
$res = Remove-UsersFromShareAndGroup -ShareName $shareName -SamAccountNames $sams -Config $global:AppConfig
foreach ($l in $res.Logs) { & $appendShareLog $l }
foreach ($l in $res.Logs) { & $script:appendShareLog $l }
[System.Windows.MessageBox]::Show($res.Message, "그룹 해제 완료", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
& $script:reloadShareData
@@ -759,7 +759,7 @@ function Navigate-ToPage {
$txtStatus = $view.FindName("TxtWsExecutionStatus")
# Launch Resolver Handler
$handleOpenResolver = {
$script:handleOpenResolver = {
$curr = if ($txtTokens) { $txtTokens.Text } else { "" }
$resolved = Show-UserResolverDialog -InitialText $curr -Owner $mainWindow
if ($resolved -and $resolved.Count -gt 0) {
@@ -771,8 +771,8 @@ function Navigate-ToPage {
}
}
if ($btnLaunchResolver) { $btnLaunchResolver.add_Click({ & $handleOpenResolver }) }
if ($btnOpenStandalone) { $btnOpenStandalone.add_Click({ & $handleOpenResolver }) }
if ($btnLaunchResolver) { $btnLaunchResolver.add_Click({ & $script:handleOpenResolver }) }
if ($btnOpenStandalone) { $btnOpenStandalone.add_Click({ & $script:handleOpenResolver }) }
if ($btnQuickCheck) {
$btnQuickCheck.add_Click({
@@ -792,14 +792,14 @@ function Navigate-ToPage {
}
# Multi-DC Active DC Detection Handler
$detectActiveDcAction = {
$script:detectActiveDcAction = {
if ($txtActiveDcInfo) { $txtActiveDcInfo.Text = "NetApp 도메인 컨트롤러 바인딩 탐색 중..." }
$dcInfo = Get-NetAppActiveDc -Config $global:AppConfig
if ($txtActiveDcInfo) {
$txtActiveDcInfo.Text = "Active DC: [$($dcInfo.ActiveDC)] (Node: $($dcInfo.Node), 상태: $($dcInfo.Status))"
}
}
if ($btnDetectActiveDc) { $btnDetectActiveDc.add_Click({ & $detectActiveDcAction }) }
if ($btnDetectActiveDc) { $btnDetectActiveDc.add_Click({ & $script:detectActiveDcAction }) }
# Dry-Run Simulation
if ($btnDryRun) {
@@ -1235,7 +1235,7 @@ function Navigate-ToPage {
& $script:loadSettingsToUI
$updateSqlAuthUi = {
$script:updateSqlAuthUi = {
$v = $ViewCache["Settings"]
if (-not $v) { return }
$cmb = $v.FindName("CmbSqlAuthType")
@@ -1283,9 +1283,9 @@ function Navigate-ToPage {
$cmbSqlAuth = $view.FindName("CmbSqlAuthType")
if ($cmbSqlAuth) {
$cmbSqlAuth.add_SelectionChanged({ & $updateSqlAuthUi })
$cmbSqlAuth.add_SelectionChanged({ & $script:updateSqlAuthUi })
}
& $updateSqlAuthUi
& $script:updateSqlAuthUi
# Test AD
if ($btnTestAd) {
@@ -1458,7 +1458,7 @@ function Navigate-ToPage {
$btnReload.add_Click({
$global:AppConfig = Get-AppConfig
& $script:loadSettingsToUI
& $updateSqlAuthUi
if ($script:updateSqlAuthUi) { & $script:updateSqlAuthUi }
Update-ModeBadgeUI
[System.Windows.MessageBox]::Show("config.json 설정을 다시 불러왔습니다.", "알림", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
})