A New Beginning

A New Beginning

This is my attempt at curing a case of Analysis Paralysis that I've had for awhile.

I promised myself that I'd rebuild my blog by the end of Feb so here goes nothing. I've been procrastinating for awhile so I figured if I pulled the plug on the old software, I'd be more motivated to do the rewrite. I'll be slowly adding content back in and trying to come up with a good design.

Castle ActiveRecord Configuration: The ProxyFactoryFactory was not configured

After updating to the latest Castle trunk and trying to run a simple ActiveRecord test I got this error:

In hind sight the answer to the problem is in the exception message, but I searched google anyway.  Here's a description of the IProxyFactoryFactory change that causes the above exception.  My updated config looks like this now(note the proxyfactory.factory_class addition)


  
    
    
    
    
    
  

1
2
3
4
5
6
7
8
9

 

27000 Requests Per Second

WOW

HighScalability.com has a good post on the Digg scaling strategies.  Man that would be fun to have that challenge, how do you handle 27000 requests per second? crazy.

Delete Svn Folders

I knew I had seen this somewhere beforeHere's the zipped up reg file, use at your own risk.

HtmlBuilder: Simple Grid

Here's a little sample of how I might use HtmlBuilder to generate a simple HTML table bound to a list of stuff.  For convenience sake I'm just adding an extension method for the HtmlHelper that ships with ASP.NET MVC.

Here's what I want to do.  Say I have a Customer class that has some simple properties.  I want to write this:


1

Which spits out a [lame] table where the header contains the name of every public property on the Customer type, and the rows contain values for the matching properties for each instance in the collection of Customers passed in via ViewData. 

Header Row

Here's how I build the header row using HtmlBuilder:

var headerRow = new Element("tr");
foreach (PropertyDescriptor property in properties)
{
  headerRow.Append(new Element("th").Update(property.Name));
}
var thead = new Element("thead", headerRow);
table.Append(thead);
1
2
3
4
5
6
7

Item Rows

This is pretty straight forward.

var tbody = new Element("tbody");
foreach (var item in items)
{
  var row = new Element("tr");
  foreach (PropertyDescriptor property in properties)
  {
    row.Append(new Element("td")
      .Update(property.GetValue(item).ToString()));
  }
  tbody.Append(row);
}
table.Append(tbody);
1
2
3
4
5
6
7
8
9
10
11
12

The Result

The extension method signature looks like this:

public static Element Grid(this HtmlHelper @this, string id)
1

Notice how it returns an Element? This is handy, because since an Element is just as good as a string as far as ASP.NET MVC is concerned, you can do extra stuff.  When I first ran the sample, my grid looked like this:

Looks like crap, i don't like the cellspacing issue and I want the grid a little wider.  Since I am returning an Element, I can do this easily, like this:


1
2

Now the grid looks like this:

Here's the sample project.

Color Banding Courtesy of Prototype.js

$$('table#Customers tbody tr:nth-child(2n+1)').each(function(el){
  el.setStyle('background-color:#e0e0e0');
});
1
2
3

TODO: DynamicProxy Tutorials

Krzysztof Kozmic has a series of tuts on Castle's DynamicProxy I want to run through. Castle Dynamic Proxy tutorial part V: InterceptorSelector, fine grained control over proxying.

But *insertcoolprojecthere* Already Does That

I was looking into the concept of DynamicProxy the other day and came across DynamicProxies by Jason Bock.  Looking through his blog for info on the project, I found one entry that got an interesting comment: " ...why start a new Open Source project if Castle Project DynamicProxy already does that..." 

This reminds me of a good post by Jeff Atwood the other day, Don't Reinvent The Wheel, Unless You Plan on Learning More About Wheels.  I do this all the time.  I wrote my own  IOC container for HyperActive.  Yes I could have just referenced another assembly for that functionality, but it was fun coding one of those up, I now have a better understanding of how they work.

