How to design your SPA to work with Angular CLI and DoNet Core

When building new apps, you need both client and server-side pieces.  This article focusses on how to structure a SPA that is made out of angular for the client and dotnet core for the server.

There are numerous questions I needed to answers when mixing these technologies.

  • Should I host my angular app inside an MVC View or just serve the angular app from static files.
  • Should I host the angular app inside the same application that serve the Web-Api or serve it from a separate site?
  • How to setup a productive development environment?
  • How should I integrate angular-cli together with a ASP.NET Core app?
  • Should I use Vs.Code or VisualStudio ?
  • How to package and deploy the application for on prem or in the cloud?

Of course, the answer to all these questions is always the same: it depends! After experimenting with several options, I finally decided that I should go for the simplest solution that could possibly work and started with just serving static files inside a Web-Api application.  Yet, during development, what I found the most productive, is to completely separate the Angular app from the Web-Api solution. I like that my Angular and the ASP.NET Web-Api apps live separate folders beside each other. It’s only at build time that Msbuild assemble the parts by calling “ng build”.  To do that I needed to configured angular-cli to output the build in the \wwwroot folder of the ASP.NET app.

Concerning the IDE, what I found the most productivity was to develop my angular app using Vs.Code.  Thus far, for the Web-Api part I tend to prefer VisualStudio and Resharper. So, I optimized my Angular app for working with Vs.Code and my Web-Api project for VisualStudio.  During development I usually run the backend and launch the Webpack dev server through an “npm start” command.  At publish everything is nicely packaged together inside a ASP.NET app, so deploying to Azure can simply be done by using the VisualStudio publish wizard.  

On my github project core-angular-example, you can download the solution template I use for making SPA’s with Angular-cli and DotNet Core.

Here I explain the steps you need to follow to setup the basis of such an app:

0) First you need to install:

1) From a powershell console:

mkdir angular-dotnetcore
cd angular-dotnetcore
mkdir web-api
cd web-api
dotnet new webapi
cd ..
ng new angular-app

2) Open VisualStudio code and open the angular-dotnetcore folder

 

Angular2 vs React from the perspective of a .Net fullstack developer

FightClub

Intro

Currently we had a lot of discussion on which web framework we should invest: Angular2 or React. Therefore I decided to experiment with both and make my own meaning. 

Coming from Angular1 and loving it, I can’t pretend I’m completely objective. Nevertheless being a little frustrated with the breaking changes and late arrival of Angular2 and hearing a lot about the goodness of React, I wanted to give it a try and compare both frameworks with an open mind-set.  

I took the perspective of an Enterprise .Net developer.  In this comparison I value support for tooling that just work over purity/beauty of the framework.  I also tested the integration with Visual Studio 2015 and Visual Studio Code.

In our environment applications have a lifecycle that can easily stretch over 10 years. In this context be able to support big projects and keep maintaining them over time is key. This is why I took Typescript as a given.  Coming from a .Net background and having built all my Angular apps with the help of Typescript I don’t wanted to get back to pure JavaScript. I love the static type checking and all the tooling support, code completion and refactoring typescript brings to the table.  So the applications I wrote to compare both frameworks used Typescript and the ease of programming with Typescript is for me important.

Overview

React

React is a declarative Javascript UI library, created by Facebook that handles a very specific set of concerns, composing and packaging your UI in components and rendering these components. What could seem odd in the beginning is that React doesn’t separate the HTML from the JavaScript.  Frankly I got used to it and learned to appreciate the advantages of this. You can still separate the logic from the presentation by creating components that only render Html and Components that handles the logic  (named “Controller Views” components). 
Here is a simple example of a React component:

import * as React from "react";

export class HelloWorld extends React.Component<{}, {}> {
    render() {
         return (
            <div>

                <p>Hello world from react!</p>

            </div>
        );
    }
}

