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

Generator project moved to Castle

Thanks to hammett, my code generator project has been accepted as a Castle contrib project. Everything is still the same but you now have to checkout the code from http://svn.castleproject.org/svn/castlecontrib/generator/trunk/.

By the way I’d like to say thanks to Carlos, Tanner, Peter and Kevin for their help and support.

8 Comments

Filed under Castle, Generator

Getting MonoRail closer to Rails again

In a previous post I’ve bloged about the scaffold generator for Castle MonoRail. And now it’s time for the fully-packed-turbo-ultra-cool MonoRail project generator. Just type generate project MyProject (or make a link for monorail like in the vid).

Some people won’t like the directory structure I’ve used, which is inspired by Rails ratter then by Visual Studio. I find it more secure, more structured and more fun. If you want to argue on this, please do in this post comments! this is a work in progress and I’m pretty open to constructive suggestions and comments.

As usual : watch it live!!!

This work is not complete! If you intend to use it, you understand that this is an alpha release. The source is at http://svn.castleproject.org/svn/castlecontrib/generator/trunk.

If someone is interested in adding Visual Studio support just contact me by email.

4 Comments

Filed under Generator, Monorail

Code generation and scaffolding

With all the respect that I have for the Castle projects and team members, their are two things I don’t like about the projects.
– Visual Studio Integration rather then a command line tool
– The scaffolding

So instead of complaining, here’s what I’ve done: The Generator, mouhaha! :
To compile and run:
1. Run svn co http://svn.castleproject.org/svn/castlecontrib/generator/trunk
2. Run nant in the base directory to compile
3. Run generate to get help

It’s a fully customizable code generator written in Boo and templates with ASP style syntax. I’ve made 4 generators: controller, model, generator and scaffold.

The scaffold generator is heavily inspired by RoR, it generates real code you can modify for the controller, the views, layouts, css and tests. The CRUD views will look similar to current MR scaffold with the difference that the code is live in you project so you can add a field, color, validation, change the workflow without copy pasting for the last controller you’ve done! Plus you already got some running tests! (just 2 simple for now)

To use it :
Edit the file Generators\Config.boo to fit your project structure
run bin\generate from your project root folder.

This is a work in progress so contributions or comments are welcome.

Oh and I almost forgot, a short video: Video

20 Comments

Filed under Generator