Add PowerShell cmdlets and update project structure

This commit is contained in:
GraceSolutions
2025-04-10 21:13:24 -04:00
parent e5a7f10ade
commit 7cd5962115
56 changed files with 2356 additions and 3914 deletions
+35 -59
View File
@@ -1,84 +1,60 @@
# Example: Asynchronous Notification
# This script demonstrates how to show an asynchronous notification and check its status later
# This script demonstrates how to show an asynchronous notification
# Load the WindowsNotifications assembly
# Import the module
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath "..\PowerShell\WindowsNotifications.psd1"
Import-Module $modulePath -Force
# Initialize the notification system
$dllPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WindowsNotifications\bin\Release\WindowsNotifications.dll"
if (Test-Path $dllPath) {
$bytes = [System.IO.File]::ReadAllBytes($dllPath)
$assembly = [System.Reflection.Assembly]::Load($bytes)
}
else {
Write-Error "WindowsNotifications.dll not found at $dllPath. Please build the solution first."
exit
}
Initialize-WindowsNotifications -DllPath $dllPath
# Create a notification manager
$notificationManager = New-Object WindowsNotifications.NotificationManager
# Show an asynchronous notification
$result = Show-Notification -Title "Background Task" -Message "A background task is running..." -Buttons "Cancel", "View Details" -Async
# Create custom notification options
$options = New-Object WindowsNotifications.Models.NotificationOptions
$options.Title = "Background Task Running"
$options.Message = "A background task is running. You can continue working."
$options.Async = $true # Run asynchronously
$options.PersistState = $true # Save state to database
# Add buttons
$viewButton = New-Object WindowsNotifications.Models.NotificationButton("View Progress", "view")
$cancelButton = New-Object WindowsNotifications.Models.NotificationButton("Cancel Task", "cancel")
$options.Buttons.Add($viewButton)
$options.Buttons.Add($cancelButton)
# Show the notification
Write-Host "Showing asynchronous notification..."
$result = $notificationManager.ShowNotification($options)
# Display the result
# Display the initial result
Write-Host "Notification displayed: $($result.Displayed)"
Write-Host "Notification ID: $($result.NotificationId)"
# Simulate doing some work
Write-Host "Performing background work..."
# Simulate a background task
Write-Host "Performing background task..."
for ($i = 1; $i -le 5; $i++) {
Write-Host " Working... ($i/5)"
Write-Host "Working... ($i/5)"
Start-Sleep -Seconds 2
# Check if the notification has been interacted with
$currentResult = $notificationManager.GetNotificationResult($result.NotificationId)
$currentResult = Get-NotificationResult -NotificationId $result.NotificationId
if ($currentResult -ne $null -and ($currentResult.Activated -or $currentResult.Dismissed)) {
if ($currentResult.ClickedButtonId -eq "cancel") {
Write-Host "User canceled the task!"
break
}
elseif ($currentResult.ClickedButtonId -eq "view") {
Write-Host "User viewed the progress!"
if ($currentResult -and ($currentResult.Activated -or $currentResult.Dismissed)) {
Write-Host "User interacted with the notification"
if ($currentResult.ClickedButtonId) {
Write-Host "Button clicked: $($currentResult.ClickedButtonText) (ID: $($currentResult.ClickedButtonId))"
# Show a new notification with updated progress
$progressOptions = New-Object WindowsNotifications.Models.NotificationOptions
$progressOptions.Title = "Task Progress"
$progressOptions.Message = "Progress: $i/5 steps completed"
$progressOptions.Tag = "progress" # Group with the same tag
$notificationManager.ShowNotification($progressOptions)
# Handle button clicks
if ($currentResult.ClickedButtonText -eq "Cancel") {
Write-Host "User cancelled the task"
break
} elseif ($currentResult.ClickedButtonText -eq "View Details") {
Write-Host "User wants to view details"
# In a real script, you would show details here
}
}
break
}
}
Write-Host "Background work completed"
Write-Host "Background task completed"
# Show a completion notification
$completionOptions = New-Object WindowsNotifications.Models.NotificationOptions
$completionOptions.Title = "Task Completed"
$completionOptions.Message = "The background task has finished."
$completionOptions.Tag = "progress" # Replace previous notification with same tag
$notificationManager.ShowNotification($completionOptions)
# Get the final notification result
$finalResult = $notificationManager.GetNotificationResult($result.NotificationId)
if ($finalResult -ne $null) {
# Get the final result
$finalResult = Get-NotificationResult -NotificationId $result.NotificationId
if ($finalResult) {
Write-Host "Final notification state:"
Write-Host " Activated: $($finalResult.Activated)"
Write-Host " Dismissed: $($finalResult.Dismissed)"
if ($finalResult.ClickedButtonId) {
Write-Host " Button clicked: $($finalResult.ClickedButtonText)"
Write-Host " Button clicked: $($finalResult.ClickedButtonText) (ID: $($finalResult.ClickedButtonId))"
}
}