Thursday, 28 May 2015

So you want to be DevOps?

The DevOps juggernaut is well on it's way, careering through an enterprise near you. Ripping Configuration Engineers up of the ground like a tsunami and demanding they automate themselves out of existence. Developers are no longer headphones-on-code-slingers Agile Developers Engineers but polyglot superstars who walk every last line of BDD/TDD code from the IDE vagrant/docker container to a scripted live cloud deployment and when they're not hacking on open source projects at night they are checking out their monitoring dashboard splunk feed they have built to check every last twitch from the live system.

Except it's not like that. At least that's from my experience and from from the speaking to people who work in enterprises.

DevOps has created a ripple and quite rightly so - we (developers) were sitting in silos cranking out code and blissfully unaware of the downstream carnage that can be caused.

But what is this big bang DevOps movement? We've all read the Phoenix Project and follow #devops but what are we trying to achieve?

We want to be DevOps

Damn you Spotify and Netflix - you guys are fantastic but you've put DevOps on the radar of the people who wear suits and that is causing devastation downstream in the engine room.

Yes we like what we've read and heard about DevOps but being told to transform into a DevOps organisation often seems like an impossible task.
You Can't always get what you want
But if you try sometimes you might find
You get what you need - Richards/Jagger
We want DevOps but what do we need?

Well for starters, lets start with this one:

We need to deliver features faster

It's not uncommon for enterprises to release software quarterly - we want to release daily, if not hourly or even better - be in control of our releases and choose to deploy to live anytime we want.


What's the problem?

There are many problems, mostly down to the scale of the changes required at enterprise level.

Delivering faster takes discipline and cultural buy in and Enterprises have a lot of stakeholders. Getting everyone to buy into the dream is hard and it only tales one or two senior nay sayers to cause lots of pain.

The Enterprise may be based in the backend of nowhere - getting the right people that are enlightened is not easy. Many Enterprises chug along with sub par development teams churning out buggy software that doesn't do exactly what the business or customer want but this rubbish works well enough and is profitable enough to warrant not rocking the boat.

How can we fix the problem?
Success is the sum of small efforts - repeated day in and day out - Robert Collier
Faster Delivery is the end goal and is a side effect of the sum of a number of small factors. We can create a ruler to measure where we are now and where we need to be in order to achieve our goal of delivering features faster. Here are some ideas to deliver software faster:

Level 1 - Basic building blocks


  • Basic Agile Methodology followed
  • Coding standards and peer review in place
  • Source code is in version control
  • Continuous Integration (CI) in place
  • Unit tests run on the CI server
  • Static code metrics in place (Code coverage, cyclomatic complexity, etc)
  • Acceptance test behaviour written in common language between business and development teams (BDD)
  • Test Driven Development (TDD) practiced
  • Code pairing is common practice 
  • Code reviews in place
  • Architecture is modular
  • Time allowances for teams to work on dealing with technical debt
  • Stable teams
  • Test environments that mimic live


Level 2 - Intermediate progress


  • Development Teams provide out of hours support for the features they own
  • Software built with components
  • Scripted one click test environment build
  • Living documentation built from acceptance tests
  • Database is in version control
  • Integration tests run on CI server
  • Monitoring awareness by all teams
  • Configuration in version control
  • Configuration as code in place for deployments
  • Developers and testers integrated
  • Culture of learning and self improvement, proper staff training available



Level 3 - Advanced progress

  • Acceptance tests run on CI Server
  • Automatic Performance tests
  • Automatic database deployment
  • Live systems monitoring accessible to all
  • Infrastructure as code
  • Software can be deployed to live with no downtime
  • Zero touch deployment 
  • Development team integrated with operations team



Of course different enterprises will have different ways of operating so some of the above may not apply but everyone in the team has a very important role to play in delivering software faster.

Tuesday, 17 June 2014

A Dummy REST API with Go Lang

Sometimes I just want to try out a few ideas in a HTML/JavaScript client without having to scaffold a server to provide a bunch of RESTful APIs so I've built myself a dummy REST API to do just that.

Here's how I did it!

My requirements were:
  • Serve up the contents of a file based on a route for example \Customers would serve a file in the \Customers directory
  • Allow Cross-origin resource sharing and/or JSONP 
  • Allow me to change the JSON being served without having to restart anything

I decided to write the server in Go Lang since it's fun to scaffold up http web services with and the resultant utility will be cross platform so I can tinker away on my Mac with few issues. I've used Martini framework to get up and running quickly.

So the file directory will contain the files that I want to serve up as per:




The code to scan the file directory for the files is straightforward:

The code to serve up the file based on the matching route:

So with the GET file populated with some appropriate JSON:



So now when we run the servicestub application:



And if we choose a specific item:




Now to write some JavaScript!

Code here:

Monday, 1 July 2013

Setting up a Go Development Environment on a Samsung Chromebook

Since I've become an owner of a Samsung Chromebook, setting up a comfortable offline dev environment has been an ongoing goal.

I've been tinkering with various configurations for a while and have come up with this as as a starter for getting a Go Development environment up and running.

Part 1 - Installing the Go compiler

From start to finish this step should take about 40 minutes.

1. Boot the Samsung Chromebook into Developer Mode

The quick way to do this is to hold down escape + refresh + the power button.

Then press Control + D at the next page and over the course of the next 10-15 minutes the chromebook will wipe itself and install a developer mode enabled version. This brings a few things to the table like a command line shell.


2. Install Ubuntu with the help of Crouton 

I've tried dual booting Ubuntu on my Samsung Chromebook with ChrUbuntu which is fairly awesome but I had serious issues with the track pad, sound and general performance. I'm sure these issues will be ironed out over time and that being said - the wireless connectivity was much better on the Ubuntu boot than in Chrome Os - I didn't have to do the turn it off and on again song and dance with my router to get the Chromebook to connect which I frequently have to do with the Chrome Os boot.

Then I discovered Crouton and quickly I came to the conclusion that it is amazing. Ubuntu runs really smooth, the hardware works as per my Chromebook and whats more - I can switch between my linux distro and Chrome os at the touch of a button. Well four buttons (ctrl + alt + shift + Forward\Backward), but you get my point.

Installing Crouton is a piece of cake:

(i) Download the latest release from here: http://goo.gl/fd3zc
(ii) Open a shell (ctrl + alt + t) then type "shell" at the command prompt
(iii) type: sudo sh -e ~/Downloads/crouton -t unity

I've chosen unity over xfce which is used on the Crouton github page, no real reason here other than I preferred the look and feel.

Once it's finished installing it can be fired up with:

sudo enter-chroot startunity


3. Go

Go Lang is also very easy to install with apt-get and works beautifully:

sudo apt-get install golang


now check that Go is installed by typing: go version



Great, the Go compiler is in place.

Part 2 - Installing LiteIDE

This step takes about 20 minutes to complete.

Now compiling from the command line is one thing but I'm from the camp of developers that likes thumping out code in an IDE.

There are a couple of IDEs for Go that could be used - for example Eclipse + goclipse.

However I've chosen to go with LiteIDE for the time being as I like its simplicity.

There are a number of tools that need installing first that are missing from the crouton unity install:

1. make

sudo apt-get install make

2. g++

sudo apt-get install build-essential g++

3. GDB

sudo apt-get install gdb

4. QT4

sudo apt-get install libqt4-*

5. Git

sudo apt-get install git

6. LiteIDE

The only difference I had here from the instructions on the LiteIDE project page was with the QTDIR path which differs from the default path used by apt-get.

One further tip here - don't use sudo for the next few lines or you'll end up making work for yourself.

The build takes about 10 - 15 minutes. Once finished, we have a working LiteIDE in \litelide\bin

Opening the liteide application and confirming that traditional "hello world" code compiles and runs:


Excellent!

Friday, 14 June 2013

Mocking OS X with Mono and Moq

A quick way to test units of code with dependencies on other objects is to mock them up. This is not a new concept and the internet is awash with decent mocking frameworks and documentation on how to use them but I thought I'd jot a quick example anyway on how to go about mocking with mono on OS X.

I've built a simple class that has a dependency manually injected into its constructor.

