Пример #1
0
 /// <summary>
 /// Changes the service status.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="status">The status.</param>
 /// <param name="changeStatus">The change status.</param>
 public static void ChangeServiceStatus(ServiceController controller, ServiceControllerStatus status, Action changeStatus)
 {
     if (controller.Status == status)
     {
         ServiceLog.DebugFormat(controller.ServiceName + " status is good: " + Enum.GetName(typeof(ServiceControllerStatus), status));
     }
     else
     {
         ServiceLog.DebugFormat(controller.ServiceName + " status is NOT " + Enum.GetName(typeof(ServiceControllerStatus), status) + ". Changing status...");
         changeStatus();
         var timeout = TimeSpan.FromSeconds(3.0);
         controller.WaitForStatus(status, timeout);
         if (controller.Status != status)
         {
             throw new InvalidOperationException("Unable to change " + controller.ServiceName + " status to " + Enum.GetName(typeof(ServiceControllerStatus), status));
         }
         ServiceLog.DebugFormat(controller.ServiceName + " status changed successfully.");
     }
 }
Пример #2
0
 private static void InstallMsmqIfNecessary()
 {
     ServiceLog.DebugFormat("Checking if MSMQ is installed.");
     if (IsMsmqInstalled())
     {
         ServiceLog.DebugFormat("MSMQ is installed.");
         ServiceLog.DebugFormat("Checking that only needed components are active.");
         if (IsInstallationGood())
         {
             ServiceLog.DebugFormat("Installation is good.");
         }
         else
         {
             ServiceLog.DebugFormat("Installation isn't good.");
             ServiceLog.DebugFormat("Going to re-install MSMQ. A reboot may be required.");
             PerformFunctionDependingOnOS(() => Process.Start("OCSETUP", "MSMQ-Container;MSMQ-Server /passive /uninstall"), () => Process.Start("OCSETUP", "MSMQ-Server /passive /uninstall"), new Func <Process>(MsmqInstallation.InstallMsmqOnXpOrServer2003));
             ServiceLog.DebugFormat("Installation of MSMQ successful.");
         }
     }
     else
     {
         ServiceLog.DebugFormat("MSMQ is not installed. Going to install.");
         PerformFunctionDependingOnOS(() => Process.Start("OCSETUP", "MSMQ-Container;MSMQ-Server /passive"), () => Process.Start("OCSETUP", "MSMQ-Server /passive"), new Func <Process>(MsmqInstallation.InstallMsmqOnXpOrServer2003));
         ServiceLog.DebugFormat("Installation of MSMQ successful.");
     }
 }