Week roundup

Last week recap and links:
Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , , , | Leave a comment

WPF localization

To repro a bug I’ve created a simple WPF application that displays two labels bound to the same DateTime object. The bottom one is converted to a string using a IValueConverter. Both should be formatted the same but aren’t.
wpf_localization_1

By adding some trace lines to the Convert method I’ve discovered that the CultureInfo (en-US) parameter is different from the CurrentThread.CurrentCulture (nl-NL). I’ve configured my English Windows 8.1 with Dutch formatting for datetime.

On stackoverflow someone pointed me to IFormattable and the ToString overload that would accept the culture. My Convert method now looks like below.

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
    System.Diagnostics.Trace.TraceInformation( "Convert Culture: {0}", culture.ToString());
    System.Diagnostics.Trace.TraceInformation( "Thread  Culture: {0}", System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
    System.Diagnostics.Trace.TraceInformation( "ThreadUICulture: {0}", System.Threading.Thread.CurrentThread.CurrentUICulture.ToString());
    var formattable = value as IFormattable;
    return formattable.ToString( null, culture);
}

Now the formatting looks alike, but not what I expected. The formatting should have been in Dutch (dd-MM-yyyy).
wpf_localization_2

By setting the Language property for the top framework element, the CultureInfo passed to the Convert method is changed. This has to be repeated on every Window. A very usefull tip from Rick shows how to do this in the OnStartup all at once.

protected override void OnStartup(StartupEventArgs e){
    base.OnStartup(e);
    FrameworkElement.LanguageProperty.OverrideMetadata( typeof( FrameworkElement),
        new FrameworkPropertyMetadata(XmlLanguage .GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}

wpf_localization_3

Now the dates are printed the way you specify in the Control Panel > Region > Format. Remember to restart the Application (or Visual Studio when debugging) after you’ve changed the setting.

References

Stackoverflow answer to use IFormattable
WPF Bindings and CurrentCulture Formatting – Set Language App global

Posted in Development | Tagged , , | Leave a comment

Loadtest with Azure VM

For an upcoming release we decided to do a loadtest on our Azure test environment. Until now we used a set of local machines for this. The setup uses 6 machines that host our product, which consists of a number of WCF services and a website. We must produce the load from “within” Azure or else it would be blocked as being a DDOS. So we provisioned an additional VM with Visual Studio 2013 and started the test.

Result

We soon discovered that it had to be run in 64 bit mode to use the 28 Gb (A6!) memory we gave the VM. This is done in the testsettings file under hosts.
loadtest_64bit
Running in 32 bit resulted in an out-of-memory exception since it can only use 3 Gb.

In the Azure portal we would follow the metrics of the VM’s hosting our product. This information is lagging behind and sometimes we want to know what is happening in real time. Using remote powershell we call the Get-Process commandlet. It provides just enough intel.

After the first test runs we experienced bugs and hickups. Some fixes are applied and another loadtest is run. This had been unnoticed on our local machines. Loadtesting in Azure is already a huge success.

Next

If we had a Visual Studio Online account we could have used their loadtest. Maybe somewhere in the future, one-step at a time.

After two days of testing this setup my Azure subscription freaked out and notified my that I possibly had insufficient funds for the rest of the month. We all laughed and shutdown the machines for the weekend. That is cloud computing!

Posted in Test | Tagged , | Leave a comment

Week roundup

Last week recap and links:
Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , | Leave a comment

Powershell optimization

After rewriting my PowerShell test environment automation script with functions I optimized some parts to improve memory usage, automate IIS Webfarm configuration and batch starting/stopping all machines is a Azure Cloud Service.

Download

For installation of software the script downloads the MSI from Azure storage. The download is done with Invoke-WebRequest which generates a lot of output. I’ve seen over 6Gb of memory usage to hold this output in a job even with Receive-Job being called every 15 seconds.

Now I’m using the .NET webclient and memory usage is back to normal. Since the installation should be a black box I only want to know when it fails and not how much bits are downloaded.

$client = New-Object net.webclient
$client.Downloadfile($file, $msi)

Webfarm

During creation of the VM I run a custom script to install IIS. This however does not configure IIS for a webfarm setup. Most important is the machinekey setting for encryption/decryption of the viewstate.

# add masterkey to machine.config for webfarm
$configFile = "$ENV:windir\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config"
$xml=New-Object XML
$xml.Load($configFile)
$machinekey = $xml.CreateElement("machineKey")
$machinekey.SetAttribute("decryption", "AES")
$machinekey.SetAttribute("decryptionKey", "DECRYPTION_KEY_HERE")
$machinekey.SetAttribute("validation", "SHA1")
$machinekey.SetAttribute("validationKey", "VALIDATION_KEY_HERE")
$machinekey.SetAttribute("compatibilityMode", "Framework45")
$xml.configuration.'system.web'.AppendChild($machinekey) | Write-Debug
$xml.Save($configFile)

To generate the keys use one of the references from this post: Setting up a machine key.

Batch start/stop

After creating a lot of machines for our test we sometimes want to keep the VM’s. When the machines are running they cost money, but once stopped only the storage is billed. Stopping all VM’s in a Azure Cloud Service can be done by using a wildcard. MSDN documentation states this is not supported but it works.

# stop all VM in a Cloud service
Stop-AzureVM -ServiceName $service -Name * -Force
# start all VM in a Cloud service
Start-AzureVM -ServiceName $service -Name *

You’ll need at least Windows Azure PowerShell 0.6.19. Best is to install the latest version from here.

Posted in Development | Tagged , , | Leave a comment