yysun's space

Recently I have made some improvements to the Rabbit Framework. I figured out how to inject a base class between WebPage and the Razor page, so that to create a Web Form or a MVC controller is just to inherit from the base classes.

@inherits Rabbit.WebForm
@functions {
         void button_click(string name)
         {
         }
}

Or

@inherits Rabbit.MvcController
@functions {  
    [Get("/")]
    void Index() {
}

Another interesting thing I did is to sync data between C#, JavaScript and HTML inputs.

1. C# fields (both public and non-public) are populated with HTML inputs.

<input type=”text” name=”txtEmail” value=”@txtEmail”/>

@functions {
    string Email = “”; // it will have the value user typed after post.
}

This is similar to the model binding concept found in ASP.NET MVC. The difference is here we bind to fields, where ASP.NET MVC binds to action parameters (actually, we do that too).

2. C# public fields are synced with JavaScript through a JavaScript object, called webForm.

@functions {
      public int count = 20;
}

<script>
alert(webForm.count); // it shows 20
<script>

And vice versa, if changed the value in JavaScript, the C# field has the new value after post.

The C# data are serialized into JSON. On the client side, it can be rendered into HTML using jQuery template or jsrender.

It also could be a solution to view state to some degree I think.

Download the sample site to see how it works.

Advertisements

In the Git Web Access, git.exe is required on the server in order to handle clone/pull/push requests as well as to list commits for odata services. I have been thinking replace it with some git wrapper libraries. Tried a few, none of them works.

libgit2sharp, a wrapper to the libgit2 linkable C Git library, supposed to provide native speed, freaked me way off after seeing a few time memory access violation exceptions.

GitSharp,  manual port of JGit to C#. The project is a bit old and seems stopped updating. I was able run it locally and on Azure, but have not figured how to walk the commits yet.

ngit, automated JGit port to C#, is newer than GitSharp. It has a strange behavior that every time you open a repository, it tries to read configure files which do not exist on the server that has no git installed.

Good news is that I was able to deploy Git.exe to Azure by following this post.

image

I have been manually editing the .nuspec XML file and running the command line to create two packages. One of the MIX 11 section mentioned the NuGet Explorer. It is a great tool that can save a lot time and effort. I used it to create my third package. Enjoyed it.

BTW, I haven’t touched Windows applications for a while. The source code of the NuGet Explorer has many goodies to explore.

Tags:

I found myself hitting F5 in IE like crazy. Every time after modified the web files, in order to preview the result, I need F5 to refresh IE.

So, I created a small Windows Forms application that monitors the web site folder (using FileSystemWatcher). When web file changed, it searches all IE browsers that are from the web site. and send key F5 (actually post message via p-invoke).

It works very well especially on two monitors. Saving files on one monitor, browser refreshes on the other.

image

It is very convenient. After saved the files, I will see the result immediately. It is not only useful for developing UI. It is also great for unit testing.

After modified and saved the tests in the Rabbit Framework, the test runner page refreshes automatically.

I didn’t make it a Visual Studio Plug-in, because I need it when using Visual Studio Express and WebMatrix.

I have built Web Forms on top of ASP.NET Web Pages.

The HTML is clean and unobtrusive. It uses HTML 5 data attributes. No messed up Ids. No view state. It supports multiple forms on a page.

image

The server side event handler has meaningful parameters. My Web Forms engine will feed the parameters with data comes in the HTML form posted.

image

Nice and simple. I will release it in the Rabbit Framework.

After Part I and Part II, here comes the part of making a dynamic site.

I am always impressed by PHP based CMS, like Joomla, Drupal, Wrodpress and etc. Nothing from .NET comes close to them.

With the WebMatrix, I want give it a try myself to build a dynamic and extensible site. It is going to have features of

  • Modules
  • Plugins
  • Templates
  • NuGet Package

 

Modules are a deployment packages of certain functionality. E.g. Pages, Blog, News, User Management … Modules are deployed as NuGet Packages. Modules can be enable and disable at runtime.

Many CMS have the concept of module (Drupal, XOOPS, DotNetNuke, Orchard…). It is called Component in Joomla.

Module functions are extensible. Modules publish extension points to allow other modules to extend functions.

The concept of Extension points is famous in Eclipse. MEF uses Import and Export. WordPress uses Hooks. Inspired by WordPress, I will use Hooks.

Hooks are a loosely coupled event publication and subscription. From anywhere of the site modules, you can request to run a hook (like fire a event). If any module has added (registered) the hook implementation, it will be invoked. The result of all hooks are chained.

E.g. In the _PageStart, there is a line.

Layout = Site.RunHook("get_layout") as string;

The template module responses to the hook get_layout and return the layout file name.

That’s it. The core mechanism of a dynamic site is that modules request hooks and as well as implement the hooks. Hooks glue all program pieces together.

Put it all together I will create a framework, the Rabbit Framework for WebMatrix.

Name it Rabbit, just because rabbit are small, light, fast, delicate … and this year is the Year of Rabbit.


  • None
  • Pk: The horizontal view is a pleasure to use! Good thinking
  • randyburden: A valiant and commendable effort. Your use of Tuple is a little weird but it offers a feature that most other microORMs don't. Your use of a static Gu
  • reav: great work done on Rabbit Framework. just started to learning it, and by now i think it will solve all my problems and questions, that i had in webpag

Categories