Welcome

This is the generic homepage (aka Aggregate Blog) for a Subtext community website. It aggregates posts from every blog installed in this server. To modify this page, look for the Aggregate skin folder in the Skins directory.

To learn more about the application, check out the Subtext Project Website.

Powered By:
Powered by Subtext

Blog Stats

  • Blogs - 7
  • Posts - 705
  • Articles - 40
  • Comments - 185
  • Trackbacks - 741

Bloggers (posts, last update)

Latest Posts

DDD South West

This weekend was DDD South West, part of the ever increasing DDD brand, run by Guy and his crew, who did a most excellent job as usual. Situated at the University of West England in Bristol, we had perfect weather to accompany the great talks, and for once I saw a talk in every slot. I started out with Liam’s talk on software development and how not to go bust, a feat which I’ve barely managed to accomplish. Next was Chris Alcock and reactive extensions; I’d seen Jon Skeet do a talk on this a few weeks ago and wanted to learn more, and Chris’s talk was pitched perfectly; lots of simple examples, giving a really good overview of the features and uses. I finished off the morning with Phil talking about crap code, a session that was mostly a WTF list of things not to do. It turned into a good discussion and really brought the audience together, since it seems almost everyone has seen (and written perhaps) code like this.

After lunch was jQuery with George Adamson, which for me was the best talk of the day. I know enough about jQuery to not have to concentrate too much, which left me to really enjoy George’s style; there’s a little bit of mad professor in him I think, and I really enjoyed both his style and the talk itself.

I finished off with my talk on Clean User Interfaces with WebForms, which despite the good marks, I wasn’t really that happy with. It needs more content I think. Phil suggested taking a few bad WebForm pages and working through them to clean them up, and since I’m doing this talk at NxtGenUG next month, I’m going to make some changes to add a bit more practicality to it. I was generally happy with the deck though, which was a big change for me; just pictures, no bullet points. I’m not sure that style will fit every talk I do, but I think it worked for this one. Plus it had kittens. The deck and sample application can be downloaded from the samples page.

Overall it was a great weekend, and with 300 people attending it shows what a great community we have in the UK. Lots of motivated people, new speakers, great talks.

Flickr Tags:

posted @ 6/8/2010 9:24 AM by Dave Sussman

Site Map Security Trimming With WebForms and Routing

The routing framework that was introduced with MVC has been available for use in WebForms since version 3.5, but doesn’t integrate well with some existing features, notably security trimming with site maps. This is where the site map provider will honour authorisation, only showing nodes for which the user is authorised. The trouble is, the url in the site map would be a route url, not the url of the physical file, so the security checking on the node doesn’t work. It doesn’t fail, just doesn’t work at all.

The solution is to customise the provider, which is easy enough since the code for all the providers is available at http://tinyurl.com/ASPNETProviders. Modifying the XmlSiteMapProvider, you can add the following:

public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
    if (!this.SecurityTrimmingEnabled)
        return true;

    SiteMapNode newNode = node.Clone(true);

    if (!string.IsNullOrEmpty(node["routeName"]))
    {
        Route r = (Route)RouteTable.Routes[node["routeName"]];

        if (r != null)
        {
            newNode.Url = ((PageRouteHandler)(r.RouteHandler)).VirtualPath; ;
        }
    }

    return  base.IsAccessibleToUser(context, newNode);
}

This simple looks up the route name in the route table and gets the url of the physical file, passing that through to the base security checks. You also need to add the routeName attribute to your siteMapNode, so that an easy lookup can be done. You could iterate over the site map nodes finding the right one, but this is a slightly faster solution, although “faster” may not be that measurable.

posted @ 6/2/2010 9:15 AM by Dave Sussman

Fixing Internationalisation in ASP.NET

I’ve just read this blog post and while I’m keen to encourage localisation of web application and anything that makes it easier, I’m curious as to why Jason feels the need to say that localisation is “hopelessly broken in ASP.NET” and you have to do all the localisation by hand, for every control. There’s no comments feature on his blog, which is why I’m commenting here.

I’d agree that localisation in ASP.NET isn’t perfect; the server code has to have the additional meta resource keys, and you have to wrap all text to be localised, but this doesn’t have to be done by hand. Visual Studio will automatically parse the page, adding the meta resource keys to all controls that are localisable and creating the resource file for you. Yes it’s an XML file, but Visual Studio has an editor for it, and there are other tools I’ve seen that allow editing of resource files, so it’s not like you have to hand edit the XML. It’s obviously harder if you need an external person to do the translation, but not that much harder.

The other issue I have is Jason says:

In practice, it's so much extra work that nobody actually does it. That, my friends, is the reason you hardly ever see any multi-language websites written with ASP.NET.

That’s a really sweeping statement and completely misses the point. Most people don’t do localisation because they don’t care; English is their major language, a language spoken by the majority of the people they target their site to, so it’s just not relevant. It’s also a much bigger issue than just the text on the page, with database text (eg product descriptions, etc) requiring the same treatment, support for right-to-left languages, etc.; those, I’d agree, are areas where ASP.NET’s localisation falls down.

In the spirit of fairness, I too admit to not having localised many sites, but those I have done have been done very quickly. Yes you have to process each page, which is a burden, but a relatively small one since Visual Studio does it for you. I have a fairly large application to localise soon and it will take me a while to go through all of the pages, but the real effort of what I need to do is support right-to-left languages, so it’s not just the text that needs changing, but the entire site layout. That though, is another issue.

Jason’s idea is sensible in some areas, in that if you code from scratch using his method, then localisation is simply a matter of the source text, so you don’t need to touch your site at all. Likewise, I could have done the same with every site I’ve done, using the built-in features. Jason’s method might fit you better if you’re in the MVC space or have come from another framework.

I don’t wish to be negative about this Jason; please continue to localise sites and to push localisation as a good thing to do. Use whatever method is suitable. But don’t discourage people from using the built-in methods when the tools provide some great features; let’s tell everyone all the methods available, give guidance on the pros and cons of each and let them pick the best for their needs.

