pulsar's blog

Yes Firefox, I'll behave!

No Idea what the English verson might be saying, but the button in the German version basically says "I'll be careful, I promise!" LOL?

I'll be careful!I'll be careful!

Blender, Yafray and Me

Recently I decided to get used to Blender. Several years ago I've been using Alias Wavefront and 3D Studio Max at work, so I am already spoiled. But what buggs me the most, is the lack of a decent renderer. The built-in kinda sucks and the only one good looking addon renderer with good integration into blender was yafray. This one supports all the latest hype like GI or Caustics. It looks even pretty good and produces a nice natural lightning.

That did not hold be back from running into an issue which I would cosider being a bug. Here is what I've done:

Blender / Yafray SettingsBlender / Yafray Settings

  • Remove everything from your Scene but the camera
  • Add a plane which will be our floor
  • Add a ball or any other shape ontop of it
  • Add a Area-Light above it (we have no other lights)
  • Remove all Ambient-Lightning
  • Switch on Photons in the Yafray's config
  • Hit F12 - Render.

If you are lucky, you will see some kind of inversed lighting. If not, you will see only darkness. Pump up the Emit Power in the Yafray's config a bit or resize the AreaLight in the object properties window up to 100 and pump up the power to maybe 5.

Is it me not getting here something, or is it just a bug? Take a look at the picures, they look kinda cool (despite being plain wrong):

AreaLight Green OverdriveAreaLight Green Overdrive

There are more variations of this image over at the yafray gallery - If you got yourself an account on this site, you can download the original size of the image.

Update:
Ok, call me an idiot. Even the manual says more or less clearly that one should use area lights together with light emiting objects. The area light does only emit photons which are used to calculate indirect light and the color bleeding.

 

Setup Log4Net for a project in less than 2 minutes

Sometimes documentation is plain anoying. I've been using log4j since ... I don't know, maybe 5-6 years? The setup was as simple as dropping a log4j.xml into the class path and using the logger right away.

Log4Net ist not really much more complicated, but it requires a little bit more attention. Here is what you need to start logging via log4net in less than 2 minutes:

  • Grab the log4net zip over at: http://logging.apache.org/log4net/download.html
  • Copy the log4net.dll (for instance bin\net\2.0\release in the zip archive) into your project. Ignore the other zip content if you don't care.
  • Add the library reference
  • Create an App.Config file using the big xml chunk provided below
  • Call log4net.Config.XmlConfigurator.Configure(); once to initialize the log4net stack
  • Done
  1. <?xml version="1.0" encoding="utf-8" ?>
  2.  
  3. <configuration>
  4.  
  5. <configSections>
  6. <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  7. </configSections>
  8.  
  9. <log4net debug="true">
  10. <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net" >
  11. <param name="File" value="Debug.log" />
  12. <param name="AppendToFile" value="true" />
  13. <maximumFileSize value="10MB" />
  14. <maxSizeRollBackups value="2" />
  15. <layout type="log4net.Layout.PatternLayout,log4net">
  16. <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
  17. </layout>
  18. </appender>
  19. <root>
  20. <priority value="ALL" />
  21. <appender-ref ref="LogFileAppender" />
  22. </root>
  23. </log4net>
  24.  
  25. </configuration>
some hints and tips to make your life easier:

Here is a pretty elegant way to obtain a logger with the category automatically set to the current class - (there is no equivalent to this in Java by the way - at least not for static fields)

  1. private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

The Logfile will be created next to the executable. Oh, and just in the case you did not know, you can use system envoronment variables in the App.config. For instance you could be foolish (or lazy if you prefer) and log directly onto the Windows system drive:

  1. <param name="File" value="${SystemDrive}\Debug.log" />

FlexCel Studio for .NET

If you are looking for a toolkit to generate Excel-Files using a pure .NET implementation of the Excel Fileformat - look no more. Head over to TMS Software and give FlexCel Studio a try.
End Of Line.

Using native SQL in nHibernate

Today I ran into a situation in a nHibernate based project where I needed to execute a very specialized query. Using HQL was rather not practical since I had to query tables which were not "directly" mapped to entities.

So, if you need execute queries behind nHibernate's back and map the results to a Bean / Object not specified in the mappings, You might come up with a solution like this:

  1. string someComplexQuery = @"select ... from ...";
  2.  
  3. IQuery sqlQuery =
  4. sessionFactory.GetCurrentSession().CreateSQLQuery(someComplexQuery).
  5. AddScalar("Id", NHibernateUtil.Int32).
  6. AddScalar("Firstname", NHibernateUtil.String).
  7. AddScalar("Lastname", NHibernateUtil.String).SetResultTransformer(
  8. Transformers.AliasToBean(typeof(Person)));
  9.  
  10. IList<Person> people = sqlQuery.List<Person>();
  11. foreach (Person person in people)
  12. {
  13. // ...
  14. }

For a good measure, here is the Person class:
  1. class Person
  2. {
  3. private long id;
  4. private string firstname;
  5. private string lastname;
  6.  
  7. public long Id
  8. {
  9. get { return id; }
  10. set { id = value; }
  11. }
  12.  
  13. public string Firstname
  14. {
  15. get { return firstname; }
  16. set { firstname = value; }
  17. }
  18.  
  19. public string Lastname
  20. {
  21. get { return lastname; }
  22. set { lastname = value; }
  23. }
  24. }

Works like a breeze, /me likes!

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

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:

Syndicate content