Friday, 8 February 2013

Make your path through OWIN with Flux

Introducing OWIN

If you never heard about OWIN, I'll introduce it quoting what appear in the website:

OWIN defines a standard interface between .NET web servers and web applications. 

Most of peoples (included me first time) would think immediately to a new open source web stack. But it would be wrong.
OWIN is a specification and hence never an implementation will be the official one.

At the moment of writing it is one year old; so more time passes and more it is possible that some implementations become reference implementations (but this is something completely different).
To clarify I'll post the remaining introductory explanation:
The goal of the OWIN interface is to decouple server and application, encourage the development of simple modules for .NET web development, and, by being an open standard, stimulate the open source ecosystem of .NET web development tools.

Anyway the intent of this article is not to deepen every aspect (it would take a book), but I want just to share with you the path that made me easier to understand this emerging specification, which I find very interesting.

So said that, how are defined OWIN data structures that let developers write applications, middleware and OWIN compliant-host? For a full reference please jump into full specification.

Here I'll present you how OWIN define an application:
using AppFunc = Func<
  IDictionary<string, object>, // Environment
  Task>; // Done
As you can see from previous C# alias, the application is defined using a Func delegate and standard .NET standard types.

You do not depends on any particular assembly and any OWIN compliant-host must be able to load and execute your application.

But how looks a simple OWIN application? (Here, full GitHub project).

This application does nothing than printing some HTTP request headers when pointed by the browser.

As promised this post leaves to the reader further investigation on the subject. So how can you run this OWIN application?

Flux, an OWIN compliant-host

Flux is lightweight web server written in .NET using C# and implements the actual OWIN specification, hence we can say that it's an OWIN compliant-host.

It's author is Mark Rendle (author also of SimpleWeb framework) and you can find full sources on GitHub.

Running this post companion sample is very easy with Flux.
  • clone and then build the sample repository
    • git clone
  • clone and build also Flux
    • git clone
  • copy SimpleOwinApp.dll in same directory of the Flux.exe executable
  • start Flux with the desidered port number
    • flux 1234
  • and finally point your browser on:
    • http://localhost:1234
Was it difficult? I think it wasn't...

Flux relies on another project (of the same author) to locate and load assemblies that contains OWIN applications.
This project is named Fix and you can find it here.

This article and sample application was born on my personal investigation on OWIN that started with this thread on .NET HTTP Abstractions Group.

I hope that this can be a good starting point also for you.

Have fun with OWIN and Flux!

Monday, 28 January 2013

Learn by need

Sometimes when you want learn a new language, you may find difficult find opportunity to use.

Using it in a new project at work, could be an unacceptable risk during the learning phase.
But in an open source project you've no time constraints and no boss screaming against you!

These days I'm heavily refactoring Command Line Parser Library, as you know written in C#.
I decided to change methods naming convention from camel-case to a normal phrase separated by underscore.

Here is the chance! Finally a simple task to be coded in F#, a language I'm starting to love.
Maybe that the following is not the best F# snippet ever (and probably is not).

Anyway this post is not about the code, but about a learning technique that always worked for me.


Thursday, 10 January 2013

Command Line Parser Library verb commands

