Post Code with Dignity

After finally getting really really fed up with Windows Live Writer about the way it tries to tidy up your HTML code I decided that I need to do something about it.

So I did, writing a Live Writer plugin is very easy and straight forward, so I did a plugin that will take your clipboard, replace typical things like < > through &lt; &gt; and replace every 2 spaces through 2 &nbsp;.
So make sure you are using a even number of spaces for source indentation in your IDE.

The plugin is far away from perfect, and I think I'll make it a bit more configurable tomorrow. I also think I'll put it up on Google code and maybe release it to the Windows Live Gallery.

They key? Windows Live Writer fucks up your markup no matter what you do. So I simply departet from posting pure text as a ContentSource, yet the plugin is treating HTML as a SmartContentSource that will appear as a block inside Windows Live Writer, saving it from it's catastrophic markup-killing html-tidy algorithm.

Update: I already released the source at CodePlex and you can get the most up to date binary from there:

CodePlex Project Page: http://www.codeplex.com/wlwPostCode

Installation:
Simply put the dll into your Live\Writer\Plugins directory and start WLV!
It will now show up in your Insert-List as Insert Code..

Btw: The Plugin assumes you are using the same syntax highlighting script as I do and will put your code into a <pre> tag.

Read more →

Exporting Data to CVS in ASP.NET

So, today I tried the ASP.NET Wiki that's currently in Beta and thought, best way to do so is to expand an article. I'll blog about my Wiki experience later, but for now I'd like to share my code on this one.

I started out with the Wiki Article Export to CSV file (revision 3) and thought on how to improve it.

As you may have noticed, the topic at hand is so simple, it doesn't really need improving, except for the main flaw where you have to specify all column headers in code.

My take on this was to use the DataBinder API from the System.Web.UI namespace and remove the whole HttpContext.Current stuff to an instance variable so it's easier to test the stuff and you can put it into a class library (if you want that).

Let's assume I have a list of type Person I want to write to CSV

public class Person
{
    public String Name
    { get; set; }
    public String Family
    { get; set; }
    public int Age
    { get; set; }
    public decimal Salary
    { get; set; }
}

Now here's the CVSExporter class that you just need to pass 3 things: Your List<Person>, your HttpContext.Current and a List<String> that specifies what columns you want printed out (eg. Name, Family).

public class CSVExporter
{
    public static void WriteToCSV(List<Object> dataList, HttpContext httpContext, List<String> columnNames)
    {
        InitializeHeaders(httpContext);

        WriteColumnNames(httpContext, columnNames);                  foreach (Object data in dataList)         {             WriteData(data, httpContext, columnNames);         }                  httpContext.Response.End(); //Everything has to end..     }

    private static void InitializeHeaders(HttpContext httpContext)     {         string attachment = "attachment; filename=PersonList.csv";         httpContext.Response.Clear();         httpContext.Response.ClearHeaders();         httpContext.Response.ClearContent();         httpContext.Response.AddHeader("content-disposition", attachment);         httpContext.Response.ContentType = "text/csv";         httpContext.Response.AddHeader("Pragma", "public");     }

    private static void WriteData(Object data, HttpContext httpContext, List<String> columnNames)     {         StringBuilder stringBuilder = new StringBuilder();         foreach (String column in columnNames)         {             AddComma(                 System.Web.UI.DataBinder.Eval(data, column).ToString(),                 stringBuilder);         }         httpContext.Response.Write(stringBuilder.ToString());         httpContext.Response.Write(Environment.NewLine);     }

    private static void AddComma(string value, StringBuilder stringBuilder)     {         stringBuilder.AppendFormat("{0}, ", value.Replace(',', ' '));     }

    private static void WriteColumnNames(HttpContext httpContext, List<String> columnNames)     {         StringBuilder stringBuilder = new StringBuilder();         foreach (String column in columnNames)         {             stringBuilder.AppendFormat("{0}, ", column);         }         httpContext.Response.Write(stringBuilder.ToString());         httpContext.Response.Write(Environment.NewLine);     }

}

So that's it for now. I guess there is still room for improvement, and if you need performance you should go with the original solution, DataBinder.Eval does some type-casting internally so it won't run at lightning speeds, but you get the idea of what can be done with the DataBinder control :).

And now I'm off to writing a Windows Live Writer Plugin that will allow me to paste longer code without jumping through loops like a madman (I posted the code in my Wordpress admin-gui because doing it from wlv simply didn't work!)

Read more →

Am I an island?