The render() method is the core method of the React component.  React implements a virtual DOM, this is an internal representation of the DOM.  Using his own representation of the real DOM and only rendering what was changed since last time render() was called. 

A react component is typically written in a JSX file.  JSX enables to mix the HTML tags inside the JavaScript part.  To transform the JSX at runtime or compile time you typically need to use Babel. Now TypeScript provide support for JSX, this enable us to use the TypeScript compiler instead of Babel. Adding the compiler option: “jsx”:”react” in your tsconfig.json file will enable support for the the TypeScript compiler.  When this is done you can use the “tsx” extensions in order to support “JSX” with typescript.

I found that VisualStudio 2015 and VS Code provided a good support for the TSX format.  It differentiates the HTML and TypeScript part quiet well. With TSX you even get auto completion in the HTML parts.
 

To illustrate other key concepts of React we need a more sophisticated example:

 

Notice on line 9, the two type arguments we pass to declare our AuthorComponent class.  The first is the “prop” the other is the “state”.  These two concepts should not be confused.  “state” is an internal concern of the component, it holds the internal data (model) of the component and can change, and every time it changes the virtual DOM is adapted.  “props” are passed to the component and are not meant to be changed.  An illustration of the use of “props” is with “Controller Views Components”, these are parent components that host child components. “props” are typically used to pass the component properties:

Here author, onChange, onSave, errors are “props” of the AuthorForm component.


In contrast with Angular, React is only a UI library; therefore it’s usually used with other libraries like Redux.  Redux help us to manage the application data flows.  You don’t absolutely need Redux but usually when building large scaled Enterprise applications it’s something you’ll want to add to your React apps.  In fact you can even use Redux with Angular but the unidirectional flow of React lent itself very well to the Redux model.  Redux is based on the original Facebook Flux library. It help to manage the application State. I found that managing state in a React application without Flux or Redux demand a considerable effort. Nevertheless these frameworks bring also a great amount of concepts.  Explaining these is outside the scope of this article.

Angular2

Although Angular2 comes with a lot of breaking changes and you can’t upgrade directly from Angular1,  Angular2 still feels like an evolution of Angular1 and I felt that’s the big changes that where introduced where relatively easy to learn coming from an Angular1 background.

For me coming from the .Net/MVVM world, Angular always felt familiar and I appreciate the similarities with the WPF data binding model.  Nevertheless I still have troubles with the new binding syntax that is quite different of the used in Angular1. 

Angular advocates the separation of HTML and Code.  Although these can now be in the same file you don’t mix code & HTML in Angular.   This’s usually a good practice especially when working with web designers.  The downside of using a specific data-binding syntax  is that you don’t get the code highlighting & code completion you get with React.

Angular2 is a framework and a quite complete one.  With Angular you get all in a box.  You can replace many parts but I never really needed to.  From an Enterprise viewpoint, be able to count on a complete but modular toolbox is an advantage.  It helps new hired developers to be productive faster and enforce consistency.

Here is an example of what a “Hello world” Angular2 app looks like.  A small tutorial is available on the site of angular on how to setup a quickstart app.  It took me less than 5 minutes to complete.

After completing this 5 min tutorial you get basically everything you need for client side development including a small web server (BrowserSync) configured to do edit & continue. 

Angular separate the HTML from the code, you can add the Html inside a Component but it’s still in a separate section. To be able to add view logic inside the HTML you need to use the Angular2 template syntax. A simple Angular HTML component looks like this:

The *ngFor, {{todo.title}}, (click), [todo] and <todo-detail> elements are all Angular2 template syntax.  The <todo-detail> tag represent a TodoListComponent.
The todolist.component.ts code could be like this:

Here is an example of how to define a two-way databinding works in Angular2:

<input type="text" [(ngModel)]="user.first_name" />

 

Every Angular2 app begins by declaring at least one module.  This is an example of such a module:

 

import { BrowserModule } from '@angular/platform-browser';

