Amplify.js & ASP.NET Web API: Getting the error message

I’m still learning my way around ASP.NET Web API and have started using Amplify.js in my web apps to consume my web services. I originally learned about Amplify.js from John Papa’s excellent Pluralsight course, “Single Page Apps with HTML5, Web API, Knockout and jQuery”.

Today I noticed that when a server-side error occurs, I was not getting the JSON response that contains the error information in my client-side Amplify error() function (see “Exception Handling in ASP.NET Web API” for an explanation). Taking a look at the Amplify source code revealed that, “out of the box”, Amplify always sends null to the error callback function’s data parameter.

To override this behavior, I created a custom decoder that would use the XHR responseText to feed the error callback data parameter, like so:

amplify.request.decoders.mydecoder =
        function (data, status, xhr, success, error) {
            if (status === "success") {
                success(data, status);
            } else if (status === "fail" || status === "error") {
                try {
                    error(JSON.parse(xhr.responseText), status);
                } catch(er) {
                    error(xhr.responseText, status);
                }
            }
        };

Now I’m able to read the Message property and any other information returned from Web API when a server-side exception is thrown.

Posted in .NET, JavaScript | Comments Off

Entity Framework DbContext and mapping decimal properties with more than 2 digits of scale

Posting this mostly as a reminder to myself that when more than two decimal places of scale (i.e. to the right of the decimal point) is needed when mapping an EF entity property, you must specify the property’s precision in your DbContext’s OnModelCreating event like so:

public class MyDbContext : DbContext, IDbContext
{
   protected override void OnModelCreating(DbModelBuilder modelBuilder)
   {
      modelBuilder.Entity<OutYearPoolRate>().Property(r => r.Rate).HasPrecision(14, 8);
      base.OnModelCreating(modelBuilder);
   }
...

Failure to do so causes EF to truncate the values to 2 decimal places when updating the database.

Posted in .NET | Comments Off

Windows Azure Leap Year Bug

Wow. Yesterday, I wrote about a bug in Windows Home Server that shows up on every February 29th (confirmed; everything works fine today – March 1st), and today I see Windows Azure had it’s own problems:

http://www.zdnet.com/blog/microsoft/microsofts-windows-azure-has-a-meltdown/12076

Hey Microsoft, you might want to have your developers read this: http://en.wikipedia.org/wiki/Leap_year

Posted in Windows | Comments Off

Windows Home Server Leap Year Bug

http://forum.wegotserved.com/index.php/topic/878-whs-connector-this-operation-cannot-be-completed-at-this-time/

I just wasted the last half hour trying to get an old PC I’ve been neglecting connected to my Windows Home Server. Turns out I decided to do this on the one day it won’t work: February 29th. According to the discussion at the link above, it will work just fine tomorrow…

Posted in Windows | Comments Off

I have a bad feeling about this

Star Wars films converted to 3D: 2012 release date for Episode I
sciencefictionworld.com
Star Wars creator George Lucas is converting all 6 Star Wars films to 3D with the first due for release in 2012.

Posted in Uncategorized | Comments Off

ASP.NET Wizard Control Oddness

Haven’t posted anything in over a year, but decided to break the silence to write about something that caused me to waste more time than it should have. Hopefully, it will save someone else (or future me) from wasting more time on it.

I’m developing an ASP.NET site using the Wizard control and have code that saves the user’s progress in a database. The idea here is that the user can return to the site and pick up where they left off. Simple enough, but I got caught in what seemed like a never ending debugging session when I couldn’t figure out why the "Previous" button didn’t work when I came back into the site to resume a previous session. The wizard simply would not step backwards when starting on any step in the middle. To make a long story short, turns out the genius at Microsoft who implemented this control decided to make the "previous" button work like the browser "back" button, i.e. clicking previous steps you back in your "history" since you starting using the wizard. In this case, there is no "history" when starting in the middle, so the button does nothing! Not at all intuitive.

I found this discussion enlightening: http://forums.asp.net/p/973337/1235981.aspx

The workaround is simple. Handle the PrevousButtonClick event and decrement the ActiveStepIndex property:

protected void MainWizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e) { MainWizard.ActiveStepIndex--; }

Hope this helps.

Posted in .NET | Comments Off

Home Sweet Home

Syracuse makes CIO Magazine’s The Worst U.S. Cities to Work in IT list.

Technically, I don’t live in Syracuse. I live about 15 minutes north in Clay, which is #2 on the top 101 cities with highest average snowfall.

Posted in Uncategorized | Comments Off

Flash Player 10 Causing Internet Explorer Hang

Some folks (including me) are experiencing problems with version 10 of the Adobe Flash player and Internet Explorer. Oddly enough, I didn’t seem to have any trouble until after this month’s “patch Tuesday” (Microsoft updates).

For now, I’ve downgraded Flash to version 9 to workaround the problem. Adobe has older versions of Flash available for download here:

http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14266

Posted in Windows | Comments Off

Escaping characters for an XML string in .NET

From the stuff I should know but didn’t until yesterday dept:

Handy method in the System.Security namespace for replacing invalid XML characters with their escaped equivalents:

SecurityElement.Escape(string str)

Posted in .NET | Comments Off

Vista Sleep Problem Solved?

I decided to check on the state of Vista fixes last night by installing the latest updates from Windows Update and the latest NVidia drivers.  Unfortunately, my system would still hang when waking from its second slumber.  These kinds of sleep problems with Vista are widely reported on blogs and discussion forums all over the Internet, so I thought I’d post about what appears to fix the problem for me.

I don’t know what made me think to do this, and I think I’ve tried this in the past, but I disabled hybrid sleep (Control Panel, Power Options, Change plan settings, Change advanced power settings, expand Sleep, expand Allow hybrid sleep, change setting to Off, click OK).  Now my PC wakes from sleep every time!

Hybrid sleep is new in Windows Vista and is a cross between the old "standby" mode and "hibernation".  Standby works by powering down just about everything except the RAM, which saves the machine’s state so that it can very quickly resume where you left off when you power it up again.  Hibernation saves the computer’s state to the hard drive and powers down completely.  Resuming from standby is many times faster than resuming from hibernation, since loading the state back from the hard drive takes some time.  Windows Vista’s hybrid sleep mode saves the state to the hard disk but then goes into standby mode, keeping the state in RAM as well.  The idea here is that the state is protected in case the power is lost to the PC (which would wipe out the state in RAM), but most of the time the machine wakes up quickly by using the state stored in RAM.

I don’t know what it is about my hardware that is preventing a wake from hybrid sleep and not "plain old standby" mode.  I have a UPS connected to this machine, so I’m not particularly concerned about it losing power while it’s sleeping.  XP only supports standby and hibernation and that had been working without and problems, so that may be what finally made me think to disable hybrid sleep. 

So now I think I’m going to give Vista another chance.  At least until I run into the next show stopper…

Posted in Windows | Comments Off