Using Spring.NET's PropertyPlaceholderConfigurer

I found the documentation on this topic rather confusing, so here is my cheat-sheet:

Choice 1:

If you store the Configuration-Keys in the Web.config:

File Web.config / App.config

  1. <configuration>
  2.  
  3. <configSections>
  4. <section name="MyConfigSection"
  5. type="System.Configuration.NameValueFileSectionHandler, System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  6. </configSection>
  7.  
  8. <MyConfigSection>
  9. <add key="ParameterName" value="ParameterValue"/>
  10. </MyConfigSection>
  11.  
  12. </configuration>

File spring-whatever.xml

  1. <objects ...>
  2.  
  3. <object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
  4. <property name="ConfigSections" value="MyConfigSection"/>
  5. </object>
  6.  
  7. <object id="SomePOJO" type="SomeType">
  8. <property name="Foo" value="${ParameterName}"/>
  9. </object>
  10.  
  11. </objects>

If you use more than one config section in the App.config / Web.config file, you will need to register all the sections in the Spring's PropertyPlaceholderConfigurer object by adding them to its ConfigSection property. The values should be separated by a comma.

Choice 2:

Don't use web.config at all, define everything in in spring's object xml only:

File: spring-whatever.xml

  1. <objects ...>
  2.  
  3. <object id="appPropertyConfigurer"
  4. type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
  5. <property name="MyConfigSection">
  6. <name-values>
  7. <add key="Foo" value="ParameterValue"/>
  8. </name-values>
  9. </property>
  10. </object>
  11.  
  12. <object id="SomePOJO" type="SomeType">
  13. <property name="Foo" value="${ParameterName}"/>
  14. </object>
  15.  
  16. </objects>

WCF, XStream, Serialization Issues and Debugging

Maybe you are familiar with the XStream Serializer which was initially available for Java and ported later on to .NET. If you aren't - its worth checking out. Its a very simple XML serializer able to handle complex objects with cyclic dependencies. It has some minor issues though. If you are aware of them, you most probably won't shoot yourself into the foot. ... Yeah, most probably ... I did!

Lets take one step back. I've been consuming a method (lets call it GetFoo()) exposed over WCF Service by an ASP.NET Client. The method would look like this:

  1. public SomeComplexObject GetFoo(long id)
  2. {
  3. String xml = DAO.GetSerializedObjectById(id);
  4. return (SomeComplexObject) XStream.fromXML(xml);
  5. }

SomeComplexObject would be a class properly annotated with the DataContract and DataMember Attributes. Calling this Method over the WCF Service would bail out a generic error message on the ASP client, basically telling you that the remote side of the connection has quit abruptly.

I must admit that I am still new to the WCF / ASP.NET development so I had no clue where to look for the exception generated by the WCF layer. After hitting Google with this question, I have figured out how to use Microsoft Service Trace Viewer to investigate the SOAP Messages passed around- and more importantly the Exception which occured somewhere deep inside the WCF stack.

The Exception type has been "System.Runtime.Serialization.InvalidDataContractException" and basically said that ".xsdyn~SomeComplexObject" has not been annotated with the DataContract Attribute and thus could not be used in a WCF Call.

.xsdyn? It turns out that XStream will create a fake assembly and create a dynamic instance of the "SomeComplexObject" in case one would not provide a default constructor for the class to be deserialized. Gee! Thats dumb! I mean, not only the way of handing the lack of an default constructor, but also my own dumbness making this mistake.

To sum it up, if you are going to use XStream for .NET, pay attention to include a) the default constructor in each class you wish to deserialize, b) use protected and not private modifiers to class variables if you are going to derive from that class. Otherwise you will be missing the fields in the serialized output. It does not matter if the properties would be public or not.

Oh, and by the way... Setting up the WCF logging was fun. The trace log generated is pretty useful if you need to inspect the SOAP messages / headers and the call history. But if you just need to check the Exception generated by the WCF Stack - take a look into the Windows EventViewer - way more convenient!

Eclipse Vs SetPoint 4.4 on Vista 64

