Exemplo n.º 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);
             }
         }
     });
 }
Exemplo n.º 2
0
        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."));
        }
Exemplo n.º 3
0
 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 => { });
 }