import { FormsModule }   from '@angular/forms';

import { HttpModule }    from '@angular/http';

import { Router }        from '@angular/router';

import { AppComponent }             from './app.component';

import { TeamComponent }            from './team/team.component'

import { TeamService }              from './services/team.service'

import { routing }                  from './app.routing';

 
@NgModule({

    imports: [

        BrowserModule,

        FormsModule,

        HttpModule,

        routing

    ],

    declarations: [

        AppComponent,

        TeamComponent,

    ],

    providers: [TeamService],

    bootstrap: [AppComponent]

})

 
export class AppModule {

}

 

My evaluation

Angular2 loves TypeScript

For me the biggest difference between both is that Angular2 is TypeScript native and React just tolerates it. Sure you can use TypeScript with React, I provided some examples how you can do that nevertheless I spend a lot of time on figuring how.  This is especially a problem when you consider that the React examples you find on the web are inconsistent. You can find many ways to do the same but some of them are not TypeScript friendly.  During my experimentation with React I often was forced to use the <<any>> type.  This means that I lost the goodness of working with TypeScript: compile time type checking, autocomplete and refactoring support.

Angular2 feels like home for C# devs

The React documentation provided by facebook is quite good but the Angular2 official documentation is just superb.  Following the quickstart guide I was able to construct a full application in less than 5 minutes.  You can also find a complete guide that covers every topic of the framework.  The Angular2 “Tour of Heroes” is a tutorial where you build a real world application using every important aspect of Angular2. 

Every example in the Angular2 documentation is provided in TypeScript.  For React most documentation is in ES6. On other internet sites I found that most of the examples are still in ES5. Finding an up-to-date tutorial on how to bootstrap a standard React application with TypeScript is not easy. You can find one on the TypeScript site but it’s very basic.  When you compare this to Angular2 where you even have guidance on how to setup VisualStudio you immediately understand that Angular2 is far more welcoming for C# devs as React.  The only guidance I found on how to integrate TypeScript was on the TypeScript site. What I learned here is that usually you need to figure out by yourself how to use TypeScript with React as you don’t find a lot on the internet. So during my React experimental project I’ve wasted many, many hours in converting Javascript examples to TypeScript. I had some problems with inconsistencies between type definitions; sometimes I needed to tweak this myself to get my project compiled.  I didn’t have any of these problems using Angular2, the type definitions where always up to date and all provided libraries worked well together.   

I love mixing Html inside JavaScript

When working with React in VS.Code and VisualStudio, I was first disappointed as these editors didn’t support the JSX syntax correctly.  All this changed when I converted my first code to TSX (the TypeScript equivalent of JSX).  Here React really shined as I got type checking & code completion even inside my TSX templates.   Mixing typescript inside the HTML was for me a little revelation.  I still think web designers will not really like this but for me other frameworks should copy this great idea.  You don’t need to learn another programming or templating syntax. You can use the same programming language everywhere. When you use TypeScript you even get static type checking in your templates what considerably diminish the number of mistakes you can make. Those who have already used Angular will certainly see the benefit of this.  With Angular I can’t count the number of times I got a blank page or things missing on my page because I misspelled some property in the template or used the wrong templating syntax.  

ErrorMessages feels a lot better

Another great aspect of React is the explicit error messages it provides.     

     

In Angular1 you get usually at best a blank screen with completely useless error messages, now I found the error messages had improved tremendously in Angular2. It usually returns explicit messages with descriptions on how you can solve the problem. 

Many ways to do the same thing

A pain point concerning React is the many ways to do the same thing. For example I found the following ways to create a React component: using the ES5 Create Class Component, using the ES6 class component, using stateless components, with Object.Create, with Mixins, creating Parasitic Components and with the StampIt library.    Also a primary concern for me is the high churn rate of React, currently React is at version 15.  This is a high number for a framework that is only a couple of years old.

Conclusion