Broken "Colors and Fonts" DialogBroken "Colors and Fonts" DialogThis was bugging me for about 2 days by now. After I've installed a fresh copy of Eclipse (3.3.something, stable) I was kinda surprised that some of the dialogs were not rendering correctly. It took me several hours to test various JVMs among 32 and 64 Bit versions of the SWT / Eclipse package - no luck. Still could not access the "Colors And Fonts" dialog for instance.

It tuns out that the Logitech Setpoint 4.4 software is interfering in  some way with the way SWT works. I think there might be some shell hooks involved into this problem. I have noticed similar issues with Shell Enahncer which is also hooking into the window and mousemanagement of Windows to provide some nice features like X-Windows-like window moving and resizing.

For those who cannot believe, check the Screencast (SWF File) I have attached!

Update:
Now I can get rid of the SetPoint Tray-Application to remap my mouse buttons: http://www.highrez.co.uk/downloads/XMouseButtonControl.htm - Thaks mate!

Historical Overview Of File Systems

Stumbled over an article about File Systems over at Ars Technica today. Damn nice reading, I strongly recommend that one: http://arstechnica.com/articles/paedia/past-present-future-file-systems.ars

Mass Effect - Money Maxed Out

Mass Effect - Money Maxed Out
maybe I was playing too much - just a little bit :)

Port Redirection with Windows

Today I have been asked for a copy of a discontinued port-forwarding and proxy tool I have been once recommending. Unfortunately the program page did disappear quite a few years ago and I was not able to find that tool (bouncer from r00ted.co.uk) in my backup files.

After poking a few minutes at google I came across a Port of "rinetd" which I use a lot on my linux boxes: http://www.boutell.com/rinetd/ - a very simple daemon for port redirections. Just feed it with a config file like this:

  1. #bindaddress bindport connectaddress connectport
  2. 192.168.1.145 80 192.168.1.254 8080

Obviously, the config above will redirect all traffic arriving at the "192.168.1.145:80" to "192.168.1.254:8080". Unlike the bouncer tool, rinetd can handle more than one redirection per process. You can define as many forwarding rules in that config as you like.

Last but not least, I have made a tiny change to the source by altering the default location of the config file. Hardcoded location was "/etc/rinetd.conf" which does not make much sense on windows. The attached binary will look for the rinetd.conf next to the executable itself. I have also provided a sample config for that matter:

Combined Access Log Format for a proxed Tomcat

If you need to let your Tomcat write access logs while being proxied by Apache's mod_proxy using the combined format, you will soon notice the lack of the client IP address. Pretty useless if you would like to get some access statistics for that particular instance.

Fortunately the Apache's mod_proxy will add some extra headers with the missing information to each request. Just set up your Log-Configuration in Tomcat as follows:

  1. <Context>
  2. <Valve
  3. className="org.apache.catalina.valves.AccessLogValve"
  4. prefix="access_log"
  5. pattern="%{X-Forwarded-For}i %l %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;"
  6. rotatable="false"/>
  7. </Context>

