以编程方式安装Umbraco

时间:2018-02-24 07:58:06

标签: umbraco umbraco7

我试图在不使用可视界面的情况下安装Umbraco,以提高我的工作效率。

目前我的代码如下:

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 = "my@email.com",
    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);

代码在此行失败:https://github.com/umbraco/Umbraco-CMS/blob/dev-v7.8/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs#L47,我相信它是因为ApplicationContext没有为每个安装步骤更新(例如,在创建数据库后没有更新)。

是否可以在安装进度的每一步之后手动更新ApplicationContext,还是必须在单独的HTTP请求中触发所有安装步骤?

如果我在单独的HTTP请求中运行每个步骤,代码就可以工作。

0 个答案:

没有答案