Category Archives: Generator

Castle Generator now on Castle trunk

A couple of weeks ago the Generator project was voted to be moved from the contrib repo to Castle main trunk. I’m ambivalent about this. Initialy I was happy to find lots of great people finding it usefull. Then, when I realised that I had lost control of the projet, I was frustrated. I know this was part of the contract. But it’s hard to just… let go.

7 Comments

Filed under Castle, Generator

Ajax Scaffolding with Castle Generator

Dan Bunea created an generator for Ajax Scaffolding, check out the step by step instructions on his excellent blog, Becoming Agile.

Wow!

3 Comments

Filed under C#, Castle, Generator

Live coding revisited

I previously bloged about a script that enabled automatic rebuild and restart of the web server on change of the source files. The script was working great, but sometimes some strange errors start poping out.

Thanks to Nick Hemsley who submited a patch that uses FileSystemWatcher, we now get much better results!

I refactored the script a bit and here’s the result:

import System
import System.IO
import System.Threading
import System.Diagnostics

# The command to launch the web server
SERVER_CMD = argv[0]
# Determine if the web server has to be restarted
# afther a built
SERVER_RESTART = argv[1] == 'restart'
# Arguments to send to with the server command
SERVER_ARGUMENTS = join(argv[2:], ' ')

# Arguments to send to nant when building
# Typically the target that builds and some arguments
NANT_ARGUMENTS = 'build -nologo -q'

# Time to wait before watching for changes again
REBUILD_DELAY = 1000 #ms


######## Stop editing here unless you're a damn cool Boo hacker ########
watcher = FileSystemWatcher(Directory.GetCurrentDirectory(), "*.cs")
watcher.IncludeSubdirectories = true
print "Starting live server process, hit CTRL+C to stop"

serverProcess as Process
rebuild = true

while (true):
  print "nant ${NANT_ARGUMENTS}"
  buildProcess = shellp('nant', NANT_ARGUMENTS)
  buildProcess.WaitForExit()
  rebuild = false

  if (buildProcess.ExitCode == 0):
    if SERVER_RESTART or serverProcess == null:
      # Try to stop the server
      if (serverProcess != null):
        try:
          serverProcess.Kill()
        except e:
          pass
        serverProcess.WaitForExit()
      # Starts the server
      print "${SERVER_CMD} ${SERVER_ARGUMENTS}"
      serverProcess = shellp(SERVER_CMD, SERVER_ARGUMENTS)
  else:
    print "Build failed! Errors:"
    print '=' * 80
    print buildProcess.StandardOutput.ReadToEnd()
    print '=' * 80
  
  Thread.CurrentThread.Sleep(REBUILD_DELAY)
  change = watcher.WaitForChanged(WatcherChangeTypes.All)
  print "File change detected (${change.Name})"

Whenever a .cs file is modified, nant is called to recompile the app and the web server is restarted.

Usage: booi script/server.boo YourWebServer.exe restart|norestart Argument For Your Web Server

On with Mono, you got to enable MONO_MANAGED_WATCHER, or else sub directories wont trigger a rebuild.

export MONO_MANAGED_WATCHER=1
booi script/server.boo xsp2 restart --root public $*

If the restart parameter is used, the web server will be restarted on each file change.

This script is now part of Castle Generator. To be as cool as I am, get into live coding:

svn co http://svn.castleproject.org:8080/svn/castlecontrib/generator/trunk generator
cd generator
nant install
cd ..
monorail MyBlog
cd MyBlog
nant setup
script/server


and start coding!

Leave a comment

Filed under Generator, Monorail

Database migration for .NET

Migration for .NET first official release is out and supporting MS SQL Server 2000, MySql 4 and Postgre 8 and fully integrated with Castle Generator.

Continue reading

23 Comments

Filed under Castle, Generator, Monorail

Generator vs burritos

If you want to join the fun, be sure to check my other post, on how to install this great piece of technology.

page_1.png

All images taken from Google with some random keyword search

1 Comment

Filed under Generator

Installing and using the Generator

A new script has been added to the generator. Now, to install, all you have to do is:

svn co http://svn.castleproject.org:8080/svn/castle/trunk/Tools/Generator
cd generator
nant install

and then you can type from your command line generate or monorail to get help and usage.

Have fun!

9 Comments

Filed under Generator

Live coding with MonoRail

In my constant quest to bring Castle MonoRail closer to Ruby on Rails development style, one of the thing that kept me from choosing MonoRail over Rails for fun and pleasure was the code-compile-refresh process. Because we’re working in the static compiled world, a usual scenario looks like this.

  1. Add or remove some code
  2. Compile from the IDE or run NAnt
  3. Restart the web server (under *nix XSP needs to be restarted to load the new assembly)
  4. Refresh the browser (and wait for the app to restart AR and all other services)

This is painful! Why can’t we just code and refresh like with scripting languages?

While reading an article on reddit about Live coding, I had a idea…

# Rebuilds the project periodically and restarts the web server on success

 import System
 import System.IO
 import System.Threading
 import System.Diagnostics

 SERVER_CMD = 'xsp2'
 SERVER_ARGUMENTS = '--root public'
 NANT_ARGUMENTS = 'build -nologo -q'
 PROJECT_ASSEMBLY = 'public/bin/MyBlog.dll'
 REBUILD_DELAY = 1000 #ms

 serverProcess as Process
 lastWriteTime as DateTime

 print "Starting runner process, hit CTRL+C to stop"
 while (true):
  buildProcess = shellp('nant', NANT_ARGUMENTS)
  buildProcess.WaitForExit()

  if buildProcess.ExitCode == 0:
   if FileInfo(PROJECT_ASSEMBLY).LastWriteTime > lastWriteTime:
    print "Project recompiled, restarting the server"
    if serverProcess != null:
     try:
      # Stops the server
      serverProcess.Kill()
     except e:
      pass
     serverProcess.WaitForExit()
     serverProcess = null
    serverProcess = shellp(SERVER_CMD, SERVER_ARGUMENTS)
    lastWriteTime = FileInfo(PROJECT_ASSEMBLY).LastWriteTime
  else:
   print buildProcess.StandardOutput.ReadToEnd()

  # Waits a couple of seconds
  Thread.CurrentThread.Sleep(REBUILD_DELAY)

If you can’t see what this is about…

The other thing that keep me from dropping Rails for MonoRail is C# extra verbose and lack of fun and style. But I can’t do nothing about that, except use Boo whenever I can.

Note that this script will soon be integrated in the Generator so when you generate a new MonoRail project, the server script while run something like this.

3 Comments

Filed under Generator, Monorail