Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin 3 posts 73 karma points
    Feb 14, 2018 @ 21:32
    Martin
    0

    Installing Umbraco programatically

    I'm trying to install Umbraco without using the visual interface, in order to increase my productivity.

    Currently my code looks like this:

    var installApiController = new InstallApiController();
    var installSetup = installApiController.GetSetup();
    
    var instructions = new Dictionary<string, JToken>();
    
    var databaseModel = new DatabaseModel
    {
        DatabaseType = DatabaseType.SqlCe
    };
    var userModel = new UserModel
    {
        Email = "[email protected]",
        Name = "My name",
        Password = "somepassword",
        SubscribeToNewsLetter = false
    };
    
    foreach (var step in installSetup.Steps)
    {
        if (step.StepType == typeof(DatabaseModel))
        {
            instructions.Add(step.Name, JToken.FromObject(databaseModel));
        }
        else if (step.StepType == typeof(UserModel))
        {
            instructions.Add(step.Name, JToken.FromObject(userModel));
        }
    }
    
    var installInstructions = new InstallInstructions
    {
        InstallId = installSetup.InstallId,
        Instructions = instructions
    };
    
    InstallProgressResultModel progressInfo = null;
    do
    {
        string stepName = "";
        if (progressInfo != null)
        {
            stepName = progressInfo.NextStep;
        }
    
        try
        {
            progressInfo = installApiController.PostPerformInstall(installInstructions);
        }
        catch (Exception e)
        {
            throw new Exception(stepName, e);
        }
    
    }
    while (progressInfo.ProcessComplete == false);
    

    The code fails at this line: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7.8/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs#L47, and I believe it's because the ApplicationContext isnt updated for each of the installation steps (e.g. not updated after the database is created).

    Is it possible to update the ApplicationContext manually after each step in the installation progress, or do I have to trigger all installation steps in separate HTTP requests?

Please Sign in or register to post replies

Write your reply to:

Draft