Kevin Mees

i write code at Experts Inside

7DRL 2012 - Challenge Accepted

Permalink

From March 10th to March 18th, this years Seven Day Roguelike Challenge takes place. The goal of the challenge is to create a roguelike game in, well, seven days. I actually tried to participate in last years challenge, but due to a car accident about a week before the challenge, I wasn’t really able to focus on it. Hopefully, this years challenge runs smoothly for me such that I can get a game finished.

I will try to blog about my progress on each of the seven days if I can manage to find some spare time. I’m also thinking about streaming/recording the development process but I don’t know if I can get everything set up in time. In any case, the project will of course be hosted on github !

NuGet Aside for Octopress

Permalink

I just finished as aside for Octopress that list the Top N downloaded packages where you are an author. It also adds a link to your NuGet gallery profile if you have one. The style is basically the same as the style of the github aside.

Since there is no official way to publish 3rd party add-ons for Octopress yet, I created a github repository with the required files and setup instructions in the ReadMe.

CMContrib WPF Demo Goin’ Metro

Permalink

Inspired by the DownmarkerWPF, I decided to change the Style of the CMContrib WPF Demo to Metro. I used the same Metro framework, namely MahApps.Metro as DownmarkerWPF which is really cool. The only control that I wasn’t able to ‘metroize’ was the WebBrowser control which displays the code. Its scrollbars still have the old Windows look. Another small letdown is that there is no free Pivot control available for WPF but it was quite easy to create a simplified version of it which was sufficient for my needs.

Anyway, I’m quite happy with the result especially since this is my first Metro app. Any feedback is appreciated !

Context-Based Views for Dialogs

Permalink

Retrospect

In my CMContrib Project I use a MVVM approach for showing dialogs to the user. The model for the dialog has a dialog type (Question, Error,…), a subject (or title), a message and a list of possible responses the user can choose from. The default response in CMContrib is an Answer enum with values for Ok, Cancel, Yes and all the other standard answers but you can also use a complex type as a response.

Here’s an example of how to ask the user a question and cancel the coroutine when the user responses with No.

1
2
3
4
5
6
7
8
9
10
11
12
public override IEnumerable<IResult> AskAQuestion()
{
    var question = new Question("The Subject",
        "The Message",
        Answer.Yes,
        Answer.No);

    yield return question.AsResult()
        .CancelOnResponse(Answer.No);

    // ...
}

Migration to Octopress

Permalink

I am currently migrating my blog from Wordpress to Octopress. The main reason for the migration is the awful (at least for coding blogs) post editor in Wordpress. With the migration I can write the posts in Markdown and Vim which, hopefully, leads to more posts !

And because Octopress is new and shiny and geeky !

MVVM Dialogs With Caliburn.Micro

Permalink

Background

In every applications life there comes a time when you need to show some kind of message to the user. Be it a question whether he really wants to delete something or a simple message that says that some operation was successful. The most simple way to do that is the good ol’ MessageBox.Show() with its zillion overloads.

1
MessageBox.Show("Foo", "Bar", MessageBoxButton.OKCancel);

But in the shiny MVVM World , polluting your ViewModels with MessageBoxes is usually frowned upon since it breaks a lot of stuff, especially automated unit testing and theming.

You can find quite a lot solutions about how the MVVMize MesasgeBoxes and dialog screens in general. Most of them involve wrapping the MessageBox.Show() in some kind of IService, setting up some kind of event infrastructure and other funky stuff. Surprisingly, all of those solutions completely ignore the first M in MVVM, namely the Model, and none really tackles the problem at its heart.

Handling Errors in Caliburn.Micro’s IResult - Part II

Permalink

Preface

In my last post I gave two possible approaches and a preview of my final solution for handling errors in IResults. The syntax for my final solution was

1
2
3
yield return new ProcessDataResult()
        .Rescue().With(coroutine: IORescue)
        .Rescue().With(coroutine: GeneralRescue);

This means that

  • whenever the result completes with an error of type IOException, the IORescue coroutine is executed
  • whenever the result completes with any other error, the GeneralRescue coroutine is executed

So the behaviour of the Rescue is similar to a try/catch block

1
2
3
try {}
catch (IOException e) { //IORescue }
catch (Exception e) { //GeneralRescue }

Handling Errors in Caliburn.Micro’s IResult - Part I

Permalink

The Problem

One of Caliburn.Micro’s nicest feature is, hands down, the concept of Actions. In that concept the IResult plays an important role, especially when using Coroutines. If you don’t know about them, you should definately read up on them here first.

So, let’s assume we are executing a Coroutine which does the following:

  • show a loading screen to the user,
  • start processing a lot of data
  • hide the loading screen once the processing is finished.

Since the processing is also likely to fail for whatever reason we want to handle the error by executing a Rescue Coroutine.

Pseudo Coroutine
1
2
3
4
5
6
7
8
public IEnumerable ProcessData()
{
    yield return new BusyResult("Processing...");

    yield return new ProcessDataResult();

    yield return new NotBusyResult();
}

The implementation of those results is irrelevant since we want to have a look at how we can handle the error during the processing in a nice (reusable) way.