OffMaps for the IPhone: Avoiding Data Roaming with Cached OSM Maps

Posted by Dave Bouwman | Posted in IPhone | Posted on 29-07-2009

0

When we met up with Peter Batty at DIA yesterday, we were lamenting the price of international data plans, and he showed me OffMaps on his IPhone. Essentially it’s a slippy map based on OpenStreetMap, and it lets you download an area into your phone. As expected, the GPS is integrated, which makes locating yourself a cinch. It also integrates with Wikipedia, and has an online mode that supports searching etc.

photo

(Screen cap from my phone showing downtown Vancouver)

If you are in your normal service area, and have an “all you can eat” data plan, this is “neat” but not too compelling when you’ve got Google Maps for free. However, if you have a limited data plan, or you are travelling and are subjected to international data roaming charges, this is AWESOME and totally worth the $2.99 price tag. Although I’ve been in Vancouver a number of times, I don’t know it that well, and this has been really helpful for navigating the area.

GeoWeb: Withering in the Vancouver Heat

Posted by Dave Bouwman | Posted in Community, GeoWeb | Posted on 29-07-2009

0

GeoWeb is now underway, and Brian Noyle and I have made our way up to Vancouver, Canada, just in time for a heat wave – not what you’d expect for this part of the world, but better than rain.

We got in yesterday, and spent most of the afternoon roaming around downtown with a posse of geo-blogger/tweeters, including James Fee (@cageyjames ), Sean Gorman (@SeanGorman), Steve Citon-Pousty (@TheSteve0 ).

IMG_0555

Somewhere around 5:00 we picked up Peter Batty (@pmbatty), crashed the local OSGeo meeting.

IMG_0556

After finishing off their pizza, and a brief a WxS vs. REST skirmish, we acquired Jason Birch (@jasonbirch) and others. As could be expected, beers, food and geogeekness ensued.

Not a lot of tweeting-on-the-fly though as many of us are on very limited/pricey roaming data plans. Assuming the wireless at the conference stays up, there should be some interesting stuff flying around. Seems to be a mix of #geoweb09 and #geoweb being used as hashtags at this point, so maybe pop up a search column in TweetDeck and follow along (or heckle from afar!) More later…

ASP.NET MVC Custom Authorization ActionFilter

Posted by Dave Bouwman | Posted in ASP.NET MVC, Security | Posted on 22-07-2009

3

The out-of-the-box ASP.NET MVC Authorization filter works nicely if you are using the out-of-the-box ASP.NET Membership and Authorization (roles) capabilities. However, we never seem to be able to utilize them directly because our clients have existing user databases, or we need a richer “user” schema.

Of course we could implement custom providers to plug a different database into this framework, as detailed at MSDN, but this rubs me the wrong way. If my application is going to use a repository pattern for data access, and I’m going to have specific controllers and views for creating/editing users, why should membership and authorization be routed through this other framework?

So, we’ve been “rolling out own” so to speak. We still use System.Web.Security.FormsAuthentication to set cookies, but other than that, we’re on our own. One side-effect of this is that we need to create our own Authorization ActionFilter which will allow us to decorate our controller methods to restrict access based on roles (we dropped the option to restrict by user name). For those not working with ActionFilters yet, this is what it looks like in code.

[Auth(Roles = "Role1, Role3")]
public ActionResult Index()
{
    //do things...
}

By decorating this controller method with [Auth(Roles = "Role1, Role3")]  we automatically restrict access to users who are in “Role1″ or “Role3″.

If someone in Role2 tries to call this method (i.e. they have typed in the url, or were sent a link which they try to visit after logging into the system) we want that logged, and we want the user notified that they have reached an invalid page. We don’t want to just bounce them to the login screen which is confusing.

Since we do use session in the application, we want this filter to also check to make sure the session is valid, and if it is not, redirect the user to the login page, with a message that their session has timed out.

