Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for the ‘Castle’ Category

Deploy MonoRail on IIS7

with 3 comments

Note to myself

1. On Default Web Site, click Add Application

2. Change Application Pools = Classic .NET AppPool , go to Application Pools and click on Classic .NET AppPool then take Advanced Settings

Calssic .NET Application Pools, Advanced Settings

3. Add the following setting to web.config

	<system.webServer>
		<handlers>
		  <clear />
		  <add name="PageHandlerFactory-ISAPI-2.0-64" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0" />
		  <add name="PageHandlerFactory-ISAPI-2.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />
		  <add name="MonoRail64" path="*.castle" verb="*" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="4194304" />
		  <add name="MonoRail" path="*.castle" verb="*" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="4194304" />
		  <!--
		  <add name="UrlRewriting64" path="*" verb="*" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="4194304" />
		  <add name="UrlRewriting" path="*" verb="*" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="4194304" />
		  -->
		  <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
		</handlers>
	</system.webServer>

We good to go, hope I don’t waste my time again on this thing.

Advertisements

Written by Chorn Sokun

November 4, 2010 at 4:10 pm

Storm the Castle in Action

with 2 comments

felt bore today and decided to tune into studio and record some stuff :D hope you enjoy it.

I know, I know the quality is bad but I don’t know I am not do much with youtube so it the luck I get :) BUT as always orginal video can be download here.

Source code: http://storm-the-castle.googlecode.com/svn/tags/barcamppp

Written by Chorn Sokun

October 23, 2009 at 5:50 pm

MonoRail, IRescueController Handle Unexpected Exception

with one comment

By default you can intercept unexpected exceptional error occur in MonoRail you can opt to render a specific view from Views/Rescues folder or let MR pick standard one such as 404 page not found …

How how about you want to log the exception then you need to build a custom controller class that implement IRescueController interface just like this:

public class RuntimeExceptionController : SmartDispatcherController, IRescueController
{
  public void Rescue(Exception exception, IController controller, IControllerContext controllerContext)
  {
    // ... log via log4net ...
    // ... render & send error back home :) whatever you find helpful
  }
}

// usage: simple
[Rescue(typeof(RuntimeExceptionController))]
public class HomeController: SmartDispatcherController{
  public void Index(){
     throw new Exception("Boom !");
  }
}

Written by Chorn Sokun

October 1, 2009 at 10:38 am

(N)How simple could that be?

with 2 comments

projection-skill-in-action

Wonder how this report get produced from model above it? If you guess was

  • NHibernate
  • MR (did you say <table>?)

You right and I must say I finally master the NH Projection skill or in another word (stealling from JXII) level up!.

What I did by taking AreaCode as primitive data connect it through and transform set of progress records into columns pretty cool trick, no NH hack is required it all natural.

Happy Projections day

Written by Chorn Sokun

May 29, 2009 at 12:19 pm

MonoRail & jQuery

leave a comment »

Last year I blog about using jQuery.ajaxForm() to send http post request to MonoRail action and finally it depend on JSGenerator to produce javascript and send it back to client.

But overtime I find it pretty scary using that approach:

  • It give too much control to the server – the server can generate a bunch of javascript and send off to the client sort of invade client responsibility.
  • In some scenario I even specify from the server which div element I want to render my data table in
  page.ReplaceHtml('#divId', "content_to_be_replace_from_server")
  • using approach in previous post I was not be able to ensure 100% that if I send piece of jquery script that it combine into the main DOM properly for instance I did have a form & a jQuery to confirm the form into ajaxForm but that behavior is not always reliable.

So what the deal now? well, I happen to change the strategy a while ago just haven’t got time to blog about it the solution is pretty simple “Don’t make JSGenerator your new hammer.”, Let see my simplify approach:

<div id='dlist'>
  <!-- I am going to render list of data in this div --></div>
<input type="button" value="Show data" onclick="showData();" />
<input type="button" value="Add more" onclick="addData();" />
<div id='dform' style='display: none;'>
  <!-- I am going to load form into this div --></div>

That pretty normal HTML markup right? 2 div one for display list of data second one for display form for adding more data and I also have 2 buttons to invoke client script (jQuery).