posted @ 3/2/2010 9:45 AM by Dave Sussman

Windows Media Centre – Does the UK care?

I’ve been a big fan of PVRs for years, buying a TiVo for the few months they were available in the UK. I retired that and bought an Acer Aspire iDea 500 as soon as it was released in 2006, it being the first MCE machine designed for the UK; Core 2 Duo, quiet(ish), plenty of connections, including SCART, which given my ancient CRT TV is a requirement. To this day it’s one of the few, if perhaps only, machine with SCART. These days plasma and LCD TVs are easy to connect to, but any CRT TV in the UK is SCART based.

Recently the power supply on the MCE box failed (a common problem it seems, which could be why Acer don’t make it any more), but a new one was sourced, more memory was added and I installed Windows 7. It’s perhaps a little underpowered, the VFD display doesn’t work, but otherwise is mostly excellent. Occasionally, and for the last few days, a couple of channels are suffering massive breakup and are therefore unusable and won’t record. It could be the transmitter, the weather, or maybe one of those fat pigeons I see in the garden, sitting on the aerial. My Windows 7 machine upstairs has no problems, nor does the TV itself, which puts it down to a tuner/driver issue, but given the MCE box under the TV isn’t officially supported by Windows 7, I have little come back. But I can’t live without it and can’t afford a new one. So I’m left to rant, like the old man I am.

Looking around, there are very few dedicated MCE machines in the UK, even fewer designed as one you’d want under the TV. There are a fair number of dedicated PVRs, obviously cheaper, but more limited in capabilities than MCE and from what I’ve seen, mostly having awful UIs that are hard to use. No one seems to care. Hardware manufacturers don’t, and I doubt Microsoft do either. There’s so little MCE in stores that most people haven’t heard of it. A PVR is a consumer product, sold alongside TVs, literally, shelved underneath them in the stores. An MCE machine? Well, computers are over the other side of the store; they’re computers, not PVRs, right?

And anyway, I’m not sure I’d recommend it for the general public anyway. So many have enough problems with PCs that a PC under their TV controlling the recording of their shows, just isn’t sensible. A dedicated PVR, at around £100 and you don’t expect perfection and is almost an impulse buy; a PC for £500, well, you think twice about the cost and expect it to work. All the time. No problems.

The MCE interface itself is consumer ready, but everything around it isn’t and until these things get to the white goods level of simplicity I doubt they’ll ever take off big time. Apart from Windows and Office, Microsoft’s penetration into the consumer market in the UK is so small that it’s no wonder things don’t get released here. The vicious cycle of “no product, no demand” just escalates. The Windows Phone 7 Series will be interesting once it reaches these shores; a device firmly aimed at consumers might raise awareness and might be the tip of the iceberg for Microsoft realising that the UK actually exists.

posted @ 2/25/2010 12:31 AM by Dave Sussman

Want to be an author?

Since I don’t have time to write books at the moment, I’m forwarding this to world. Packt Publishing, are expanding their portfolio and looking for books on Visual Studio Integration, Administration and Reporting.

Packt Publishing today announced their plan to advance their line up of Enterprise focused titles, and invited potential authors with Visual Studio skills and book ideas.

When it says today, it actually means last week, but I’ve just found out about it. If you’re interested in writing Visual Studio books, Packt wants to hear from you! Please visit the Packt Authors Website for submitting your book ideas and title suggestions.

Other publishing companies exist. Your royalties may go up or down depending upon the economy.

posted @ 2/10/2010 12:09 PM by Dave Sussman

The Conference Speaker’s Dilemma

Gary has an interesting post about conference feedback, in particular around the usefulness of a session. As both a speaker and organiser, I was going to reply in the responses, but maybe it’s worth a broader audience. Is the usefulness of a session actually relevant to anyone at all? I go to plenty of sessions that aren’t useful in my day to day job, but that doesn’t mean it wasn’t a good session or I didn’t enjoy it. Here’s what I make the choice based on:

  • Do I have a pressing need to learn the topic and will the session give me the knowledge I need? It’s mostly about pointers to the technology, the speaker’s insight, that one nugget of information that makes it worthwhile.
  • Do I enjoy the speaker? Sometimes a session is worthwhile just because the speaker is entertaining, even if I know I’ll get nothing out of it.
  • Is it something I know nothing about? I sometimes attend sessions I know will have little or no impact on my daily work, just because I feel I ought to have a passing knowledge of the topic; sometimes that’s even as slight as what the heck it is.
  • Is it something I know I’ll never master? I’ll attend lots of design and user experience talks, because those are particular interests of mine. I know I have limited (none, some would say) design skills and am intensely jealous of people who do. But I go in the faint hope that some of the sparkle will rub off.

Assuming I stay through the session, or the majority of it at least, I’ll always leave feedback, because as a speaker I know I value that feedback. If I did badly I want to know why, which is why it’s so frustrating to receive a low score with no indication of why. I once had “terrible session” written alongside a low score; if I’m so bad, how am I going to know why you thought it was terrible? My response is “terrible feedback”. Still, it beats “didn’t like his accent”; sorry, but it’s the only one I’ve got.

Now technical knowledge, speaker ability, etc, are easier to score numerically, and these are valuable to the organiser. But usefulness? Maybe for a big conference, trying to gauge the sessions to include, but for smaller events such as DDD, where the topics are picked by the public? Don’t blame the conference or the speaker if it wasn’t useful, you picked it. Now it’s a different matter it the session didn’t match the abstract, as that’s what you made your decision on, and that is useful information; maybe the speaker didn’t write a concise enough abstract, or got off topic, or any number of other reasons, but don’t just say it wasn’t useful, say it didn’t match the abstract.

I’m not suggesting we get rid of usefulness altogether as a question, it can help balance the other scores (eg a new speaker, with nerves, who doesn’t perform well, but still provides useful information). Maybe we just need to force a textual response if the usefulness is scored low. Or perhaps if any session is scored low.