Hence we're finally here. Command Line Parser Library supports verb commands. This was a feature promised some time ago to the community and now with help of contributors is finally implemented.
It allows you to extend the grammar supported by your application. Anyway when you switch to version Beta one small change is required to your code (and it doesn't relate to verbs).

Short name given to options is now modeled on a character rather than a string constrained to one single character. Community asked for it and after all this is a minor breaking change that made the API cleaner.

It impacts following options definition:
that should become:
So it will not  makes you lose sleep...
Coming back to verb commands, these allow you to define a very familiar syntax to *nix world. If you use git, you probably typed
$ git commit -a
a lot of times or for example
$ zpool status tank
to request ZFS storage pool status in Solaris or SmartOS.

We are at the point; backing to git example commit is the verb command and -a is a switch (in our jargon a BaseOptionAttribute derived type that maps an ordinary option). It applies only to the preceding verb command. If you have another verb, say add, that does not support -a option, parsing will fail.

The following class define options for the verb command named add:
And this is the master options class that must be passed directly to the parser:
It is interesting to note that the parser can create instances for you as these are defined with a parameterless constructor. If this is not the case or you want initialize types by your own (e.g. using a Inversion of Control / Dependency Injection framework) you're free to do that; the library will not overwrite an existing object instance.

As final thought remember that to use the facilities provided by HelpText::AutoBuild you still need that master class and now its child types inherit from CommandLineOptionsBase (this thing should change in a very near release).
Following snippet illustrates how to call the helper method in a verb scenario:
I hope this new feature give you even more freedom when designing command line syntax for your brand new application or important upgrade!
Last thing, don't forget to have fun while programming...

Tuesday, 27 November 2012

Customizing Eclipse IDE

In the last year I've become increasingly busy on mobile development. Evaluating many technologies that try to promote code reuse across all major mobile OS, I came to the conclusion that none of these allows you to create an application that really feels native for its environment.

So, starting to develop with Google Android, the more convenient choice is certainly to stay open source with Eclipse. If like me you can't develop smoothly as long your IDE is not customized, here there are some suggestions from which to take inspiration (or I hope so).
Figure 1 - Eclipse IDE in Ubuntu 12.04
First add the Eclipse Color Theme plugin using this software source: You can do this using Install New Software from the Help menu. This will add Color Theme in the preference window (Window -> Preferences) under General -> Appearance section. The one choosed in Figure 1 is Wombat.

I've also installed a new theme called Dark Juno from here Clone the repository, follow easy instructions in the README file and set the theme in Window -> Preferences -> General -> Appearance.

Finally I suggest you to use a better programming font like Monoco, available here for example. Also this is done in the preference window under Appearance -> Colors and Fonts section. If you don't like it, check out some good blog post on the web about this argument, e.g. this one.

Have fun!

Monday, 30 April 2012

Opa: attractive web development in cloud age

Opa combines in a single model server and client programming. It can take care of persistence of let you choose MongoDB. Following the node.js influence the latest version can use a javascript like syntax.
Let's see how it looks like:

With easy you use the # marker for HTML IDs, e.g. #vala, used here for input box. Reading the value using

is easy like writing it back to another HTML element identified by ID

Give it a try:
$ opa easycalc.opa
$ ./easycalc

Then point Chrome (or your favourite browser) to http://localhost:8080/. Opa compiler will take care of everything!

Have fun!

Tuesday, 17 April 2012

.NET in the Cloud

I know that cloud computing is just another marketing term, but everyone use it so I'll do. Anyway I think that could be more interesting dive in the meaning of this concept. You can read what St. Wikipedia says about it (pointing Chrome at or we can summarize and simplify it saying that ICT is moving forward (or returning) to a server-side computational model, rethought with advanced concept like PaaS / SaaS. This two concepts push cloud computing in a brand new position that simply moving program execution to the server side.

If you like me writes a lot of code in .NET and certainly loves what C# compiler can do :D, you maybe interested in AppHarbor. This interesting technology is implemented with PaaS philosophy and bring seriously your .NET code to the cloud. In my personal opinion is significantly higher than Windows Azure.

Are you interested? Wants to know more? I found very useful these videos:
  • AppHarbor, background workers, RavenDB and NuGet | watch.
  • From zero to hero with AppHarbor | watch.
  • AppHarbor ASP.NET MVC3 SQL Server Tutorial | watch.
Good coding for cloud computing!

Friday, 16 September 2011

External HD for all flavors...

Recently I had to prepare an external 250GB usb hard disk which can be read and written by Ubuntu, Mac OS X and Windows.
After some tests I found that the best result was accomplished creating two partitions using Mac OS X Disk Utility.
Disk Utility

I've formatted the first partition with NTFS and the second with HFS+.

In this way I'm able to access all partitions with Ubuntu (read/write), I can use the first (NTFS) with Windows and run Time Machine against the second one with Mac OS X. With this last operating system I can even read and write the first partition with MacFUSE and NTFS-3G.

Under Mac OS X Lion you may found this article useful,

Saturday, 27 August 2011

And sometime under Mac OS X

In *nix world .NET is called Mono and this awesome open source development platform works excellently under Mac OS X Lion.

Developing with Mono on Mac OS X

Another operating system gains Command Line Parser Library. That's good...


Wednesday, 17 August 2011

CommandLine.dll now developed under Ubuntu Linux/Mono

Because of laziness I'm still carrying out many  NET projects. with Visual Studio Express on Windows platform.

Recently I'm developing my open source parser for the command line using Mono under Ubuntu Linux operating system.
Developing with Mono on Ubuntu

MonoDevelop has not forced me to change project format (I keeped my .sln e .csproj files) and it worked just as before, or I would say better. Integration with NUnit is awesome! Religion wars aside, who more really need Windows?

Good coding!