Thursday, December 3, 2009

Yowsers…Bing Maps is the new Black

The new version of Bing Maps (still in Beta) has been built from the ground up on Silverlight.  They’ve integrated not only the features from the original maps software, but also way better image streaming, smoother scrolling, Photosynths, and…wait, did I just say Photosynths?

Oh yes, I sure did.

image

That’s pretty cool stuff, right there. 

Deep Integration for Developers

Along with the built-in things that are pushing the envelope of what we will expect from mapping software comes this integrated platform that developers can leverage to enhance (or pervert) the mapping experience.

image

There appears to be 16 current applications that are tuned-in to the user’s current view, coming from a variety of application providers.  Some of the applications, such as Twitter Maps by Bing, are actually doing some pretty cool things to leverage streams of data.  I zoomed into Union Square in New York City and began to see tweet indicators, some adorned with plus signs.  When you hover over those tweets, they cleverly expand to reveal via animation that multiple tweets have come from the same location.

image

Also interesting is that you can refine your search to only include tweets about certain keywords, topics or Twitter users.  Hrm…not too far from a dating service and nearly crosses the line to stalking service.

Now, on a tangent, it sort of makes me wonder if we aren’t heading into the age of reverse-Orwellianism. Rather than Big Brother watching where you are, where you go, people are actually broadcasting this information freely and readily to the world?  Weird.  I wonder if they even know they’re doing it…have we become that narcissistic?

Oh wait.  I guess I’m blogging, aren’t I?  Perhaps we are.

</tangent>

Some application developers are “getting it”, too, by providing baked-in examples of how their software works and in which contexts.  So, the travel-oriented web cam application has a list of popular (or selected) web cams and will take you right to the place on the globe where the camera is hosted from.  From there, you see all the other served web cams in the area and can view live images from those.

General Shiny-ness

The features flow together well and when you get into the apps side of Bing (are they called Map-apps?) you can start to see some really interesting convergence.

The animations can be quite smooth, though the experiences are always the same.  For example, when you use the Hotel Finder application when focused on an area, it will zoom out, pan over and zoom back into the next hotel you click on.  This is nice, as it give you a sense of spatial relationship to the two locations.  However, when you do a search in the Bing bar, the locations returned are located by a simple pan animation (and it’s really fast on my PC) so you lose a little of the context to the distance.

I must say, however, that overall this is a very slick products as far as betas go.

Image troubles…

…just switching over to a new web server and having a little difficulty posting images.  Apologies if you’re not seeing images on the blog for the next little while…

Wednesday, December 2, 2009

Coding for Christmas Cheer

Our office has decided this year to take part in the local Christmas Cheer Registry.  Families sign up, requesting a food and goods hamper, and then people or organizations attempt to fill all the needs of the community.  It really is a great cause.

Merry ASP.NET MVC to You

The MVC framework that is now available for ASP.NET is quite powerful.  Last night I was able to create a web-based application for our company where we can input the items, allow our staff to “claim” the items (indicating that they will donate them) and keep track of when the donations have been brought in.

While it’s not by any means fancy, I was able to implement all features in about an hour.  After sending out the email to invite others to participate, we nearly filled the list (and it looks like we’re going to adopt another family!).

image

LINQ to Christmas Chicken

What would otherwise be a chore to imagedevelop was made quite simple with LINQ functionality.   This is an extremely simple data model, with only two tables.  I used an mdf in the App_Data directory rather than a full-blown SQL Server Deployment.

LINQ to SQL starts things off for us nice and easy to give us a simple data access layer.  Because the dbml tools end up generating partial classes, I was able to easily extend the model to add properties to the Donations data.

image

For the purposes of this site, a hamper item is considered ‘claimed’ when a name is assigned to the item.  While there is no Boolean value saved in the database, the model (and subsequently the auto-generated Views) is easily adapted to provide this information at the class level.  Now, I have an easy way to test for claimed or unclaimed hamper items without having to check for nulls.

MVC – Making it Viable for Christmas

…but also known as Model-View-Controller.  It’s one of the oldest recognized patterns but it is also an entirely different direction from the Page-Controller experience we’ve had since the inception of ASP.NET.

Without taking into account the recent addition of Areas in MVC, you can think of the organization in this way: there are three folders, one each for your Models, your Controllers and your Views.  The Models are the objects you are working with.  The Views are what the user looks at.  The Controllers respond to user input, build up the models (or load them) and send them back with the appropriate View.

There will obviously be larger projects in your future, but for ours I knew we’d hit a limit of 8-10 views and therefore just elected to use the default Home controller.  I stripped out account management and opted to use the domain name of the user to simplify even further.  There is no about page and very few management pages.

image Creating the views was almost as simple as creating the LINQ to SQL diagram.  Visual Studio 2010 has integrated some editor tooling that picks up on code cues and prompts you for the magic.

To access the Add View wizard you simply right-click in the code editor for your controller.  The view name is pulled from the controller method where you clicked – in my case, AddDonation was the name of my method – but you can also customize as you feel is appropriate.  For my view I have also asked the wizard to use a template and create a draft of my data class Donation.  The template is driven from my View content selection “Create”, which stubs out a form for new records using the fields from my model.

Christmas Cheer in an Hour

There you have it.  A total of 1 controller, two classes in my model (one of them the DBML, so it was created with the designer), and a combined 10 views – all of which were largely auto-generated – and we’re well on our way to helping out a family for Christmas.  In fact, as I finish this note there are only two items left on the list and almost half of the items have already been brought in.

Though it may be early, this geek wishes you the Merriest of Christmases this year.

Monday, November 23, 2009

Talking Shop with Scott Guthrie

I’m in an online session right now in the LIDNUG group with Scott Guthrie who is answering questions related to PDC announcements, ASP.Net and Silverlight. 

