CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

January 2007 - Posts

  • The page life-cycle is not just hard for developers

    A recent post by Karl on the page_load event again mentioned how hard it is to fully understand the life cycle of an asp.net page. In a comment Fregas even mentions switching to PHP (or RoR) to get a better grip on it. IMHO this is running away from the core of the problem which is (still imho) the web itself. Every web page is by definition an individual request; every sense of state is an illusion. Even when the platform or the developer using it is good; it's no problem for an average user to ruin every experience.

    Ways to ruin I daily have to observe at home:

    • Use the back button of the browser. Smartnavigation or no smartnavigation it's very hard for a web app to handle this right.
    • Open the page in a new window.
    • Re-open the page via the favorites.

    As a result:

    • Forms filled in are blanked again
    • Shopping baskets are emptied
    • Shopping baskets containing all items twice (or more)

    I guess you will recognize this. Trying to help and explain I find there is only one satisfying answer: understand the life cycle of a web-page. Which is beyond the level of any non-technical user.

  • Iso Images and Vista

    More and more software is rolled out in the form of an ISO image. You can do two things with these: mount them in a virtual drive or burn them to (re-)writable disk. Both options were cumbersome and still are under Vista.

    A lot of DVD burning packages, like the popular Nero, support both options. I have a great dislike for software like Nero. It takes longer to download than a Vista RTM and the major part of the download consist of extra crapware which usually ruins your system configuration. Besides that many a virtual drive does not support the format of the iso's distributed. MS CTP's are notorious for this. I used to be a big fan of Daemon tools, a freeware tool which have saved my day on several occasions. Now there is a DT version for Vista as well. Looks like freeware but it is spyware. Not until the setup you are informed it will also install some adware. Do you always read EULA's ? Or just click next, next, finish ? Bad, bad, bad. End of confidence, end of my recommendation for Daemon Tools.

    So now I'm burning all images to disk. Using a rewritable to limit the amount of junk my office produces. A great tool is isoRecorder. It is a very nifty tool. After installing you only need to right click an iso image file to burn it to disk. Works like a charm. But to burn a disk you always have to start with an iso file. The second part of the isoRecorder package is an extra option in the folder context menu (right click) which should create an iso file out of the folder's content. Should, in my experience this part of isoRecorder always crashes. Both the Vista and the xp version, the latter with the notorious 80004005 error. I don't know why and I can't find anything on the web.

    So when I want to archive things I need a simple program to create the ISO file. Finding one took some time. There are loads and loads of packages around but they are either filled with ad-ware or are limited to a maximum of 300mb while evaluating. Finally I found something nice. Finalburner looks and works just fine.

    Simple and honest package and really free. The only ads are the ones for their pro packages.

  • The outlook calendar, iCalendar and RFC 2445

    You can exchange Outlook appointments with other applications. One way is to export or import files in the iCalendar format. In the formats supported by Outlook you will also find the vCalendar format, iCalendar is basically a newer version of this one. The iCalendar specs are based on RFC2445, it is supported by several manufacturers and can be used to interchange appointment data with non Outlook users as well.

    In my case I have an applet which generates a list of appointments which are to be imported by an Outlook user. Getting this to work was a little more complicated than it looked due to the somewhat cryptical language of an RFC, contradicting sources on the web and different behavior of Outlook versions. Let me share what I found.

    The applet will produce a text file with an ics extension containing. The appointments are fed from a dataset, where each row describes an appointment. The contents of the file are constructed using a stringbuilder.

    public class IcalMaker

    {

    private StringBuilder sb;

    private string uid;

    public string MakeCalender(IcalActiviteiten acts, bool reminders)

    {

    sb = new StringBuilder();

    uid = Guid.NewGuid().ToString();

    sb.AppendLine("BEGIN:VCALENDAR");

    sb.AppendLine("PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN");

    sb.AppendLine("VERSION:2.0");

    sb.AppendLine("METHOD:PUBLISH");

    for (int i=0; i < acts.IcalActiviteit.Count; i++)

    addEvent(acts.IcalActiviteitIdea, i, reminders);

    sb.AppendLine("END:VCALENDAR");

    return sb.ToString();

    }

    The code sets up the stringbuilder, an unique id, the opening lines and starts looping through the appointments.

    Building these has a little quirk, although the code itself is very straightforward. Each event is enclosed in a BEGIN and an END line.

    private void addEvent(IcalActiviteiten.IcalActiviteitRow act, int id, bool reminder)

    {

    sb.AppendLine("BEGIN:VEVENT");

    sb.AppendLine(string.Format("DTSTART:{0:yyyyMMdd}T{1:hhmmss}", act.Datum, act.Aanvang));

    sb.AppendLine(string.Format("DTEND:{0:yyyyMMdd}T{1:hhmmss}", act.Datum, act.Einde));

    sb.AppendLine(string.Format("LOCATION:{0}", act.Zaal));

    sb.AppendLine(string.Format("TRANSP:OPAQUE"));

    sb.AppendLine(string.Format("SEQUENCE:0"));

    sb.AppendLine(string.Format("UID:{0}-{1}", uid, id));

    sb.AppendLine(string.Format("DTSTAMP:{0:yyyyMMdd}T{0:hhmmss}", act.Datum));

    sb.AppendLine(string.Format("CATEGORIES:{0}", act.ActiviteitsNaam));

    sb.AppendLine(string.Format("DESCRIPTION:{0}", "Your description here");

    sb.AppendLine(string.Format("SUMMARY:{0}", act.ActiviteitsNaam));

    sb.AppendLine("PRIORITY:5");

    sb.AppendLine("X-MICROSOFT-CDO-IMPORTANCE:1");

    sb.AppendLine("CLASS:PUBLIC");

    if (reminder)

    {

    sb.AppendLine("BEGIN:VALARM");

    sb.AppendLine("TRIGGER:-PT15M");

    sb.AppendLine("ACTION:DISPLAY");

    sb.AppendLine("DESCRIPTION:Reminder");

    sb.AppendLine("END:VALARM");

    }

    sb.AppendLine("END:VEVENT");

    }

    The format and value of the event start (DTSTART) and end (DTEND) time needs special attention. Anyone who ever took their outlook data to a different time zone will have noticed all appointments moving in time when changing the time zone in Windows. Personally I find this frustrating, for instance when preparing for the PDC (in the Netherlands) I entered all sessions I didn't want to miss in my Outlook schedule. Having arrived in LA after adapting to the local culture Outlook wanted me to turn up in the middle of the night to hear Anders Hejlsberg speak. You can wake me up any time for such a presentation but I just known he won't be there. Outlook stores the times in UTC time and presents them using the actual time zone. Moving to another time zone, moves the appointments.

    When feeding Outlook from an external application this same problem pops up. My application, Syllabus plus scheduling software, has no notion of time zones at all; it just thinks local time. At first sight you could recalculate all times to UTC times. But then you have to be aware of the dates the offset from UTC changes, that is the date the environment changes to day-lights saving time. You will end up with quite complicated configuration settings in your app. According to RFC 2445 a time zone can be added to a timestamp. But in that case you have to set up a time zone administration in you app, not very compelling either.

    The good thing is that you can enter timestamps as so-called floating time, which indicates that the moment in time is determined by the local time zone. The bad thing is that Outlook 2000 does not support this, Outlook 2003 does and Outlook 2007 will bombard you with error messages telling it doesn't. To make things even more confusing I found my Outlook 2007 complaining about nothing, it does import all floating time events and does translate them quite right. For the moment I just have to tell my users to ignore the error message when using Outlook 2007.

    The difference between a floating time and an UTC time is one letter. This is an UTC time

    "DTSTART:{0:yyyyMMdd}T{1:hhmmss}Z"

    And this a floating time

    "DTSTART:{0:yyyyMMdd}T{1:hhmmss}"

    The UTC time has an extra Z.

    Another property which needs some explanation is UID, the unique ID. This is supposed to be unique for every event. In my case I generate a guid for the series and append the event's sequence. Outlook will not complain when the ID is not unique, but it is part of the spec.

    In case you want to add a reminder to the appointment add a VALARM. In the example this is hard coded at 15 minutes : TRIGGER:-PT15M

    Using this code I have all information Outlook needs in one string. A web app can write this directly to the response, following the minimal code to get that done.

    IcalMaker icm = new IcalMaker();

    IcalActiviteiten acts = getAppointmentData();

    Response.Clear();

    Response.ContentType = "application/binary";

    Response.AddHeader("Content-Disposition", "attachment;filename=YourAppointments.ics");

    Response.Write(icm.MakeCalender(acts, CheckBoxReminders.Checked));

    Response.Flush();

    Response.End();

    Adding the appointments to outlook is now a click away.

    That's it. I don't claim to understand all settings and fiddlings. But it works well; and that's enough for the moment.

  • Blog tag

    Sander tagged my blog; now it's my turn. Five things you (probably) don't know about me and maybe don't want to know either.

    1. Over the years I already introduced my sons Niek (1996), Cas (1998) and Mees (2000). Their mum, my wife Mirjam, so far escaped public chatter. She is the nightmare of any IT department; managing to blow up any application others have been using without a problem for months. She is also a marvelous usability tester; when she understands an app the majority of potential users will find their way. Don't get me wrong; she knows how to work with the regular Office apps but I never managed to explain her what a blog is. Never mind, there are more things to family life.
    2. My passion of cycling already reached the web in my CycleBetter blog. Recently I started running as well; this year's ambitions is to run the Groninger 4 mijl in a somewhat respectable time. I don't feel like a real sportsman at all; just need some compensation for all the desk work. And don't get me started on soccer; this country's most popular "sport".
    3. I started programming while studying biology. My main specialization was systematic zoology and evolutionary biology. My claim to fame was describing and publishing Tachysphex picnic, van Ooijen 1987. Which is a 10 mm sized digger wasp from Turkey.
    4. Over the years I did travel a lot of countries which taught me to put my life in a wider perspective. These days you can find loads and loads of global (musical) culture on the web. But nothing beats being there in person. My favorite, most fascinating country is India. The most remote place I visited was eastern Turkey at the foot of mount Ararat.
    5. In the Netherlands I've lived all over the country. Born in the west (Rotterdam), primary school in the South (Eindhoven), secondary school in the North (Drachten), university in the middle (Utrecht) and now quite happy in the North-East (Groningen). I even spent a year outside the Netherlands. My dad worked for Philips, when I was 11 we spent a year in Sussex England. I was dropped on an ordinary British school; quite a crash-course to learn English. Which helped me later when we moved to Drachten where the street language was Frisian. Without a passive knowledge you were an outsider. In every other country I visit since I try to pick up something of the local language. Nobody speaks Dutch.

    This should provide some fodder for casual chatter in case we meet in person. After all, that what the game of tag started about.

    Hereby I'm tagging:

    Warner Boekkooi living nextdoor

    Dennis Vroegop omnipresent in the Dutch .Net community

    Arie Leeuwensteijn Dutch MS evangelist

    Brendan Tompkins fellow CB blogger an Code/Cycle-better blog evangelist

    Jay Kimble fellow CB blogger making .NET evangelism into theology.

More Posts