Mittwoch, 19. Mai 2010

1. Attemp to use .NET isolated storage with modeless WPK windows

 

The following attempt is not working with modeless windows (replace -show #-asjob    by -asjob). Using -show it works. Please run the code, do some selection within GUI, finally call  Get-value to check the result.


ipmo WPK                        
            
                        
$env:WPKResult = "auto"            
            
function action            
{            
    param (            
        $value            
    )            
    $env:WPKResult = $value            
                
    $changedProperty = $value            
    Write-Host "Value of $changedProperty changed to $value"                        
            
    try {            
    $useriStorage = [System.IO.IsolatedStorage.IsolatedStorageFile]::GetUserStoreForAssembly()            
    $file = New-Object System.IO.IsolatedStorage.IsolatedStorageFileStream("SQLSettigs.xml",[System.IO.FileMode]::Create,$useriStorage)            
    $xml = New-Object System.Xml.Serialization.XmlSerializer($changedProperty.GetType())            
    $xml.Serialize($file,$changedProperty)            
    $file.Close()            
    $useriStorage.Close()            
    }            
    catch {            
        $env:WPKResult = 'error'            
    }            
            
}            
                          
New-StackPanel {                        
    New-RadioButton -Content "auto"     -GroupName Results -IsChecked $True -On_Click { action "auto" }                        
    New-RadioButton -Content "list"     -GroupName Results -On_Click { action "list" }                        
    New-RadioButton -Content "table"    -GroupName Results -On_Click { action "table" }            
    New-RadioButton -Content "grid"     -GroupName Results -On_Click { action "grid" }            
    New-RadioButton -Content "variable" -GroupName Results -On_Click { action "variable" }            
    New-RadioButton -Content "csv"      -GroupName Results -On_Click { action "csv" }            
    New-RadioButton -Content "file"     -GroupName Results -On_Click { action "file" }            
} -show #-asjob                        
                        
            
function Get-value            
{            
    $useriStorage = [System.IO.IsolatedStorage.IsolatedStorageFile]::GetUserStoreForAssembly()            
    try {            
        $file = New-Object System.IO.IsolatedStorage.IsolatedStorageFileStream("SQLSettigs.xml",[System.IO.FileMode]::Open,$useriStorage)            
    }            
    catch {            
        Write-Host "UISettings.xml is not found"            
        return            
    }                        
    $xmlReader = New-Object System.Xml.XmlTextReader($file)            
    $xml = New-Object System.Xml.Serialization.XmlSerializer('abc'.GetType())            
    $newISEOptions = $xml.Deserialize($xmlReader)            
    $newISEOptions            
}

Keine Kommentare:

Kommentar veröffentlichen