Posts

ASP MVC encoding route values

I’ve recently been using ASP MVC 2 to develop a business application.  As you may already know the ASP MVC routing system works with URLs which look like this http://localhost/Client/Details/IBM In standard ASPX apps the URL would look more like this http://localhost/Client/Details.aspx?code=IBM The first URL obviously looks much nicer than the 2nd, however it comes at a cost.  What if the “code” of your object is something like “N/A” for “Not applicable”?  You end up with a URL that looks like this http://localhost/AbsenceCode/Details/N/A What we really need is to have ASP MVC encode the value “N/A” as “N%2FA”.  The problem is that even if it did do this then by the time ASP MVC receives the value it has already been decoded, so we get a “400 bad request” error.  This is a real pain, because in business we can’t really tell a customer “You can only use characters A to Z, 0 to 9, underscore and minus in your codes” because they will tell you that they have used the code N/A

ECO and distributed transactions

My current app is a website, each client gets their own unique database in order to help prevent possible data access from other clients (and meet various legal requirements too.)  One of the features of this application is that there is some core data (such as countries/currencies) which is maintained on behalf of the client.  This data will be identical for all clients, and only maintained by a system administrator. Obviously expecting the admin to log into each client to perform updates is unreasonable, so I have structured my app so that there is a separate Admin website which updates a master database and propagates the changes to all of the clients. When the master website does an update it performs it within an IUnitOfWork, and then tells the same update command to execute for each client database too.  If any of these updates fail for whatever reason then the whole thing needs to be cancelled whether one of the child databases updated or not. using (var distributedTransac

Tightly coupling generic types

Update : Instead of decorating responses with IResponseFor<T> I now instead decorate the command/query with IExpectResponse<T> - Each command/query should only have one response type, and this way it makes it possible to specify the return type should be something simple like a GUID. My server application works purely on a request/response pattern, like so var query = new GetCustomerQuery(customerUniqueID); var response = AppServer.Execute < GetCustomerQuery , GetCustomerQueryResponse > (query); What I wanted to avoid though was the possibility that the user (me writing the client app) would do something silly like the following code and use the wrong pair combination var query = new GetCustomerQuery(customerUniqueID); var response = AppServer.Execute < GetCustomerQuery , GetEmployeeQueryResponse > (query); Up until now I had the server interface defined like this, so that I can at least ensure the generic parameters are a Query and R

ECO Persistence Mapper per connection

The Enterprise Core Objects Persistence Mapper is a singleton which is used by all EcoSpace instances.  It’s purpose is to load mapping information from the DB when your app starts and to cache it, improving performance. I needed a connection per client, all running within a single application.  This was a problem because once the PMP is created its connection string is tied to a single database.  So I had to come up with a new PersistenceMapperDynamicSharer component.  It is used on the EcoSpace to specify the PMapper type; additionally you can specify a connection string to use. It works by dynamically creating a descendant class of your PersistenceMapperProvider at runtime, one for each connection string. public class PersistenceMapperDynamicSharer : PersistenceMapperSharer { static ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(); static Dictionary < string , PersistenceMapperProvider > MapperProviders = new Dictionary < string , PersistenceMapperPr

PropertyChangedEventHandler is not marked as serializable

My data-transfer-objects implement INotifyPropertyChanged, which was giving me a problem whenever I tried to serialise them over a Remoting session.  If you try to add [NonSerialized] to the event you get an error informing you that you can only apply this attribute to fields, and not properties. The solution is pretty simple, I think the .NET compiler should do this by default. [NonSerialized] PropertyChangedEventHandler propertyChanged; public event PropertyChangedEventHandler PropertyChanged { add { propertyChanged += value; } remove { propertyChanged -= value; } }

Partial declarations of must not specify different base classes

I wanted to use a common base class for a set of UserControls in my WPF application, but when I changed the class’s ancestor in the code file and compiled I would get the error “Partial declarations of must not specify different base classes” This is because when you compile a WPF application Visual Studio generates a partial class in a code-behind file automatically, the base type specified is always “UserControl”.  To solve this problem change your XAML from this   < UserControl x:Class ="MyApp.MyControl" /> To this < local:SomeBaseTypeYouWantToUse x:Class ="MyApp.MyControl" xmlns:local ="clr-namespace:NameSpace.To.Your.BaseClass" />

A WebServer for MonoTouch that also parses posted form data (HttpListenerRequest)

I found a few examples of web servers for MonoTouch but none of them parsed the data sent in a POST request.  I looked around the web and was unable to find any examples of how to achieve this.  So now that I’ve written it myself I’ve decided to share my own implementation.  This includes not only the code for processing the form post data but also for registering request handlers etc. Here is an example of how you would use the web server public BookUploadViewController() : base ( " BookUploadViewController " , null ) { RequestHandler = new DefaultRequestHandler(); var defaultActionHandlerFactory = new DefaultActionHandlerFactory(); RegisterActionHandlers(defaultActionHandlerFactory); RequestHandler.AddActionHandlerFactory(defaultActionHandlerFactory); WebServer = new EmbeddedWebServer(RequestHandler); } void RegisterActionHandlers(DefaultActionHandlerFactory factory) { fact

Embarcadero should revive Bold for Delphi

I've recently been doing some work on a Bold for Delphi application. I am really quite surprised how much I am still impressed with this framework, it really was (and still is) so much ahead of its time. Embarcadero really should revive this product and put it back into Delphi. They could make it a free addition to Delphi, or maybe even ship it with Delphi as an open source project. Embarcadero! You have a great tool here, don't hide it away, use it!

Free: One year TechNet Plus subscription

http://arstechnica.com/microsoft/news/2009/06/free-one-year-technet-plus-subscription.ars Update: The UK link from this site has been taken down :-)

Bing

I searched for "mrpmorris" on bing.com recently.  Now on Google it would show the address of my blog as the first result, which is very relevant.  On Bing it showed a page from a web chat from over 3 years ago, not very impressive. Not sure how long this photo will remain on the web for, but I found it quite interesting... http://farm4.static.flickr.com/3604/3585051300_d23a37a32e_o.png

Generation gap - update

Martin wrote to me and explained something I wasn't aware of. He doesn't catalogue best practises or only the ones he likes, he is cataloguing all patterns he can find. He said he would rather someone made an informed bad decision than an uninformed good one. Not quite sure I agree with that either :-)

Generation gap

I have just read this blog by Martin Fowler. I like a lot of what Martin writes, but this is not one of them. The article suggests using inheritance to separate code-generated classes and manually written classes. You would descend from a code-generated class instead of trying to modify the code-generated source. The problems I see with this are Attributes If I have a descendant of a code-generated class how do I attach .NET attributes to members? I’d have to override them and add the attribute in the descendant which would mean all of my members need to be virtual. Obviously this wouldn’t work for Private members. I expect you’d have to attach all of your attributes in the tool which generates the source code, but I don’t like this idea. I will explain why later. Sealed / final What if we want to create a sealed/final class? We can’t. What if we want a specific member to be sealed/final? Then we couldn’t add attributes to the members. Partial Microsoft introduced Partial clas

I've just ordered some books

Someone kindly gave me a £100 gift certificate for Amazon.  I posted a request for book suggestions to 3 groups where I would expect to receive good recommendations    http://tech.groups.yahoo.com/group/altdotnet/    http://tech.groups.yahoo.com/group/domaindrivendesign/    http://groups.google.com/group/RhinoMocks I received a lot of recommendations (thanks everyone!) - here are the ones I have bought:   Building Domain Specific Languages in Boo   Writing Secure Code, Second Edition   Analysis Patterns Reusable Object Models (OBT)   How to Solve It: A New Aspect of Mathematical Method   Object Oriented Project Design   Extreme Programming Explained: Embrace Change   Getting Things Done: How to Achieve Stress-free Productivity    Here are the books that made it onto my "future" list which I didn't have enough cash for this time around.   http://www.amazon.co.uk/gp/registry/wishlist/13GXONVVMLHZZ I generally went for the cheaper books first, so that I could get as much inp

MUMS - How good you are when things go wrong

I always say this so I have probably blogged it in the past, in light of my MOZY incident probably recently, but "It's not how good you are when things go right, it's how good you are when things go wrong". My wife and I are (unexpectedly) expecting our 4th baby.  We paid for a private scan at MUMS last week.  Part of the package is a DVD of the scan.  The scan was a really good one, but unfortunately when we got home we realised our DVD was completely blank. I phone them up and they offered a free scan.  I was still disappointed because there was a beautiful part of our previous scan that would be lost, where we were zoomed right into our baby's hand as she repeatedly clenched and reopened her hand, but I agreed because at least we would have something . When we had our scan they gave us probably double the normal amount of time.  In addition to that they upgraded our scan from a plain ultra sound to one of those 4D scans.  We were given twice as many printed ph

Bletchley Park

If you are unaware Bletchley Park played a vital part in World War II, it undoubtedly shortened the war (possibly by years) by decoding intercepted Nazi messages which had been encoded on the Enigma machine.  This site is credited with being the place where the first programmable computer was used to crack the more complex Lorenz Cipher Machine. According to this petition number 10 Downing Street... http://petitions.number10.gov.uk/BletchleyPark/ ...the park is severly lacking in funds and has at best 2 to 3 years before it is forced to close down.  The idea that a site with such a historical significance could be bulldozed and redeveloped is astonishing! Please help to preserve this computer related historical UK site by making as many UK residents as possible aware of this petition!

Locking in ECO 5

Jonas has just added the following feature to ECO 5 which should turn up in the next build. Let's say you have a package with a single class LockObject in it. This LockObject must have TimeStamp locking, but you use this package in many applications.  In ECO 5 you can set the default locking mode for a package. Now let's say you have multiple packages that you use in many applications and the locking type is different per app.  App 1 uses AllMembers locking, App 2 uses no locking at all; how can you specify the locking type?  Now you can add a .NET attribute to the top of your application specific EcoSpace class.... [UmlTaggedValue("Eco.OptimisticLocking", "AllMembers")] public class Application1EcoSpace : DefaultEcoSpace {   etc.... } Locking is determined like so: The kind specified on the class itself. The kind specified on any super class. The kind specified on the package. The kind specified on the EcoSpace.
Someone I know recently got stung by this, so I thought I’d mention it... static void Main(string[] args) {   int a = 1;   int b = a;   Console.WriteLine(AreSame(a, b).ToString());   Console.ReadLine(); } static bool AreSame(object a, object b) {   return a == b; } What’s the output to the console? Does a equal b? Even if you didn’t know the answer you will have guessed it is False otherwise this blog would be totally pointless! It’s false because the parameter types of AreSame are both "object". For a value type such as "int" to be passed as an object it needs to be boxed, so a new object instance is created which stores the value "1", but this is done for both parameters so we end up with 2 new instances both holding the value 1. 1 equals 1 for value types but the default comparison for System.Object is to compare references. If they are not the exact same object (and in this case they are not) then the result is false. Now if we typecast both a and

I don't like AccuRev

A company I have been contracting for decided to use AccuRev as its source control solution. I've not liked it from the start because it is too much work, the terminology in it is quite frankly stupid, and it is far too "chatty" when you work remotely.  Anyway, for some time now I have suspected it has been losing source code. On a few occasions I have found myself looking at source code and thinking "I could swear I have already done this!". Well, last week I wrote some pretty nice code which used multiple threads in a test case to ensure I experienced expected behavior when multiple users update the same objects in a database.  Today one of the other programmers said to me "Didn't you write more tests than this?" and showed me the tests.  My multi-threaded tests were gone! I knew it all along, but now it is indesputible, AccuRev has been losing my work!

The Pragmatic Programmer

My copy of this book has just turned up. I am book hungry these days, can't wait to read it :-)

Connascence

I’ve just finished reading What every programmer should know about object oriented design . The first couple of sections are a bit useless really, but the 3rd section is very good. I particularly liked the section on the difference types of connascence in software. There’s some basic information about it here if you fancy a brief overview of what it is about. It’s a really good book, I recommend you read it! Should only take a day if you only read the 3rd section.

I've just ordered a Java book

Image
http://java.sun.com/blueprints/corej2eepatterns/index.html It was only $0.41 used in the USA, came to about £6 with posting to the UK. I don't write Java and at the moment have no interest in learning it, but I expect I will be able to read it without problems (never really looked at it). So why did I buy this book? Because it is about this... That's why :-)

Prism - Invariants, and pre/post conditions - update

Just found out that I can do this too public invariants   Overdraft >= 0 : ’OverdraftGreaterThanOrEqualToZero’;   Balance + Overdraft >= 0 : ’BalancePlusOverDraftGreaterThanOrEqualToZero’; end; Then in my handler routine I get that message! if not IsValid then   throw new Exception(ErrorMessage); Excellent :-)