media, books comments edit

Amazon Kindle - 6" - Wi-Fi and
3GI bought an Amazon Kindle and it arrived yesterday. I got the 6” model with Wi-Fi and 3G on it. So far, I generally like it, but figured I would share my thoughts so far, having about a day with it.

Pushing books from the Amazon web site to the Kindle is not super intuitive. I think this is partly my fault. I thought I’d be slick and try to “pre-load” a few things on there using the Kindle app on Android so when I got the Kindle, I’d have some stuff to get reading. After unboxing the thing and setting it up, I looked and… couldn’t find my stuff. It was in this “Archived Items” area on the Kindle, but (as a new user) what the hell is that supposed to mean? Doesn’t look archived on my phone.

After a bit of poking around I did figure out how to download them onto the Kindle, but I went in thinking all this stuff would be automatically synchronized.

The Kindle app for Android comes with books not in the Kindle store. When you first get the Kindle app for Android you get two or three free books (Pride and Prejudice, Aesop’s Fables, and Treasure Island, if I remember right). Thing is, while it’s the same content as the ones on the Kindle store, they’re not actually connected to your account or the Kindle store, so when you actually get a Kindle, those books aren’t on there. Let me tell you how long it took me to figure that one out. I eventually deleted the local ones and “purchased” the free books out of the Kindle store so now I can keep everything in sync, but this definitely contributed to my confusion over how to get things onto the Kindle.

The screen is beautiful. I mean, truly crisp, like a printed page. When you get the Kindle, there’s a little diagram on the screen showing how to plug it in and start the battery charging. I sat for a good couple of minutes trying to figure out how to peel that sticker off when I realized it’s an image on the screen, not a sticker. Yeah, it’s that clear. Of the reading I’ve done on it, it’s nice and easy on the eyes. And when you turn the Kindle off, a classic book cover or portrait of an author comes up on the screen and stays there, and they’re all gorgeous looking.