Once of the biggest problems conference organisers have is getting feedback, and therein lies an immediate dilemma. The paper feedback form, handed in at the end of a session (or the day) gives you the immediacy; you’re less likely to forget what you thought of the session, but sometimes you need time to think about it. Plus, the organisers need to type all this information in if they want any form of analysis. On the other hand, the online form is convenient for later analysis and probably easier for attendees, but lacks the the ability for immediate response, unless it’s available during the session and there’s a network connection available.

So ultimately this comes down to a plea. If you attend an event, no matter what size, and are asked for feedback, please give it; make it useful feedback though, tell us what did and didn’t work, what you liked and what you didn’t. Certainly for UK events, where we have an active community, all of that information gets shared, so all events benefit.

posted @ 2/8/2010 12:20 PM by Dave Sussman

ASP.NET Web Forms and MVC

I’m not really sure I need to blog this, because if you read this blog and not Scott Guthrie’s I’d be very surprised, but Scott just posted about technical debates, including WebForms versus MVC. Worth a read, including the comments.

posted @ 1/25/2010 8:47 AM by Dave Sussman

RedGate SQL Search

I’m a big fan of RedGate’s tools, and their next little one has hit beta. SQL Search provides a quick and simple way to search for, and through, objects on SQL Server and is invaluable if you have a large number of objects. It’s fast, unobtrusive and works really well. Go give it a try.

posted @ 1/21/2010 12:29 PM by Dave Sussman

WebForms aren’t dead

The post could equally be about me, given my lack of content recently, but clients, lack of time and general apathy all play their part. However, what I really want to say is mostly explained by the title, that of the future of WebForms, in particular that they have a future. A lot of what we read in blogs, articles, etc is MVC related and that’s fair; it’s still relatively new to the ASP.NET arena, and new and shiny always gets press; WebForms had lots of coverage when it was released – it was “A Big Thing”. Those that blog and speak at conferences and user groups tend to be the ones passionate about their technology, the vocal few who believe strongly, and it’s easy to get sucked into the new technology vortex, the belief that what they are saying applies to every project you are on.

Recently on a mailing list I’m on, there’s been a thread about MVC versus WebForms. Lots of good arguments and one exceedingly well constructed message from someone important; I hope it gets blogged because it will go a long way to quell the fears that many have, that WebForms is a dying technology. It’s not. It’s still being actively developed (the WebForms and MVC teams are about the same size) and still plays an important part in Microsoft’s web strategy.

The thing is, there are good and bad points for both frameworks and which one you use depends on many factors: the project requirements, available skills, etc. Here’s my take.

MVC

Advantages

  • Complete control over UI. With no server control framework you can construct exactly what you want, how you want, making it easier to use script frameworks.
  • Great for Test Driven Design. The separation between components makes TDD much easier. It doesn’t solve all your TDD problems, but it does make them easier.

Disadvantages

  • More UI work. Since you don’t have a rich set of controls, you have to create your UI yourself, although there are helpers to, well, help.
  • Learning curve. While MVC isn’t hard to learn, it’s very different from WebForms, so don’t think you can just jump in.

WebForms

Advantages

  • Maturity. It’s a well established, stable framework. Don’t confuse older with superseded.
  • Control framework. The rich set of controls make pulling together a UI very quick. That can have disadvantages, but if you know what you’re doing the UI can be almost as clean as an MVC one.
  • Postback and ViewState. Yes they are hacks on top of HTTP and can cause many issues, but they work very well for what they were designed for. The event based lifecycle is very easy to understand, especially for beginners.

Disdvantages

  • ViewState. The defaults produce more ViewState than is really necessary, leading to larger pages.
  • Test Driven Development can be hard, especially testing UI code. Abstracting as much code out of code-behind files can help, but you’re still bound to the postback architecture.

That’s just my top picks, there are plenty of other points worthy of mention. I’m a big fan of WebForms, but that doesn’t mean I don’t like MVC too. Bits of MVC I don’t like, in particular the standard view engine (I’ve never really liked inline <%%> code , even in ASP and ASP.NET WebForms, but that’s a personal thing), so I’d probably use Spark View instead. The one thing I’ve said right from the very first previews of MVC is that it needs some form of control architecture; not server controls, because remember, there’s no page lifecycle, but controls to abstract the common rendering; some people, including myself, find the <%%> hard to read, while a declarative control is easier. I doubt a control framework will appear when the helpers work so well, hence my preference for another view engine, which is another advantage – better pluggability. I like the controller architecture, and routing (oh, and routing is supported in WebForms too).

It’s also important to remember that not every project has the same requirements. Two projects I work on are WebForms, mainly because they predate MVC, but even if they didn’t, I’d still use WebForms. Why? Well they are both Intranet/Extranet applications, low numbers of users; one has lots of data editing via forms, the other less so, but still enough that WebForms and the UpdatePanel (yes, I use the UpdatePanel) work perfectly well. Page size and rendering performance aren’t an issue in these applications (and considering that one of them uses databases with 30-50 million rows of data; rendering is a minor issue compared to database performance).

And furthermore, both MVC and WebForms are just a part of ASP.NET; remember all the services (membership, roles, etc), providers, and so on, that are fully supported by both frameworks. ASP.NET 4.0 improves WebForms and although the changes look small, they have an important impact on the framework. Just because WebForms isn’t evolving at the same rate as MVC, doesn’t mean it’s been forgotten. WebForms doesn’t need to evolve so fast.

Scott Hanselman did a blog post on Dynamic Data, which is a good read in itself, but at the bottom there are a bunch of links to WebForm resources. Some may talk about MVC, but there’s still plenty of movement on the WeForm front.

posted @ 1/21/2010 11:42 AM by Dave Sussman

Silverlight Bing Maps Zoom Scrolling Bug

If, like me, you’ve just upgraded to the V1 release of the Silverlight Bing Maps Control, and are wondering why the mouse wheel no longer zooms the map on browsers other than IE, it’s because you’ve got Windowless set to true. Eg:

