/// <summary>
 /// Starts the IIS Express server.
 /// </summary>
 /// <param name="throwExceptionOnError">if set to <c>true</c> an exception, that occurs during launching the server process
 /// is thrown right after logging it to <see cref="System.Diagnostics.Debug"/> and <see cref="Console.Error"/>;
 /// otherwise the exception is catched and the method will return <c>false</c>.</param>
 /// <returns>
 /// A value indicating, whether the server start has succeeded.
 /// </returns>
 /// <exception cref="InvalidOperationException">Error launching server. Only thrown if <paramref name="throwExceptionOnError"/> was <c>true</c>.</exception>
 public bool StartServer(bool throwExceptionOnError = false)
 {
     _instance = IISExpress.Start(AppHostConfigFilePath, SiteName, AppPool, LauncherRelativePath);
     if (_instance is IISExpress.Process.Failed fail)
     {
         var errorText = new StringBuilder("Error starting IISExpress.")
                         .AppendLine()
                         .AppendLine($"Error: {fail.Exception.Message}")
                         .ToString();
         System.Diagnostics.Debug.WriteLine(errorText);
         Console.Error.WriteLine(errorText);
         return(!throwExceptionOnError ? false : throw new InvalidOperationException("Error launching server.", fail.Exception));
     }
     else if (_instance is IISExpress.Process.Started)
     {
         return(true);
     }
     else
     {
         if (throwExceptionOnError)
         {
             throw new InvalidOperationException("Unknown error launching server. StartServer() returned unexpected object.");
         }
         return(false);
     }
 }
Ejemplo n.º 2
0
 internal Started(IISExpress iisObject)
 {
     _iisObject = iisObject;
 }