internal override async Task StartAsync(Site site)
{
var name = site.Applications[0].ApplicationPoolName;
var pool = ApplicationPools.FirstOrDefault(item => item.Name == name);
var fileName =
Path.Combine(
Environment.GetFolderPath(
pool != null && pool.Enable32BitAppOnWin64
? Environment.SpecialFolder.ProgramFilesX86
: Environment.SpecialFolder.ProgramFiles),
"IIS Express",
"iisexpress.exe");
if (!File.Exists(fileName))
{
fileName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
"IIS Express",
"iisexpress.exe");
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = site.CommandLine,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
}
};
try
{
process.Start();
process.WaitForExit(5000);
if (process.HasExited)
{
throw new InvalidOperationException("process terminated");
}
site.State = ObjectState.Started;
}
catch (Exception ex)
{
throw new COMException(
string.Format("cannot start site: {0}, {1}", ex.Message, process.StandardOutput.ReadToEnd()));
}
finally
{
site.State = process.HasExited ? ObjectState.Stopped : ObjectState.Started;
}
}