Recent posts

A day and night at the NRW09 Conference in Germany

About 1,5 year ago I first met Daniel Fisher when he and two colleagues from NewTelligence, a German consultancy firm, hosted a full-day session on advanced .NET 3.0. During the breaks, we ended up talking about software factories and stayed in contact through MSN and email.

Since then, he started DevCoach, his own company, and became very active in the German .NET community through the Just Community initiative. In 2008, he and Stephan Oetzel organized their first full-day event, the NRW Conference, roughly comparable to our SDN events. Last year he invited me to do a talk in Wuppertal, but due to holiday conflicts I had to drop the opportunity. But this year, I did make it, and it was fun.

The event started on Thursday evening with a speakers dinner in Pöschkes, a local restaurant. Since I wanted to avoid the traffic, I left Rijswijk at around 14:00 and arrived at Wuppertal at around 17:00. I forgot how fun it was to drive the German autobahn where most of it still does not have any speed limit. Diner started not until 20:30, so that gave me some time to take a walk in the vicinity of the Ibis hotel, which by the way, was a simple but descent hotel. Unfortunately, it had no Wi-Fi and my phone's GPRS connection did not work either. I then went to the event location to meet the rest of the speakers, which appeared to be a rather unusual place. Instead of the typical conference center this event was held in a kind of cultural center/club named "Die Börse". Definitely an interesting place to hold an event for developers.

Dinner was excellent, but lasted a bit long and other than Daniel and Stephan it appeared to me that most Germans are a bit too reluctant to speaking English. Fortunately, I was sitting next to Sergey, who accompanied Daniel in the Netherlands, Lars Corneliussen, a very funny but loud German speaker, and Phil Winstanley, the only other non-German speaker. Although very young, he appeared to be a seasoned speaker and has been MVP for many years. The three of us enjoyed some interesting discussions throughout the entire evening and finished the night at around 01:00 with a final drink at the hotel's bar.

