简体   繁体   English

您如何让安装程序暂停/允许验证?

[英]How do you get an installer to pause / allow validation?

I'm creating an installer that currently creates a new website in IIS, creates an application pool and then assigns this pool to the website. 我正在创建一个安装程序,该安装程序当前在IIS中创建一个新网站,创建一个应用程序池,然后将该池分配给该网站。 I created a custom action to do this and this works fine. 我创建了一个自定义操作来执行此操作,并且效果很好。

Now I'm trying to build some checks into the user inputs (site name, target directory, port number etc.). 现在,我正在尝试对用户输入(站点名称,目标目录,端口号等)进行一些检查。 This is where I come unstuck. 这就是我解脱的地方。 I'm currently trying to display a message box to the user if the port number isn't 'valid' ie is > than 65535, is less than 0, null or blank, or is currently in use by another site. 如果端口号不是“有效”,即大于65535,小于0,为空或空白,或者当前正在由其他站点使用,则我目前正在尝试向用户显示消息框。 This is done in the OnBeforeInstall method. 这是在OnBeforeInstall方法中完成的。

At the point of the user getting the message and clicking 'Ok' I want the installer to stop and allow the user to enter another port number. 在用户收到消息并单击“确定”时,我希望安装程序停止并允许用户输入另一个端口号。 To clarify, I don't want the installer to rollback or close, just allow the user to enter a new port number and then try and click 'next'. 为了澄清,我不希望安装程序回滚或关闭,只允许用户输入新的端口号,然后尝试单击“下一步”。 I also run other checks in the OnBeforeInstall method such as checking to see if the website already exists. 我还在OnBeforeInstall方法中运行其他检查,例如检查网站是否已经存在。 I don't want to run these checks until the basic inputs from the user have been validated. 在验证来自用户的基本输入之前,我不希望运行这些检查。

Here's my code thus far: 到目前为止,这是我的代码:

    protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
    {
        base.OnBeforeInstall(savedState);

        string msg = "The port: " + targetPort + " is invalid.";
        string caption = "Invalid Port Supplied";
        MessageBoxButtons buttons = MessageBoxButtons.OK;
        DialogResult result = DialogResult.None;

        int UserPort;
        Int32.TryParse(targetPort, out UserPort);

        if (UserPort <= 0 || string.IsNullOrEmpty(targetPort))
        {
           result = MessageBox.Show(msg, caption, buttons);
        }
        else if (UserPort > 65535)
        {
            result = MessageBox.Show(msg + " Please enter a port number less than 65535.", caption, buttons);
        }
        else if (!IsValidPort())
        {
            result = MessageBox.Show(msg + " The port is already in use.", caption, buttons);
        }

        if (result == DialogResult.OK)
        {
            //Pause installer
        }

        ...more checks...

    }

Any help would be appreciated. 任何帮助,将不胜感激。

This looks like a Visual Studio setup project, and you can't do that validation with a VS setup project. 这看起来像一个Visual Studio安装项目,您无法使用VS安装项目进行验证。

Despite its name OnBeforeInstall runs after the install has completed and the files are installed, so the dialogs that were used have come and gone and you cannot access the values. 尽管其名称为OnBeforeInstall,它在安装完成并安装文件后运行,所以所使用的对话框已经过去了,您无法访问这些值。 Display a message from that code and see where it is relative to the progress bar. 显示来自该代码的消息,并查看其相对于进度条的位置。 You may even find that the web site has already been created. 您甚至可能发现该网站已经创建。

The way validation is done in MSI installs is that custom action code is triggered by buttons in the dialog, so that if the values are incorrect the Next button will be disabled and a message displayed. 在MSI安装中完成验证的方式是,自定义操作代码由对话框中的按钮触发,因此,如果值不正确,则将禁用“下一步”按钮,并显示一条消息。 You cannot do this with VS setup projects. 您无法使用VS安装项目执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM