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); } } }); }
public override void Execute( IConfiguration configuration, CommandLineArguments commandLineArguments) { ThrowHelper.ThrowArgumentNullIfNull(configuration, "configuration"); ThrowHelper.ThrowArgumentNullIfNull(commandLineArguments, "commandLineArguments"); log.Debug(m => m("Executing run command...")); var serviceLocator = ServiceLocator.Current; if (serviceLocator == null) { throw new InvalidOperationException("An error occured while getting service locator."); } var servicesToRun = new List <ServiceBase>(); foreach (var serviceInfo in configuration.Services) { if (!ServiceControlHelper.IsServiceInstalled(serviceInfo.ServiceName)) { log.InfoFormat("Service '{0}' is not yet installed.", serviceInfo.DisplayName); continue; } var serviceInstance = serviceLocator.GetInstance <IServiceInstance>(serviceInfo.ServiceName); if (serviceInstance == null) { throw new InvalidOperationException( string.Format("An error located while resolving service instance '{0}'. ", serviceInfo.ServiceName)); } servicesToRun.Add(new WindowsServiceBase( serviceInfo.ServiceName, serviceInstance)); } try { log.Info("Starting service process..."); ServiceBase.Run(servicesToRun.ToArray()); } catch (Exception e) { log.Error(e); } log.Debug(m => m("Done executing run command.")); }
public void Uninstall( IConfiguration configuration, CommandLineArguments commandLineArguments, string assemblyPath) { performOperation( configuration, commandLineArguments, assemblyPath, serviceInfo => !ServiceControlHelper.IsServiceInstalled(serviceInfo.ServiceName), serviceInfo => string.Format("Service '{0}' is not yet installed.", serviceInfo.DisplayName), "There are no serices to uninstall. Skipping uninstall operation.", displayNames => string.Format("Uninstalling services '{0}'...", displayNames), installer => installer.Uninstall(), displayNames => string.Format("Services '{0}' successfully uninstalled.", displayNames), services => { }); }
// If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { PropertyDescriptorCollection propertyDescriptorCol = context.DataContext.GetProperties(); foreach (PropertyDescriptor pd in propertyDescriptorCol) { if (string.Equals(pd.Name, Singleton <Constants> .UniqueInstance.ServiceVariableName)) { string[] services = (string[])pd.GetValue(context.DataContext); foreach (string service in services) { ServiceControlHelper.StartService(service); } } } // Obtain the runtime value of the Text input argument string text = context.GetValue(this.Text); }
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); }