<asp:Silverlight ID="Xaml1" runat="server"
Source="~/ClientBin/SilverlightApplication1.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%"
Windowless="true" />

 

The solution is to set Windowless to false, or remove the attribute since false is the default. Of course, if you need windowless, then you might have to wait for a fix, or use IE.

There’s a post on the forums where you can document and discuss bugs.

posted @ 11/11/2009 12:24 PM by Dave Sussman

SQL Server Spatial and Invalid Geography data

I’ve been investigating the issues with dealing with invalid geography data, from live GPS points, and how that can be stored in SQL Server spatial types. Firstly I must retract the statement about using TRY/CATCH, since although you can use it, the resultant type won’t contain invalid data, it will be null. I have so much data I screwed the tests. So now my options are to create MULTILINESTRINGs or use the Geometry type, both of which I’ve considered and are both solutions that were suggested as a comment on the previous entry. I also spent some time yesterday discussing this with Johannes Kebeck (who incidentally is a great speaker), and he pretty much came to the same conclusions.

Using MULTILINESTRINGs

Let’s look at the MULTILINESTRING option in more detail, using some realistic data. Consider the following set of points:

-0.173721313476559 51.503727323059300
-0.171961784362805 51.503860889088400
-0.168142318725583 51.503820819320800
-0.168292522430424 51.502338213148900
-0.171983242034926 51.502324856117400
-0.172004699707046 51.503834175913900
-0.168099403381342 51.503794106122800
-0.165288448333734 51.503727323059300

This represents the following line:

image

It’s difficult to see the flow properly here, but it’s along, down, back, up, along again. If I shift a couple of points down a bit, you can see the flow a little better, starting from the left, doing a loop down before heading back to the right.

image

In real life we could end up with either up these situations; the difference between points 2 and 6 (the top left of the box area) in the second picture is only 4 metres, so well within the bounds of GPS drift. But, the above diagram is just to illustrate the flow of points better, so is really an aside. Let’s get back to the original point data, which we’d normally load into a spatial type using the following:

DECLARE @coords nvarchar(max) = 'LINESTRING(-0.17372131347655934 51.50372732305939, -0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085, -0.16829252243042417 51.50233821314898, -0.171983242034926 51.5023248561174, -0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085, -0.1652884483337343 51.50372732305939)'
DECLARE @line Geography = Geography::STGeomFromText(@coords, 4326)

But of course we can’t use this code, because the data creates an invalid geography type; the lines between points 2 – 3 and 6 – 7 are the same.With the MULTILINESTRING approach, we’d use the following:

DECLARE @coords nvarchar(max) = 'MULTILINESTRING((-0.17372131347655934 51.50372732305939, -0.17196178436280585 51.50386088908848),(-0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085),(-0.168142318725583 51.50382081932085, -0.16829252243042417 51.50233821314898),(-0.16829252243042417 51.50233821314898, -0.171983242034926 51.5023248561174),(-0.171983242034926 51.5023248561174, -0.17196178436280585 51.50386088908848),(-0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085),(-0.168142318725583 51.50382081932085, -0.1652884483337343 51.50372732305939))'
SET @multiline = Geometry::STMLineFromText(@coords, 4326)

This just repeats each pair of coordinates, apart from the first and last. It’s still an invalid geography type though, so I’m not sure of the value of this. Everything I’ve read, and the blog comment plus Johannes’s comments led me to the view that this would be valid, but I still get an exception when trying to create this.

Making valid data with Geometry types

The second option is to load the original data into a geometry type instead of a geography type:

DECLARE @coords nvarchar(max) = 'LINESTRING(-0.17372131347655934 51.50372732305939, -0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085, -0.16829252243042417 51.50233821314898, -0.171983242034926 51.5023248561174, -0.17196178436280585 51.50386088908848, -0.168142318725583 51.50382081932085, -0.1652884483337343 51.50372732305939)'
DECLARE @line Geometry = Geometry::STGeomFromText(@coords, 4326)

This loads without an exception because the geometry type can contain invalid data. You can use IsValid() to check, and MakeValid() to make it into a valid type:

DECLARE @fixed Geography = Geography::Parse(@line2.MakeValid().ToString())

We now have a geography type, with corrected data. What does it look like? Well, on an image, pretty much the same:

image

The points however, show that the data has changed:

  Original     Made Valid  
1 -0.173721313476559 51.503727323059300   -0.173721313476559 51.503727323059300
2 -0.171961784362805 51.503860889088400   -0.171961784362805 51.503860889088400
3 -0.168142318725583 51.503820819320800   -0.168142318725583 51.503820819320800
4 -0.168292522430424 51.502338213148900   -0.168292522430424 51.502338213148900
5 -0.171983242034926 51.502324856117400   -0.171983242034926 51.502324856117400
6 -0.172004699707046 51.503834175913900   -0.171961784362805 51.503860889088400
7 -0.168099403381342 51.503794106122800   -0.168142318725583 51.503820819320800
8 -0.165288448333734 51.503727323059300   -0.165288448333734 51.503727323059300

It’s not so easy to see, but points 6 and 7 have changed. What’s the difference? Well, we can use the spatial features to find out:

DECLARE @p1 geography = Geography::Point(51.503834175913900, -0.172004699707046, 4326)
DECLARE @p2 geography = Geography::Point(51.503860889088400, -0.171961784362805, 4326)

DECLARE @p3 geography = Geography::Point(51.503794106122800, -0.168099403381342, 4326)
DECLARE @p4 geography = Geography::Point(51.503820819320800, -0.168142318725583, 4326)

PRINT @p1.STDistance(@p2)
PRINT @p3.STDistance(@p4)

The answer for both is 4.20861 metres apart. Is this accurate enough? Possibly, depending upon your application, but I’m not sure it is for me, especially if you consider the data could be used for legal reasons. We’d still have the original point data, but if the corrected line string data is used to make decisions, there could be an issue. It would be good to work out what the formula used is when SQL Server makes this line string valid (one day I’ll delve into the assembly and look); the real question is, could making the line valid radically change the ordering of points, as it does for some geometry types. Consider the following:

