Wednesday, December 22, 2010

Ext.ux.JSONP v2.0

The ExtJS library does include a JSONP component, but I found it to be lacking a very important piece of functionality.

The Problem: No Error Handler

Anyone who know's anything about JSONP is immediately going to call attention to the fact that JSONP isn't capable of supporting error handling by design. While that is true, it doesn't mean that we don't have to handle errors. One of the more well known jQuery plugins for JSONP includes a callback method for "complete" which enables you to know when a request failed.

One additional nitpick that I had with the ExtJS JSONP component what that I did not feel it was coded in a very Object Orient fashion, but that's probably just a personal gripe.

The Solution: v2.0

I rewrote the Ext.ux.JSONP component to include additional parameters that match up with a normal Ext.Ajax.request. This means that you can access handlers for success, failure, and callback.

Also, I made the code much more OO.

Download

Ext.ux.JSONP v2.0

Examples

// Old
Ext.ux.JSONP.request('http://api.flickr.com/services/feeds/photos_public.gne', {
   callbackKey: 'jsoncallback',
   params: {
       format: 'json',
       tags: Ext.fly('search-value').dom.value,
       tagmode: 'all',
       lang: 'en-us'                            
   },
   callback: updateResults
});

// New
Ext.ux.JSONP.request({
   url : 'http://api.flickr.com/services/feeds/photos_public.gne',
   params: {
       format: 'json',
       tags: Ext.fly('search-value').dom.value,
       tagmode: 'all',
       lang: 'en-us'                            
   },
   success : this.updateSuccess,
   failure : this.updateFailure,
   callback : this.updateCallback,
   scope : this
});

Thursday, November 11, 2010

Migration in Progress

Welcome to my new blog, TomDuPont.NET

I am currently in the process of migrating my old blog to this site. I have been actively blogging since 2008, so getting all of those entries moved over is a little daunting, but I am getting there!
For now, assuming you were looking for content, please visit my CodeSmith Tools Blog.

Wednesday, October 13, 2010

Insight Launch Party a Huge Success

The CodeSmith Insight Launch Party was a huge success. Thanks to the almost one hundred people that came out and partied with us. It was a blast, thank you all so much for coming out!

We did a 15 minute demo of Insight before we gave out prizes. To show that we had nothing up our sleeves the demo was completely unrehearsed and using our live production servers. I am pleased to say that it went off without a hitch! We even had some surprise audience participation as people in the crowd sent in emails to our demo instance during the presentation; not only was that fun, but it also really helped demonstrate the power and versatility of Insight in real time.

At the end of the demo we actually went overtime doing Q&A about Insight. Not only did we get asked a ton of questions from all around the room, but honestly they were great questions! This was flattering for two reasons: 1) As the speaker those questions told me that the audience was paying attention, and that what I was saying was intelligible. 2) As a developer it was great to see other developers thinking about use cases for Insight, and then being able to be one step ahead of the game and say "Yes, we support that."

Here are a few of the questions we were asked about Insight:

  • Can Insight report handled exceptions?
    • Yes. Insight's client API allows you to create cases for anything at anytime, and provides a series of CreateCase method overrides to make it especially easy to create a report from a caught exception.
  • Can Insight be used to submit feedback without reporting errors?
    • Yes. Insight can be configured to not report unhandled exceptions, and then you can still use the feedback forms and API to create and submit cases based only on user feedback.
  • Does Insight integrate with Microsoft Exchange?
    • Yes. Insight can send and receive email from almost any POP3 or IMAP server, that includes Microsoft Exchange.
  • Do you offer an installed solution?
    • This is the only question to which I had to answer "no." However, we are very interested in offering installed solutions in the future, so if you are interested in this please contact us directly (at sales@codesmithtools.com) and we will be more than happy to try and work with you!

In summary, the party was a blast. I think everyone had fun; I know I did. Insight is now released and available to log exceptions for developers everywhere. Also, feel free to check out the party photos we posted up on Facebook. (If you are in one and want to be tagged just let us know!)

Thanks again,
Tom DuPont

On behalf of,
The CodeSmith Tools

Friday, October 8, 2010

MVC2 Unit Testing, Populating ModelState

I love how testable ASP.NET MVC is, I also love MVC2's model validation. However when trying to unit test a controller method that used the ModelState, I quickly learned that the ModelState is not populated when just newing up a Controller and calling one of its public methods. As usual, I think this is best narrated by example:

Example Model and Controller

public class PersonModel
{
  [Required]
  public string Name { get; set; }
}

public class PersonController : Controller
{
  [AcceptVerbs(HttpVerbs.Get)]
  public ViewResult Register(Person person)
  {
    return View(new PersonModel()); 
  }

