Please allow me to introduce myself…

Tags:
1 Comment »

… I’m a man of wealth and taste. (Stones)

Yes, I am the new kid on the blog. Thanks to Benjamin for the first introduction. To introduce myself I tried to write a short version of my ‘computational biography’, but I ended up writing pages. If you really would like to read it, you will find the whole story here soon – with all comments and debug symbols. Now here is the compilied version:

Aged 33, I am living in the beautilful city of DĂĽsseldorf (near Cologne) with my wonderful girl Grace. Thanks to my father I started programming 25years ago and couldn’t stop. In school I liked mathematics and languages, which was a strange but unique combination. Consequently (meaning ‘through wild twists in my personal life’ 🙂 ) I became a student of linguistics and quickly came to the field of computational linguistics. I graduated and after some more turbulences I started working for a nice company in Cologne. That’s where I first met Benjamin: The company was working on “java to .NET”-thing, Ben had already done the difficult tasks and I should type in some simple wrappings. I had learned C# like a week ago and felt dump like sh*t.
But I had time to improve and two year later we did the coolest project my working life so far: A converter from C#-Code to a special kind of process diagrams. I still like that tool a lot and realising it involved some of my major fields of interest like building parsers and pushing around graphs.
Since mid of 2006 I am a freelancer and currently I am working for a big German retail and logistics company.

I am interested in almost any subjects related to computers, except networking stuff :-). I am attracted most to games (boardgames as well, especially chess) and gaming theory, parsing, solving problems using graphs and .NET (of course).

My personal main task for 2008 is to lose some significant amounts of weight. I am not a fat guy, but during the last couple of years I gained the typical IT-belly.

I’ll come up soon with a nifty little post about comparing numbers. Stay tuned!

First steps on aspect oriented programming

Tags: , , ,
No Comments »

Since I saw the first implementation of aspect oriented programming (AOP) frameworks for java I became a fan of AOP but it took a long time till now before I could start using AOP in my projects. The main reason was that simply no good and easy to use AOP framework for .net existed. There was one research project but you weren’t allowed to use their utilities in project other then research projects.
But a few weeks ago I discovered PostSharp and it is really great and very simple. If you have no idea what’s all about AOP you should read the Wikipedia article or the start page of the PostSharp project. There you find a short example showing the usage of an aspect in C# code.
I also want to show you my first experience with some aspect oriented programming.

First: the problem I want to address
I sounds very simple: I’ve got a base-class and some sub-classes. All provide a method GetName(). All sub-classes within the same type should return the same name that is given at compile time. It’s just a const string for each class. The following code addresses these needs in a straight forward way:

class BaseClass

{

    public virtual string GetName()

    {

        return “-“;

    }

}

 

class ClassA : BaseClass

{

    public override string GetName()

    {

        return “A”;

    }

}

 

class ClassB : BaseClass

{

    public override string GetName()

    {

        return “b”;

    }

}

Second: what I don’t like with this solution
This seems good, but I’ve got some more special needs. All classes are generated by the DSL Tools that means they contain much other code and no line written by me. In my use case these classes are shape-objects.
Thanks to the partial keyword in C# I could extend every class within its own .cs-file, but I didn’t like this. It would mean I have to create many additional .cs-files only for providing a single string to the class. But all other definition is stored in the DSL-model described by the DSL Tools and some part of the shape declaration is located in the .cs-files.
In the DSL-model I can provide each class with a custom attribute, so I’m looking for a solution with no additional code in the sub-classes besides a custom attribute.
With the use of reflection it could be the following:

class NameTextAttribute : Attribute

{

    public NameTextAttribute(string name)

    {

        this.Name = name;

    }

 

    public string Name { get; set; }

}

 

class BaseClass

{

    private string name = null;

 

    public virtual string GetName()

    {

        if (name == null)

        {

            object[] a = this.GetType().GetCustomAttributes(

                            typeof(NameTextAttribute),

                            true);

 

            if (a.Length > 0)

                name = ((NameTextAttribute)a[0]).Name;

            else

                name = “-“;

        }

 

        return name;

    }

}

 