<script>
function showData(){
   $('#dlist').load( '/task/list.rails', {'status': 'incomplete'} );
}

function addData(){
   $('#dform').load( '/task/add.rails', {}, function(){
      $('#dform').show();
    });
}
</script>

Now that instead of using $.ajax I use $(‘#elementId’).load() instead because load() will inject html render by MonoRail action in the DOM and it just as native element.

Note : line 07 dform had style apply so that without having form inside it don’t occupy space in the page however one content loaded we need to set visibility for it.

For your reference the final piece of the puzzle is purely view code like this (View\task\add.brail)

<form method='post' id='taskForm' action='/task/create.rail'>
  Name: <input type='text' name='t.Name' />
  <input type='submit' value='Create' />
</form>

<!-- not inject some jQuery script along make the form submit via ajax -->
<script>
   $(function(){
       $('#taskForm').ajaxForm ({
          success: function(response){
            $('#dlist').html(response);
          },
          error: function (xhr, status, error) {} // handle error if you wish
        });
   });
</script>

Notice on line #09 : need the form to submit using ajax and line #11 the client take control where it want to place the result (list of task).

It seem like we have to write a bit more code (jQuery) but after all that the fun part of being a programmer write code that :) Hope this would help.

Written by Chorn Sokun

March 26, 2009 at 9:13 pm

Posted in Castle, MonoRail, Tips & Tricks

Tagged with ,

MonoRail vs ASP.NET MVC Take #1 HTTP verbs

with 2 comments

Along came ASP.NET MVC although I am not the fan of ASP.NET MVC but it doens’t heard reading ASP.NET free chapter (nerddinner) and I did learn a few tricks, I will try my best to map concept between the two framework now let see

Why differentiate via HTTP verbs? read the book and find out, but here the deal

  • ASP.NET MVC [AcceptVerbs(HttpVerbs.Post)]
  • and [AccessibleThrough(Verb.Post)] in MonoRail
// GET: /Payroll/Delete/2
public void Delete([ARFetch("id"}] Payroll payroll){
   if (payroll == null)
   {
      RenderView("InvalidRequest");
   }
   else
   {
       PropertyBag["payroll"] = payroll;
       RenderView("DeleteConfirm");
   }
}

// POST: /Payroll/Delete/2
[AccessibleThrough(Verb.Post)]
public void Delete([ARFetch("id"}] Payroll payroll, bool confirm){
   if (payroll == null)
   {
      RenderView("InvalidRequest");
   }
   else
   {
      if(confirm){
     ..... // drop the record off the database
     ..... // do whatever you want.
      }
      else
      {
          RedirectToAction("Delete", "id"  + payroll.Id);
      }
   }
}

MonoRail Rock!

Written by Chorn Sokun

March 26, 2009 at 10:17 am

Posted in Castle, MonoRail, Tips & Tricks

Tagged with

Brail Daily Use Macros #2

with 2 comments

Imagine you had to associate multiple skill to your “Profile”

Multiple skill

Suppose we have the following Profile & Skill class

class Profile {
  public virtual int Id { get; set; }
  public virtual string Name { get; set; }
  //.... other properties as necessary
  public virtual IList<Skill> Skills { get;set; }
}

// a lookup class per say
class Skill {
  public virtual int Id { get;set; }
  public virtual Profile { get; set; }
  public virtual string Title { get; set; }
}

Assume that we know how to apply AR attribute on these two class make it persist able to a database. The important thing is Profile has many Skills that all you have to concentrate on right now.

Ok ! today recipe is to generate UI with checkbox which allow user to tick and save the choices without any hassle. With the help of FormHelper method YES, WE CAN

<%
list = Form.CreateCheckboxFieldList("p.Skills", skills, {@text:'Title', @value:'Id'})
// we need a loop
for item in list:
%>
  ${list.Item()}  ${item.ToString()}
<%
end
%>

Don’t panic let me explain a bit ${list.Item()} will generate individual html checkbox where ${item.ToString()} will generate a label for each one.

Written by Chorn Sokun

March 16, 2009 at 5:00 pm