For me the conclusion is that if you are a C# enterprise developer who wants to get all the goodness Typescript brings to the table, Angular2 is the obvious choice.  React is a beautiful library that enforces good design but it doesn’t embrace Typescript as Angular2 does.  React has certainly some advantages compared to Angular2 like using JavaScript as templating syntax but Angular2 is what an enterprise developer wants. It’s complete, opinionated and his Typescript native support makes it more crafted for large scale applications.  Angular2 two-way binding also result usually in a higher productivity rate and less code to maintain when it comes to building business applications.

 

Building TypeScript with Gulp

In the preceding post I show how you can build your TypeScript with Tsc, you can also simply use Visual Studio and use the option: “Compile TypeScipt on Build” in the Build properties of your ASP.NET Core project. While these are valid options I generally prefer to use Gulp to setup my own workflow. 

In this post I’ll explain how you can use Gulp to setup and fine tune your Typescript build.

Pull Gulp npm packages

First will need to use npm to pull down some gulp packages that will help us in setting up our Typescript build.

The npm packages we need are:

"gulp-rimraf": "^0.2.0",

"gulp-sourcemaps": "^1.6.0",

"gulp-typescript": "^2.13.4",

"gulp-uglify": "1.2.0",

"rimraf": "2.2.8"

 

To install these packages you can copy paste the list here above right under the “devDependencies” of the package.json file but I prefer to use npm.

Navigate to the root of your project and use the command:

c:\Dev\MyClub\web>npm install [packagename] --save-dev

The --save-dev option is used to update our packages.json and put the new dependencies under the “devDependencies”.

Create the Gulp Tasks

Here we’ll use gulp-typescript to compile automate the typescript build. The documentation can be found here. Open the gulpfile.js and modify as follows:

  • Require the following packages:
  • Add following path variables
  • As we’ll use the tsconfig.json file to set the build properties we’ll create a project:
  • Write the typescript build task
  • Write the clean tasks
  • If you use VS2015 you can bind the gulp tasks with your VS build. The clean tasks should run before our build and after our build we should run first the ‘tsbuilld’ and then the ‘min’ task.

 

 

  • If you want that the ts build is triggered when a ts file changes write a watch task:

 

  • If needed modify your angular script links. As the predefined min:js gulp task mimifies all js files we can choose to use the mimified app.js file in production.

 

Now every time you compile your project or save a typescript file the ts compiler should build your javascript files.

Build your Arduino Robot and program it with Javascript

In this post I explain step by step how I build an Arduino based Robot. This can be a handy if you want to build your own. I explain which design choices I made, which frameworks and technologies I used and how I program and configured the robot. Here you can find a video of the end result.

What is needed?

The robot is based on a RoverV2 + Bluetooth Arduino robotic kit sold by Robotshop.  This kit contains:

  • A compatible Arduino board including:
    • Dual H-bridge and onboard voltage regulator
    • An onboard charger
  • A Bluetooth module
  • An aluminum frame
  • Tamiya Twin-Motor Gear Box
  • Tamiya Track and Wheel Set
  • Lithium Polymer Battery Cell – 3.7V 1000mAh

robotshop

The kit is complete and well documented but if you want to go hard core and start with a classic Arduino board, you can obtain the same result with following components:

  • An Arduino compatible board
  • An Arduino motor shield
  • A pair of two 5v motors and 4 Wheels & frame
  • A Bluetooth module
  • 4xAA battery & holder

The goal of this article is to set the basic building blocks to build a robotic platform that you can extend to finally build an autonomous robot.  Therefore, to enable the robot to sense his environment we extend the base platform with:

3 x ultrasonic sensors HC-SR04

ultrasonic

1x Accelerometer MMA7361.

accelerometer

1x Compass HMC5883L

compass

You can find all these components, including the wheels & frames in shops selling Arduino compatible boards online like SainSmart or Robotshop.

 

Design