Please note that I'm rotating the Tomcat logs using logrotate. Therefore the "rotatable" attribute is set to "false" above. Just in any case, here is the logrotate config for my setup:

  1. /home/tomcat/logs/*_log
  2. {
  3. weekly
  4. rotate 48
  5. create 640 tomcat www-data
  6. sharedscripts
  7. postrotate /etc/init.d/tomcat restart
  8. endscript
  9. compress
  10. }

Nvidia's VMR Woes

For some reason, NVidia does not seem to get their drivers right regarding the video output using VMR-7/9 on digital panels hooked up via DVI. The drivers should detect the display type and use the enhanced color range (0-255) instead of the TV-Scale (16-235) to output video streams on your screen. Obviously they don't!

Once, NVidia has documented a registry hack in their driver release notes (AFAIR in 80.xx-90.xx driver revisions) which would force the driver to use the enhanced color range for videos. Never worked for me - I had to look for other workarounds. All I wanted was a true black (0,0,0) and a true white (255,255,255) on my screen. How difficult can it be?

You have various options to get rid of this nasty behavior. One would be to let your video player use RGB colorspace instead of YUV when rendering the video onto a VMR Surface. FFDShow Codec can do that. This workaround will obviously only work for video players using FFDShow. DVD Playback or in-game video might not be affected by using this method. The most reliable method I found was to use the video color correction in the recent NVidia drivers.

I grabbed a color test pattern movie over at Burosch (look for the link labeled "Download: 1920 x 1080 mit Stereo - Ton"), had set up my player to loop the video, and did a lot of screenshots which I pasted into Paint.NET to colorpick the black and white values while fiddling with the video color settings of the NVidia color panel. Sounds like pain in the ass? It feels like that too!

Anyway, in the end if have came up with following settings which look just perfect on my setup:

NVidia video color settingsNVidia video color settings

Now tell me one thing, why isn't it possible to export the color settings from the new oh-so-fancy-and-sluggish-nvidia-control-panel? WTF!? If you look at the screenshot above, you might think, that you only need to adapt percentage values. Think again. Between each decimal step, there are about 5-6 intermediate steps which you can only access via the keyboard / cursor keys. The driver does not always apply values set this way onto the live video, so you have to uncheck/check the "Use the NVIDIA Control Panel color settings" checkbox each time to let the driver accept fine-tweaked settings. JEEZ! Can I have the old snappy control panel back?

P.S. don't be as naive as I was to fire up Regmon / Process Monitor to take a look where the control panel stores the settings. Dragging a slider bailed out 64316 Registry-Access-Events (Open, Query, Close) PER SECOND! WTF! Now I have an idea why the control panel feels that slow!

How to set Nullable Types via Reflection on Properties in C# / .NET

Here is a Code-Snippet from a generic CSV -> Object Importer/Mapper I wrote. At some point I ran into an issue with Nullable types / values which I had to set (and convert) based on strings from the CSV file.

  1. public virtual void HandlePropertyAssignment(PropertyInfo pi,
  2. string propertyValue,
  3. T instance)
  4. {
  5. try
  6. {
  7. if (
  8. pi.PropertyType.GetGenericArguments() != null &&
  9. pi.PropertyType.GetGenericArguments().Length > 0 &&
  10. pi.PropertyType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))
  11. )
  12. {
  13. Type genericType = pi.PropertyType.GetGenericArguments()[0];
  14. pi.SetValue(instance, Convert.ChangeType(propertyValue, genericType), null);
  15. }
  16. else
  17. {
  18. pi.SetValue(instance, Convert.ChangeType(propertyValue, pi.PropertyType), null);
  19. }
  20. }
  21. catch (System.Exception ex)
  22. {
  23. throw new DAOException(String.Fromat("Could not convert {0} to property {1} of type {2}",
  24. propertyValue,pi.Name,pi.PropertyType),ex);
  25. }
  26. }
Note: T is a Generic Type.

Enable AHCI SATA Mode for Vista

Today I decided to finally give AHCI a try on my Vista setup. Unfortunately I've installed Vista with no AHCI support enabled in the BIOS, so no drivers were installed by Vista for this very mode automagically.

How difficult can it be? Reboot, Enable AHCI in the BIOS, Boot back up again: Boom - Bluescreen. Here is something I can't get, why does Windows bug me with plenty of useless dialogs to confirm or cancel but does reboot automatically about 2 seconds after throwing a Bluescreen which IS actually important? If you are lucky, you can catch a glimpse at the error message for about 1-2 seconds but if your shiny new TFT is busy synching to the new video mode you won't even notice it!

This can be fixed by adjusting the Crash Control Registry settings:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl\

Set AutoReboot to 0.

OK, next time I will be able to read which component did cause the Bluescreen. Nevertheless I started looking around for others having problems switching to AHCI. Aside very adventurous solutions like moving the boot device to a separate SATA controller, enabling the AHCI mode on the other and booting up so Vista can install proper drivers or hacking the hell out of the Registry and some Intel-Raid application I have found a way more convenient way to enable AHCI.

It turns out that Vista will disable AHCI support for good if you did not had it enabled during the setup. To switch it back on you will need to do one tiny Registry Hack:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Msahci

Set Start to 0

Yes, 0 to enable it. Don't ask.

Reboot, toggle the AHCI Support in your Bios and everything should be fine.

Syndicate content