Oak

Frictionless development for ASP.NET MVC single page web apps. Prototypical and dynamic capabilities brought to C#.


Project maintained by amirrajan Hosted on GitHub Pages — Theme by mattgraham

What is Oak?

Single page web apps are becoming the norm as opposed to the exception. And with that comes a large part of your code base existing on the client side with a lot of JavaScript, JSON and async HTTP. Oak gives you a way to quickly build these kind of apps by:

Publications

First Time (Prerequisites)

Start Coding Now - Bootstrapped Solution With Oak

Run the following commands to quickly create a fully loaded .Net solution bootstrapped with Oak:
using a command prompt that supports ruby
(be sure to run the command prompt as an administrator):

warmup http://github.com/amirrajan/loam Blog (creates a .Net solution)
=== OR if you want a solution that includes UI Automation ===
warmup http://github.com/amirrajan/walkingskeleton Blog
cd Blog
rake (builds the .net app)
rake server (starts iis express)
start Blog.sln (opens the solution)
watchr dotnet.watchr.rb sidekick.bat (starts your feedback loop)

Interactive Tutorial

Oak comes with an interactive tutorial. Once you have taken the steps above, go to http://localhost:3000 and try out Oak interactively.

Growl Support for Continuous Development

To get the most out of the Interactive Tutorial, take the time to install Growl for Windows with a nice notification theme:

Jump to the Sample Apps


The Screencasts - It's all about reducing friction


Frictionless Development Cycle - Oak's Walking Skeleton

Oak has an addicting development life cycle that incorporates rapid application development, fast feedback loops, testing, and UI automation. Watch the video to see Oak in action:

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Adobe Flash Player. If you are using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Adobe Flash Player by downloading here.


Frictionless Data Access, Change Tracking and Validation - Oak's dynamic Entity Model: Cambium

Oak has a dynamic entity model called Cambium which is amicable to dynamic strcuctures (ie JavaScript classes). Cambium makes validating, detecting changes, saving, retrieving, and defining associations ridiculously easy. Check out the Sample Apps and the Wiki for more info. Here is a sneak peek at what Cambium can do:

Validations

dynamic blog = new Blog(); //new up a blog, validate
blog.Name = "";
blog.IsValid(); //this would be false
blog.FirstError(); //this would return "Name is Required"

public class Blog : DynamicModel
{
    //validation, name is required
    IEnumerable<dynamic> Validates() {
        yield return new Presense("Name");
    }

    Blogs blogs = new Blogs();
    public Blog(object dto) : base(dto) { }
    public Blog() : base() { }
}

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Adobe Flash Player. If you are using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Adobe Flash Player by downloading here.


Associations

Blogs blogs = new Blogs(); //data access by convention
Comments comments = new Comments(); //data access by convention
dynamic blog = new Blog();
blog.Name = "Blog Name";
blog.Id = blogs.Insert(blog); //inserts into the database returns an Id
var comment = blog.Comments().New(new { Body = "new comment" });
comments.Insert(comment); //inserts comment into database

public class Blogs : DynamicRepository 
{
    public Blogs() { Projection = d => new Blog(d); }
}

public class Comments : DynamicRepository { }

public class Blog : DynamicModel
{
    //a blog has many comments
    IEnumerable<dynamic> Associates() {
        yield return HasMany(comments);
    }

    Comments comments = new Comments();
    public Blog(object dto) : base(dto) { }
    public Blog() : base() { }
} 

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Adobe Flash Player. If you are using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Adobe Flash Player by downloading here.


Frictionless Schema Generation - Oak's Seed

Schema generation should be simple. Period. Here's what simple looks like:

var seed = new Seed();

//create blogs table
seed.CreateTable("Blogs",
    seed.Id(), 
    //seed.Id() is an alias for 
    //new { Id = "int", Identity = true, PrimaryKey = "true" }
    new { Name = "nvarchar(255)" },
    new { Body = "nvarchar(max)", Default = "Lorem Ipsum" }
).ExecuteNonQuery(); 
//Seed's CreateTable method returns a string that's valid sql,
//ExecuteNonQuery will execute that string

