Reputation: 5126
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. 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' i.e. is > than 65535, is less than 0, null or blank, or is currently in use by another site. This is done in the OnBeforeInstall method.
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. 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.
Upvotes: 0
Views: 777
Reputation: 20790
This looks like a Visual Studio setup project, and you can't do that validation with a VS setup project.
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. 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. You cannot do this with VS setup projects.
Upvotes: 1