The next morning at 8:00 we all met at the venue to receive some drinking coupons and our speakers shirt. The first session started at 9:00 with a rather spectacular recap of last years edition and some encouraging words from the organization. Luckily I do understand German (although I don't speak it that well).

My session started at 11:10 and appeared to last only one hour instead of the usual 75 minutes. The session was held in the main room where the keynote was held, so it looked rather empty, even though there were about 35 people in it (of the 102 attendees in all four tracks). The talk ran fast and reasonable smooth, but at the end, nobody asked questions. However, I got a score of 1.7 on a scale between 1 (excellent) and 6 (aweful) so it is probably the language. Most Germans are not accustomed to speaking English even though I did not expect that from a developer community. Phil, who gave an excellent interactive talk on ASP.NET MVC versus WebFoms did not get any questions either.

I also attended Sergey's session on Orthogonal Architecture where he explained how you could apply the S.O.L.I.D. principles on an architectural level. I found that idea very interesting, so I just might ask Sergey whether I could use his slides to do this talk in the Netherlands. Since I had plenty of time to spare I also went to a talk on JQuery delivered by a German speaker I forgot his name off. I have not used JQuery yet, but I see why Microsoft decided to include it in the next version of ASP.NET. At around 18:30, after attending Phil's session and having dropped him off at the Dusseldorf airport, I finally drove back home.

You can view (or download) the slides below and download the source code of my demos from here.


Published: 01-09-2009 by Dennis Doomen | 0 Comments | 0 Links to this post
 

Keeping an eye on your visitors…

When we build an e-commerce site, our customers are really interested who is visiting and what they are doing. A free and really good option to get this kind of information is Google Analytics. Google Analytics gives you all the standard information like how many visitors per day, how many page views, the time spent, where visitors came from and which browser they used.

 Google Analytics Dashboard

But there is more: using the e-commerce, you can get reports on the amount visitors spent on your site and which products they spent it on. Interesting information but you can probably also get this from your ERP system.

But what your ERP probably cannot do is apply the e-commerce data to other data in Analytics, giving you information such as which percentage of my revenue is caused by visitors using Internet Explorer version 7.0, or how much revenue is caused by visitors originating from the Google search engine. You can get all of this information by placing a small piece of java script on all your pages.

Also interesting is that Analytics allows you to segment your visitors on all kinds of data. By default you get segments like new visitors, returning visitors and traffic coming from search sites. But you can also create your own. This way you can create a segment representing all the visitors that bought a specific product.

But wait, there is even more: using simple java script, you can also track all kinds of events. For instance, you can track when people add something to their basket and which product this is, but you can also track downloads for files or any outbound links you might have. As you can see, the possibilities are almost endless.

But there is one thing Analytics doesn’t do and that is give you insight into what is happening on your site now. Google Analytics always has a log of several hours, which makes it impossible to see in real-time if your e-mail campaign is working.

I recently stumbled onto chartbeat, a web based service that does give you real-time insight into what is happening on your site. By placing a small piece of java script on your site, it does some things Analytics doesn’t do: it shows you how many people are on your site, which pages they are visiting, where they are coming from and what they are doing (reading, writing or idle) and more, all in real-time.

 Chartbeat Dashboard

You can also set up e-mail and SMS alerts for such things as when the number of visitors to your site goes above the monthly average or the load time of a page is more than normal.

Chartbeat is not free (only for the first month) but US$ 10 per month is not too much for this kind of information.

Chartbeat and Google Analytics give you valuable insight into what is happening on your site.


Published: 30-08-2009 by Erwin Werkman | 0 Comments | 0 Links to this post
 

MVC.Net and throwing a proper http 404 statuscode

The cool thing I find about MVC.Net is that it takes you back to the basics of HTTP instead of worming your way around it. It also shows you how much you take for granted when using webforms, which one could also lead to decide not to use it.

For the last months my college Patrick and myself have been working on and off on a small side project using MVC.net. Using MVC.net has been at times wonderful but also very cumbersome, although that could be a lack of experience speaking.  When we started we where using the first beta and one of the things we couldn’t find were guidelines one how to do “stuff”. So we have been flying on blog fuel, articles and common sense. Many obstacles we faced were overcome by embracing the web and using it as it was meant to be used.

One of our latest  obstacles we had was getting a proper http 404 statuscode out of our application when a resource couldn´t be found within a controller action. After a lot of tinkering and searching we finally found the answer to our problems via a post by Richard Dingwall. His code probably worked on the technical previews, but it did work for us directly so with a small alteration it also worked for us.

   1:  public class HandleResourceNotFoundAttribute : HandleErrorAttribute
   2:      {
   3:          public override void  OnException(ExceptionContext filterContext)
   4:          {
   5:              Controller controller = filterContext.Controller as Controller;
   6:              if (controller == null || filterContext.ExceptionHandled)
   7:                  return;
   8:   
   9:              Exception exception = filterContext.Exception;
  10:              if (exception == null)
  11:                  return;
  12:   
  13:              // Action method exceptions will be wrapped in a
  14:              // TargetInvocationException since they're invoked using
  15:              // reflection, so we have to unwrap it.
  16:              if (exception is TargetInvocationException)
  17:                  exception = exception.InnerException;
  18:   
  19:              // If this is not a ResourceNotFoundException error, ignore it.
  20:              if (!(exception is ResourceNotFoundException))
  21:                  return;
  22:   
  23:              filterContext.Result = new ViewResult()
  24:              {
  25:                  TempData = controller.TempData,
  26:                  ViewName = View
  27:              };
  28:   
  29:              filterContext.ExceptionHandled = true;
  30:              filterContext.HttpContext.Response.Clear();
  31:              filterContext.HttpContext.Response.StatusCode = 404;
  32:          }
  33:      }

 

I don’t know if this is the best way to handle http errors but I do know this, the customErrors section in the web.config isn’t worth the bytes it takes up. As mentioned in Richard Dingwall’s post, the url path gets changed and worse there is no 404 error shown instead, it uses a 302 and then a 200.

Further digging around shows that .net  3.5 SP1 offers up a new attribute redirectMode:

   1:  <customErrors mode="RemoteOnly"  redirectMode="ResponseRewrite">
   2:      <error statusCode="404" redirect="404.html" />
   3:  </customErrors>

 

The new attribute ensures the url path stays the same unfortunally this attribute only works when you leave out line 2 and let IIS serve it’s default 404 errorpage. Otherwise the html gets served up as a normal 200 OK.

Look out for more MVC.net post soon!!

 

Hans


Published: 30-08-2009 by Hans ter Wal | 0 Comments | 0 Links to this post
 

Convention over configuration

Ruby on rails makes heavily use of the Convention over configuration design paradigm. At the moment it is getting a hot topic in the .NET world too. If you are like me and are lazy and hate doing repetitive work, then you should really check it out, if you are not, you should check it out anyway. In my opinion, when properly applied, convention over configuration can save developers a lot of time and effort.

So what is convention over configuration? One of the best examples can be found in the Fluent Nhibernate project. This is a project that facilitates configuring Nhibernate, without the use of those horrible XML mapping files. One feature of this project is Automapping, which is convention over configuration in its purest form. I will just assume you are familiar with the Nhibernate mapping files, if not, you can read all about in the Nhibernate documentation.

Let’s say you have a domain entity Customer:

public class Customer
{
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
}

 

And you would have your corresponding Nhibernate mapping file as we know it all too well:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="NHibernate.Examples.Customer, NHibernate.Examples" table="Customer">
    <id name="Id" column="Id" type="Int">
      <generator class="identity" />
    </id>
    <property name="Name" column="Name" type="String" length="40"/>
  </class>
</hibernate-mapping>

 

I used to have mapping files like these all over the place. Writing these mapping files gets really boring and mistakes are easily made and hard to debug. The Automapping feature makes all of this a thing of the past. With Automapping it is possible to provide, for example a namespace, and automatically map all the entities in that namespace to a database. This mapping takes place based on conventions. One such convention can be that an entity’s property with the name Id always maps on an identity field named Id in the database. Or that a many to one relationship always maps on to a certain column. For example Order –> Customer automatically maps to the column Customer_id in the Order table. With the fluent nhibernate automapping it is also really easy to overwrite the default conventions by providing your own. Off course, this is not very useful when mapping to a legacy database, but in most of the green field Nhibernate projects it can be applied successfully. So in this case, in stead of configuring all of the mappings in XML files, we have certain conventions that allow Fluent nhibernate to assume entities are mapped to the database in the same consistent way.

 

Another good example of convention over configuration is the registration of services with an Inversion of Control container. In a lot of TDD based systems, there are loads of interfaces that only have one implementation. So why have to register all of these services one at the time? Why not just say to the container automap all services that fulfill a certain requirement, like being in a namespace or deriving from a certain base interface. Structuremap has this functionality out of the box. Unity doesn’t have this yet, but Derek Greer has created a Unity extensions to provide this, which he describes in this blog post.

So instead of doing this:

Container.RegisterType<ICategoryRepository, CategoryRepository>();
Container.RegisterType<ICustomerRepository, CustomerRepository>();
Container.RegisterType<IOrderRepository, OrderRepository>();

It allows you to do stuff like this:

Container
    .AddNewExtension<ConventionExtension>()
    .Using<IConventionExtension>()
    .Configure(x =>
                  {
                     x.Conventions.Add<ImplementationConvention<IRepository>>();
                     x.Assemblies.Add(Assembly.GetExecutingAssembly());
                   })
    .Register();

Which automatically maps all the services deriving from IRepository in the executing assembly. This can save you a lot of work, personally I always forget to add the service I made to the container. However, it also involves a lot of black magic. The wiring gets done under the hood, so how you debug a problem when something goes wrong? Well you will need some diagnostics. For example, it is possible to have Fluent Nhibernate spit out all the mapping xml file that are used under the hood, which makes it easy to debug. So when diagnostics are provided, convention over configuration can be really useful and is a welcome addition to my bag of tricks.


Published: 04-08-2009 by Jonne Kats | 1 Comment | 0 Links to this post