//create comments table
seed.CreateTable("Comments",
    seed.Id(), 
    new { BlogId = "int", ForeignKey = "Blogs(Id)"
    new { Body = "nvarchar(max)", Nullable = false }
).ExecuteNonQuery();

//ad hoc
"drop table Foobar".ExecuteNonQuery();

Frictionless Testing - NSpec and SpecWatchr

Oak is bootstrapped with NSpec and SpecWatchr. Driving out your implementation with tests ensures that you have a maintainable code base.

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Adobe Flash Player. If you are using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Adobe Flash Player by downloading here.

Frictionless UI Automation - Canopy

Oak is bootstrapped with a UI automation framework called canopy. With the increased use of client side javascript, UI automation tools are absolutely necessary. Canopy gives you a terse DSL written in F#. Very easy to pick up!

open canopy
start "firefox"
url "http://google.com"
"input[type='text']" << "hello world"
click "input[type='button']"

Frictionless Dev Environment Setup - RakeDotNet

Oak comes installed with a suite of rake scripts that will build your solution, deploy your web app, run NSpec tests and run UI automation tests. These scripts can be leveraged directly by your build servers. Using a command prompt that supports ruby (be sure to run the command prompt as an administrator), you can type any of the following commands:

rake
  builds and deploys your application

rake server
  starts up iis express pointing to your deploy directory

rake simulate_load_balance
  sets up iis express in a round robin load balanced configuration

rake reset
  regenerates your schema

rake sample
  inserts sample data into your db to help with development

rake export
  exports your schema to a set of sql scripts

rake tests
  runs all tests

rake ui
  runs ui automation

Frictionless Scaffolding - scaffold.rb

Oak comes bootstrapped with a suite of rake scripts that help you scaffold common files in your solution. These scripts can be leveraged by you to quickly generate classes. Using a command prompt that supports ruby (be sure to run the command prompt as an administrator), you can type any of the following commands:

all scripts are customizable and are located in scaffold.rb

rake gen:controller[name]
    adds a controller class to your mvc project

rake gen:model[name]
    adds a dynamic model class to your mvc project

rake gen:repo[name]
    adds a dynamic repository class to your mvc project

rake gen:script[name]
    adds javascript file to your mvc project

rake gen:test[name]
    adds a test file to your test project

rake gen:view[controller_and_name]
    adds cshtml to your mvc project

Smaller Sample Apps


Minimal Implementation: DynamicBlog

This is..you guessed it...a blogging app. It's a really minimal implementation. Look at the other sample apps for a deeper dive into Oak.

Hello World Single Page Apps: Peeps

This is a really simple app that adds and updates records to a single table over ajax. It's a really minimal server side implementation for a number of JavaScript front end frameworks:

You may want to look at the Task Rabbits sample app for a deeper dive.

Two Player Game, Complex Object Graph: BattleShip

This is a web based version of the game BattleShip. Open up two browsers and start playing!

Single Page App, JS framework integration: Task Rabbits

This is a web application that shows how you can integrate Oak with some popular JavaScript frameworks such as :

Single Page App, CoffeeScript, Complex DB Queries: Crib

This is a web application that tracks consultants and when they roll off of a client engagement. Consulting companies like Improving Enterprises would use this app to manage their resource pool.

Single Page App, REST Api: Todo List

This is a web application that uses Oak to implement a REST api using Oak. A simple todo list that allows you to add items, remove them, and mark things as done.

THE Reference App - Borrowed Games


This is a full blown reference implementation that uses all aspects of Oak. Borrowed Games is a single page web app that allows a circle of friends to borrow games from each other. This site is deployed and in production at http://borrowedgames.com.

More Stuff