Getting your own files onto the Kindle is confusing. They talk about how to get your own books or documents onto the Kindle, but the way it’s written is kind of confusing. You get an email address with your Kindle (like “mykindle@kindle.com” and they tell you that you can send documents to that address and they’ll show up on your Kindle, except there’s some sort of charge… unless you send to “mykindle@free.kindle.com” in which case there’s no charge but there’s some sort of manual work involved. Alternatively, you can connect the Kindle to your computer through USB and drop files into a “documents” folder on the Kindle (which appears like a drive on the computer)… but can you create folders inside the “documents” folder to separate your purchased content from personal content or not? I finally figured it out and have used Calibre to convert a couple of Cory Doctorow books and transfer them to my Kindle, but it wasn’t the simplest thing. I can’t see non-tech people getting the most out of that functionality, or maybe they just suck it up and eat the costs.

Pricing on Kindle books is odd. Sometimes they’re really competitive, like The Hunger Games being only $5 on Kindle, but $9 in paperback - Kindle version’s about half price. Other times, you wonder about the cost, like Catching Fire (the sequel to The Hunger Games) being $8.52 on Kindle but $8.97 in hardcover - the electronic version costs only $0.45 less than a hardcover physical book? One would think if I’m not taking up the resources of the printing process, the savings could be passed along to me.

The organization of books on Kindle is confusing and kind of annoying. When you first get your Kindle, all the books show up right on the home screen. If you only have like three books, that’s not a big deal, but out of the box you’ve got two dictionaries and the Kindle User Guide listed. I don’t need to look at that stuff every time I fire up the Kindle.

Fortunately, they have the notion of “collections.” A collection is sort of like a “tag” or a “folder” you can put your books in. You create a collection, then you add books to that collection. You can add a book into multiple collections, too - so if you have, say, a collection called “Science Fiction” and a collection called “Classics,” you could put The Time Machine in both collections. You can read more about collections in the Kindle User Guide.

A Kindle home screen organized in
collections.

There are three problems with collections.

Collection Problem 1: If a book is in a collection, you can’t also pin it to your home screen. That is, once you’ve got things organized into collections, you generally show your home screen organized by collections so, you know, you can see your organization in action. (Alternatively, if you sort your home screen by, say, author, you see every book listed right on the home screen and no collections at all. Sort of defeats the purpose of collections. Unfortunately, once you put a book into a collection and you sort your home screen by collections, the only books that appear on the home screen are the ones not in collections. You can’t have a book in a collection and say “pin this to the home screen because I’m reading it right now.” Granted, you can create a “Current Reading” collection and just use that, but that’s sort of a hack, you know?

Collection Problem 2: Collections are always sorted by “most recently updated,” not by collection name. This is the most frustrating bit of collections. You set all of your collections up, then sort your home screen by collection and they appear not in alphabetical order, but in descending order from most to least recently updated. (By “updated,” I mean either you read a book in that collection or you added/removed an item in the collection.) There’s a blog article talking about a workaround for this, but this, too, is a hack. One would think someone would have said, “Hey, you know what? Why don’t we separate the ‘grouping’ concept (collection, title, author) from the ‘sorting’ concept (alphabetical, date) so people can see things they way they want?” I guess not.

Collection Problem 3: Collections are device-specific. I might go through and totally organize my library on my Kindle, but when I open the Android app it doesn’t support collections, so I don’t see that. If I were to get another Kindle and connect it to my account, I wouldn’t even have the collections there unless I did this process of downloading all the books to the Kindle and then adding the collection from the “Archived Items” folder. (See the “To import a collection from another Kindle” section in the user guide.)

Aside from this stuff, I’m enjoying my Kindle so far. I’m planning on taking it to Australia with me at the end of the month, so that should really be the true test of how I like it.

dotnet, gists, aspnet, csharp comments edit

If you’ve worked with Windows Identity Foundation, you’ll find it very nearly mandates that you implement a passive security token service using classic ASP.NET web forms rather than MVC. It doesn’t lend itself well to testability, and in some cases it writes content directly to the response stream without you being able to govern when/how that happens.

All is not lost, though. Here are a couple of helpers and tips when working with Windows Identity Foundation in ASP.NET MVC to create a passive STS.

Programming Windows Identity FoundationFirst, drop what you’re doing and go buy a copy ofProgramming Windows Identity Foundation by Vittorio Bertocci. The documentation on WIF is surprisingly thin and this book is like the lost set of docs that makes everything clear. Will it directly help you specifically with ASP.NET MVC and WIF? No, but it will help you to understand what is going on with WIF so you know where you may need to insert yourself. It’ll also explain how things are supposed to work, so when you’re setting it up in MVC you can tell if things are going right or not.

Reflectoris your friend. I am not condoning that you copy/paste anything out of the WIF assemblies, but using Reflector to figure out what it’s doing is key.

For example, in WIF samples and in the WIF STS template you’ll see a call to FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest followed closely by FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse. The ProcessSignInResponse method takes in an HttpResponse rather than an HttpResponseBase, which removes you from the ability in your MVC controller to use the System.Web abstractions for testability. However, if you look at what ProcessSignInResponse is actually doing, it’s just taking the SignInResponseMessage that comes from ProcessSignInRequest and then it’s writing it out to the response stream. You can do the same thing yourself in your controller using the controller’s Response property and HttpResponseBase, allowing you to break that tie to the concrete System.Web classes.

Make use of model binding. In the STS template, the Default.aspx page they provide has a big if/then block that switches on query string parameter values to determine which WS-Federation action the incoming message has. Rather than that, wouldn’t it be better to have a controller action that looks like this?

// This ostensibly replaces Default.aspx in the STS template
public class DefaultController : Controller
{
  public ActionResult Index(WSFederationMessage message)
  {
    if(message.Action == WSFederationConstants.Actions.SignIn)
    {
      // Do your signin processing
    }
    // ...and so on; alternatively you could switch on message.Action.
  }
}

That, of course, assumes you have a model binder that will look at the incoming query string and parse a WSFederationMessage out of it. That’s not too hard to do, and we can pretty easily add support for the derived WSFederationMessage types to it, too, like SignInRequestMessage.

using System;
using System.Web.Mvc;
using Microsoft.IdentityModel.Protocols.WSFederation;

namespace MyNamespace.ModelBinders
{
  public class WSFederationMessageBinder : IModelBinder
  {
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
      if (controllerContext == null)
      {
        throw new ArgumentNullException("controllerContext");
      }
      if (bindingContext == null)
      {
        throw new ArgumentNullException("bindingContext");
      }

      try
      {
        var message = WSFederationMessage.CreateFromUri(controllerContext.HttpContext.Request.Url);
        if (!bindingContext.ModelType.IsAssignableFrom(message.GetType()))
        {
          throw new WSFederationMessageException();
        }
        return message;
      }
      catch (WSFederationMessageException ex)
      {
        bindingContext.ModelState.AddModelError("", ex);
        return null;
      }
    }
  }
}

You can then register that model binder for the various WS-Federation message types at app startup:

var binder = new WSFederationMessageBinder();
ModelBinders.Binders[typeof(WSFederationMessage)] = binder;
ModelBinders.Binders[typeof(AttributeRequestMessage)] = binder;
ModelBinders.Binders[typeof(PseudonymRequestMessage)] = binder;
ModelBinders.Binders[typeof(SignInRequestMessage)] = binder;
ModelBinders.Binders[typeof(SignOutRequestMessage)] = binder;
ModelBinders.Binders[typeof(SignOutCleanupRequestMessage)] = binder;

Now you can actually do the controller action the way you’d like, with a strongly-typed WSFederationMessage parameter and it will work.

Of course, if you look at the Default.aspx in the WIF STS template, it throws an UnauthorizedAccessException if a WS-Federation message comes in and isn’t a sign-in or sign-out request. You can do the same thing declaratively in MVC using an authorization filter. That would change your controller action to look more like this:

[RequireWSFederationMessage(AllowedActions = WSFederationMessageActions.SignIn | WSFederationMessageActions.SignOut)]
public ActionResult Index(WSFederationMessage message)
{
  // ...handle the message...
}

Something like that, where you could allow specific message actions to pass through, otherwise the user is seen as “unauthorized.”

Create a filter attribute for ensuring only proper message types are allowed through. First you’ll need that WSFederationMessageActions enumeration so you can specify what’s allowed and what’s not.

using System;

namespace MyNamespace.Filters
{
  [Flags]
  public enum WSFederationMessageActions
  {
    All = WSFederationMessageActions.Attribute | WSFederationMessageActions.Pseudonym | WSFederationMessageActions.SignIn | WSFederationMessageActions.SignOut | WSFederationMessageActions.SignOutCleanup,
    Attribute = 1,
    SignIn = 4,
    SignOut = 8,
    SignOutCleanup = 16
  }
}

Yes, I could have just calculated the result of the “or” operation for the “All” but this way if any values change, I don’t need to mess with “All.” Do it your way if you’re not cool with this.

Next, the filter attribute:

using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.IdentityModel.Protocols.WSFederation;

namespace MyNamespace.Filters
{
  [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
  public sealed class RequireWSFederationMessageAttribute : FilterAttribute, IAuthorizationFilter
  {
    // Lookup table for converting string actions to the associated flag
    private static readonly Dictionary<string, WSFederationMessageActions> _actionLookup = new Dictionary<string, WSFederationMessageActions>()
    {
      { WSFederationConstants.Actions.Attribute, WSFederationMessageActions.Attribute },
      { WSFederationConstants.Actions.Pseudonym, WSFederationMessageActions.Pseudonym },
      { WSFederationConstants.Actions.SignIn, WSFederationMessageActions.SignIn },
      { WSFederationConstants.Actions.SignOut, WSFederationMessageActions.SignOut },
      { WSFederationConstants.Actions.SignOutCleanup, WSFederationMessageActions.SignOutCleanup },
    };


    public WSFederationMessageActions AllowedActions { get; set; }

    private object _typeId = new object();
    public override object TypeId
    {
      get
      {
        return this._typeId;
      }
    }

    public RequireWSFederationMessageAttribute()
    {
      // Default to allowing all actions.
      this.AllowedActions = WSFederationMessageActions.All;
    }

    public bool IsAllowed(string action)
    {
      if (
        String.IsNullOrWhiteSpace(action) ||
        !_actionLookup.ContainsKey(action)
      )
      {
        return false;
      }
      var enumAction = _actionLookup[action];
      return (this.AllowedActions & enumAction) == enumAction;
    }

    public void OnAuthorization(AuthorizationContext filterContext)
    {
      if (filterContext == null)
      {
        throw new ArgumentNullException("filterContext");
      }

      WSFederationMessage message = null;
      // If you can't parse out a message or if the parsed message
      // isn't an allowed action, deny the request.
      if (
        !WSFederationMessage.TryCreateFromUri(filterContext.HttpContext.Request.Url, out message) ||
        !this.IsAllowed(message.Action)
        )
      {
        filterContext.Result = new HttpUnauthorizedResult();
        return;
      }
    }
  }
}

Now you have a filter attribute that will check to make sure the incoming message is of an expected type and will deny access if it’s not.

Hopefully some of this will help you get working with WIF in ASP.NET MVC. It’d have been nice if MVC had been considered in the initial rollout of WIF, but no such luck. I don’t even see a Connect page for accepting suggestions. Fingers crossed for the next release…!

General Ramblings comments edit

On a somewhat daily basis, I have this weird sort of “aha!” moment where I realize, again, that I’m a father, and that’s really weird to me. I picture fathers as guys that are older than I am, which is to say, that “being a father” somehow equates to “higher age” even though that’s obviously not remotely true. Of course, I also don’t feel like I’m really an adult yet, either, even being in my 30’s, given concerns about getting enough time to play Rock Band overtake my desire to, say, watch the evening news. I own a house, too, and when I think about that in concrete terms it weirds me out as well.

I also have a difficult time equating “baby” and “human,” like Phoenix is some sort of small animal that needs to be taken care of (like a house cat). I find myself talking to her the way I talk to the cats, sitting her on the couch and saying, “See, now you’re on the human chair!” when, duh, she is a human so of course she’s on the human chair. I think that will probably change when she has, you know, motor control and some mechanism of communication beyond “scream.”

I don’t think Jenn has this sort of cognitive dissonance issue over feeling like she’s-a-mom-but-she’s-not-a-mom. I think it’s sort of clicked for her. I suppose I’ll get there eventually. For now, it’s just still… surreal.

General Ramblings comments edit

I find that I’m blogging less due to services like Twitter that let me blurt out truncated, incomplete thoughts and flush them from my mind without fully forming them. That, plus the breakneck pace work has taken since I returned from paternity leave, plus general malaise (in some cases) has yielded a bit of a blog drought. I won’t apologize for not blogging because I hate that. I just haven’t done it, and that’s that.

I do have some smaller, not fully-formed thoughts that I haven’t blasted out in other forms, or maybe have tweeted about and dropped, so I figured I’d flesh some of those out here. Maybe relieve a bit of the psychic weight of that “to-do” list, as it were.

I sent out a request (over various media) for suggestions for over-the-ear headphones that don’t pinch your ears. I got a few good suggestions, but I should have explained requirements. Of course, that’s hard to do over Twitter in 140 characters, so:

  • I’ll be using them (and leaving them) at work, so a $300 pair of headphone is out. People can’t keep their hands off my stuff. I just found one of my action figures on another guy’s desk last week. I don’t need some spendy headphones getting “borrowed.”
  • I’ll mostly be listening to Pandora or other fairly compressed music sources. They don’t have to be reference quality.

Sony MDR-XD200
HeadphonesI ended up getting a cheap pair of Sony MDR-XD200 headphones. $22 at Amazon at the time of this writing. I’m wearing them now, as I write this, and they seem reasonably comfortable. The bass is a little light in them, which, I’m sure, could be rectified by purchasing a more expensive, higher quality set of headphones. For work, for now, these will do.

If you find you’re being asked to do something that has no logic behind it no matter which way you slice it, it’s probably politically motivated. Think about it.

My wife, Jenn, who is awesome, proved she understands comics. I have some sitting on my bedside table (stuff I’ve not read through yet) and she was dusting. She moved the comics, dusted, waited quite some time to ensure there was no residual Pledge hanging out, then washed and dried her hands prior to replacing them. Like I said - awesome.

We still can’t really figure out which one of us my daughter, Phoenix, looks like. It’s a common source of conversation for relatives, and I entertain it well enough, but I really don’t care. Who does she look like? I have no idea. You know what I do know? I know she smells like me. If I let my hair grow long (which turns out more “big” than “long”), fail to wash my hair, or don’t put gel in my hair one day, my head has a very distinctive smell. You can smell my pillow and know which one is mine. Anyway, Phoenix’s head smells like me. So out of a room of identical kids, I’d still be able to find mine blindfolded. I think that’s pretty awesome.

Speaking of Phoenix, we have noticed she is far easier to feed when swaddled or otherwise incapacitated. If her arms are free, the bottle gets close and suddenly she has this Incredible Hulk strength and the arms fly up in front of her face into a sort of impenetrable forcefield that makes it impossible to actually get the bottle to her mouth. Move one arm and the other arm compensates. I totally can’t wait until she has some semblance of muscle control.

I’m pondering getting a Kindle. From what I’ve seen, I’d probably end up getting the smaller Kindle rather than the Kindle DX. I’ve done some research on e-readers and based on price and my general use case, I think the Kindle would work out nicely. If anything, it’d help me determine how often I use an e-reader. Eventually I want to get an iPad (on which I would use the Kindle app for reading), but given my propensity to constantly tweak things, my budget, and my Android-based phone, I think a Kindle is a good start.

I am thinking about getting a sound bar for our game room. Right now we have a full home theater system up there (receiver, game systems, TV, etc.) but the speakers I have up there are these giant towers that are nearly impossible to place reasonably given the room layout. That and my lack of ability/desire to start running wires all over leave me either with a wireless setup or a sound bar. I know you audiophiles will get up in my grill about sound quality and immersion and I know. I hear you. It’s just, again, a wire and size issue. Perhaps a decent set of satellite speakers and a throw rug would also answer the question, given that a decent sound bar costs more (in some cases) than an equivalent satellite speaker system with a subwoofer.

The Hunger
GamesI have been reading The Hunger Games based on the recommendation from just about everyone and it is a very compelling read. It’s the first book I’ve been sucked into in a while. I suppose that sort of pegs me as one of those people who doesn’t read complex stories or try to expand their reading level. You’re probably right. I don’t think the comics in The New Yorker are generally funny (which doesn’t mean I don’t understand them, just that I don’t think they’re funny); I don’t agree that most of the “classics” you’re forced to read during school are worth spending the time and effort on; and when I read for fun I don’t really want to have to expend a ton of mental effort to try and figure out what the book is trying to say. I want to have fun, relax, and escape for a while. If that means I end up reading books that show up in the “teen” section of the bookstore more often than not, well… so be it.

I [still] hate Facebook. I hate that most of the comments people leave on there have “LOL” somewhere in them, overused to the point it has lost meaning and is almost more punctuation than anything. I hate that people won’t actually send you a damn email when they have your email address and instead will do some “post to your wall” or “Facebook message” bullshit. I hate that people will leave entirely unrelated comments on things (e.g., post a picture of a house plant and get, “Hey, didn’t see you over the holidays. How was your Christmas?”). I hate that people pretty much abandon spelling, grammar, and punctuation, especially given Facebook doesn’t have the message length limitations Twitter has that would otherwise require the abbreviations and shortcuts. Yeah, I could go on all day about how much I really despise it, even amidst its obvious ubiquity on the net. I’m sure there will come a day when “Facebook” equates to “internet” for people the way that “the world-wide web” currently generally equates to “internet” for people. Get off my lawn, young punks.

I have been told by various relatives and friends that I should write a book. I’ve considered it. It’d be something you find in the humor section that has random stories and rants and sells 150 copies total. There are actually several reasons I haven’t.

  • Most of the stories people encourage me to write about would only be funny to people who were there or who know the people involved. “Had to be there,” as it were.
  • Of the remaining stories, they’re mostly at the expense of a friend or family member, and they’d only be thinly-veiled. I could probably embellish and change things a bit, but the people who know would know exactly what I was talking about and I don’t really want to hurt anyone’s feelings. Even if it would be pretty funny.
  • When I tell stories, I talk with my hands. You’d miss that in book form, and trust me, it adds to the story.
  • There would probably be a lot of dick and fart jokes, which is not something, I think, that most people expect from me. Well, people who don’t know me, right? RIGHT?

Anyway, no book. Maybe later in life, in retirement, when it won’t matter anymore. I’m sure there’s a market for that story about the wedding that had the midget in the cowboy outfit. Just not quite yet.

windows comments edit

I’m probably the only person who didn’t realize that if you hold down Shift and right-click a folder in Windows 7, you get additional commands that you don’t normally see. For example, holding shift down when you right-click a folder gives you an “Open command window here” option, which obviates the need for a “Command Prompt Here” power toy (at least for the basic prompt).

Thing is, I don’t want to have to hold Shift down. I just want it there all the time.

The “Open command window here” item is listed in your registry under HKCR\Directory\shell\cmd and HKCR\Drive\shell\cmd. If you look in those keys, you’ll see a REG_SZ value called “Extended” that is floating there without any actual value assigned.

The "Extended" registry
value

If you delete that “Extended” value, then “Open command window here” will always show up and you don’t have to hold Shift down. Conversely, if you add a no-value “Extended” key to things, they’ll stop showing up until you hold Shift down.

And don’t forget to look at both the Directory and the Drive registry keys as mentioned above or you’ll wonder why it shows up sometimes and not in others.

YMMV. This works for me, might not for you. I’m not responsible if you delete something important and your machine comes crashing down around you. You have to be extra careful when you muck with the registry.