For the design I choosed to remotely control the robot from a server (a laptop or pc).  This design overcomes the limited processing & storage of the Arduino board but it comes at the expense of autonomy. My robot will not be able to evolve without be connected by Bluetooth to his server.  This is a concession I’ve to make but it provides me quasi infinitely processing power and makes my robot accessible through the internet.

The Arduino board plays the role of central nervous system and the PC is the brain. Another advantage that offers this design is that the robot can be controlled from anywhere in the world as it is exposed through http by a node.js application.

On the Arduino board runs a small program named “Firmata”.  This program enables you to control the Arduino board remotely through the Firmata protocol.  You’ll send commands from the server to the robot through a serial connection.  On the server side you’ll program your robot with Javascript using the johnny-five node library.  This library provides an abstraction over the Firmata protocol and enable us to interact with the Arduino board and a lot of the Arduinos compatible electronic devices like sensors and motors.

The robot can be remotely controlled and followed through a web interface dashboard.  The dashboard is a single page application built with angular.js   .  The html, images, css and javascript resources are served by express.js.  Express.js is the default web application framework for node.  Express.js is also used to expose a rest based API.   Through this REST interface, the radar and accelerometer data can be retrieved and commands can be send to the motor.  This allow you to program and control the robot via any device using the programming language of your choice.

To enable real time communication in both directions between the server and the robot I’ve used socket.io.

design

 

 Assemble and configure your robot.

To assemble the DFRobotshop RoverV2 you can follow this video.  As I’m a Lego fan and that with two little boys in house I’ve a lot of little bricks, I’d no difficulties to find all pieces I needed to build a Lego frame where I could mount the ultrasonic sensors, the accelerometer and the compass on it. Here you can find a picture of the end result.

robot

It’s up to you to decide to copy the design or make your own as long as you use the same core components and follow the schematics provided here beneath the code will be compatible with your robot.

Scematics

Here you can find the schematics for your robot:

Johnny5-Radar_bb

 

Accelerometer

As the accelerometer MMA7361 can vary slightly between manufacturers and models I provide an alternative schematic only for the accelerometer:

schematicsaccel

Configure your Robot

Prerequisites:

Before you start make sure you’ve setup the following tools on your box:

– Git : https://git-scm.com/

– Node 0.10.40 for x86 : https://nodejs.org/dist/v0.10.40/

– Python 2.7.x : https://www.python.org/downloads/release/python-2710/

If you’re on windows make sure you’ve configure your PATH correctly for all of these tools, therefore I suggest you use Chocolatey to install all of these components.

 Download the code

Create your working folder:
c:\Dev>mkdir arduino
cd arduino

Clone the repository:
c:\Dev\arduino> git clone https://github.com/geobarteam/johnny5.git

Install the packages:

c:\Dev\arduino\johnny5> npm install

You could receive some warnings here, don’t panic it should still be working fine.

Flashing your Arduino board

Because the onboard bluetooth ship is limited to 9600 baud I’hd to patch the firmate protocol. This patched version can be found on the root folder.

  1. Open the Arduino IDE
  2. Connect your Robot to your PC through the usb cable and temporarly remove the bluetooth module from your Arduino board
  3. In the IDE select the correct com port
  4. Choose, File, open and select the “firmate_pulse_9600B_patch.ino” file located under: ..\johnny5\firmate_pulse_9600B_patch
  5. Push the upload button
  6. Reconnect your bluetooth module

 

Connect to your Arduino board through Bluetooth

You should go to your Bluetooth settings and associate your Bluetooth with a COM port.  On resent versions of windows you should click on the Bluetooth icon, choose “Add Bluetooth devices”.  You should see “Bluetooth_Bee_V3” click on it and enter the secret code: 1234.

You need to know which COM port windows as configured to your outgoing connections to you robot.  Therefore open the Bluetooth settings, select the COM ports tab and note which COM port is associated with your Bluetooth_Bee_V3 outgoing connection.