Due to the fact that most of university of klagenfurt's curriculum is biased towards Java sometimes makes it hard for a .NET developer to be able to go up to someone and say: "Hey, look what I did yesterday".
Either you just ran into one of those guys who just managed to get the last proprietary driver off his debian-unstable laptop and will chase you down some hallway by even saying the word Microsoft near his ears.
Or you will meet some insensible guy who's not into the study at all but decided that doing computer science after high-school is the right thing because he used to be playing computer a lot (people around here often use their studies as an excuse for not wanting to do real work).
Or there is that honest guy who just focuses on his studies and therefore is stuck in a world of Java :).

So, sometimes I read all those blogs out there from overseas about communities, ALT.NET, open spaces conferences and stuff, and start to feel a little lonely around here in carinthia.
I mean, there are plenty of people I really love to talk about tech, I even sometimes try bend my mind around to talk to some of the hardcore Linux guys around here. But there is nobody to whom I can talk about what I am up to lately (in .NET), nobody who is actually working with .NET (besides me) that I can call up to ask for advice on ... let's say WPF.

So today I decided to throw the words usergroup and Klagenfurt at my Google and I somehow ended up at ineta.org, short for International .NET Association.
After doing their usergroup search for Austria I found out that there ought to be two groups here around Klagenfurt university. Both of which seem to have disbanded (websites down etc).
Now what really struck me was that even the back of beyond (namely Vorarlberg) has a .NET user group, while Vienna and Graz having plenty of them.
Didn't they tell me when I signed up for my study that Klagenfurt is one of the major universities when it comes to computer science?
And now I'd like to know, if Klagenfurt is that good, why we can't have a .NET user group.

So is there an audience for a .NET user group in Klagenfurt? Or do I need to pony up the 60 euros per month for a bus ride and go to Graz if I want to meet like-minded people?
So it boils down to the initial question: Am I an .NET island?

Read more →

Major site rehaul

wordpress

After doing yesterday's post on CruiseControl.NET it bit me that I really really needed a new theme for my blog. Posting sourcecode on a constrained surface doesn't really work, and after seeing the XML posted yesterday I decided I need to do something about it.

So I went to themes.wordpress.net and found the theme you are currently looking at. It's nothing really special, but I like the clean look and it has no fixed width. The theme came with no widget support so I followed this handy guide and hacked them into the theme myself. It really isn't that hard after all, although I found this php-html mix quite disturbing.

After being done with the new design, I decided that source is horribly unreadable, and I'm not really happy with my previous solution of doing screenshots (not indexable, not copyable). So I found this really cool JavaScript library by Alex Gorbatchev called SyntaxHighlighter that highlights <pre> tags and adds some very nice formatting to your code.
Here's an example:

static class Program
  
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }


And while being at it I also updated to the most current version of WordPress. So if you encounter any oddities (especially with the feed), please tell me about it so I can fix it.

Oh and by the way, while being at it I installed iWPhone so that any user who visits http://tigraine.at with an iPhone or iPod touch will get a stripped down site without too much clutter that's been optimized for the iPhone resolution. Images get removed from the front-page but everything still looks cool. :)

Read more →

Setting up Cruise Control .NET

logo