image

Made up from the following points:

MULTILINESTRING ((0 10, 5 10), (5 10, 10 10), (10 10, 10 5), (10 5, 5 5), (5 5, 5 10), (5 10, 10 10), (10 10, 15 10))

Making this valid, results in the same view, the same set of lines, but the points are completely different.

MULTILINESTRING ((15 10, 10 10), (0 10, 5 10, 5 5, 10 5, 10 10, 5 10))

If all you’re describing is a shape, or a boundary, or a set of lines, then this is perfectly acceptable, but when the ordering of the points within your line is critical, then MakeValid won’t work for you. Will this affect my real life data? Who knows, I’ve yet to perform an analysis; if MakeValid only moves points (and even then that 4m move may be too much), then it might be OK, but if it strips points and re-orders, then I’ll have to abandon all plans to use line strings.

In defence of SQL Server, I understand why the data is deemed invalid, because that’s what the standard says, and Microsoft have followed the standard. But this is one area where the standard really sucks for real life tracking data; maybe these scenarios weren’t considered, or they were considered and the view was that line strings wouldn’t be suitable.

posted @ 10/9/2009 12:53 PM by Dave Sussman

Tracking GPS points with SQL Server Spatial

In my previous post I was talking about the new SQL Server 2008 spatial features and how they help with most types of location data, but I mentioned the big issue is the trace back one, where a line isn’t valid if it goes back on itself. I thought I’d explain this more clearly, so consider the following points that define a line:

-0.17187595367432515, 51.50221132119076
-0.17191886901856548, 51.503840854209066
-0.1680564880371023, 51.50378742782091
-0.17191886909856548, 51.503840854209066

This defines 3 segments: vertically up, across to the right, and then back to the left, back to the second point. It’s not immediately obvious that there are two horizontal lines, because they are so close to each other, but they are there.

image

Points 2 and 4 are almost the same, only 1 digit difference and that at the 11th decimal place, and that’s enough to make this a valid line string. Change that single digit so points 2 and 4 are the same and it’s invalid; attempt to create a LINESTRING based on the invalid points gives:

A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.ArgumentException: 24200: The specified input does not represent a valid geography instance.

The figures above are to a very high resolution, but consider a general purpose GPS unit, with perhaps only 5 significant places for it’s resolution, the chances of points overlapping increases. You can easily take two GPS readings without moving and get two different points, or three readings and three points, but giving only two locations (I have data where this has happened). The accuracy of modern GPS receivers is around 5-10m, sometimes better, sometimes worse; more expensive differential or gyro-based GPS units give more accuracy, down to centimetres, but these are more expensive and generally not available in consumer units.

Most applications that track objects, whether they be people or vehicles, could easily come up against this sort of data. It’s not hard to think of scenarios; consider tracking a car, which is stopped in traffic; a car coming the opposite way wishes to turn in front of it, so the first car reverses back a little, gives the second car room, then edges forward again as traffic moves. As we start to rely upon location based services more, our reliance upon accurate data increases. My view is that the rules on validity of line strings needs to be relaxed, although some browsing indicates that the rules are a well-established standard, so I’m on a knife edge: extend the standard or break it to make my life easier? I’m a huge fan of standards, but this one doesn’t seem to be that practical in real life. Many of the examples you see show a few individual points, or county and country boundaries, but there’s very little real life tracking data.

Multiple Line Strings

Even if Microsoft do relax the limitations on what constitutes a valid line string, it’s not going to appear until the next version, so workarounds need to be used. First is the support for multiple geometries, which is easier to explain if we go back to simple points:

0, 0
0, 10
0, 5

This is an invalid LINESTRING, so you couldn’t do this:

DECLARE @line Geography = 
        Geography::STGeomFromText(‘LINESTRING(0 0, 0 10, 0 5)’, 4326)

But you could represented this as a MULTILINESTRING:

DECLARE @line Geography = 
        Geography::STGeomFromText(‘MULTILINESTRING(0 0, 0 10),(0 10, 0 5)’, 4326)

This consists of two line strings, so it perfectly valid. The problem now becomes, how do you know where to split the list of points? You could, perhaps, build up a collection; if a point already exists in the collection, start a new set of points. It would work, but isn’t very efficient (although if you don’t create these very often that might be irrelevant), plus it’s harder to do in SQL.

Exception Handling in SQL

Another option, which I’m currently investigating, could be to just wrap the creation of the line string in a try catch. Yes, for those that didn’t know, SQL has exception handling. For example, I could do:

DECLARE @line Geography
BEGIN TRY
  SET @line = Geography::STGeomFromText(‘LINESTRING(0 0, 0 10, 0 5)’, 4326)
END TRY
BEGIN CATCH
END CATCH

This solves the problem of the invalid geometry by simply ignoring the exception. The geography object exists and contains the correct data, although there’s no guarantee that any of the spatial methods will produce the correct results when used on this invalid type.

Investigations continue …

posted @ 10/6/2009 1:18 PM by Dave Sussman

SQL Server Spatial

One of the applications I work on deals with a lot of geographical data; 32Gb database, one table having 22 million rows. Certainly not the biggest I’ve heard of, but the biggest I’ve worked on.

Most of this data is point data, which is currently stored as separate Longitude and Latitude fields, which are floats, but we’re now on SQL 2008 and using the new spatial features has some advantages, noticeably speed, and to take advantage of that we need to add a column of type Geography. Next, this column needs to be updated with the existing data:

UPDATE Waypoint
SET Location = GEOGRAPHY::Point(Latitude, Longitude, 4326)
FROM Waypoint

On it’s own this doesn’t bring us much; sure we’re now using the new type and can use the built-in functions, such as working out if one point is within 100 metres of another:

DECLARE @MyLocation Geography = GEOGRAPHY::Point(StartLat, StartLong, 4326)
DECLARE @MyBufffer Geography = MyLocation.Buffer(100)

SELECT Location
FROM Waypoint
WHERE Location.Filter(@MyBuffer) = 1

