mirror of
https://github.com/freedbygrace/WindowsNotifications.git
synced 2026-07-28 12:59:31 +00:00
Add PowerShell cmdlets and update project structure
This commit is contained in:
+25
-31
@@ -1,35 +1,29 @@
|
||||
# Example: Load Assembly from Base64
|
||||
# Example: Load from Base64
|
||||
# This script demonstrates how to load the WindowsNotifications assembly from a Base64 string
|
||||
# This is useful for embedding the assembly directly in a script
|
||||
|
||||
# In a real scenario, you would replace this with the actual Base64 string of the assembly
|
||||
# For demonstration purposes, we'll load the DLL and convert it to Base64
|
||||
# First, convert the DLL to a Base64 string
|
||||
# In a real scenario, you would have this string pre-generated
|
||||
$dllPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WindowsNotifications\bin\Release\WindowsNotifications.dll"
|
||||
if (Test-Path $dllPath) {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($dllPath)
|
||||
$base64 = [Convert]::ToBase64String($bytes)
|
||||
|
||||
Write-Host "Assembly loaded and converted to Base64"
|
||||
Write-Host "Base64 string length: $($base64.Length) characters"
|
||||
|
||||
# In a real script, the base64 string would be hardcoded here
|
||||
# $base64 = "YOUR_BASE64_STRING_HERE"
|
||||
|
||||
# Load the assembly from the Base64 string
|
||||
$assemblyBytes = [Convert]::FromBase64String($base64)
|
||||
$assembly = [System.Reflection.Assembly]::Load($assemblyBytes)
|
||||
|
||||
Write-Host "Assembly loaded successfully: $($assembly.FullName)"
|
||||
|
||||
# Create a notification manager and show a simple notification
|
||||
$notificationManager = New-Object WindowsNotifications.NotificationManager
|
||||
$result = $notificationManager.ShowSimpleNotification(
|
||||
"Loaded from Base64",
|
||||
"This notification was shown from an assembly loaded from a Base64 string"
|
||||
)
|
||||
|
||||
Write-Host "Notification displayed: $($result.Displayed)"
|
||||
}
|
||||
else {
|
||||
Write-Error "WindowsNotifications.dll not found at $dllPath. Please build the solution first."
|
||||
$bytes = [System.IO.File]::ReadAllBytes($dllPath)
|
||||
$base64 = [Convert]::ToBase64String($bytes)
|
||||
|
||||
# Now, load the assembly from the Base64 string
|
||||
$assemblyBytes = [Convert]::FromBase64String($base64)
|
||||
$assembly = [System.Reflection.Assembly]::Load($assemblyBytes)
|
||||
|
||||
# Create a notification manager
|
||||
$notificationManager = New-Object WindowsNotifications.NotificationManager
|
||||
|
||||
# Show a simple notification
|
||||
$result = $notificationManager.ShowSimpleNotification("Loaded from Base64", "This notification was shown using an assembly loaded from a Base64 string.")
|
||||
|
||||
# Display the result
|
||||
Write-Host "Notification displayed: $($result.Displayed)"
|
||||
Write-Host "Notification ID: $($result.NotificationId)"
|
||||
|
||||
# If the notification was interacted with, show the details
|
||||
if ($result.Activated) {
|
||||
Write-Host "Notification was activated"
|
||||
} elseif ($result.Dismissed) {
|
||||
Write-Host "Notification was dismissed"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user