[NameTextAttribute(“A”)]

class ClassA : BaseClass {}

 

[NameTextAttribute(“b”)]

class ClassB : BaseClass {}

This is working and as you see, no additional code is needed in the sub-classes. But nevertheless I would like to avoid using reflection. Reflection seems to me inappropriate in this case.

Third: Using AOP
The idea of AOP is to add code to the class that you can write in another position, in the aspect. The aspect weaver (in my case the PostSharp Laos library) adds this code on compiletime (not runtime!) to the class.
My strategy is to add some code after the constructor execution that will initialize the name-property:

class BaseClass

{

    public virtual string Name { get; internal set; }

 

    public virtual string GetName()

    {

        return this.Name;

    }

}

 

[NameAspect(“a”)]

class ClassA : BaseClass

{

    public void someMethodInA()   { }

}

 

[NameAspect(“b”)]

class ClassB : BaseClass {}

 

[Serializable]

class NameAspect : OnMethodBoundaryAspect

{

    private string name = “-“;

    public NameAspect(string name)

    {

        this.name = name;

    }

 

    override bool CompileTimeValidate(MethodBase m)

    {

        return m.IsConstructor;

    }

 

    override void OnSuccess(MethodExecutionEventArgs args)

    {

        BaseClass obj = args.Instance as BaseClass;

        if (obj != null)

            obj.Name = name;

    }

}