On it’s own this is an improvement from our existing code, which has to calculate distances manually, but any calculations we now use would be hampered without a spatial index:

CREATE SPATIAL INDEX Location_Idx ON Waypoint(Location) USING GEOGRAPHY_GRID

Now the filtering can use the geospatial index, which brings massive performance increases. One procedure in our old code is a complex cursor based one, matching waypoints to agreed waypoints (think mountain biking competitions, where you have to follow a set route; matching points along the way allows us to ensure the route was followed, give or take those 100 metres). Given that this table has 22 million rows, the old cursor approach barely worked at all; very high CPU usage and an eternity to run meant we didn’t really use it. The new procedure, using the spatial functions and appropriate indexes, finishes in 9 seconds – an improvement of over 30,000% – and I’m pretty sure we can improve it even further; the first attempt was simply to use the spatial features. This is a monumental improvement and will revolutionise what we can do with our application, doubled by the fact that we’ll also be using the Silverlight Bing Map control.

And now to a downside of the spatial features, which is that if your define a route as a set of waypoints and use the LINESTRING feature to define the polyline of the route, the points cannot trace back over themselves. Cross yes, but not trace back. Consider the following simplistic set of points:

0, 0
0, 10
0, 5

This describes a trace back situation, which may be perfectly valid; cycle to a marker and cycle back. Depending upon how close the forward and back routes are, the GPS points might give the above results. In fact, we have the above data issue for three points of a stationary cycle, where the GPS drift has caused the data, albeit at the 6th decimal point, to give two different readings, but ones that case a trace back. For our application, and possibly any application using GPS units, we cannot therefore use a LINESTRING; you can’t event create the Geography type with that data, because the data is “an invalid geography type”.  Why would we need this? Creating polylines allows the entire set of points to be treated as a single type for calculations, such as seeing if a point is within X metres of the route, or if one route crosses another. Without the polyline we have to iterate the points individually.

The Geometry type allows the type to be created, and I’ve yet to work out whether whether we could use this type as a fake Geography type. The Geography type has built in knowledge of the Earth and takes into account the spherical (oblate spheriod in fact) nature of the Earth in these calculations. The question I need to answer is whether the difference between using the two types would be large enough to render our calculations invalid. It may be a route (pun intended) I’m forced to use. In the meantime, I’ve logged a suggestion on Microsoft Connect asking for the rules on LINESTRING usage to be relaxed, but even if they are relaxed, it won’t show up until the next version of the product. In the meantime, I can continue to improve our product by replacing the manual calculations with the spatial ones.

posted @ 10/4/2009 12:07 PM by Dave Sussman

Windows Home Server

 

By and large, server products don't excite me; they are utility things, there because they have to be. I may be changing my mind though.

Over the last few weeks I've reorganised my servers, virtualising many of them and migrating my data to a new server; it was meant to be an old server, re-housed in a case big enough to take the 2 4-disk hot-swap drive bays, but the old motherboard didn’t fit so a new one was slotted in place. An afternoon of plumbing and an installation of Widows Home Server, and the new storage server is ready, and boy, is it a good product. Since the great disc disaster of ‘05, I’ve been paranoid about my data, keeping it in multiple places, and always hated the fact that you can have oodles of discs, but each is standalone. Unless you have a RAID controller, which I did, but failures were multiple. I was away. It was traumatic.whs

The great thing about WHS is that you don’t bother about RAID, it does it for you; it aggregates all of your discs and presents a single big volume with shares (a bit like drobo). You can specify whether files under those shares are duplicated, and WHS takes care of keeping multiple copies in case of a disc failure. Or if you want to increase your storage, you can replace a disc with a larger one. Access control is simple, nothing like the complexities of the domain model, but that’s a good thing for a home product, or even for a small business and I think Microsoft should push this to the small businesses as it’s ideal - easy to use, and fairly cheap; you can buy a ready installed server for a few hundred pounds and be up and running in an hour or so.

Easily expandable and safe storage isn’t the only benefit though, backups figure heavily too. On client machines you run the connector software and your client machine is added to the server; you then specify which drives to backup and that’s it; everything happens automatically. It even keeps backups back to 3 months (by default), and allows instant restore of entire client machines in case of disc failures. I still keep data locally (robocopying it to the WHS share nightly) and use Mozy for offsite backup, but I’m much happier knowing my machines are backed up and easily restorable.

Client integration is good too, with the server shares (Music, Photos, Videos) being automatically added to Win7’s libraries. Media Centre integrates too, so the same folders are made available

Anyone who’s got several Windows machines and wants centralised storage and backup should take a look into it.

Next step, installing DVDShrink and ripping my DVDs. There’s a MyMovies plugin for WHS, so I won’t even have to get up to play my favourite movies. Once the new PSU for my MCE box arrives of course. That was traumatic too.

posted @ 9/9/2009 7:45 PM by Dave Sussman

Upgrade your browser

As someone who has struggled with cross browser issues and wasted many hours, days even, on getting things to work in IE, I’ve joined the campaign to encourage people to upgrade. Specifically, to upgrade from IE6, which really does need taking out round the back and shooting; it’s for its own good. I’ve added a subtle push to remind people to upgrade.

I recently added Google Analytics to my blog and to my main site, never really having bothered with traffic information before; I don’t get that much traffic for it to be interesting. But, having added it, I noticed around 24% of my traffic was IE6, which seems high given the market I’m in: Web development, Standards, CSS, etc. I’ve only been tracking this for a few weeks, so statistically it’s not a great sample, but interesting none-the-less.

So a couple of custom reports brought up these figures for the IE6 users.

Continents:

  • USA, 37%
  • Asia, 34%
  • Europe, 19%
  • Africa, 5%
  • Oceana, 3%

 

Operating Systems:

  • XP, 90%
  • Server 2003, 7%
  • Windows 2000, 2%
  • Windows 98, 0.3%

 

So, to all you IE6 users, leave a comment as to why you’re still using it? Lazyness? Corporate policy? To spite me?