Here is the interface for the dependency:


Implement the interface:



Create a class that depends on the IRepository:
Now when we invoke the above class:

All works as intended, the output is "Test" which is how we implemented the IRepository.

But when testing we want to isolate the MyWorkFactory class without having to rely on the working implementation of the IRepository interface.

So there are a few ways of going about this. We could create a new implementation of IRepository with known outcomes for testing. Or we can mock the dependency up.

I'm using Moq in this example as it's lightweight, works well on mono and is easy to use.

So let's mock/moq up the repository, inject it into the MyWorkFactory class and see what happens:

So as can be seen, the MyWorkFactory object now uses our Mocked repository dependency and outputs "My Mock" so we can test the class in isolation and configure the dependencies to test all avenues.

Monday, 1 April 2013

Samsung Chromebook

I unboxed a Samsung Chromebook this weekend and was looking forward to giving it a whirl but was  immediately deflated when it would not connect to my BT Home Hub. All manner of configuration changes later and I was still non the wiser.

The good news is that there is an active support forum and quick replies from the chrome ninjas. I was advised to enable the "Experimental Static IP Configuration" via the chrome://flags  configuration page. One reboot later and what do you know? I was connected.

So now 48 hours later I'm very pleased as a lot of boxes have been ticked:


  • It's fast. Really fast. Not just in terms of the boot up but the browsing is a lot more responsive than I am accustomed to.
  • The hardware is really nice. it's compact and light. The keyboard has a great feel to it and is great for touch typing.
  • The heat dissipation is excellent - this is certainly no leg warmer like the MacBook Pro
  • There are plenty of excellent apps on the chrome store to suit my requirements - and many offline compatible ones too.
  • The battery life is very good indeed - I've been using it for two hours and it's reporting over six hours left.
  • I can remote desktop onto my Desktop  and Mac.


Will it replace the MacBook Pro?

Maybe but I have a few issues to tackle first.

I'm missing a good text editor and the ability to develop .Net code. OK Google provide a Chrome Remote Desktop application that I can use to remote onto my Windows 8 desktop PC - it's very good but not quite as responsive as the Microsoft RDP client on the Mac. It may be the case that I dual boot the machine with Ubuntu and Mono to tick this box.

I've also recently taken an interest in programming in Python. I've discovered a decent alternative for the Chromebook is to "spin up" an Amazon EC2 micro instance and SSH onto it via the built in Chrosh (CTRL + ALT + T) terminal.

I'll probably blog about programming on the Chromebook once I've researched the options properly.

Oh yes, I'm going to have to find a different game to play too...

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

http://mrward.github.com/monodevelop-nuget-addin-repository/3.0.5/main.mrep

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.


Thursday, 10 January 2013

I passed Exam 70-480 Programming in HTML5 with JavaScript and CSS3

Back in late October/ early November last year I noticed that Microsoft had refreshed their professional qualification exams and were running a promotion on one of the entry level exams - Programming in HTML5 with JavaScript and CSS3. At the time of writing the promotion is still running until the end of March 2013.

I've been interested in pushing myself to get some professional qualifications for a while so took the bate and ran through the Jump Start modules on the Virtual Academy web site which made me think passing this exam is achievable.

I took the exam today and passed it with a sense of relief - this is the first exam I've taken in a long long time. I found most of the exam reasonably comfortable - there were a few areas that raised holes in my knowledge but on the whole it was a straightforward process.

I thought I'd write some notes on how I studied for it.

Unfortunately at the time of writing there is no official study guide book, however based on the content of the "Skills Being Measured" section on the exam details page the subjects can be broken down. I went through every bullet point and played around with the feature in code.

The Jump Start modules give you a taster of the subjects that are to be tested - I found this really useful - I could download the modules to my phone and watch them over the course of a couple of weeks on my daily commute.

Getting a good book on the subject was essential to me as I have a lengthy train journey in and out of work every day- There are many to choose from but I purchased JavaScript & jQuery the missing manual which I found an excellent resource and this was a significant help to me.

