Posts

Creating a simple factory for objects with a fluent configuration API

Image
When I recently came to writing a new component for a system I thought, "I love using fluent configuration in other libraries so I'm going to write this with a fluent configuration API!". Of course, as with most projects, I made a lot of mistakes and had to keep going back and rewriting it from the ground up. I also wasn't able to find a lot of examples/discussion on creating fluent APIs for configuration so I decided to write a simple example that isn't really useful in itself but is useful as a learning exercise (at least it was for me!) I decided to put the full source on Github  rather than uploading a zip as I find downloading examples as a zip annoying! The whole idea for the example was to have a simple way of creating a factory object that is able to create objects of a certain type according to some configured rules. To make life easier, I added a constraint to only allow objects with a parameterless constructor. Or to put it another way: ...

Using Google for geocoding without displaying a map

Image
In a previous blog post  I talked about performance tuning SQL queries involving Geographies. In order to use the (now much faster) queries we needed a way of reliably getting a user's approximate location in order to figure out where they were and what the most appropriate content for them is based on that location. Originally, I thought about using the google.maps.Geocoder but I didn't really want to show a map on our UI - a requirement of using the Geocoder as mentioned in Google's ToS. While looking for alternatives, I stumbled across the places auto complete. It's full of juicy goodness, it's easy to use and the documentation even says: You can use Place Autocomplete even without a map. If you do show a map, it must be a Google map. Yay! Here's a screenshot from the documentation: Out of the box it doesn't work exactly as I wanted. I need it to only show results for a certain country and I'm only interested in lat long - I don't...

Spatial index performance tuning

Image
Getting a really good spatial index on a geography column took a lot more effort and reading than I'd ever have dreamed of! It's really hard to find good resources on them so I thought I'd type up a few of the things I've learnt over the last few days trying to get some query times down. Our queries ended up running in about 1 tenth the time as they did with the first attempt at a spatial index. However, even that first index sped the queries up by about 10x. Which leads me to my first point:  Any spatial index is always better than not having one. Hang on Rob, what queries?!  Good question! In the database we have a few thousand administrative boundaries that we want to ask questions about, for the sake of this post (and of tuning the index) our main question is: What boundaries is a point p in? In SQL this looks like: DECLARE @ p geography SET @ p = geography::Point( - 35 , 139 , 4326 ) SELECT BoundaryName FROM dbo.Boundaries WHERE data .STInter...

Importing shape files into SQL Server 2012

In a project we needed a set of boundaries in order to answer domain questions such as:   Which services that we know about can provide activity a at point p? The services we were interested in happened to coincide with the administrative boundaries of a country. For example, states and towns. I might blog about how we linked the services in our database to their boundaries later but the first challenge was getting some spatial data into a database to start messing around with. The first tool I discovered was  http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx . It looked like it would do everything I needed... However Australia and the UK provide their data in different coordinate systems. Data for the UK is available through the Ordinance Survey and uses the British Grid System funnily enough, Australia doesn't use the  British  grid! I decided to use the excellent  dotspatial  to spin up my own quick and dirty importer that wo...

Azure - transforming the csdef file

I adapted this idea from here: http://fabriccontroller.net/blog/posts/apply-xdt-transforms-to-your-servicedefinition-csdef-file/ Basically, we had a situation where we had an app hosted in Azure that was reliant on host headers to switch behavior. Now, host headers are defined within the .csdef as bindings - something like this:     <Site name="Web">         <Bindings>           <Binding name="HttpIn" endpointName="HttpIn" />           <Binding name="HttpIn_CO" endpointName="HttpIn_CO" hostHeader="www.xxx.co.uk" />         </Bindings>       </Site>     </Sites>     <Endpoints>       <InputEndpoint name="HttpIn" protocol="http" port="80" />       <InputEndpoint name="HttpIn_CO" protocol="http" port="82" />     </Endpoints> We als...

ASP.Net ViewEngine caching and how to hack it

In ASP.Net MVC, view engines are responsible for finding your views. You can have as many view engines as you like, and MVC will ask each view engine in turn whether it knows about a particular view. For performance reasons, view engines cache their results for 15 minutes using sliding expiration. When requesting a view, MVC will first ask all registered view engines whether they have already found a view for the current controller context and view name. The first engine to say yes gets to render the view. If no view engine can render the view from its cache, MVC asks each view engine in turn whether it knows how to render the view without using its cache. In an app, some controller actions render different views depending on what the current host is. For example: www.example.co.uk www.example.org Both resolve to the "Home" controller's "Index" action in the same application which always returns View(). However, there are two folders of views:    ...