Doing those kind of projects can also make you appreciate how much effort gets poured into some of that stuff and potentially how much better those projects are than the code you create.  Several years ago, I wrote my own logging tools, sql generators, etc, etc.  Today? Eff that, I'm picking up log4net or nlog, and for anything dealing with a database, it's gonna be any one of several free orms out there.

So That's What That Web.Config In The Views Folder Is For

I was trying to get a strongly typed ViewPage to work with my previous barebones templates and they just wouldn't work.  Turns out you need a web.config in the Views directory that has a significant attribute set in pages element:


  
  
  

1
2
3
4
5
6
7
8
9
10
11
12
13

Notice the ViewTypeParserFilter?  After looking at the source code, it appears this guys responsibility is just to parse out the type in a strongly typed view from the a page directive.  Anyway, after sticking that in the Views directory, all was good.  I've updated my barebones templates to reflect the change.  You can download the templates at the bottom of this post:

I'm still not sure how this works when a web.config is in the Views directory, I was under the impression that only a web.config at the root of an application is used.

HtmlBuilder

I started the project last March because I had seen another attempt somewhere and knew I could do better[the link to the other guy's example is now dead so I don't have that example to show].  Originally it was called PrototypeDotNetNotReally cuz it was just an experiment and I suck at project names.  I had posted this library on codeplex last year, and changed its named Html.  Then ASP.NET MVC came out with the HtmlHelper inside of the System.Web.Mvc.Html namespace and it collided with the name of this project.  So I changed it to HtmlBuilder and posted it up at google this morning.

I'm working on some examples and the documentation and will post those in a bit. There's also a sample project console app, and I've started on playing around with a FluentHtmlHelper thingy(and yes, I know there's one in the MvcContrib project).

If you've never written code that generates HTML(or any flavor of XML), you will have ZERO interest in this library other than to take a peek at the source code, it does have 100% code covereage through the tests.

ASP.NET MVC(RC) Barebones Editions

ASP.NET MVC ships without a project template.  Instead they include an Application Starter(as the project template).  The first thing I always have to do is delete all of the crap, like the extra controller, extra views, css, membership and profile shite in the web.config, etc.,  so I can start with a clean project template.

Removal of Scripts Directory

I prefer to have all content actually in the content folder, so I've removed the Scripts folder, and as you can see in the images below, i've just made subdirectories in the content folder for the various types of content.

HtmlHelper Extensions

I've included to extensions to the htmlhelper which are included in the Extensions folder, simple ones for stylesheet and script, and no i don't want to include a separate assembly like MvcContrib just to get that simple functionality.

public static class HtmlHelperExtensions
{
  /// 
  /// Generates a link element for referencing a css stylesheet with
  /// the href attribute pointing to the absolute path of the css file.
  /// 
  /// The instance of the HtmlHelper being extended.
  /// The virtual path in form of ~/path/to/stylesheet.css
  /// 
  public static string Stylesheet(this HtmlHelper @this, string virtualPath)
  {
    string format = "";
    return String.Format(format, VirtualPathUtility.ToAbsolute(virtualPath));
  }

  /// 
  /// Generates a javascript script element with the src attribute pointing to
  /// the absolute path of the js file.
  /// 
  /// The instance of the HtmlHelper being extended.
  /// The virtual path in form of ~/path/to/script.js
  /// 
  public static string Script(this HtmlHelper @this, string virtualPath)
  {
    string format = "";
    return String.Format(format, VirtualPathUtility.ToAbsolute(virtualPath));
  }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

ASP.NET MVC(RC) Barebones(jQuery Edition)

ASP.NET MVC(RC) Barebones(Scriptaculous Edition)

Here's the jQuery edition template: http://panteravb.com/downloads/AspNetMvcBarebonesjQueryEdition.zip

And the scriptaculous template is here: http://panteravb.com/downloads/AspNetMvcBarebonesScriptaculousEdition.zip

I blogged about how to install the templates before, you can find it here.

 
Author: , 0000-00-00