Another JavaScript book that has appeared up on my radar recently is Secrets of the JavaScript Ninja by John "jQuery" Resig - I really like the look of this one (even though the cover confuses Samurai with Ninjas) and have put it on my wish list. The publishers have generously provided a couple of chapters for download. I would seriously recommend reading Sample Chapter 6 as it is very important to understand inheritance and the infamous prototype property.

Lastly, reading about it is all well and good but I can't imagine anyone passing this without actually spending a considerable amount of time writing, breaking and fixing html, JavaScript and CSS. If you don't program for the web at work (fortunately I do) then it makes life even harder but not impossible.

If you're short on ideas on where to get started then try some of these suggestions

  • Find an interesting JavaScript library on GitHub and try and use it - play around with it. Let me know if you want a suggestion here!
  • Build a Twitter Bootstrap site and add some interactivity like form submit or a grid of data. Try and highlight menu items when the mouse hovers over them or selects them. Try and put it on top of some server code and pass data too and from it.
  • Use jQuery to dynamically add a few controls to a form. Then try it without jQuery ;-)

Basically noodling - it is a great way to learn, especially writing code that doesn't work and then figuring out why it doesn't work.

Also one thing that isn't covered by the syllabus is debugging, I'd seriously recommend getting comfortable debugging HTML, JavaScript & CSS with at least two browsers - all the major browsers have fantastic debugging tools baked in and there are lots of resources out there on how to use them, e.g. for Chrome.

Do you need to be on a Microsoft Operating system to study for this? Nope, I did most of my noodling on my Mac at home.

One final tip, understand this.

So what now? Passing this exam means I'm now a Microsoft Specialist but  I also have a few paths open to me. This exam is the first of three exams for a couple of Microsoft Certified Solutions Developer (MCSD) standards:


I think I'm going to opt for the Web Applications path to MCSD certification - next which is:

Exam 70-486: Developing ASP.NET MVC 4 Web Applications

Working with ASP.NET MVC 4 at work is a big help here but I still have a lot of studying to do - I'm aiming for mid Summer 2013 for this one...

Saturday, 29 December 2012

Hello World Application on OS X in HTML & JavaScript with node-webkit

JavaScript is the current programming hot potato, it's already possible to build Windows 8 applications in HTML & JavaScript with the excellent tools and training that Microsoft provide but what about OS X & Linux?

Another interesting way of writing HTML & JavaScript applications for OS X (and indeed Windows & Linux) is by using node-webkit.

This tutorial steps through creating a simple hello world style application and then using node-webkit to package and run it on OS X.

Full source code can be downloaded from here.

Prerequisites

Download node-webkit from here: https://github.com/rogerwang/node-webkit

Download the latest version of jQuery from here: http://jquery.com/

Step 1- Create our Hello World web application

What we want is quite simple, a button that has a click event that updates a label.

Let's get started with some HTML, create a file called index.html and populate it with this html:





We also need to create the JavaScript that deals with the button click event.

Create another new file and save it as index.events.js and populate it with this JavaScript:




Now open index.html and press the button:

Not very exciting, but it can be seen here that it's working and running in Safari. 

Step 2 - Bundle our web application as a node-webkit application

To create a node-webkit application we need to create one further file called package.json:

Now we have four files in our directory:

    index.html
    index.events.js
    jquery-1.8.3.min.js
    package.json

Create a ZIP file with the above four files and call it HelloWorld.nw.

Copy the node-webkit application into the above project directory and run it:



And there we go - our Hello World application running on OS X - source code for this demo here.



For more information on running and packaging the application see these links:

https://github.com/rogerwang/node-webkit/wiki/How-to-run-apps

https://github.com/rogerwang/node-webkit/wiki/How-to-package-and-distribute-your-apps



Tuesday, 2 October 2012

Scheduling with Quartz and Mono on OS X

Quartz.Net is a brilliant library for scheduling in .Net and a great addition to the tool kit when developing C# applications on OS X.

At the time of writing the latest version is 2.0.1. Getting this to run on Mono is a little tricky though, for starters it uses a call to a method in the System.TimeZoneInfo that at the time of writing hasn't been implemented in Mono 2.10:


public static DateTimeOffset ConvertTime (DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone){throw new NotImplementedException();}
So we have a few options, trying to implement the missing feature is a little daunting so I took a shortcut and downloaded the previous version of Quartz.net 1.0.3, tweaked my code so that it used the old feature set and discovered that it works!

using System;
using Quartz;
using Quartz.Impl;
namespace Quartz
{
    class MainClass
{
        private static IScheduler _scheduler;
 public static void Main (string[] args)
 {
     ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); 
     _scheduler = schedulerFactory.GetScheduler();
     _scheduler.Start();
     Console.WriteLine("Starting Scheduler");
     AddJob();
 }
public static void AddJob()
 {
     JobDetail job = new JobDetail("job1", "group1", typeof(MyJob));
     Trigger trigger = TriggerUtils.MakeSecondlyTrigger("MyTrigger", 10, 10);
     DateTime ft = _scheduler.ScheduleJob(job, trigger); 
}
}
    internal class MyJob : IMyJob
{
        public void Execute(JobExecutionContext context)
 {
     Console.WriteLine("In MyJob class");
     DoMoreWork();
 }
 public void DoMoreWork()
 {
     Console.WriteLine("Do More Work");
 }
}
internal interface IMyJob : IJob
{
}
}
Here is it running:

Monday, 27 August 2012

OS X - Running StyleCop in MonoDevelop on C# code

When developing on Windows I find StyleCop to be a really useful tool for keeping code consistent throughout projects and I sorely miss it when developing C# projects on OS X with MonoDevelop.

I knew about a StyleCop addin for MonoDevelop here but at the time of writing it's not compatible with the latest version of MonoDevelop (3.0.3.5).

Time to get my hands dirty then! I forked the project on GitHub and modified it so that it works with MonoDevelop 3.0.3.5, the repository is here.

Upgrading the project was relatively easy, just tweaking a few version numbers in the addin manifest and reset the references. I also adjusted the StyleCop violations to output as Warnings rather that Errors, this suited the way I like to see the violations.

Getting the addin to run is another matter though - StyleCop uses the registry. Mono has a registry implementation but I found there were security issues involved with non admin processed reading and writing to it so in order to install the addin a little tweak to the registry permissions was required:

Navigate to the registry file:

On my machine it was here:

/Library/Frameworks/Mono.framework/Versions/2.10.9/etc/mono/registry/

Then adjust the security:

sudo chmod 777 last-btime

Here is a screen shot of it running:




Download and build from here:

https://github.com/mattlaver/Stylecop-Monodevelop-Addin

Sunday, 4 March 2012

MonoMac - Open File Dialogs

Another common feature of applications are file dialogs. This blog post shows how easy it is to use them in our MonoMac applications.

The NSOpenPanel class is used here, the documentation can be seen on the Apple developer library here NSOpenPanel.

Without further ado, let's get stuck in!

1. Create a new MonoMac Project

As per the Hello OS X tutorial, edit the MainWindow.xib in xcode and add a button and an action called _OpenClick and a label called _Label1 with an outlet:



2. A small bit of coding

Add the handler for the button action to MainWindowController.cs:


partial void _OpenClick(NSObject sender)
{
        var openPanel = new NSOpenPanel();
        openPanel.ReleasedWhenClosed = true;
        openPanel.Prompt = "Select file";

       var result = openPanel.RunModal();
       if (result == 1)
       {
             _Label1.StringValue = openPanel.Filename;
       }
}

Now Run the application and test the code - pressing the Open button should invoke the Open File Dialog:


Select a random file and observe the Label being updated:



3 Additional notes

The NSOpenPanel can also be used to specify if it is for selecting just files or directories using these properties:

CanChooseDirectories
CanChooseFiles

Also note that the NSSavePanel can be used for saving files.



Monday, 13 February 2012

MonoMac - Getting started with Main Menu Items

Following on from the last post, here is a quick example demonstrating how to add a new items to the application Main Menu. Here we explore using the AppDelegate to pass a NSMenuItem Action to the MainWindowController.

1. Create an Empty project

Create a new MonoMac Project and double click on MainMenu.xib