Wow, what a day! After starting a new project today (I'll discuss that in another post) I decided that it is time to get serious with source control and continous integration. This time I thought I'd skip the java stuff and pass on JetBrains Teamcity, and instead went for the SourceControl.NET by ThoughtWorks that I heard of on Hanselminutes.

First things first: I am totally stunned of how great this has turned out. If you don't have a CI server yet, go get yourself one immediately. Even if you are programming by yourself, having someone run the build process and all unit tests for you never hurts and will save you time in the long run. Set-up of CruiseControl and the whole stuff was quite time-consuming (meaning 3 hours), but doing it on another project now really is a piece of cake, once you're done it feels quite natural.

So, to get started you should set up Subversion by simply installing VisualSVN, the server is running in less than 30 seconds, your users and repositories are in place after a mere minute. I can't think of any easier way to install Subversion, kudos to the VisualSVN team!

Now, this isn't quite standard, but really helps: Create a file called svn.bat in your C:\WINDOWS\system32\ folder with the following content:

@echo off
"C:\Programme\VisualSVN Server\bin\svn.exe" %*
Cool huh? Now you've got svn in your %PATH% without having to edit the variable itself. This will save you some time on the CCnet configuration.

The next thing was to install the newest CCnet version, and here I suggest you get the latest and hottest stuff directly from the svn. I ran into some troubles with some msbuild reports in version 1.3. Updating to 1.4 worked wonders.

Now that everything is set up (you can now access the WebDashboard through the http://<yourserver>/ccnet/ url), you need to get the whole thing configured. (The only painful thing in this installation).

A good starting point is the documentation that explains almost everything.

I won't go through everything in the ccnet.config file, just some things I want to point out:

  • Make sure to either run the latest CCnet build or use the doc that came with your binaries. New not used settings will stop the server from running.
  • While testing your build process go ahead and try to run the same commands from a shell. Especially with msbuild it took some time to sort out the quirks :)
  • Don't forget to blindly incorporate the whole list of <publishers>. I can't think of a scenario where I don't want almost all of those running, and if you skip some (like xmllogger and statistics) you will get some broken links on your dashboard.
  • VisualSVN sets up a https server. CCnet runs svn with the --non-interactive switch, so it will quietly break due to a unsigned SSL certificate. To bypass this simply run a svn list <repo> from a shell and accept the certificate permanently. And make sure the CCnet service is running under your login credentials, svn stores the certificate setting per user.
So, enough wisdom from my part on CCnet. I really had a blast in setting it up, and I can only recommend it. After the break I've postet my ccnet.config if you want to have a look.

<cruisecontrol>
      <project name="Valet">
        <workingDirectory>valet/WorkingDirectory</workingDirectory>
        <artifactDirectory>valet/ArtifactDirectory</artifactDirectory>
        <webURL>http://plato/ccnet/server/local/project/Valet/ViewProjectReport.aspx</webURL>
        <modificationDelaySeconds>10</modificationDelaySeconds>
        <sourcecontrol type="svn">
            <trunkUrl>https://plato:8443/svn/valet/trunk/</trunkUrl>
            <username>ccnet</username>
            <password>xEs6S-uW</password>
            <autoGetSource>true</autoGetSource>
            <!--<tagOnSuccess>true</tagOnSuccess>-->
        </sourcecontrol>
        <state type="state" />
        <labeller type="defaultlabeller">
            <prefix>Valet-alpha-0.</prefix>
            <incrementOnFailure>false</incrementOnFailure>
        </labeller>
        <triggers>
          <intervalTrigger name="continuous" seconds="30" />
        </triggers>
        <tasks>
            <msbuild>
              <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
              <projectFile>Valet.sln</projectFile>
              <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
              <targets>Build</targets>
              <timeout>900</timeout>
              <logger>C:\Programme\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
            </msbuild>
            <nunit path="C:\Programme\NUnit 2.4.7\bin\nunit-console.exe">
                <assemblies>
                  <assembly>C:\Programme\CruiseControl.NET\server\valet\WorkingDirectory\ValetServerTest\bin\Debug\ValetServerTest.dll</assembly>
                </assemblies>
            </nunit>
        </tasks>
        <publishers>
          <xmllogger />
          <statistics />
          <modificationHistory  onlyLogWhenChangesFound="true" />
          <rss/>
          <modificationWriter />
        </publishers>
    </project>
</cruisecontrol>
Man, I hate my blog theme. I need to get this thing wider sometimes soon!

Read more →

Disabling del.icio.us on the feed?

delicious I have been using feedburner for a pretty long time now, and one thing I thought is particularly handy is that you can let it incorporate your del.icio.us bookmarks into the feed as daily updates.
This removed the necessity of doing a blog post every week that boils down to a link-collection of the most interesting stuff I read across the web that week.

So the main thing is that due to the great Firefox3 Addon for del.icio.us I started to use del.icio.us more and more as a bookmark tool, so that I am "polluting" my feed with sometimes unnecessary stuff that you may or may not be interested in. This has led to the fact that sometimes there are 3-4 link flares from del.icio.us in between 2 of my blog posts.

So this is one question to my dear feed-subscribers: Should I remove my del.icio.us link splicer from my feed?

Ps: By the way, if you are using del.icio.us too and want to add me to your network feel free to do so through my profile, oh, and if you aren't already subscribed to the feed. You can find it easily to the right or through this link.

Read more →

Working till late...

The weather has been pretty great the last days, and I used the last weekend for some relaxing and even some bathing in Wörthersee.
I also discovered my new favorite relax location (although it doesn't serve coffee) and I also managed to make some photos (click the image for the flickr photo gallery):

Unterkreuth

But after coming home today (chilled to the bone, Wörthersee is still way too cold for bathing!), I figured out I need to do an java assignment for university till Tuesday.

Needless to say that I thought I'd be done in 2 hours doing some simple hash table implementations.
What happened? They managed to throw 10 pages of mostly meaningless gibberish that specifies how my classes should behave and how the underlying algorithms work. While detailed instructions isn't something bad per se, omitting the UML diagram IS BAD! After going through the doc 2-3 times I still haven't identified all of the "added complexity" that should be teaching us OO-design and am searching the course forums for answers to questions that aren't answered by a 10 page long assignment paper :(.

So, yeah: I started at 21:00 and now it's 3 in the morning and my concentration has hit rock bottom so I am reading through specs and their explanation without being able to see the sense in it.

If you can't remember what word preceded the one you just read - go to bed.

And while we're at it. If you bother with Visual Paradigm: Get yourself a real-edition. Doing everything twice (in code and in UML) really sucks. Especially since code stubs can be exactly derived from UML and vice-versa it sucks doing it in a so terribly clumsy tool as Visual Paradigm for UML. (VP works great, it's just a lengthy process to create a damn operation (public void main(String args[]) is easier to type than to click 30 check boxes and drop downs!)

Read more →

Quote of the Day: On PHP

If you are following Jeff Atwood at CodeHorror.com you may have already read it. But the statement is so true I really need to repost this quote by Tim Bray:

So here's my problem, based on my limited experience with PHP (deploying a couple of free apps to do this and that, and debugging a site for a non-technical friend here and there): all the PHP code I've seen in that experience has been messy, unmaintainable crap. Spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML, replicated in slightly-varying form in dozens of places.

Spaghetti-code is the main thing that always comes to my mind when I try to sit down and do a template for this website.

Read more →

Klagenfurt University could use a Campus

Don't get me wrong, I love studying at Klagenfurt University, but whenever the weather gets more and more appealing I start dreaming of some cool cafe's and other stuff on the university campus.

Currently the only café that is really located inside the university is the iQ. And that's ok, but the university is lacking more open space. Maybe you get what I mean by this picture.

university (click to enlarge picture)

The red area is university property, while the yellow stuff is parking and the blue stuff is streets (with parking).

What happens is that whenever you step outside the building after 10 meters or so you happen to either reach a parking lot or a street.
If you follow this geo-link you might find that there is plenty of green around the university, but when you are there the perception is that there is only cars :).

So here it comes, cut down some roads and open up the area. Remove the front parking (eastern parking lot) and make it a nice little park for students. Also I'd like to see the road in the east closed down and some nice cafés opened up. Giving so much space to parking is just a waste.

On the parking side: Before you can get anywhere near planning a cooler campus we need to get public transport in Klagenfurt up to speed. There should be a frequent shuttle bus from the nearby train station that may also take students to the Wörthersee in summer, so more people would consider the train a viable alternative to the car. The STW bus should come every 15 minutes at least, having 2 buses per hour is simply unacceptable.

Klagenfurt university may be one of the few universities in Austria that isn't directly located inside the city so you could make something out of the place without having to redesign transportation for a whole city. But as it's currently more space is wasted than really used. It all feels too small and not really comfortable.

Read more →

Windows Live SkyDrive could be smarter

image

Skydrive, one of the cooler things Microsoft released lately under their Live.com brand has somehow replaced my private FTP server for sharing files with myself and others.

It's cool, it's easy and it's free. You get 5 gigs of free storage with your Live.com Id that you can use to upload data to the cloud.
You then get a quite neat folder view online where you can download those files, set their permissions etc.
So, if I want to share some files with a friend I can add them to the folder's permission list and they can see them with their Live.com Ids. If anyone should be able to see something I just add it to my globally shared folder.

So, whenever I need data at university I just upload it to SkyDrive instead of emailing it to myself as I used to do. It's usually just boring university assignments but after a few weeks things start to get messy. I started out by creating one folder for every course, not dividing up into assignments. So now I have 20 files in my dbtec course folder, all called "Dbt_AssX.doc" accompanied by some .sql and .txt files.

I then tried to correct that mistake, created a new folder to split up stuff, and - voila, there is no way to move a file from folder a to folder b! That sucks!
I was already concerned about the missing API (uploading stuff through the browser isn't cool!), but being unable to move stuff around is quite annoying.

If we're at it, I'd really appreciate some sort of slightly more accessible UI. Deleting a folder isn't as easy as clicking the folder and hitting delete, no, you need to click the folder, access it's properties through clicking on it's name and then pressing delete.

Read more →