Technorati Tags:

posted @ 2/25/2009 11:44 AM by Dave Sussman

WebDD is back

Yes, WebDD is back, after a short break and with a slightly different format. We’re aiming to catch up on some of the news and maybe a session or two from Mix09, as well as a few community inspired sessions. You can both request a session as well as propose one, but be warned, we’re sticking to two tightly focused tracks, so there aren’t many speaking slots available. We’re going to arrange some sessions, but leave some open for you to choose.

And if you’re wondering why the site looks familiar, it’s the same as DDD; common code base and common membership, so if you’ve created an account to submit to DDD then you’re already registered.

 

Technorati Tags: ,

posted @ 2/18/2009 3:47 PM by Dave Sussman

This Blog Has Moved

Hello all, this is just to let you all know that if you subscribe to this feed, it has now moved to a new home at http://blog.hmobius.com. Also, you may want to update the feed address in your aggregators. The new address is http://feeds2.feedburner.com/dansarchive.

Thanks for reading this blog and I hope you'll join me at the new address.

Dan

posted @ 1/22/2009 9:40 AM by Dan Maharry

ASP.NET Site Maps, Security Trimming and Roles

This is one of the most frequently asked questions and seems a constant source of confusion for everyone, as it was for me when I first read about it. The ASP.NET SiteMap allows a navigational structure to be defined as a set of XML elements, which are perfect for describing a hierarchy of menu items. These XML items are a siteMapNode element, which has an attribute roles. It seems obvious that this defines the roles that can see this item, but the obvious is in fact wrong. Here is the most important fact about site maps:

The roles attribute does not restrict visibility of a node.

That should be clear enough, even if it still seems wrong. Here’s how it works.

All restriction to pages is handled via authorization. You can do this either in the base web.config, or in web.config files in folders. For example, assume there is an Admin folder, under which all the administration pages are kept. You only want these pages accessible to users within the Admin role. You would configure your authorization like so:

<location path="Admin">
  <system.web>
    <authorization>
      <allow roles="Admin" />
      <deny users="*" />
    </authorization>
  </system.web>
</location>

The Admin folder can now no longer be accessed by anyone who is not in the Admin role; if you aren’t in the Admin role and try to navigate to a page in the Admin folder, either via link on another page or by typing the URL directly into the browser, you’ll be redirected to the login page. You can have multiple location elements in your web.config, for different folders or even individual files; in fact if you have a restrictive site, you may want to explicitly open up certain pages, such as the login page; it’s hard to login to a site when you don’t have authorization to access the login page. If you prefer not to clutter your base web.config you can create a web.config file in the Admin folder with the same rules; you won’t need the location element since the configuration applies to the current folder.

So that’s authorization done; access to the pages is locked down. Now lets consider navigation. The ASP.NET navigation framework honours the authorization, but only if you configure security trimming on the provider, which isn’t configured by default. This means that you need to add the site map configuration to web.config:

<siteMap enabled="true" defaultProvider="AspXmlSiteMapProvider">
  <providers>
    <clear />
    <add name="AspXmlSiteMapProvider"
         securityTrimmingEnabled="true"
         type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         siteMapFile="web.sitemap"/>
  </providers>
</siteMap>

Most of this is configured at the machine level when ASP.NET is installed, but crucially the securityTrimmingEnabled value is set to false by default. What the above does is clear out the existing configuration and add a new entry with the attribute set to true. At this stage the navigation framework will now honour the authorization rules, so menu items won’t be shown if the user doesn’t have authorization for that item; it doesn’t matter if you use a Menu or TreeView to display the menu items, the crucial part is using the SiteMapDataSource (or the Sitemap API if you’re building the menu manually). If you have a custom site map provider, such as a database driven one (such as this one on MSDN), then this might have to do it’s own security checking, but it depends at which base class you inherit from. That’s another story for another post though.

So if you don’t need to modify the site map elements themselves, what’s the roles attribute for? Well this works in the opposite way you probably expect, by opening up visibility of the node, showing the node if the user is in the stated role even if they don’t have authorization to access the page itself (because the authorization rule restrict them from accessing it). Why would you do this? Well, you have to understand how security trimming works. When deciding whether a user can see a node, both the authorization and the physical file permissions are checked; if either fail then the node is deemed inaccessible. There are two very common times when physical file checks fail:

  1. The URL isn’t local. If the file doesn’t exist locally then no check can take place.
  2. There isn’t a URL. The node could be just a container node, with child pages but no page itself.

In both of these cases the physical file checks fail so the node won’t be shown. You therefore may need to open up the visibility of the node. For example, consider the following:

<siteMapNode title="Admin" roles="Admin">
    <siteMapNode url="~/Admin/membership_CreateMember.aspx" title="Create User" />
    <siteMapNode url="~/Admin/membership_GetUsers.aspx" title="View Users" />
    <siteMapNode url="~/Admin/roleManager_CreateRole.aspx" title="Create Role" />
    <siteMapNode url="~/Admin/roleManager_AddUserToRole.aspx" title="Add User to Role" />
</siteMapNode>

Here the Admin node doesn’t have a physical page, it’s purely to allow organisation of the admin items into their own submenu. Without the additional roles attribute the node and children wouldn’t appear, but roles="Admin" states that the node should also be shown to users within the Admin role, even if the security checking fails. We don’t need the attribute on the child nodes because they have physical pages, so the file checks will succeed.

So it’s fairly straightforward if you remember the rules:

  • Configure security restrictions on pages with authorization in web.config.
  • Redefine the site map provider, enabling security trimming.
  • Add the roles attribute to site map nodes to widen the visibility.

posted @ 1/12/2009 12:37 PM by Dave Sussman

A Playlist for 2008

A couple of days late but there were a few CDs in Santa’s sack so here’s my track list of highlights from 2008. Not all from 2008 but I bought them then, so hey.

Guns and Roses - Chinese Democracy
It has to be said that if even one track from the unicorn that was the new GnR album was any good, then Axl Rose was going to exceed expectations. Then lo and behold, two tracks turned out to be OK. Don’t think I’ll be holding my breath for the next album though.