Since this is pretty divergent from the System.Web.Mvc.AuthorizeAttribute  behavior, I thought it best to re-implement instead of inherit and override. So – I just popped over to CodePlex, and grabbed the source for AuthorizeAttribute, dropped it into my class, and started changing things.

As I mentioned, we use session state, and one thing we store is the user’s “Account”. This is held in an ApplicationState object in the session. So the first thing we need to do is get the session…

/// <summary>
/// Gets the session if it exists.
/// </summary>
/// <returns></returns>
private ApplicationState GetSession(HttpContextBase httpContext)
{
    var sessionObject = httpContext.Session[DRCOGApp.SessionIdentifier];
    if (sessionObject != null)
        return sessionObject as ApplicationState;
    else
    {
        return null;
    }
}

 

If get a null back from this call, we redirect to the login…

//See if the session is active
ApplicationState appState = this.GetSession(filterContext.HttpContext);
if (appState == null)
{
    //redirect to login w/ message
    filterContext.Result = new RedirectToRouteResult(
      new RouteValueDictionary {
      { "message", "Session Timed Out" },
      { "controller", "Login" },
      { "action", "index" },
      { "ReturnUrl", filterContext.HttpContext.Request.RawUrl }
    });
}

Assuming we get past that, we check for roles, if they were specified. If roles are specified, then the rolesSplit array will be populated. To make this a little cleaner we added an IsInRole method to our Account class, which allowed cleaner syntax in the if clause.

//Get the user
Account user = appState.CurrentUser;

if (_rolesSplit.Length > 0 && !_rolesSplit.Any(user.IsInRole))
{
    UnauthorizedModel model = new UnauthorizedModel();
    model.CurrentUser = user;
    model.Message = "The resource you attempted to access is restricted. This access attempt has been logged.";
    ViewDataDictionary viewData = new ViewDataDictionary(model);
    filterContext.Result = new ViewResult { ViewName = "~/Views/Error/Unauthorized.aspx", ViewData = viewData };
    //If the controller is not null, use it's logger!
    if (filterContext.Controller != null )
    {
        MyApp.Web.Controllers.ControllerBase ctl = filterContext.Controller as MyApp.Web.Controllers.ControllerBase;
        ctl.Logger.Log.Warn("Unauthorized attempt to access " + filterContext.HttpContext.Request.RawUrl + " by " + user.Login);
    }
}

The real fun happens in this block. If they are not in the role, we want to return a page which notes that they do not have access to the specified resource, and we want to log that.

Setting the filterContext.Result to the correct ViewResult was pretty straight forward, but it took a little longer to sort out the logging.

Basically, all our controllers inherit from a custom ControllerBase, which requires an instance of ILogService on it’s constructor. The injection is handled by Castle Windsor, via mvccontrib so it’s completely unobtrusive. It just took a while to realize that we could access the controller from the filterContext (a instance of AuthorizationContext). Once we had the controller, we use the logger, and we’re done.

Overall, this seems to be working pretty well. Once we’re really sure it’s bomber, and I’ve found time to decouple some aspects of it from this particular project, I’ll post the source code – in the meantime, grab the source from CodePlex and have fun rolling your own AuthorizationFilters!

Talking Smack about Jack…

Posted by Dave Bouwman | Posted in ESRI, Life | Posted on 16-07-2009

5

The ESRI User Conference is currently in full-swing, with all sorts of social media traffic flowing around. I saw this photo posted on TwitPic yesterday, and while I think it’s pretty comical, and took a good bit of creativity and pre-planning on the part of whoever made these stickers, it also got me thinking about the whole ESRI “Kool-Aid” attitude.

jack-koolaidl

In the many years I attended the ESRI User Conference, there were always those people who were “too cool” to attend the plenary. The “Jack Show” was beneath them. “No need to drink the “kool-aid” they’d say. 

I’d just nod, and make sure I was in the audience for a variety of reasons.

