Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
526c40403b | ||
|
|
7fc0602818 | ||
|
|
3039562e91 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
dist/
|
||||||
35
dist/setup.ps1
vendored
35
dist/setup.ps1
vendored
File diff suppressed because one or more lines are too long
334
setup.ps1
334
setup.ps1
@@ -1194,6 +1194,45 @@ function Get-AppStatus {
|
|||||||
return 'Installierbar'
|
return 'Installierbar'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Test-RequestQueuedInState {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=`$true)][string]`$Alias,
|
||||||
|
[Parameter(Mandatory=`$true)][string]`$Action
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not (Test-Path -LiteralPath `$QueueStatePath)) {
|
||||||
|
return `$false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
`$raw = Get-Content -LiteralPath `$QueueStatePath -Raw -Encoding UTF8
|
||||||
|
if ([string]::IsNullOrWhiteSpace(`$raw)) {
|
||||||
|
return `$false
|
||||||
|
}
|
||||||
|
|
||||||
|
`$queueState = `$raw | ConvertFrom-Json
|
||||||
|
foreach (`$item in @(`$queueState.Queue)) {
|
||||||
|
if (-not `$item) { continue }
|
||||||
|
if (`$item.CreatedAt) {
|
||||||
|
try {
|
||||||
|
`$createdAt = [DateTime]::Parse([string]`$item.CreatedAt)
|
||||||
|
if (`$createdAt -lt (Get-Date).AddMinutes(-10)) { continue }
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (`$item.State -notin @('Queued','Running','Succeeded')) { continue }
|
||||||
|
if (-not [string]::Equals([string]`$item.Alias, `$Alias, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
|
||||||
|
if (-not [string]::Equals([string]`$item.Action, `$Action, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
|
||||||
|
return `$true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
|
||||||
|
return `$false
|
||||||
|
}
|
||||||
|
|
||||||
`$form = New-Object System.Windows.Forms.Form
|
`$form = New-Object System.Windows.Forms.Form
|
||||||
`$form.Text = `$CatalogTitle
|
`$form.Text = `$CatalogTitle
|
||||||
`$form.StartPosition = 'CenterScreen'
|
`$form.StartPosition = 'CenterScreen'
|
||||||
@@ -1494,6 +1533,193 @@ function Load-AppList {
|
|||||||
`$stateRefreshTimer.Interval = 500
|
`$stateRefreshTimer.Interval = 500
|
||||||
`$script:StateRefreshPending = `$false
|
`$script:StateRefreshPending = `$false
|
||||||
`$script:RequestWorkerBusy = `$false
|
`$script:RequestWorkerBusy = `$false
|
||||||
|
`$script:RunspaceJobs = @()
|
||||||
|
`$script:CatalogClosing = `$false
|
||||||
|
|
||||||
|
function Remove-CatalogRunspaceJob {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=`$true)]`$Job,
|
||||||
|
[switch]`$Stop
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (`$null -ne `$Job.Timer) {
|
||||||
|
`$Job.Timer.Stop()
|
||||||
|
`$Job.Timer.Dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (`$Stop -and `$null -ne `$Job.PowerShell -and `$null -ne `$Job.AsyncResult -and -not `$Job.AsyncResult.IsCompleted) {
|
||||||
|
`$null = `$Job.PowerShell.BeginStop(`$null, `$null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
try { `$Job.PowerShell.Stop() } catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (`$null -ne `$Job.PowerShell) { `$Job.PowerShell.Dispose() }
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (`$null -ne `$Job.Runspace) { `$Job.Runspace.Dispose() }
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
}
|
||||||
|
|
||||||
|
`$remainingJobs = @()
|
||||||
|
foreach (`$existingJob in @(`$script:RunspaceJobs)) {
|
||||||
|
if (-not [object]::ReferenceEquals(`$existingJob, `$Job)) {
|
||||||
|
`$remainingJobs += `$existingJob
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`$script:RunspaceJobs = `$remainingJobs
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-CatalogDaemonRunspaceRequest {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=`$true)][string]`$Command,
|
||||||
|
[string]`$Alias,
|
||||||
|
`$Context,
|
||||||
|
[Parameter(Mandatory=`$true)][scriptblock]`$OnCompleted
|
||||||
|
)
|
||||||
|
|
||||||
|
`$runspace = [runspacefactory]::CreateRunspace()
|
||||||
|
`$powershell = [powershell]::Create()
|
||||||
|
`$timer = New-Object System.Windows.Forms.Timer
|
||||||
|
`$timer.Interval = 100
|
||||||
|
|
||||||
|
`$job = [pscustomobject]@{
|
||||||
|
PowerShell = `$powershell
|
||||||
|
Runspace = `$runspace
|
||||||
|
AsyncResult = `$null
|
||||||
|
Timer = `$timer
|
||||||
|
Context = `$Context
|
||||||
|
OnCompleted = `$OnCompleted
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
`$runspace.ApartmentState = 'MTA'
|
||||||
|
`$runspace.ThreadOptions = 'ReuseThread'
|
||||||
|
`$runspace.Open()
|
||||||
|
`$runspace.SessionStateProxy.SetVariable('PipeName', `$PipeName)
|
||||||
|
`$runspace.SessionStateProxy.SetVariable('Command', `$Command)
|
||||||
|
`$runspace.SessionStateProxy.SetVariable('Alias', `$Alias)
|
||||||
|
|
||||||
|
`$powershell.Runspace = `$runspace
|
||||||
|
[void]`$powershell.AddScript({
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
`$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
`$payload = [ordered]@{
|
||||||
|
Command = `$Command
|
||||||
|
AppAlias = `$Alias
|
||||||
|
}
|
||||||
|
`$json = `$payload | ConvertTo-Json -Compress
|
||||||
|
|
||||||
|
`$encoding = New-Object System.Text.UTF8Encoding(`$false)
|
||||||
|
`$client = New-Object System.IO.Pipes.NamedPipeClientStream -ArgumentList @(
|
||||||
|
'.',
|
||||||
|
`$PipeName,
|
||||||
|
[System.IO.Pipes.PipeDirection]::InOut,
|
||||||
|
[System.IO.Pipes.PipeOptions]::None,
|
||||||
|
[System.Security.Principal.TokenImpersonationLevel]::Impersonation
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
`$client.Connect(10000)
|
||||||
|
`$reader = New-Object System.IO.StreamReader(`$client, `$encoding)
|
||||||
|
`$writer = New-Object System.IO.StreamWriter(`$client, `$encoding)
|
||||||
|
`$writer.AutoFlush = `$true
|
||||||
|
`$writer.WriteLine(`$json)
|
||||||
|
|
||||||
|
`$readTask = `$reader.ReadLineAsync()
|
||||||
|
if (-not `$readTask.Wait(15000)) {
|
||||||
|
throw 'Zeitüberschreitung beim Warten auf Antwort des Softwarekatalog-Dienstes.'
|
||||||
|
}
|
||||||
|
`$line = `$readTask.Result
|
||||||
|
if ([string]::IsNullOrWhiteSpace(`$line)) {
|
||||||
|
throw 'Der Softwarekatalog-Dienst hat keine Antwort gesendet.'
|
||||||
|
}
|
||||||
|
|
||||||
|
`$response = `$line | ConvertFrom-Json
|
||||||
|
if (-not `$response.Success) {
|
||||||
|
throw ([string]`$response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return `$response
|
||||||
|
}
|
||||||
|
catch [System.TimeoutException] {
|
||||||
|
throw 'Der Softwarekatalog-Dienst ist nicht erreichbar oder startet noch. Bitte versuchen Sie es erneut.'
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
`$client.Dispose()
|
||||||
|
}
|
||||||
|
}.ToString())
|
||||||
|
|
||||||
|
`$job.AsyncResult = `$powershell.BeginInvoke()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
`$timer.Dispose()
|
||||||
|
`$powershell.Dispose()
|
||||||
|
`$runspace.Dispose()
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
|
||||||
|
`$script:RunspaceJobs = @(`$script:RunspaceJobs + `$job)
|
||||||
|
`$jobRef = `$job
|
||||||
|
`$timer.Add_Tick({
|
||||||
|
if (`$null -eq `$jobRef.AsyncResult -or -not `$jobRef.AsyncResult.IsCompleted) { return }
|
||||||
|
|
||||||
|
`$jobRef.Timer.Stop()
|
||||||
|
`$completion = [pscustomobject]@{
|
||||||
|
Context = `$jobRef.Context
|
||||||
|
Response = `$null
|
||||||
|
ErrorMessage = `$null
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
`$result = @(`$jobRef.PowerShell.EndInvoke(`$jobRef.AsyncResult))
|
||||||
|
if (`$jobRef.PowerShell.Streams.Error.Count -gt 0) {
|
||||||
|
`$firstError = `$jobRef.PowerShell.Streams.Error[0]
|
||||||
|
if (`$null -ne `$firstError.Exception) {
|
||||||
|
`$completion.ErrorMessage = `$firstError.Exception.Message
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
`$completion.ErrorMessage = [string]`$firstError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (`$result.Count -gt 0) {
|
||||||
|
`$completion.Response = `$result[-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
`$exception = `$_.Exception
|
||||||
|
while (`$exception.InnerException) {
|
||||||
|
`$exception = `$exception.InnerException
|
||||||
|
}
|
||||||
|
`$completion.ErrorMessage = `$exception.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (-not `$script:CatalogClosing) {
|
||||||
|
& `$jobRef.OnCompleted `$completion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
try { `$status.Text = 'Fehler: ' + `$_.Exception.Message } catch { }
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Remove-CatalogRunspaceJob -Job `$jobRef
|
||||||
|
}
|
||||||
|
}.GetNewClosure())
|
||||||
|
`$timer.Start()
|
||||||
|
}
|
||||||
|
|
||||||
function Start-AppRequestAsync {
|
function Start-AppRequestAsync {
|
||||||
param(
|
param(
|
||||||
@@ -1511,29 +1737,38 @@ function Start-AppRequestAsync {
|
|||||||
`$btnUninstall.Enabled = `$false
|
`$btnUninstall.Enabled = `$false
|
||||||
`$btnRefresh.Enabled = `$false
|
`$btnRefresh.Enabled = `$false
|
||||||
|
|
||||||
`$worker = New-Object System.ComponentModel.BackgroundWorker
|
`$context = [pscustomobject]@{
|
||||||
`$worker.Add_DoWork({
|
Action = `$Action
|
||||||
param(`$sender, `$eventArgs)
|
Alias = [string]`$Selected.Alias
|
||||||
`$arg = `$eventArgs.Argument
|
DisplayName = [string]`$Selected.DisplayName
|
||||||
`$response = New-AppRequest -Alias `$arg.Alias -Action `$arg.Action
|
}
|
||||||
`$eventArgs.Result = [pscustomobject]@{
|
|
||||||
Action = `$arg.Action
|
try {
|
||||||
Alias = `$arg.Alias
|
Start-CatalogDaemonRunspaceRequest -Command `$Action -Alias `$context.Alias -Context `$context -OnCompleted ({
|
||||||
DisplayName = `$arg.DisplayName
|
param(`$completion)
|
||||||
Response = `$response
|
|
||||||
}
|
|
||||||
})
|
|
||||||
`$worker.Add_RunWorkerCompleted({
|
|
||||||
param(`$sender, `$eventArgs)
|
|
||||||
try {
|
try {
|
||||||
`$script:RequestWorkerBusy = `$false
|
`$script:RequestWorkerBusy = `$false
|
||||||
`$btnRefresh.Enabled = `$true
|
`$btnRefresh.Enabled = `$true
|
||||||
|
|
||||||
if (`$eventArgs.Error) {
|
if (`$completion.Context.Action -eq 'Uninstall') {
|
||||||
`$status.Text = 'Fehler: ' + `$eventArgs.Error.Message
|
`$verb = 'Deinstallation'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
`$verb = 'Installation'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (`$completion.ErrorMessage) {
|
||||||
|
`$requestReachedQueue = (`$completion.ErrorMessage -like '*Zeitüberschreitung beim Warten auf Antwort*' -and (Test-RequestQueuedInState -Alias `$completion.Context.Alias -Action `$completion.Context.Action))
|
||||||
|
if (`$requestReachedQueue) {
|
||||||
|
`$status.Text = "`$verb eingereiht: {0}" -f `$completion.Context.DisplayName
|
||||||
|
`$script:StateRefreshPending = `$true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
`$status.Text = 'Fehler: ' + `$completion.ErrorMessage
|
||||||
`$script:StateRefreshPending = `$true
|
`$script:StateRefreshPending = `$true
|
||||||
[System.Windows.Forms.MessageBox]::Show(
|
[System.Windows.Forms.MessageBox]::Show(
|
||||||
`$eventArgs.Error.Message,
|
`$completion.ErrorMessage,
|
||||||
`$CatalogTitle,
|
`$CatalogTitle,
|
||||||
[System.Windows.Forms.MessageBoxButtons]::OK,
|
[System.Windows.Forms.MessageBoxButtons]::OK,
|
||||||
[System.Windows.Forms.MessageBoxIcon]::Error
|
[System.Windows.Forms.MessageBoxIcon]::Error
|
||||||
@@ -1541,12 +1776,11 @@ function Start-AppRequestAsync {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
`$result = `$eventArgs.Result
|
`$result = [pscustomobject]@{
|
||||||
if (`$result.Action -eq 'Uninstall') {
|
Action = `$completion.Context.Action
|
||||||
`$verb = 'Deinstallation'
|
Alias = `$completion.Context.Alias
|
||||||
}
|
DisplayName = `$completion.Context.DisplayName
|
||||||
else {
|
Response = `$completion.Response
|
||||||
`$verb = 'Installation'
|
|
||||||
}
|
}
|
||||||
if (`$result.Response.Message) {
|
if (`$result.Response.Message) {
|
||||||
`$status.Text = [string]`$result.Response.Message
|
`$status.Text = [string]`$result.Response.Message
|
||||||
@@ -1566,14 +1800,15 @@ function Start-AppRequestAsync {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Update-InstallButtonState
|
Update-InstallButtonState
|
||||||
`$sender.Dispose()
|
|
||||||
}
|
}
|
||||||
})
|
}.GetNewClosure())
|
||||||
`$worker.RunWorkerAsync([pscustomobject]@{
|
}
|
||||||
Action = `$Action
|
catch {
|
||||||
Alias = [string]`$Selected.Alias
|
`$script:RequestWorkerBusy = `$false
|
||||||
DisplayName = [string]`$Selected.DisplayName
|
`$btnRefresh.Enabled = `$true
|
||||||
})
|
Update-InstallButtonState
|
||||||
|
throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Start-RefreshStatusAsync {
|
function Start-RefreshStatusAsync {
|
||||||
@@ -1588,21 +1823,17 @@ function Start-RefreshStatusAsync {
|
|||||||
`$btnRefresh.Enabled = `$false
|
`$btnRefresh.Enabled = `$false
|
||||||
`$status.Text = 'Installationsdaten-Aktualisierung wird angefordert...'
|
`$status.Text = 'Installationsdaten-Aktualisierung wird angefordert...'
|
||||||
|
|
||||||
`$worker = New-Object System.ComponentModel.BackgroundWorker
|
try {
|
||||||
`$worker.Add_DoWork({
|
Start-CatalogDaemonRunspaceRequest -Command 'RefreshStatus' -OnCompleted ({
|
||||||
param(`$sender, `$eventArgs)
|
param(`$completion)
|
||||||
`$eventArgs.Result = Invoke-CatalogDaemon -Command 'RefreshStatus'
|
|
||||||
})
|
|
||||||
`$worker.Add_RunWorkerCompleted({
|
|
||||||
param(`$sender, `$eventArgs)
|
|
||||||
try {
|
try {
|
||||||
`$script:RequestWorkerBusy = `$false
|
`$script:RequestWorkerBusy = `$false
|
||||||
`$btnRefresh.Enabled = `$true
|
`$btnRefresh.Enabled = `$true
|
||||||
|
|
||||||
if (`$eventArgs.Error) {
|
if (`$completion.ErrorMessage) {
|
||||||
`$status.Text = 'Fehler: ' + `$eventArgs.Error.Message
|
`$status.Text = 'Fehler: ' + `$completion.ErrorMessage
|
||||||
[System.Windows.Forms.MessageBox]::Show(
|
[System.Windows.Forms.MessageBox]::Show(
|
||||||
`$eventArgs.Error.Message,
|
`$completion.ErrorMessage,
|
||||||
`$CatalogTitle,
|
`$CatalogTitle,
|
||||||
[System.Windows.Forms.MessageBoxButtons]::OK,
|
[System.Windows.Forms.MessageBoxButtons]::OK,
|
||||||
[System.Windows.Forms.MessageBoxIcon]::Error
|
[System.Windows.Forms.MessageBoxIcon]::Error
|
||||||
@@ -1610,16 +1841,21 @@ function Start-RefreshStatusAsync {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
`$response = `$eventArgs.Result
|
`$response = `$completion.Response
|
||||||
if (`$response.Message) { `$status.Text = [string]`$response.Message }
|
if (`$response.Message) { `$status.Text = [string]`$response.Message }
|
||||||
`$script:StateRefreshPending = `$true
|
`$script:StateRefreshPending = `$true
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Update-InstallButtonState
|
Update-InstallButtonState
|
||||||
`$sender.Dispose()
|
|
||||||
}
|
}
|
||||||
})
|
}.GetNewClosure())
|
||||||
`$worker.RunWorkerAsync()
|
}
|
||||||
|
catch {
|
||||||
|
`$script:RequestWorkerBusy = `$false
|
||||||
|
`$btnRefresh.Enabled = `$true
|
||||||
|
Update-InstallButtonState
|
||||||
|
throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
`$btnInstall.Add_Click({
|
`$btnInstall.Add_Click({
|
||||||
@@ -1725,6 +1961,7 @@ function Start-RefreshStatusAsync {
|
|||||||
|
|
||||||
`$stateRefreshTimer.Add_Tick({
|
`$stateRefreshTimer.Add_Tick({
|
||||||
if (-not `$script:StateRefreshPending) { return }
|
if (-not `$script:StateRefreshPending) { return }
|
||||||
|
if (`$script:RequestWorkerBusy) { return }
|
||||||
`$script:StateRefreshPending = `$false
|
`$script:StateRefreshPending = `$false
|
||||||
try { Load-AppList }
|
try { Load-AppList }
|
||||||
catch { `$status.Text = "Fehler bei automatischer Aktualisierung: " + `$_.Exception.Message }
|
catch { `$status.Text = "Fehler bei automatischer Aktualisierung: " + `$_.Exception.Message }
|
||||||
@@ -1795,10 +2032,15 @@ function Start-RefreshStatusAsync {
|
|||||||
`$stateRefreshTimer.Start()
|
`$stateRefreshTimer.Start()
|
||||||
})
|
})
|
||||||
`$form.Add_FormClosing({
|
`$form.Add_FormClosing({
|
||||||
|
`$script:CatalogClosing = `$true
|
||||||
`$stateRefreshTimer.Stop()
|
`$stateRefreshTimer.Stop()
|
||||||
`$stateRefreshTimer.Dispose()
|
`$stateRefreshTimer.Dispose()
|
||||||
if (`$script:StateWatcher) { `$script:StateWatcher.Dispose() }
|
if (`$null -ne `$script:StateWatcher) { `$script:StateWatcher.Dispose() }
|
||||||
if (`$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() }
|
if (`$null -ne `$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() }
|
||||||
|
foreach (`$job in @(`$script:RunspaceJobs)) {
|
||||||
|
Remove-CatalogRunspaceJob -Job `$job -Stop
|
||||||
|
}
|
||||||
|
`$script:RunspaceJobs = @()
|
||||||
})
|
})
|
||||||
|
|
||||||
`$list.Add_SelectedIndexChanged({ Update-InstallButtonState })
|
`$list.Add_SelectedIndexChanged({ Update-InstallButtonState })
|
||||||
|
|||||||
Reference in New Issue
Block a user