2. Configure Xcode

From Xcode click the button in the bottom left ("Show Document Outline") and expand the Main Menu:




3. Create the new NSMenuItem place holder

Drag a NSMenuItem from the Object Library and drop it below the "Menu Item - Help" object:


4. Create the Drop down menu

Drag a NSMenu onto the NSMenuItem created in step 3 and set the title of the NSMenu to "My Menu" and the title of the first NSMenuItem to be "MenuTest":




5. Create the NSMenuItem Action


Display the AppDelegate.h file and then hold down [ctrl] and drag the "MenuTest" NSMenuItem onto the code window. Change the Connection to "Action", the Name to _MenuTestClick and then press connect:




6.  Add a label to the MainWindow

Select MainWindow.xib (via the navigation  menu at the top of xcode) and add a label. Create an outlet by holding down [ctrl] and drag it onto the MainWindowController.h. Call the outlet _Label1:



See the hello-os-x-from-c-five-steps example for more detailed steps on adding label outlets ro rge MainWindowController.h file.

Save Changes and move back to MonoDevelop.

7. One small bit of coding

From Mono Develop, Open MainWindowController.cs  and add this method:

public void MenuTestClick()
{
    _Label1.StringValue = "Menu Clicked!";
}

Open AppDelegate.cs and complete the implementation of the partial method _MenuTestClick (see the designer for the implementation of this partial method):

partial void _MenuTestClick (MonoMac.Foundation.NSObject sender)
{
    mainWindowController.MenuTestClick();
}

Now Build and run the application:


Marvellous, a working Main Menu!





Tuesday, 31 January 2012

Hello OS X from C# (Five Steps)

Here is a gentle introduction to developing OS X applications with C#. Hopefully this is useful and gets some more people started with the technology.

To start with, I'm brushing over the technology, the philosophy of design patterns like MVC and how the nuts and bolts work - this is a quick and dirty guide to getting stuck into a simple hello world style application with minimal effort.

Before I begin, there are some prerequisites:

- OS X operating system - I currently use OS X Lion running on a Macbook Pro.
- XCODE 4
- Mono 2.10.8
- MonoDevelop 2.8

XCode, Mono and MonoDevelop are available to download for free and they all installed fine on my mac.

1. Create a Project

Open MonoDevelop and goto File -> New -> Solution:


Select a MonoMac Project, give it an appropriate Name and select Forward and the OK  on the project features tab.

Marvellous, we now have a project:


Check it works by right clicking on the project and selecting Run Item:






Exciting eh?

Let's get back to the task in hand. Stop the application from running by going to Run -> Stop.

2. Design the Graphical User Interface (GUI)

Double click on MainWindow.xib and wait for Xcode to open:



In the botton right hand corner is the Object Library (at least on my setup). Drag a NSButton and a NSTextField onto the Window.

Now press the Show the Assistant Editor button to get the hybrid view of the Window and the Code editor:


At the top of the code window there are arrow buttons, use them to cycle through the code files until MainWindowController.h is displayed.

3. Add the Label Outlet

Select the NSTextField on our Window, hold down the [ctrl] button and drag onto the code window. In the Popup window set the Name to be _Label1:


Now press the Connect button and the code should look like this:


@interface MainWindowController : NSWindowController {
    IBOutlet NSTextField *_Label1;
}


4. Add the Button Action

Select the NSButton on our Window, hold down the [ctrl] button and drag to the code window. Change the Connection to Action, the Name to _ButtonClick. The Type box should automatically change to id.


So the Code should now resemble:


@interface MainWindowController : NSWindowController {
    IBOutlet NSTextField *_Label1;
}
- (IBAction)_ButtonClick:(id)sender;

@end


Save (File -> Save) and then go back into MonoDevelop.

5. Wiring up the Button Click Event


When MonoDevelop is refocused it should update it's code files form the changes made in Xcode.

Double click MainWindowController.cs and add the following method:


partial void _ButtonClick(NSObject sender)
{
         _Label1.StringValue = "Hello";
 }


So in the editor it looks like this:


Now run the application again and press the button:


So as you can see, it's actually quite easy.