  [AcceptVerbs(HttpVerbs.Post)] 
  public ViewResult Register(Person person) 
  {
    if (!ModelState.IsValid) 
      return View(model); 

    PersonService.Register(person);
    return View("success");
  }
}

Example of the Problem

[Test] 
public void RegisterTest() 
{
  var model = new PersonModel { Name = String.Empty }; // This is model is invalid.
  var controller = new PersonController(); 
  var result = controller.Register(model);

  // This fails because the ModelState was valid, although the passed in model was not. 
  Assert.AreNotEqual("success", result.ViewName);
}

Solution

Other solutions I have come across were adding the errors to the model state manually, or mocking the ControllerContext as to enable the Controller's private ValidateModel method. I didn't like the former because it felt like I wasn't actually testing the model validation, and I didn't like the latter because it seemed like a lot of work to both mocking things and then still have to manually expose a private method.

My solution is (I feel) pretty simple: Add an extension method to the ModelStateDictionary that allows you to pass in a model, and it will then validate that model and add it's errors to the dictionary.

public static void AddValidationErrors(this ModelStateDictionary modelState, object model)
{
  var context = new ValidationContext(model, null, null); 
  var results = new List<ValidationResult>(); 
  Validator.TryValidateObject(model, context, results, true);

  foreach (var result in results) 
  { 
    var name = result.MemberNames.First(); 
    modelState.AddModelError(name, result.ErrorMessage);
  }
}

Example of the Solution

[Test] 
public void RegisterTest() 
{
  var model = new PersonModel { Name = String.Empty }; // This is model is invalid.
  var controller = new PersonController(); 

  // This populates the ModelState errors, causing the Register method to fail and the unit test to pass.
  controller.ModelState.AddValidationErrors(model);
  var result = controller.Register(model);
  Assert.AreNotEqual("success", result.ViewName); 
}

Thursday, September 30, 2010

Oct 12th is (Insight) Party Time!

We are very excited about our upcoming CodeSmith Insight Launch Party. We rented out the Addison Convention Center, ordered ten old school arcade machines, bought over $1,000 in prizes, booked flights for the entire CodeSmith Tools team is come in from around the country, and now we are counting down until party time!

However, there have been some questions (and even concerns) about party which I feel need to be addressed.

First: This party is NOT a time-share-condo-ploy.

We are going to speak about Insight for 10 minutes, and field questions for another 5 minutes. This is a three hour party, we are only going to do "business" for 15 minutes total. That is all.

Why? It's a PARTY. We have been working our butts off for almost two years developing Insight, now we want to CELEBRATE (good times, come on)! Seriously, we are renting arcade games because they are FUN.

Second: What does "over $1,000 in prizes" mean?

Well first of all, that number does not even include:

  • Free T-Shirts
  • Free Pizza Hut Pizza
  • 50% Lifetime Discount for all Attendees

The $1,000 in prizes is made up of the following:

  • Apple IPad
  • Crucial RealSSD C300 128GB
  • Microsoft X-Box 360
  • Nintendo Wii

...and there will be additional door prizes! THAT is what "over $1,000 in prizes" means.

Third: JOIN US FOR THE FESTIVITIES!

Please feel free to invite your coworkers, your friends, even your mother. (Seriously, my Mom will be there!)

When
Tuesday, October 12th
6:00pm - 9:00pm

Where
Addison Conference Center‎
15650 Addison Road
Addison, TX‎ ‎75001

RSVP, and I will see you there!

Tom DuPont
Vice President, CodeSmith Tools 

Friday, July 9, 2010

How To: Customize Unhandled Exception Reports in CodeSmith Insight

One of the top benefits of integrating CodeSmith Insight into your application is that it will automatically catch and report all unhandled exceptions. As quick and easy as it is to just let Insight do all the work, you may want to make customizations to these unhandled exception reports. This is very easy to do: Just register for the UnhandledExceptionReporting event in your application startup, and then you can use an event handler to programmatically customize your reports.

Example

protected void Application_Start(object sender, EventArgs e)
{
    InsightManager.Current.UnhandledExceptionReporting += OnUnhandledExceptionReporting;
}

void OnUnhandledExceptionReporting(object sender, UnhandledExceptionReportingEventArgs e)
{
    // You can get access to the report here...
    var report = e.CaseReport;

    // ...and make any updates you wish!
    report.Tags.Add("Unhandled");
}

Friday, June 18, 2010

Video: Mailboxes in CodeSmith Insight

The primary goal of CodeSmith Insight is to "unite different forms of communication", and email is a crucial medium with which users communicate with us. This is why Insight is capable of both importing and sending email, and this is why Insight includes a complete email client build into it's web UI.

Insight's email capabilities are all controlled by Mailboxes inside the system. To help demonstrate the configuration and use of these Mailboxes, I have created a new tutorial video:

Mailboxes in Insight

Enjoy!

Real Time Web Analytics