scriptcs and using Azure Mobile Services from your scripts

Hopefully by now you have already heard about the sriptcs project, which allows you to write script based applications with C# and Nuget.

If not, have a look at the readme and the great introduction post by Scott Hanselman to get started.

Actually, just today, we have released v.0.4 of scriptcs! To celebrate that, let’s revisit one of our favorite topics – Azure Mobile Services – and how you can use it with scriptcs.

Extending scriptcs

Scriptcs provides a robust extensibility model, called script packs, where developers can provide their own extensions for script authors.

The extensions can be automatically discovered by scriptcs and accessed from script context using the node.js-like Require syntax.

You can find a master list of all script packs in the scriptcs wiki. Most importantly, script packs are supported both in regular script execution mode, as well as in the brand new scriptcs REPL (interactive shell) mode!

Azure Mobiles Services in scriptcs

Azure Mobile Services now provides a managed client library, to use in all .NET 4.5 projects, allowing you to access ZUMO easily from your .NET code.

However, the library uses async/await internally, which currently are not supported in the scriptcs (since they are not supported by Roslyn CTP), making it unusable in script context.

To remedy that, I have created an Azure Mobile Services script packs that solves all these problems – which is built around the REST API of Azure Mobile Services. This library, is currently synchronous (explicitly blocking), as the major point of script-based code is simplicity, and not dealing with Task continuations (and again, simple “await” is not yet doable).

To get started, install ScriptCs.AzureMobileServices from Nuget – and there are a few ways to do that.

1) using scriptcs direct installation

2) using scriptcs packages.config installation

3) using nuget.exe


You can now start writing a CSX script that is capable of accessing your Azure Mobile Services.

This grabs the Zumo script pack. You can now initialize an individual table, by passing in the name of your Zumo service and a Type to be used for serialization:

Note: due to the convention in Azure Mobile Services, the primary key column of your data object needs to be a nullable int with the name “id” (or marked with [JsonProperty(“id”)] or [DataMember(Name=”id”)]). Otherwise the serialization will fail.

If you require an AUTH key, you can pass that too:

The name of the table is inferred from the class you are using. If that’s different, you can pass that in as well:

That’s it!

Next you can start performing the typical CRUD operations on the table. Add and update operations will return the modified/created object.





Get all

And that is it! You can combine this functionality with other script packs, or simply use in your scripts to easily persist/retrieve data and information.

This script pack works both from regular CSX script, and from the new scriptcs REPL.

Here is a full example with a screenshot:

You can access the source of this project at Github.