comports

Configure and start the server

With your preferred IDE modify the variable “comport” in the “app.js” file with the COM port you connected the Arduino with.

On the Johnny5 folder, start the program => “node app.js”

console1

console2

Start your preferred browser on http://localhost:3000 , you should now be able to control your robot through the interface:

dashboard

 

Enjoy!

Get started with ASP.NET Core, Angular and MongoDB

Here I’ll start a series of little post that will build a new application based on the following stack: ASP.NET MVC5, Angular 1.5.x and MongoDB.

The code used in these tutorials can be found under my git hub project: myClub

Every post has his own dedicated branch, so you can just use  “git checkout <branchname>” to find all the source code of the post you’re interesting in.

1.0  Create a new MVC core project

To generate a new project we’ll use Yeomen.  Open a commend prompt/bash shell or powershell shell on the location you want to put your new project.

 

mkdir myClub
cd myClub 
yo aspnet 

 

Choose Web Application Basic

Provide a name.

1.1.           Add Angular to MVC app

 

1) Add Angular, from command line inside you project dir: 

bower install angular angular-ui-router –save

 Add angular to _layout.cshtml : 

<script src="~/lib/angular/angular.min.js"></script>

2)      Create two js scripts under wwwroot


app.config.js

(function () {
    'use strict';

    angular.module('myClub')
    .config(initrouter);

    function initrouter($stateProvider, $locationProvider, $urlRouterProvider) {
        $locationProvider.html5Mode(true);
        $urlRouterProvider.otherwise('/');
        $stateProvider
            .state(
                'home',
                {
                    url: '/',
                    templateUrl: 'app/home.html',
                    controller: "HomeController",
                    controllerAs: 'vm'
                }
            )
            .state(
                'myteam',
                {
                    url: '/myteam',
                    templateUrl: 'app/myTeam.html',
                    controller: "MyTeamController",
                    controllerAs: 'vm'
                }
            );
    }
})();

app.module.js

(function() {
    'use strict';

    angular.module('myClub', ['ui.router']);
})();

  3) Add two controllers

myTeam.controller.js 

(function () {
    'use strict';

    angular
        .module('myClub')
        .controller('HomeController', myTeam);

    myTeam.$inject = ['$location'];

    function myTeam($location) {
        /* jshint validthis:true */
        var vm = this;
        vm.players = [];


        vm.title = 'Home';

        activate();

        function activate() {
           
        }
    }
})();

home.controller.js

(function () {

    'use strict';

 

    angular

        .module('myClub')

        .controller('HomeController', myTeam);

 

    myTeam.$inject = ['$location'];

 

    function myTeam($location) {

        /* jshint validthis:true */

        var vm = this;

        vm.players = [];

 

 

        vm.title = 'Home';

 

        activate();

 

        function activate() {

          

        }

    }

})();

      4) Add two html pages

home.html

<div class="jumbotron">
    <div class="container">
        <h1>MyClub</h1>
        <p></p>
    </div>
</div>
<div>
    
</div>

myteam.html

<div>

    <p>My Team</p>

</div>

 

 

5) Reference the js scripts in _layout.cshtml

     <script src="~/lib/angular/angular.min.js"></script>
    <script src="~/lib/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="~/app/app.module.js"></script>
    <script src="~/app/app.config.js"></script>
    <script src="~/app/home.controller.js"></script>
    <script src="~/app/myTeam.controller.js"></script>

 

6)      Add angular app inside and move the navbar from _layout.html to index.cshtml

Index.cshtml

 

Update your Azure infrastructure as part of a build

In this post I demonstrate how you can create and update your Azure infrastructure as part of a build in Visual Studio Online (VSO).  This enable to deliver and test your code and your infrastructure continuously. 

Under your VSO project, choose build, and right click your build and choose “edit”, add an Azure Resource Group Deployment.

To be able to provision the infrastructure from your VSO build your Resource Group Deployment need to receive the permission to be modify infrastructure in your Azure subscription.  Therefore you can use a Service Principal.  This msdn article details how you can create a service principal inside your subscription and use it inside your deployment.

Watch out: if you’ve several subscriptions, chances are that you run under the wrong subscription, this will result in the following error: “The provided information does not map to an AD object id”.
You’ll need to select the proper subscription, just after the step: “Add Azure Account” use the following command: Select-AzureSubscription -SubscriptionId <subscription-id>

The remaining steps are obvious.


Select your Azure Subscription, provide a name to your resource group, select the ARM template inside your VS solution and the parameter file you want to use for this deployment.

Now you can include this step inside your continuous integration build or create a specific build for your infrastructure setup that you can trigger at will. 

How To: Use Azure Resource Manager in Visual Studio for creating Web Apps

Here we want to create our Azure Web App from within visual studio.  The goal is to be able to recreate the infrastructure at will and host a web app on it.  We do this by including an Azure Resource Group project inside our solution. This bundle the code of our website with the definition of the infrastructure that is needed to host the website. The Azure Resource Group project contains the description of your infrastructure inside an ARM(Azure Resource Manager) template and one or many parameter files. With this project you make sure that your configurations can be consistently repeated, tested, shared and promoted across different environments. This concept is called “infrastructure as code”.

First we need to add an Azure Resource Group project to our visual studio solution.

Right-click Add, new project.

If you didn’t have downloaded the Azure SDK, you first need to install it.

Choose “Get Microsoft Azure SDK for .Net” from the Cloud category and complete the installation steps.

Once the Azure SDK installed, reload your solution, right click on your solution, add, new project and select Cloud, “Azure Resource Group”, provide a name to your project and click OK.

Here we’ll setup a simple website.

 

Then we’ll need to fill in the parameters.  You can do this via the deploy wizard or directly inside the “Website.param.dev.json” file. The file is located under your ARM project in the folder Templates.

The siteName and hostingPlanName are up to you, you can fill in what you like or provide the name of an existing one.  For siteLocation you’ve to choose between one of the Azure datacenter regions, you find the list under: https://azure.microsoft.com/en-gb/regions/

Just Copy the name of the region that is appropriate to you.

 

Right click your ARM project and choose Deploy, New Deployment.

 Click on Deploy

 

Once completed you should see the newly created website in the portal.

 

Now you can publish your web app through Visual Studio.

Right Click your web project, choose publish and select “Microsoft Azure Web App”.

Setup, develop and deploy your ASP.NET MVC Umbraco website on Azure

 

To run Umbraco on Azure you can choose to use the build in Azure template.

pic1

 

For simple websites this could do the job but if you want to extend the portal with your own code or if you want to version control your site you’re better of starting with a blank MVC website.

 

Umbraco development lifecycle

Managing the lifecycle of an Umbraco application is somewhat challenging as Umbraco is one platform made out of several components (code/DB/content) and it’s not always clear what you need to deploy to promote content or features.  Especially deploying database changes can be cumbersome.  I personally chooses to avoid to have to stage DB changes by running all my environments (local/integration/production…) on a single DB hosted on Azure.

Because Umbraco already has a notion of staging you can for most cases work safely on the production database from your local machine without fearing to impact production.   Nevertheless when I need to make risky changes to my application or when I need to test a major Umbraco upgrade then I setup a clone of my production DB and do the development and testing on the clone.

For most of the changes my development cycle goes as follow:

  1. All my changes are made locally through the local umbraco portal (running on my local machine) or for Extensions through Visual Studio.
  2. When new content is added to the site I make sure these are included in my local Visual Studio project.
  3. I make sure that everything run nice locally.
  4. I check-in all the changes
  5. Publish the changes to Azure through the publish wizard.
  6. Test that everything runs fine in production.
  7. Promote the content once everything is tested