Gutter Twins - Bete Noire
The Gutter Twins’ Saturnalia is probably my album of 2008 - a gleaming, polished piece of melancholia from the lead men of the Afghan Whigs and the Screaming Trees. The arrangements are simple yet heartfelt and their voices aged old from years of abuse. Bete Noire in this case showcases Mark Lanegan’s almost sub bass vocals brilliantly. The link above is to a live performance in Helsinki, but you can find the album track here if you prefer.

Alps - Hallucinations
It would be easy to pull a tracklist just from the output of Type Records 2008 releases but for me, this is the highlight, a seven minute aural spliff. Dry and desert-like, the rolling bass figure is a calm anchor for the shimmering sounds the trio put over the top.

Portishead - Machine Gun
We didn’t wait quite as long for the new Portishead album as we did for “Chinese Democracy”, but the Bristolians delivered a much bigger punch than did those from Los Angeles. Ten years later, Third is a different, angrier beast from Dummy or the eponymous album but the quality control is just as high. The highly sample drum machine and pure John Carpenter breakdown towards the end (80s synth soundtracks ahoy) are a joy.

Ihsahn - Threnody
The second solo album, AngL, from Emperor’s front man was a revelation. While The Awakening was an obvious attempt to move himself away from the black metal sounds of his former band, AngL saw him not afraid to tread wheresoever he broke a path, albeit not mix-and-matching styles within individual tracks as Opeth would. Threnody comes late in the album; a calmer moment amidst a tightly focused storm.

Joe Satriani - Andalusia
I am an unashamed Joe Satriani fan and will probably remain so for a good while to come. Unlike the previous album however, the “Professor Satchafunkilus” album that appeared last year hadn’t the immediate appeal and bright songs of Super Colossal in 2006. This one required more listening to get past the standard issue with his songs that intro, verse and solo often jarred rather than flowing into each other. The final track however doesn’t have that problem. A homage to Spain in his own inimitable style, it begins with flighty flamenco guitars laying down theme and variations until his electric enters with a longform solo and more variations on a par with classics such as ‘Echo’ and ‘Slow Down Blues’.

Vangelis \ Scott Bolton - Launch Approval
Besides Ridley Scott’s Final Cut of the film and various HD box sets to accompany it, the 25th anniversary also saw the release of a 3-disc issue of the Blade Runner soundtrack comprising the original 1994 release, a second disc of more inserts from the film and a final disc comprising original music composed by Vangelis and collaborators taking inspiration from the sounds in recognition of the anniversary. For me, Launch Approval recaptures the spirit of the film the best. You can hear the police cars flying through neon-drenched snow between pillars of flame.

Slipknot - Danger Keep Away
A revelation for me this one. While they had their moments, the first two Slipknot albums were in general a bit Meh! for me and so I ignored them for a few years. Then All Hope Is Gone came out last year and by chance I saw the previous album, ‘The Subliminal Verses’ in a bargain bin and bought it for a laugh. And then got blown away by it. In a reversal of happenstance, there was but one bad track here and 13 solid tunes with the nonet confident enough not to rage through every track. Danger Keep Away closes the album, a brooding warning to be heeded.

Kingdom of Sorrow - Hear This Prayer For Her
Side projects have a tendency to imitate marmite - you either love ’em or you hate ’em. The Kingdom of Sorrow album has been a long time in gestation and while Kirk Windstein (Crowbar, Down) and Jamey Jasta (Hatebreed) have obviously been busy, this debut album is a bit of a one track pony. Listen to it from track 1, Hear This Prayer For Her, and you’re drawn into a rhythm and groove for the rest of the album but join at any other point in time and the hook is lost. Hear The Prayer then - either five or fifty minutes long. Linked is the (better) five.

Joseph Arthur - Morning Cup
By far the best find on the KEXP Song of the Day podcast, Morning Cup is a gentle greeting for a fine, warm spring day. From Arthur’s Could We Survive EP, one of four he released in 2008, for this we can forgive the facial hair borrowed from Liam Gallagher.

Fatboy Slim - Wonderful Night
The man Norm doesn’t often put a foot wrong in the Big Beat department and this three minute wonder from his Greatest Hits album is just one of many I could have chosen. Right Here Right Now is probably the best single dance track in history, but Wonderful Night is pure joy.

Mark Ronson - God Put A Smile Upon Your Face
I’m a bit late to the Mark Ronson party - the smarmy grin on Buzzcocks spoiled him for me and Lily Allen collaborations didn’t help, but I’m happy to admit that cockney girl and one other track aside (Yes, please do “Stop”) it is genuinely good. And this big band cover of Coldplay’s only upbeat tune in three albums is a great way to start the morning.

Meshuggah - Combustion 
Meshuggah have been due a good album for a couple of years and ObZen delivered in spades for the Swedish math-metallers. Harsh angular riffs, uncomfortable time signatures and drill sharp vocals characterize the sound they have delivered over several albums - like Tool but with extra hatred.

Clint Mansell - Together We Will Live Forever
Whether you know it or not, soundtracks are a true treasure trove for great music and Clint Mansell has composed several blinders since Pop Will Eat Itself broke up. This is from The Fountain.

posted @ 1/5/2009 10:16 PM by Dan Maharry

What would you like to see in the next edition of Programming ASP.NET?

With the .NET 3.5 cycle out of the way and ASP.NET 4.0 on the horizon, it's time to try and figure out a way to incorporate the many new features and techniques that have emerged \ been released into the next editions of ASP.NET books.

So then, what would you put in 'Programming ASP.NET 4.0' and what would you NOT put in it? Books are supposed to be for the programming community so here's your chance to have your say.

Feel free to add comments here or in the thread I've started on Stack Overflow about the same topic.

posted @ 12/1/2008 4:05 PM by Dan Maharry

Latest Images

From Me Photos
From Ebay
From General pictures
From Misc
From Me Photos
From Me Photos
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends
From Friends