Contrib Code Generator

0 views
Skip to first unread message

Lee Henson

unread,
Jan 17, 2008, 2:19:57 PM1/17/08
to Castle Project Development List
I've updated the code generator for use with the latest routing stuff.
It's hacked together a bit, and I'm pretty sure I don't quite grasp
exactly all the nuances of the routing engine.

[StaticRoute("Products", "products")]
public void ProductsList()
{
}

Accessible via: Routes.Products()
Set up via: RoutingModuleEx.Engine.Add(RouteDefinitions.Products)

[PatternRoute("Product", "products/<productKey:guid>")]
public void Product(Guid productKey)
{
}

Accessible via: Routes.Product(new Guid())
Set up via: RoutingModuleEx.Engine.Add(RouteDefinitions.Product)

[PatternRoute("Complex", "<thing:anyof(this|that)/<foo:guid>/<bar:int>/
<zoo>/[beep]", "thing=this")]
public void Parp(Guid foo, int bar, string zoo, string beep)
{
}

Accessible via: Routes.Complex(fooGuid, intBar, zoo, beep)
Set up via: RoutingModuleEx.Engine.Add(RouteDefinitions.Complex)

Adam Tybor

unread,
Jan 18, 2008, 1:11:07 PM1/18/08
to castle-pro...@googlegroups.com
Can I get contrib commit access? One thing I noticed is that using
int as validation try's to call ValidInt instead of ValidInteger. I
am also missing the MyRoutes now and Site.Routes.

James Curran

unread,
Jan 18, 2008, 1:19:19 PM1/18/08
to castle-pro...@googlegroups.com
Email Hamilton with the Userid/Password you want.  Of course, with the current server issues, there may be a delay....

On Jan 18, 2008 1:11 PM, Adam Tybor <adam....@gmail.com> wrote:

Can I get contrib commit access?  One thing I noticed is that using
int as validation try's to call ValidInt instead of ValidInteger.  I
am also missing the MyRoutes now and Site.Routes.




--
Truth,
   James

Lee Henson

unread,
Jan 18, 2008, 5:24:41 PM1/18/08
to Castle Project Development List
> One thing I noticed is that using
> int as validation try's to call ValidInt instead of ValidInteger.

Fixed.

> I am also missing the MyRoutes now and Site.Routes.

Yeah I've commented out the MyRoutes as it felt a bit wrong to
associate routes with a specific controller. I think I've probably
been overzealous there though. It's easy enough to add back in though.
Site.Routes doesn't exist I don't think, it's just
Routes.<RouteName>()

I'm off to the Alps now for a week, so I look forward to lots of
improvements when I get back! ;p

On 18 Jan, 18:11, "Adam Tybor" <adam.ty...@gmail.com> wrote:
> Can I get contrib commit access? One thing I noticed is that using
> int as validation try's to call ValidInt instead of ValidInteger. I
> am also missing the MyRoutes now and Site.Routes.
>

Ken Egozi

unread,
Jan 19, 2008, 6:51:33 AM1/19/08
to castle-pro...@googlegroups.com
you mean "Apls.NET"? is that the yet new name for the altnet user group?

;)

have fun.

Ken Egozi

unread,
Jan 19, 2008, 6:52:13 AM1/19/08
to castle-pro...@googlegroups.com
Ruined the joke with a typo, damn it
:-0

Steve Wagner

unread,
Jul 4, 2008, 11:12:42 AM7/4/08
to castle-pro...@googlegroups.com
I think there is a problem in the implementation of the this "Routes.Products()". Example

[PatternRoute("Foo", "feed/foo/<id>")
public void Foo() {}

[PatternRoute("Bar", "feed/bar/<id>")
public void Bar() {}

If i call now Routes.Foo() or Route.Bar() if always get the same url. This is because the generates generates this:

public virtual string Foo(string id) {
System.Collections.IDictionary routeParameters Castle.MonoRail.Framework.Helpers.DictHelper.Create();
routeParameters.Add("id", id);
return this.engineContext.Services.UrlBuilder.BuildUrl(this.engineContext.UrlInfo, new System.Collections.Hashtable(), routeParameters);
}

public virtual string Bar(string id) {
System.Collections.IDictionary routeParameters Castle.MonoRail.Framework.Helpers.DictHelper.Create();
routeParameters.Add("id", id);
return this.engineContext.Services.UrlBuilder.BuildUrl(this.engineContext.UrlInfo, new System.Collections.Hashtable(), routeParameters);
}

And on my perspective this calls are the same. I think this calls must be look like this:

public virtual string Foo(string id) {
System.Collections.IDictionary routeParameters Castle.MonoRail.Framework.Helpers.DictHelper.Create();
routeParameters.Add("id", id);
return RouteDefinitions.Foo.CreateUrl( routeParameters );
}

public virtual string Bar(string id) {
System.Collections.IDictionary routeParameters Castle.MonoRail.Framework.Helpers.DictHelper.Create();
routeParameters.Add("id", id);
return RouteDefinitions.Foo.CreateUrl( routeParameters );
}

I someone can confirm this i will look forward to write a patch for it.

Steve

Lee Henson schrieb:

Lee Henson

unread,
Jul 7, 2008, 10:19:04 AM7/7/08
to Castle Project Development List
Hi Steve

Yeah I see that behaviour too. Did you get around to writing a patch?
I can commit it for you.

Steve Wagner

unread,
Jul 10, 2008, 11:33:51 AM7/10/08
to castle-pro...@googlegroups.com
Ok ive start writing a patch but i could take some time i am really busy
at the moment.

Steve

Lee Henson schrieb:

Lee Henson

unread,
Jul 21, 2008, 8:57:02 AM7/21/08
to castle-pro...@googlegroups.com
Steve, I just committed a patch for this. Please verify that this has fixed your problem.

2008/7/10 Steve Wagner <li...@lanwin.de>:

Steve Wagner

unread,
Jul 25, 2008, 8:04:17 AM7/25/08
to castle-pro...@googlegroups.com
Hi Lee thanks for doing it! I am too busy at the moment and i could test
it first next week.

I also have a few other things in my head which the generator can be
extend and i list them here. Possibly you find the time and interest to
code them before i get time to do it.

* RouteDefinitions.AddAll(RoutingEngine engine)

* Add a sample project which demonstrates how to use the generator

* Generate a the needed SiteMapControllerBase into SiteMap.generated.cs
(The Controller which provides access to Site and Routes)

* Routes.Foo should return a IRouteActionReference and
IArgumentlessRouteActionReference insted of a string

* Extend IArgumentlessControllerActionReference with "RouteUrl"

By
Steve

Lee Henson schrieb:

Lee Henson

unread,
Jul 25, 2008, 8:15:50 AM7/25/08
to castle-pro...@googlegroups.com
Steve,

2008/7/25 Steve Wagner <li...@lanwin.de>:


Hi Lee thanks for doing it! I am too busy at the moment and i could test
it first next week.

I also have a few other things in my head which the generator can be
extend and i list them here. Possibly you find the time and interest to
code them before i get time to do it.

Alas, that looks unlikely. I'm only in this code because I need to add support for rest routes.
 


* RouteDefinitions.AddAll(RoutingEngine engine)

The problem with this is the ordering of the rules. If you wanted them automatically registered you would need to put some sort of index parameter on the route attributes: [PatternRoute(25, "sdfasdf", ....)]. We used to have this, but as soon as you start to get past anything other than a trivial amount of rules, it quickly gets obscure. Better to have all the rules registered in one place where you can see them at one glance.
 

* Add a sample project which demonstrates how to use the generator

* Generate a the needed SiteMapControllerBase into SiteMap.generated.cs
   (The Controller which provides access to Site and Routes)

That forces you to use a specific base class for your controllers. While that may be valid in some scenarios, it is not for all. By adding the appropriate methods/properties yourself, you remain in control of how class hierarchy.
 

* Routes.Foo should return a IRouteActionReference and
IArgumentlessRouteActionReference insted of a string

Reasonable.
 

* Extend IArgumentlessControllerActionReference with "RouteUrl"

Reasonable.
 

Steve Wagner

unread,
Jul 30, 2008, 3:33:36 AM7/30/08
to castle-pro...@googlegroups.com
Seems to works fine here. Nice work!

Lee Henson schrieb:

Reply all
Reply to author
Forward
0 new messages