First, it’s a hell of a show. This is a serious, big production event that the ESRI team, including Jack, work for months to pull off. Check out this time-lapse photo of Jack prepping his talk (from ESRI’s Flickr stream)

jack-time-lapse

A well orchestrated event on the scale of the plenary is something to behold in it’s own right. The fact it’s germane to my area of expertise makes it that much better. Although smaller, the same level of care and effort goes into the Dev Summit opening session too.

The second reason I attend Jack’s talk is inspiration. Aside from the shiny “version next” stuff about the software, Jack’s talks are inspirational. They are about reaching beyond the status quo, towards a better, brighter future. Yes, GIS is a tool that enables to that vision, but the end goal is not a droid army of GIS analysts crisscrossing the countryside GPSing flower pots and snapping vectors. His vision is for a fundamentally “better” future – cleaner air and water – responsible use of resources – space to live – for everyone.  Jack is genuine, passionate, and cares about the bigger picture – and that comes through in his talks. And that’s what makes him inspirational.

Yet, somehow, this seems to rub some people the wrong way. After so many greed-based corporate implosions of the last few years, how can having a vision beyond the bottom line be a bad thing? Imagine how much good we could do if we were not spending billions trillions of dollars bailing out a banking system and automobile industries that collapsed because of executives who’s vision did not extent beyond their bonuses and second homes in the Hamptons? What if those executives had shared a fraction of Jack’s vision? What if we did not have to spend trillions bailing them out, but were able to spend a fraction of that money creating the “green economy”, and leading the world towards a brighter future for everyone? Nah, let’s just be “too cool” and go play golf. Someone else will take care of that.

Personally, I’m glad I work in an industry where the de facto leader is thinking beyond quarterly profits, and trying to actually make the world a better place.

Thanks Jack.

 

(For anyone who skipped the plenary, or who were not at the 2009 UC, the plenary will be online at http://www.esri.com/uc “soon”, according to @alylawson via Twitter)

ESRI UC: The Conference I Love to Hate to Miss

Posted by Dave Bouwman | Posted in ESRI, General | Posted on 11-07-2009

3

Ah yes, it’s that time of year – the ESRI International User Conference.

esri It’s a crazy event – somewhere in the neighborhood of 10,000 GIS people milling around the San Diego convention center talking shop and looking for free swag. Really though, I worked for companies that had large booths and significant swag budgets, and I was always stunned by those people who’d troll through with two bags full of various squish toys, pins, flyers, and pens. They’d then try to grab a stack of pens. Nah, one would not be enough – they needed thirty. What’s with these people? Does their company reimburse them based on the weight of the crap they bring home? Anyhow…

I think I attended for 10 years in a row, and presented something like a dozen papers over those years. After ESRI started the Dev Summit, I stopped attending the User Conference for two reasons:

Overwhelming

Let’s face it, with 10,000 people milling around, it’s hard enough meeting up with the people you know. Actually networking at a conference of this size is extremely difficult. Combine that with a zillion simultaneous sessions, and it’s a frantic week. Attempting to take it all in is a recipe for feeling inadequate and exhaused  (What – you’re not an expert in ArcSDE Admin on Oracle, Flex Development, third party model integration via Python with a little PLTS on the side? – how feeble!).

My advice: Pick something you are interested in (lets say Flex), hit those sessions, and then hang out at the ESRI island on that topic. Get to know the ESRI staff. Get their cards. Buy them drinks. Talk to them and make sure you build a bit of a rapport so they will remember you when you email them the next week ;-) Really though – as long as your reasonably cool, and ask intelligent questions, you can use the UC as a chance to build relationships that will allow you to side step tech support. Oh, and if you’ve been dealing with someone from tech support who really helped you out, find them and thank them. Really.

“User” Conference?

