Posts

EcoRail validation

Here is yesterday's update. I wanted a way to validate the user input. Seeing as there are constraints in the model to me this was the obvious approach to take. The HTML in my main layout (MasterPage) was changed like so <body>   #if ($Errors && $Errors.Count > 0)     <ul class="errors">       #foreach ($currentError in $Errors)         <li>$currentError</li>       #end     </ul>   #end   $childContent </body> This outputs all errors passed in PropertyBag["Errors"] or in my case I used Flash["Errors"]. To validate my product input I changed my controller like so: [AllowEcoSpaceDeactivateDirty(true)] public void Modify([EcoDataBind("Product", Allow = "ID,Name", NoObjectIdAction = ObjectIdAction.CreateNewInstance)]Product product) {   PropertyBag["Product"] = product;   IList<string> errors = GetErrorsForAllDirtyObjects();   if (errors.Count > 0)     Flash["Erro

Changing the URL structure

I wanted the following URL structure in my website www.mysite.com/product/myproductname/whatsnew but the default url mapping in MonoRail would translate this as www.mysite.com/[controller]/[action]/[id] So it would expect to find this public class ProductController {   public void MyProductName(string id)   {   } } whereas what I actually want is public class ProductController {   public void WhatsNew(string productName)   {   } } Open Web.Config Locate the monorail node Locate the routing child node Now add a new <rule> to the top of the list: <rule> <pattern>/(product)/(\w+)/(\w+)</pattern> <replace><![CDATA[ /product/$3.rails?productName=$2]]></replace> </rule> As this is at the top of the list it will have the highest priority. If the URL matches /product it will remap the url From: www.mysite.com/product/myproductname/whatsnew To: www.mysite.com/product/whatsnew.rails?productname=MyProductName without the user ever seein

ECO docs progress

I'm currently in the process of migrating the QuickStart series from BDS over to VS and recreating the accompanying source code. There's quite a lot of information in those articles, I hadn't realised how much I had written! Well, the transcription is going quite well. So far I have made it as far as article number 5. This one is going a bit slower because it is also a translation from VCL .NET to WinForms.

Inversion of control

As you may already know I am writing a website. I've chosen to use MonoRail for the web part and ECO for the persistence. Today has been great fun! I have modified the Castle.MonoRail.EcoSupport library with the following enhancements. You can now specify a [DefaultEcoSpaceType(typeof(MyEcoSpace))] on either the class or method. On the EcoDataBind reflection attribute you can now specify as little as [EcoDataBind("Product")] on your method parameter, this will use the specified DefaultEcoSpaceType specified, or throw an exception if no default was specified. This lets me write code like this [AllowEcoSpaceDeactivateDirty(true)] [UseEcoSpacePool(false)] [UseEcoSpaceSession(EcoSpaceStrategyHandler.SessionStateMode.Never)] public class ProductAdminController : BaseController {   public void Create()   {     PropertyBag["Product"] = new Product(GetEcoSpace<MyWebSiteEcoSpace>());     RenderView("Modify");   } } I can now easily create actions Creat

MonoRail

I'm working on a new website for work. I've decided to use ECO for the business model due to how much time it saves me. I took a look at the new MVC ASP approach provided by Microsoft recently and was a bit disappointed. There were bugs in some pretty basic errors that would have been an annoyance to code around, and it just didn't feel "ready". So, I've decided to take another look at MonoRail. I'd already written an ECO implementation for MR in the past but I decided to start the implementation from scratch. This was mainly inspired by the new EcoSpaceManager in ECOIV for ASP .NET. Using an EcoSpaceManager you can easily utilise many instances of different types of EcoSpace in the same page. I decided I would do the same. Unlike the EcoSpaceManager I haven't gone for unique string values for identifying the EcoSpace instance I want. That approach is good in ASP .NET where you want to bind different components together to generate your HTML bu

What's in a name?

When thinking of a name for a new product I wish people would be more original. For example, I have just spent ages looking for information about how to create a ternary in a scripting language known as Brail. Instead of finding what I want I have had to work my way through loads of information about blind people.

Single application instance

I needed my app to be a single-instance app. It was easy to implement, like so: bool mutexIsNew; Mutex mutex = new Mutex(true, "SomeUniqueID", out mutexIsNew); if (mutexIsNew) Application.Run(new MainForm()); A problem arose though when my app started to need to receive command line arguments. How do you also pass those onto the original app? There is a class for this purpose named "WindowsFormsApplicationBase", it's in Microsoft.VisualBasic.dll 01: Add a class to your project like so: internal class SingleInstanceApplication : WindowsFormsApplicationBase { private MainForm MainFormInstance; internal SingleInstanceApplication() { IsSingleInstance = true; EnableVisualStyles = true; MainFormInstance = new MainForm(); MainForm = MainFormInstance; } protected override bool OnStartup(StartupEventArgs eventArgs) { return base.OnStartup(eventArgs); MainFormInstance.AcceptCommandArguments(eventArgs.CommandLine); } protected o