A runtime for Umbraco - Part 4

September 25, 2015

This is an old archived post, content maybe out of date, links may be broken and layout may be broken.

It has been a while since I wrote about the Moriyama runtime for Umbraco - and that is because it has undergone quite a bit of development.

I want to talk about the concept of a Deployment Adapter - that hooks into Umbraco publish and unpublish events to add and remove content to a runtime.

The serialisation of content has already taken place. The deployment adapter is simply responsible for sending that content somewhere:

The definition of a deployment adapter looks like this:

using Moriyama.Runtime.Models;

namespace Moriyama.Runtime.Umbraco.Interfaces
    public enum DeploymentAction
        Deploy, Delete

    public interface IDeploymentAdapter
        void DeployContent(RuntimeContentModel model, DeploymentAction action);

At Moriyama we have several implementations:

  • FTP
  • Azure Blob storage
  • Amazon S3
  • GIT
  • REST
  • ZIP

We’ll take a look at the last one. The REST deployment adapter sends the serialised content to an endpoint and allows the receiving application to do what it needs with the content. In most cases this would just be to write the content to the local filesystem.

using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using Hotspots.Api.Domain;
using log4net;
using Moriyama.Runtime.Models;
using Moriyama.Runtime.Umbraco.Interfaces;
using Newtonsoft.Json;

namespace Hotspots.Cms.Classes.Deployment
    public class JamDeploymentAdapter : IDeploymentAdapter
        private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        private readonly IEnumerable _endpoints;
        public JamDeploymentAdapter(string config, string sitemapFile)
            _endpoints = JsonConvert.DeserializeObject<IEnumerable>(File.ReadAllText(config));

        public void DeployContent(RuntimeContentModel model, DeploymentAction action)
            Logger.Info("Got deployment request");

            if (model == null) return;
            foreach (var endpoint in _endpoints)
                    var url = endpoint.EndPoint + "Admin/CmsApi/Deploy";

                    Logger.Info("Deploy to URL: " + url);

                    using (var client = new WebClient())
                        var reqparm = new NameValueCollection
                            {"Key", authKey},
                            {"Json", JsonConvert.SerializeObject(model)},
                            {"Action", action.ToString().ToLower()}

                        Logger.Info("Sending to API: " + url);
                        Logger.Info(JsonConvert.SerializeObject(reqparm, Formatting.Indented));

                        var responsebytes = client.UploadValues(url, "POST", reqparm);
                        var responsebody = Encoding.UTF8.GetString(responsebytes);

It is a very simple yet powerful concept. Umbraco already has excellent support for writing Media into CDN (S3, Azure etc), and this is the equivalent for content.

Currently I’m excited about the opportunity to plug this into Umbraco as a service. This would allow you to use Umbraco as your CMS but push your content to any type of application - and the setup would take minutes.

Once you have all of your content in a Zip, GIT repo or cloud storage you can have a language specific implementation of the runtime over that store to consume your content on a mobile app, smart TV app or any other such emerging platform.

About the Author

About Darren

Leave a Comment

Comments are manually moderated and added once reviewed.