Although I presented a dozen “papers” over the years, I don’t think I was ever in a room that could hold more than 20 people. Not that it mattered, because it was about a quarter mile from the super theaters where the ESRI sessions are held. Now that slideshare.net exists, at least I could make it worthwhile by re-posting the slides there, but quite simply the user presentations are such a low priority that they are barely worth the effort. While I understand that for some agencies, being able to say that you are “presenting” at the ESRI conference is a way to get the trip approved, don’t expect an audience. Really, this is the ESRI International Marketing Conference, and most attendees seem to be ok with that.

That said, it’s always hard not being there. It’s a fun feeling being at a “big event”. The plenary session is always interesting with some kind of cool new thing and some cool demos. (on a side note – check out this time-lapse photo of Jack Dangermond preparing for the plenary). Then there are all the fun events through the week – the Regional User Group meetings, Dick’s Last Resort, map beer gallery, The Bitter End and other sundry watering holes. And this year, ESRI seems to be drinking from the social media fire hose – twitter seems to be the focus, so I’ll be following #esriuc to see what’s shaking. Not sure if there will be an IRC back channel, which is interesting to follow, but more fun if you are there.

In the end though, since I’m not with “giant corp”, and we don’t have a 30 by 30 space-ship booth and 10,000 furry globes to give away, there’s no way for me to hide the expense of attending in someone’s marketing budget. Thus, I’ll be coding away next week, but for everyone heading out (or already there) – have fun, play safe (beware the martini’s at the Bitter End) I’ll see some of you at the end on the month at GeoWeb in Vancouver!

Pragmatic Choices: Bye Bye Silverlight

Posted by Dave Bouwman | Posted in ASP.NET MVC, M-V-VM, Silverlight | Posted on 09-07-2009

2

Just in time for the release of Silverlight 3, I’m bidding farewell to Silverlight on my current project.

bye-silverlight

I’ve been working with Silverlight for about a month, and despite my best efforts it became clear that my project was just not going to come together the way I’d hoped. Thus I pulled the plug on Silverlight, and switched back to ASP.NET MVC and Dojo. Interestingly, I was able to re-build all the existing functionality in less than one day – things go fast when you’ve got a lot of experience with a technology!

I made this switch for a number of reasons, not the least of which was simple pragmatism – I was making relatively little progress with Silverlight, and the application did not really “require” Silverlight per-se.

I had chosen to to use Silverlight for a number of reasons:

1) The promise of ADO.NET Data Services (aka Astoria) to streamline the Data Access service layer

2) The promise of XAML Data Binding and/or DataForms to simplify client-side form management.

3) Prism’s promise of an easy to use, testable, application model with clean separation of concerns.

What I found is that while each of these features is really killer on it’s own, actually rolling all of them together is non-trivial. Learning all of these technologies while trying to build a large application (more than 50 data entry screens and lots of business logic) was just not viable. I’m sure if I had a team of 3 developers, and we had 6 months to get up to speed on XAML, ADO.NET Data Services / RIA Services, Prism, Commanding, XAML Data Binding, and Silverlight Unit Testing, then this application would merely be “challenging”. Since my team and I have built multiple similar apps using ASP.NET MVC and Dojo, there are significantly fewer “unknowns” as well as a ton of existing code we can leverage.

So, as I bow out, here are some thoughts about Silverlight…

Silverlight itself is pretty cool, but the tooling for Xaml at Silverlight 2 was harsh at best. The Xaml intellisense in Blend3 is a big improvement in the work flow. Designing the UI’s took a little getting used to because you don’t really have all the Windows or HTML form controls. Thus a fair bit of time was spent just getting up to speed with what was viable.

One I got a handle on what I could do in the UI, it was time to figure out how to build the application itself. Prism (Composite Application Guidance for WPF and Silverlight) is really cool, and there are a lot of intro level posts and videos out there. From what I can see, this is “the” way to build a “serious” Silverlight application. However, unless you’ve got a solid handle on Xaml, and DataBinding in WPF/Silverlight, it’s not easy to sort out how the View separation is supposed to work in non-trivial situations (i.e. taking commanding beyond simple buttons).