Umbraco first deployment

In this part I explain the steps to take to deploy the skeleton of an empty ASP.NET MVC Umbraco website.

Through the Azure portal:

  • Create a SQL server DB, don’t forget to note your password!
  • Create a new web app

Open VS: Start new project, Web, Asp.Net web application

Manage Nuget packages, umbracoCms

 

pic2

 

Click RUN in VisualStudio and launch the website locally.

Enter you Name, email & password and click Customize.

As Database type choose Microsoft SQL Azure.

You can find your connection details from the Azure portal (via old portal): select your DB, dashboard, Show Connection strings.
Use the ADO.NET connectionstring, copy each relevant part in the textboxes, for the server you need to provide the “server” part but without the leading “tcp”.
Click next.

Before publishing your website to Azure you first need to include files/folders to your project:

  • App_browsers
  • App_Plugins
  • umbraco
  • umbraco_client
  • config\splashes
  • css
  • js
  • media
  • scripts
    If you used a template also include the cshtml files under the Views folder.

 

pic3

Also set the build actions of the following web.config files to “none”.

– \umbraco\install\web.config

– \umbraco\Xslt\Web.config

 

pic4

Now publish the website: right-click your web project, choose publish.
Select your Azure Web App, the connectionstring should be retrieved by VS from your project.

 

If you followed everything in the exact order you should see your website running on Azure!

Learning Kodu links

Here a couple of links in dutch, french and English with info on how to learn Kodu to kids:

In het Nederlands:

http://www.bs-windekind.be/Computerhuisje/Afbeeldingen_downloads/Programmeren%20met%20KODU.pdf

Vidéos

Les1: Basis

https://www.youtube.com/watch?v=NpY6-qIJMUg

Les2: Uitgebreid

https://www.youtube.com/watch?v=qCFxZU-1dqo

Les3: Vijand

https://www.youtube.com/watch?v=ZRF7cgOQHwM

Les4: Padden

https://www.youtube.com/watch?v=qe8pEuvKKEo

Les5 : Race Game

https://www.youtube.com/watch?v=gwQG-BcWZhs

Getting started with Kodu Game Lab

http://www.cs.unb.ca/~wdu/gamecamp/kodu-manual-2010.pdf

Tutorial pdf:

http://resources.hkedcity.net/downloadResource.php?rid=1356004239&pid=1142185599

Videos

Basics :

https://www.youtube.com/watch?v=XXhJ1_ijE7k

Football :

https://www.youtube.com/watch?v=zRZp27K6dUc

Racing Game :

https://www.youtube.com/watch?v=eRJuEm0-vSA

Kodu en français

Installer : http://jdolle.simdif.com/programmation_jeux.html

Initiation :

http://edutechwiki.unige.ch/fr/Kodu

Vidéos

Leçon 1:

https://www.youtube.com/watch?v=xdxztxjJu98

Partie2 :

https://www.youtube.com/watch?v=gfePm7VpK4A

Partie3 :

https://www.youtube.com/watch?v=71GDXPp8Ez4

Learning Arduino for beginners

Through this link you can download my course for Arduino beginners. This course is one of the many I use to entertain kids during our coding-dojos sessions.  Yesterday it was the first time in Brussels we gave an Arduino session. We got kids going from 10 to 14 years. The session was a success. Despite the fact that none of them had any electronic or c-like programming background most of them managed to build one or several projects and present it to their colleagues.

Each project is intended to be built in two steps.  First the students can simply follow the schematic and can copy/paste the code they’ll find by following the provided link.  Then they need to complete a simple assignment consisting in extending what they build in the first step.  To complete the second step they need to make simple changes on the board and in the code.  Hints are provided to help them, so no real coding or electronic know-how is required.

The first project is simply making a led blink, the students should all start with this one.  Once the first assignment done they can choose between three different projects: a love-o-meter, music instrument and a lazer-tag.

Download link