The base-class now provides a property name (declared with the new C# 3.0 syntax) and the GetName() method returning the property value. As in the last example the sub-classes have the attribute declared and contain no other code.
The magic happens in the attribute (or, if you like, somewhere in the PostSharp.dll). It is derived from OnMethodBoundaryAspect, an aspect base type where I can add code to a method in another class before and after the method call and on exception and on success of the method call.
My constructor of this aspect gets only the name string and stores it in a variable.
The code that should be executed every time a constructor of a class with this aspect is calls can be find in the OnSuccess()-method. Here only the property of the BaseClass will be set.
With the CompileTimeValidate()-method I can specify at compiletime for witch methods the code should be injected. For my needs this is only the constructor. All other methods of my class will not be changes by this aspect.

Fourth: behind the scene
With adding the PostSharp references to my project the PostSharp postcompiler is called automatically after compiling my assembly and the code is added. If you take a look with the Reflector you will see the following:

class ClassA : BaseClass

{

    static ClassA()

    {

        if (!~PostSharp~Laos~Implementation.initialized)

            LaosNotInitializedException.Throw();

        ~PostSharp~Laos~Implementation.~targetMethod~3 =

                methodof(ClassA..ctor);

        ~PostSharp~Laos~Implementation.NameAspect~3.RuntimeInitialize

                (~PostSharp~Laos~Implementation.~targetMethod~3);

    }

 

    public ClassA()

    {

        MethodExecutionEventArgs ~laosEventArgs~1;

        try

        {

            ~laosEventArgs~1 = new MethodExecutionEventArgs(

                    methodof(ClassA..ctor, ClassA), this, null);

            ~PostSharp~Laos~Implementation.NameAspect~3.OnEntry(~laosEventArgs~1);

            if (~laosEventArgs~1.FlowBehavior != FlowBehavior.Return)

                ~PostSharp~Laos~Implementation.NameAspect~3.OnSuccess(~laosEventArgs~1);

        }

        catch (Exception ~exception~0)

        {

            ~laosEventArgs~1.Exception = ~exception~0;

            ~PostSharp~Laos~Implementation.NameAspect~3.OnException(~laosEventArgs~1);

            switch (~laosEventArgs~1.FlowBehavior)

            {

                case FlowBehavior.Continue:

                case FlowBehavior.Return:

                    return;

            }

            throw;

        }

        finally

        {

            ~PostSharp~Laos~Implementation.NameAspect~3.OnExit(~laosEventArgs~1);

        }

    }

 

    public void someMethodInA() {}

}

I really don’t know what’s that all about but I can see that there is code added only to the constructor, someMethed() is empty as in my given source code.

In the next weeks I will try to cover more examples and solutions with PostSharp and AOP.

GPS Logger Wintec G-Rays 2 and GPS Babel

Tags: , ,
1 Comment »

Previously I wrote about geotagging and my photo tagging software PhotoTagStudio has build in support to tag photos with GPS coordinates from nmea files. I used to generate these nmea log files with a Windows CE PDA and imported the log files into my photos with PhotoTagStudio.

Now I bought a small GPS receiver with a build in datalogger. It’s named Wintec G-Rays 2 or WBT-201. And by the way: it is a great idea giving one product one or more name nobody can remember. For some reason Apple products always have only one name everybody can always remember. Back to my new WBT-201: it is very small, cost about 100 €, has a build in rechargeable battery and can be used as an ordinary Bluetooth GPS receiver. But besides this it can act as a GPS logger and store up to 130000 GPS positions.
I bought this device only for logging and combining these data with photos using PhotoTagStudio.

The software for configuring and getting the logged data is called Time Machine X and looks and acts like crap. It looks like written by an amateur programmer using Visual Basic 3 on Windows 3.11. But you need this software to configure the logger. I set it to capture every 2 seconds the position. That’s it. To use the logger you need only turn the power on and it’s working. With the track button you can record some waypoints at the given position but I didn’t use this feature.

To read the logs you can use Time Machine X, but I don’t like it and you cannot script this application. An alternative is the open source software GPS Babel. GPS Babel can read and write nearly every GPS related file format. So you can read the data directly from a serial COM port (this can be the USB or a Bluetooth connection to the WBT) and write it as a nmea file.

The following command reads from COM10 (this is a Bluetooth serial port an my computer) and writes a nmea file named out.nmea:
gpsbabel.exe -t -w -i wbt -f com10 -o nmea -F out.nmea

To delete the logged date from the WBT device you can use the following command:
gpsbabel.exe -t -w -i wbt,erase -f com10 -o nmea -F out.nmea

The -t parameter reads the whole logged track and the -w parameter reads the recorded waypoints.
The output file can be read by PhotoTagStudio v.6.2 and above and other software that is capable of reading nmea files. Or you can use GPS Babel to create files with other formats. For example kml files for Google Earth and Google Maps.

Now is only one thing missing: a display device for the GPS date and status when I am not caring my PDA or notebook with me. In will write another article where I will show how to use a mobile phone to display the data of a Bluetooth GPS receiver.

Something going on in 2008

Tags:
No Comments »

I started this blog in November 2006 as a secondary blog besides my private Livejournal and didn’t know where it was going. I posted a few random links and news stories from the web and later some technical articles.

In the past year I posted more and more (but not on a regular basis) technical articles. Technical article means something I discovered or learned while working with computers, windows, programming and thing like that. Now I will turn this blog in a real tech blog.

First we changed the name: now this blog is called “Ticklish Techs – a mostly .NET but also some other cool techs blogâ€? and the name is pretty much a vague description of the upcoming content. Every time I have something to say about computers, software, programming (especially .NET) I will blog it here. And I will try to do this on a regular basis.

And of cause with a new name the blog needs a new domain: www.ticklishtechs.net

The second news: I have to introduce my new co writer: Wolfram. He’s a colleague and friend of mine from Düssledorf, Germany. We used to work together for different clients and still work on our private projects together. From my point of view he is one of the top 20 percent programmers I know. The first time he appeared here in September last year on an article regarding the Win32 shell. He will start to write more articles worth reading here soon.
I think 2008 will be interesting for us and this blog. Let’s see what’s coming. As a small outlook I will write some more articles on GPS and NMEA the next days and when I begin to work on my diploma thesis the next month I will certainly write some articles about Visual Studio 2008 (Orcas) Extensibility (VSX) and the DSL tools.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in