image

I asked him about a couple of things, here are his responses:

  1. Will there be better tooling for ASP.NET MVC 2 Areas in the IDE?
    1. Yes, some of those tools were released with the last bits and Scott has a blog post coming up on that soon.
  2. The level-of-depth for the Nerd Dinner MVC example was great for beginners, but we don’t all need that level of depth for MVC 2.  For the next version can there be a walkthrough for people with more development experience?
    1. Yes, in an upcoming blog post Scott is going to do a feature walkthrough, highlighting what is important and why in MVC 2 without the introductory-level code bits.

Sorting Out Entities with Multiple Relationships in LINQ to SQL

There is a very common scenario in data design where you define a table as having two relationships with a single (other) table.  This especially comes into play if you have anything in your model with an “assignment” where someone assigns something to someone else.

In this case, We are tracking work tickets that are created by someone for someone else.  Both are stored in the ticket table.

image

Above is a snip from the DBML designer for LINQ to SQL. The two arrows represent the relationships between Person and Ticket, namely, that CreatedFor and CreatedBy are Person references.  If you have set up the foreign keys in the database, these associations are created for you automatically.

Convenient, yes, but code-revealing, no.  Here’s the result of the default naming as a result of the relationship being automagically created:

image

Now, which is which?  Are you looking for Tickets or Tickets1?  The default method for selecting a name is pretty ambiguous.

Directing LINQ to SQL Naming

Thankfully, the designer gives us a way to control the code generation tool and its naming conventions.  Click on one of the association lines on the DBML canvas and look at your properties windows.  Verify the members that are in use in the “Participating Properties” property, then drill into the Child Property detail.

There, you can set the name of the Child property to something more meaningful to developers using your code down the road.  Or, for yourself six months from now.

image You also have a chance to disambiguate the Parent property.  And, as a result, you have more readable syntax working from the child and walking to the parent record.

Wednesday, November 18, 2009

SqlGeography and Linq to Sql

I have a love-hate relationship with Microsoft SQL Server 2008’s Geography type.

I love working with it, but I hate it’s inaccessibility with some of my other favourite technologies. 

Specifically, I am trying to store GPS co-ordinates in the database as geography types.  This is a simple use, however, and although I’m only using points right now, we have other, more complex shapes that we must store.

I have figured out a couple of workarounds (that really aren’t workarounds at all) that allow me to use tables with the geography type in Linq to Sql.  These only really work for the point type and would get increasingly arduous as the shapes contain greater complexity.

Making SQL Server’s Geometry Play Nice with Linq to Sql

Unfortunately the Linq to Sql provider does not contain the data type support required for geometry or geography.  We’re not left with many options, at that point.

I tried a couple of hacks by creating the table by hand in the designer (it won’t let you drag the table onto the canvas) and stubbing in the field as a string, then banging up the code-behind to make it jive with the right types.

No go.  At the provider level it is not happy and there is no visible way to coax it into supporting the type.  Even if you cross your fingers AND your toes, you still get an error to the tune of:

The specified type 'geography' is not a valid provider type.

image

So, we’re stuck with less-pretty approaches.  I’m going with number one.

  1. Use Lat and Long as float types in the tables.  This allows seamless use in the Linq-to-Sql editor.  Create views that represent those columns as a single geometry point for reading the data in non-Linq-to-Sql scenarios.
  2. Store the co-ordinates in a geography field in the table and use stored procs to read and insert data as floats (lat and long).  Convert the data in the procs both ways.  Add the procs to your DBML.  This isn’t as good, because we lose some of the coupling in being able to ‘walk’ across your model in code.

I have also seen a recommendation to store the geo data as xml in the database and then do conversion on the client (casting to the proper types in code when needing to tap the data), or even pushing the data around as varbinary.  This approach would work, but generally I’m working with points right now and won’t need the added complexity.

Future Versions of Linq to Sql and Geometry

There have been suggestions from Microsofties on the forums that there will be support for these types down the road.  Right now, I’m sure it has to do with the fact that the assembly you need to access the type isn’t in the GAC by default and can’t be relied on to be present when someone’s in the throws of development (must have SQL Server installed to even get at the assembly in question).  Perhaps promoting the types to a more common distribution surface would alleviate this and open up the designer (and provider) to supporting them.

For now, Visual Studio 2010 Ultimate, Beta 2, does not have the support added.

Rx Comes to Fruition

The RxTeam last night announced the official release of the Rx Extensions (which has been called the Reactive Framework as well as the Rx Framework).  Developers now have a suitable set of tools – complete with concurrency support – for tackling asynchronous computation scenarios that respond to UI- and UX-driven events (or anything else that you need to subscribe to).

We no longer have to use the IL-hacked version of the library that targeted the Win-friendly version of mscorlib.

If you haven’t used it or heard of it already, Rx is the baby of Erik Meijer, the brains behind Linq.  The library is a collection of extension methods, interfaces and helpers that let us (subscribers) listen to events (publishers) in a Linq-friendly and developer-friendly way.

image

Above is the picture of Erik.  I wanted to post this snapshot of the video to ensure that t-shirt was recorded for all of mankind in the future to witness.   Assuming they will read this blog, that is…

The process of developing a standard library to encapsulate the long-standing Observer pattern went through many cycles between many teams.  The result is a set of extensions that flow seamlessly through from what we already know about working with collections: the Linq methods we have been working with for the last few years have been ported over to the Observable bits.

In addition to that, some new helpers and methods were spawned from the process that served IObservable really well.  Because it is the dual of IEnumerable, the team saw benefit to back-porting that functionality to original interface.  Read another way: IEnumerable isn’t being left behind as the dumb older brother.  The old dog is learning new tricks.

A lot of learning ahead, folks, get the bits and start playing!