Beispiel #1
0
 public void Install(
     IConfiguration configuration,
     CommandLineArguments commandLineArguments,
     string assemblyPath)
 {
     performOperation(
         configuration,
         commandLineArguments,
         assemblyPath,
         serviceInfo => ServiceControlHelper.IsServiceInstalled(serviceInfo.ServiceName),
         serviceInfo => string.Format("Service '{0}' is already installed.", serviceInfo.DisplayName),
         "There are  no serices to install.  Skipping install operation.",
         displayNames => string.Format("Installing services '{0}'...", displayNames),
         installer => installer.Install(),
         displayNames => string.Format("Services '{0}' successfully installed.", displayNames),
         services =>
     {
         foreach (var serviceInfo in services)
         {
             ServiceControlHelper.SetServiceRecoveryOptions(
                 serviceInfo.ServiceName,
                 serviceInfo.RecoveryOptions);
             if (commandLineArguments.AllowServiceToInteractWithDesktop)
             {
                 ServiceControlHelper.AllowServiceToInteractWithDesktop(serviceInfo.ServiceName);
             }
         }
     });
 }
Beispiel #2
0
        public void SetAndGetRecoveryOptions()
        {
            var expected = new ServiceRecoveryOptions();

            expected.FirstFailureAction       = ServiceRecoveryAction.RunAProgram;
            expected.SecondFailureAction      = ServiceRecoveryAction.RestartTheService;
            expected.SubsequentFailureActions = ServiceRecoveryAction.RestartTheComputer;
            expected.MinutesToRestartService  = 5;
            expected.DaysToResetFailAcount    = 2;
            expected.CommandToLaunchOnFailure = "Sample.exe";
            expected.RebootMessage            = "OMGWTFBBQ!!!!";

            var serviceInfo = configuration.Services[0];

            ServiceControlHelper.SetServiceRecoveryOptions(serviceInfo.ServiceName, expected);
            var actual = ServiceControlHelper.GetServiceRecoveryOptions(serviceInfo.ServiceName);

            Assert.AreEqual(expected, actual);
        }