Sunday, 10 February 2013

OS X - Super Simple Database Application with C# in 5 steps

There have been a couple of recent developments in the Mono world that have made creating applications on OS X even easier.

One useful tool that has recently appeared on the scene is Nuget. Visual Studio developers have had access to nuget for many years and now and finally it is available to Mono users. It's made very easy to use via Matt Ward's MonoDevelop nuget add in.

This blog post will walk through using Nuget on MonoDevelop on OS X to create a simple database application.

Install the Nuget Addin into MonoDevelop, there are instructions here, I added a new repository via the Add-in repository manager that points to

1) Create a new Console Application

File -> New -> Solution -> Select C# and then Console Project

2) Create the model

The model is a simple POCO that will map directly to the database:

Nothing complicated here.

3) Use Nuget to add ServiceStack.Net OrmLite

There are many Object Relational Mappers out there for C#, for example Mono added Microsoft's Entity Framework last year shortly after it became open source. I'll blog about using Entity Framework in the future but for this post I'm going to use an ORM called ServiceStack.Net OrmLite to access a SQLite database.

Goto Project -> Manage Nuget Packages

Add the following package:

  • ServiceStack.OrmLite.Sqlite.Mono

Use the search box to locate the package and hit the Add button to add the package to your project:

4) Add a couple of additional references.

In order to use Linq to query the database a few additional references are required, add these by right clicking on the references folder and selecting Edit References...

  • System.Core
  • System.Data
  • System.Data.Linq

5) Use ORMLite to create the database, populate it with data and query it

When run:

The code for this blog post is available for download here.

Saturday, 9 February 2013

What's your crash plan?

Just over a week ago my trusty hand built Windows machine horrified me by presenting me with this message:

"Back up your files immediately to prevent information loss"

Oh dear - I hadn't backed up my files on my PC for a few months and even then it was just to an external hard drive and the Mac was even worse - my apple time machine had been gathering dust in a box somewhere since I moved house. This has bugged me for a while so now it's time for action!

I started exploring options for backing up the data from all the machines used by the household. After totalling the size of the data I currently wanted to back up (around 140 GB) it became apparent that free cloud storage offered by the usual software suspects just wouldn't do. For starters these services are not really aimed at backing up the contents of your household computers, their focus is on sharing documents.

I then remembered a Hanselman blog post from last year where he documented his back up strategy. He uses a service called Crash Plan so I thought I'd give it a try. 

The software supplied by Crash Plan installed perfectly and was super simple to setup and use on all the household machines running either OS X or Windows and has just worked.

Crash plan also provide a free application for the iPhone and Android phones used in the house - this application provides me with the status of all backups and also allows me to access individual files that have been backed up when I want.

Now I don't have particularly fast upload speed on my line but one week later and I am fully backed up. 

The hard drive still hasn't crashed but I now know if it does all is not lost.