Additionally, there is lots of talk about Model-View-ViewModel as “the” design pattern to use, yet the Prism guidance does not show any examples of this (it focuses on Supervising Controller and Presentation Model). The best resource I found for M-V-VM in Prism was David Hill’s Prism quick start kit and sample app. The sample app is still pretty simple, but it is M-V-VM, and you can follow what’s going on. If this was extended to show best practices integrating ADO.NET DataServices, creation of client side proxy classes implementing INotifyPropertyChanged (needed for Two-Way data binding), it would be an awesome resource. Along those lines I did come across some T4 templates that facilitate creating client side proxies that actually support Two-Way databinding (on a side note, the next release of Astoria will have updated client proxy generators which will include INotifyPropertyChanged)

Also the Prism Reference implementation mixes both of these patterns in different areas of the app, which makes it difficult to keep things straight. Not to pick on the reference app, but it also side-steps the issue of talking to “real” services by just stubbing the services out pulling from static, client-side data sources. It would be really good to have some example code that’s calling back to ADO.NET Data Services over, oh, I don’t know, let’s say Northwinds ;-)

Managing resources in Prism projects was also confusing. If you want Blend to see your resources (mainly images in my case) they need to be in the assembly containing the module. However, I could not sort out a clean way to then have those resources move over to the Shell assembly and thus make their way into the xap file. I ended up simply having copies of all my images in both my module assemblies and the shell assembly. Not ideal, and I’m sure there is a good way to handle this, but it was the least of my concerns.

Another thing I struggled with was that my UI was going to be pretty complex – the final app will have over 50 screens. The UI Composite capabilities of Prism would be nice to use, but given that we are an Agile shop, we don’t do big design up front. But, the regions need to be defined in the Shell at the beginning of the development cycle. I sense some problems down the road with this. Additionally, in order to decompose the Views and ViewModels into convenient pieces I would like to have different sets of regions in the app. I’m sure that the patterns & practices guys could work a way to make that happen, but it sure was not clear to me how to whip that up.

Summary

Overall, it was an interesting journey, and I’m planning on building a much simpler resource planner application using Silverlight in my spare time. I intend use Prism on it, and give that it’s much smaller (4 screens) I think it will be a better starting point.

On a side note for the GIS people reading this, I never really got to the point of using the ESRI Silverlight control in this project. The few demo apps I’ve built with this control would indicate that it will be just as easy to use as any other Silverlight control.

Silverlight DataGrid Current Item as Click.CommandParameter

Posted by Dave Bouwman | Posted in M-V-VM, Prism 2, Silverlight | Posted on 02-07-2009

0

Note: This applies to Prism v2 with Silverlight 3 Beta.

So I’ve added a button into a column of my DataGrid, and I want to bind in the Click handler to my ViewModel, as well as pass the selected item into said handler.

I’m not going to go into the details of Commanding in Prism at this time (maybe later), but here’s what the xaml looks like:

...
<data:DataGridTemplateColumn Header="Details">
    <data:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Button Commands:Click.Command="{Binding Path=Value, Source={StaticResource ViewDetailsCommand}}"
                    Commands:Click.CommandParameter="{Binding}"
                    Cursor="Hand"
                    Content="Details" />
        </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
...

The Click.Command is a little out of the ordinary in that the Binding Path is set to Value, and the Source is a StaticResource on the control. There are a few hoops to jump through on this, but the Prism reference implementation application (RIStockTrader) does show how this works.

What had me scratching my head was how to send in the object which represents the current row in the grid. All of the examples looked like this:

Commands:Click.CommandParameter="{Binding Path=ItemId}"

Which is great when you just want to send the Id of the item in. But in my case, I want the actual object so I can send that to the "Details" form for editing. In hind sight it’s obvious that you would set the CommandParameter to the "Binding", since that’s the item itself, but it was one of those things that you don’t think would make sense.

Anyhow – through the power of Google, I hope this saves someone else some time/frustration.