• NancyFX - Revisiting Content Negotiation & APIs (Part 1) posted on 22 Apr 2013

    I thought I would revisit this topic since I don't believe I did it enough justice last time around, and I believe it really is important when creating an API that is going to be consumed not only by the public or client, but by you also!

    When the browser asks for text/html its negotiating with the server. So really your website is an API, your Views are just an additional type of content that your API serves up when requested.

    Example

    Lets say you're building Twitter, the initial page shows a list of tweets, so the browser makes a call to /tweets and the server responds with a list of tweets rendered with using HTML.

    Once the page has loaded, the client uses JavaScript to load new tweets, so it calls /tweets again, this time it returns a json result, and the client-side templating engine then renders and appends those to the top of the existing list, keeping the client up to date with the latest tweets.

    What's nice is no new data needed to be written on the server!

    Read more...

  • NancyFX - Implementing your own routing! posted on 09 Apr 2013

    With the up and coming release of 0.17 of NancyFX, the routing has been completely rewritten, and now it's super easy to implement your own routing. So I'm going to show you how.

    How it works

    The routing works by defining a route:

    Get["/products/{id}"]

    The route is then broken up into segments:

    1. products
    2. {id}

    Each segment is checked against a Node Condition in the TrieNodeFactory like so

    if (segment.StartsWith("(") && segment.EndsWith(")"))
    {
        return new RegExNode(parent, segment, this);
    }
    

    When a request comes in, the segment is compared to the node for a match and returns true/false + the captured parameter.

    These are a bunch of conditions for checking different nodes, currently Nancy supports out of the box the following nodes.

    Existing Nodes

    This is brief description of the existing nodes that currently exist in 0.17.

    CaptureNode

    This node captures {foo}, or basically any value defined in the segment.

    Read more...

  • Raygun.io - JavaScript error logging! posted on 09 Apr 2013

    Often when building applications we worry about error handling on the server, we may not do anything with the logs after we log those errors :P but we care about them enough to attempt to make the code resilient enough to not fall over should an error occur.

    But often we overlook errors happening on the client, and if a user hits one of those errors we don't know about it, unless they are kind enough to tell us. Should they tell us, we can't reproduce it, don't know where it's happening, etc etc.

    Its really important that we give the end user a good user experience, and that means ensuring that the client code is functioning well! If an error occurs and prevents the code from being executed, we could lose a customer, and if this happens with one customer, it could be happening with many.

    Enter Raygun

    Raygun offers a JavaScript API that's super easy to wire up to capture all errors by default, in-fact it's one line of code, not including the reference to the Raygun JS file.

    Download and Install

    Unfortunately there's no NuGet for this yet, hopefully they will add one in the future.

    Head on over to the MindscapeHQ Github Repository and download the file raygun.min.js (or grab the non-minified version if you wish), and reference in your app.

    <script src="/scripts/raygun.min.js"></script>
    

    Configuring Raygun

    Usually when you want to wire up an event to capture all errors you would need to do something like:

    window.onerror = function someError(errorMsg, url, lineNumber) {
        //handle the error
    }
    

    But there's a lot more to error handling on the client than just the onerror event. So rather than just giving you the ability to send the error, Raygun offers the ability to attach itself to the onerror event and capture as much necessary information as it can to give you the best possible information.

    So to setup Raygun all we need to do is:

    <script>
      Raygun.init('yourApiKey').attach();
    </script>
    

    You can share the same API key for Client/Server, so if you're already using Raygun for your Web Application, you can use the same API key for the Client.

    Should you want to stop capturing errors you can call:

    Raygun.detach();
    

    Lets see it in action!

    Lets start out by capturing unhandled exceptions/errors, in a new project we will create a new index.html file with the following:

    <script src="scripts/raygun.min.js"></script>
    <script>
    
        (function() {
          Raygun.init("* my key *").attach();
    
          var test = function() {
            throw "Something went wrong!";
          };
    
          test();
    
        })();
    
    </script>
    

    Running up the page we should get an error in the chrome console:

    Now if we head on over to the Raygun.io Dashboard

    We can see our error was logged. Lets do something a little different next, lets add a 2nd JavaScript file, and call a function inside that file:

    In our sample.js file we have:

    function DoSomething(value) {
    
        return Math.power(value, value);
    
    }
    

    The method power doesn't exist on Math, it should be pow, so we should get an error when calling it.

    Now in our page we can include the sample.js file, and call the method:

    <script src="scripts/raygun.min.js"></script>
    <script src="scripts/sample.js"></script>
    <script>
    
        (function() {
            Raygun.init("* my key *").attach();
    
            var total = DoSomething(100);
    
            console.log(total);     
        })();
    
    </script>
    

    As you can see we captured the same error in Chrome as we did on the Raygun dashboard.

    Raygun also tries to capture as much information to help you sort out the issue as it can, such as the error, when it occurred, and where it occurred.

    It tells you the URL and Browser it occurred on:

    It even tells you

    Read more...

  • Raygun.io - a few features that I love posted on 08 Apr 2013

    I've been using Raygun.io for a couple of months now and seen a whole heap of new features added.

    Email Spam

    If you had multiple apps you would get spammed with 1 summary email each day for each app, now you get an aggregation of all apps which is much nicer.

    If you receive an email for an exception, and that exception keeps occurring, it will email you a little while later saying that you're still receiving the exception, the rate at which its occurring, and if it's happening more or less.

    These changes are great! Still the same valuable information, but more smartly distributed to the user.

    Commenting

    I had an error, that occurred a lot...

    So after fixing it, which took a little bit of effort to figure out, I commented on it!

    Read more...

  • My must have (short) list of programs/extensions etc... posted on 02 Apr 2013

    It's been 1 year since I posted my list , well.. 1 year has come and gone, and I missed posting this on the same date. None the less its April now and here's my post.

    Visual Studio 2012

    I'm still a .NET Dev but ah... god it's painful going back to VS 2010... The new Black Theme makes this so much easier to use while sitting in the dark.

    Still using

    Raygun.io

    http://raygun.io

    This Software as a Service for Error Handling has replaced my use of ELMAH. It's simply amazing. Been tracking errors in my applications more closely with this.

    Read more...

  • What I would like to see from Microsoft regarding OSS posted on 02 Apr 2013

    I had an awesome conversation on Monday with Glenn Block about Microsoft in regards to OSS, as a result Glenn asked me to write a post about what I would like to see Microsoft do.

    To be clear, everyone has their own opinions about what Microsoft is doing with Open Source Software, whats working, whats not, that isn't the point of this post. This is about what I would like to see, and why.

    Promote itself with the community, not against it

    One of the things I think Microsoft does is promote itself against the community, it has opened sourced MVC and WebAPI, but people outside the community don't know about the alternatives.

    I'm not suggesting that Microsoft actively promotes frameworks like FubuMVC, NancyFX, ServiceStack etc as their own, or in such a way that it overshadows their own stuff. What I would like to see is Microsoft promoting itself along side other frameworks. A lot of the guys who create these other frameworks are advisories for MVC/WebAPI, they help make Microsoft frameworks better, and there's all the people who contribute, and in my personal opinion Microsoft doesn't really give anything back to the community through its main channels.

    Read more...

  • Everyone should get the opportunity to learn to program, but school is a waste of time posted on 04 Mar 2013

    I just got done reading a blog post by @fekberg titled "Everyone Should Learn Programming"

    This idea that everyone should learn to program seems to be a growing trend. But I disagree.

    I don't think everyone should learn to program, I think everyone should get the opportunity to learn to program. Schooling in general is a waste of time because it caters to this idea that life evolves around English, Math, Art, Science and General Knowledge. But real life doesn't, and these things don't help children figure out what they are good at or enjoy.

    There's an awesome TED video by Sir Ken Robinson titled "Do Schools Kill Creativity"

    http://www.youtube.com/watch?v=iG9CE55wbtY

    It's worth watching, awesome talk and very funny

    Read more...

  • Windows Store App with Caliburn.Micro - Binding Converters posted on 26 Feb 2013

    In my last post about Basic Binding we added the ability to Hide/Show a control using Viability property of the control to make it Visible or Collapsed

    However the View Model shouldn't have any real knowledge of how the view works, meaning it shouldn't actually dictate the visibility using the controls properties.

    Note: I left this out of the original post because I wanted to keep it 'Basic' without confusing binding with converters and such, making the topic more complicated

    If in the future you changed from say TextBlock to a 3rd party control called BananaTextBlock and that 3rd party decided that they were not going to use the built in Viability enum, and instead decided to create their own naming convention, and enum etc. You would be forced to change your ViewModel, which isn't good.

    That's where Value Converters come in handy.

    Read more...

  • Windows Store App with Caliburn.Micro - Getting Started (Updated) posted on 20 Feb 2013

    Note: This is an update post for Windows Store App with Caliburn.Micro - Getting Started

    Back in December I blogged about getting started with Caliburn.Micro, not long after I created the post a new version (v1.4.1) was released.

    The changes in this release break my previous blog post so I'm updating here.

    Note: The original post still applies, the change is only to the setup of the App

    App Setup

    In the previous post when we configured the container, all we needed to do was Register the WinRT Services.

    Read more...

  • Windows Store App - Adding Advertising posted on 14 Feb 2013

    I searched for hours trying to figure this out and I think the information is a little scarce or not obvious.

    Basically I wanted to add some advertising to my app, I'm trying to cover multiple different area's in order to learn what's involved, and I thought I had it all down, only to work out that the advert's that were displaying were test adverts and not the real thing.

    Now don't get me wrong, when you actually do find the correct URL (by searching Advertising rather than Ad) the MSDN link does have all the information, I didn't find this out until my friend actually sent it to me...

    http://msdn.microsoft.com/en-us/library/advertising-windows-sdk(v=msads.10).aspx

    There's two main things you need to do (besides installing the correct SDK, I had the Beta first time around)

    1. Implement the advert into your app
    2. Setup an advertising account

    The first part is easy... (well the 2nd part is too... but I didn't realise that at first)

    Read more...