示例#1
0
        private void PowershellDescriptionCommand(string computer, InstallSettings settings)
        {
            //Create Settings
            PowershellSettings powerSettings = new PowershellSettings()
            {
                FormatOutput       = true,
                LogOutput          = true,
                OutputToAppConsole = settings.OutputToAppConsole
            }
            .WithArguments(args =>
            {
                args.AppendQuoted(settings.ServiceName);
                args.AppendQuoted(settings.Description);
            });



            //Remote Connection
            if (!String.IsNullOrEmpty(computer))
            {
                powerSettings.ComputerName = computer;
            }

            this.SetWorkingDirectory(powerSettings);



            //Run Command
            _PowershellRunner.Start("& \"sc.exe\" description", powerSettings);
        }
示例#2
0
        /// <summary>
        /// Assemble the args to pass to sc.exe
        /// </summary>
        /// <param name="computer"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public ProcessArgumentBuilder CreateInstallArguments(string computer, InstallSettings settings)
        {
            ProcessArgumentBuilder args = new ProcessArgumentBuilder();

            string pathArgs = "";

            if (settings.Arguments != null)
            {
                pathArgs = settings.Arguments.Render();
            }

            this.SetFilePath(computer, settings);


            if (!String.IsNullOrEmpty(settings.ServiceName))
            {
                args.AppendQuoted(settings.ServiceName);
            }

            if (String.IsNullOrEmpty(pathArgs))
            {
                args.AppendSwitchQuoted("binPath=", " ", settings.ExecutablePath.FullPath);
            }
            else
            {
                args.AppendSwitch("binPath=", " ", "'" + @"\""" + settings.ExecutablePath.FullPath + @"\"" " + pathArgs.Replace("\"", "\\\"") + "'");
            }


            if (!String.IsNullOrEmpty(settings.DisplayName))
            {
                args.AppendSwitchQuoted("DisplayName=", " ", settings.DisplayName);
            }

            if (!String.IsNullOrEmpty(settings.Dependencies))
            {
                args.AppendSwitchQuoted("depend=", " ", settings.Dependencies);
            }

            if (!String.IsNullOrEmpty(settings.StartMode))
            {
                args.AppendSwitchQuoted("start=", " ", settings.StartMode);
            }

            if (!String.IsNullOrEmpty(settings.Username))
            {
                args.AppendSwitchQuoted("obj=", " ", settings.Username);
            }

            if (!String.IsNullOrEmpty(settings.Password))
            {
                args.AppendSwitchQuotedSecret("password="******" ", settings.Password);
            }

            return(args);
        }
示例#3
0
        /// <summary>
        /// Specifies a path to the service binary file.
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="path">The path to the service binary file.</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings SetExecutablePath(this InstallSettings settings, FilePath path)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.ExecutablePath = path;
            return(settings);
        }
示例#4
0
        /// <summary>
        /// Specifies a friendly name that can be used by user interface programs to identify the service.
        /// </summary>
        /// <param name="settings">The process settings.</param>
        /// <param name="name">The friendly name of the service</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings SetDisplayName(this InstallSettings settings, string name)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.DisplayName = name;
            return(settings);
        }
示例#5
0
        /// <summary>
        /// Gets or sets the credentials to use when connecting
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="password">The password to connect with.</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings UsePassword(this InstallSettings settings, string password)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Password = password;
            return(settings);
        }
示例#6
0
        /// <summary>
        /// Gets or sets the credentials to use when connecting
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="username">The username to connect with.</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings UseUsername(this InstallSettings settings, string username)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Username = username;
            return(settings);
        }
示例#7
0
        /// <summary>
        /// Specifies a description for the specified service. If no string is specified, the description of the service is not modified. There is no limit to the number of characters in the service description.
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="description">The description of the service</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings SetDescription(this InstallSettings settings, string description)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Description = description;
            return(settings);
        }
示例#8
0
        /// <summary>
        /// Specifies the names of services or groups that must start before this service starts. The names are separated by forward slashes (/).
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="dependencies">The names of services or groups that must start before this service starts</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings SetDependencies(this InstallSettings settings, string dependencies)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Dependencies = dependencies;
            return(settings);
        }
示例#9
0
        /// <summary>
        /// Specifies the start type for the service. The default setting is start= demand.
        /// </summary>
        /// <param name="settings">The process settings.</param>
        /// <param name="mode">The start type for the service</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings SetStartMode(this InstallSettings settings, string mode)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.StartMode = mode;
            return(settings);
        }
示例#10
0
 private void SetFilePath(string computer, InstallSettings install)
 {
     if (String.IsNullOrEmpty(computer))
     {
         install.ExecutablePath = install.ExecutablePath.MakeAbsolute(_Environment);
     }
     else
     {
         install.ExecutablePath = install.ExecutablePath.MakeAbsolute(new DirectoryPath("C:/"));
     }
 }
示例#11
0
        /// <summary>
        /// Sets the arguments to use during installation
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="arguments">The arguments to append.</param>
        /// <returns>The same <see cref="InstallSettings"/> instance so that multiple calls can be chained.</returns>
        public static InstallSettings WithArguments(this InstallSettings settings, Action <ProcessArgumentBuilder> arguments)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.Arguments == null)
            {
                settings.Arguments = new ProcessArgumentBuilder();
            }

            arguments(settings.Arguments);
            return(settings);
        }
示例#12
0
        private void PowershellCreateCommand(string computer, InstallSettings settings)
        {
            //Get Arguments
            var args = CreateInstallArguments(computer, settings);


            //Build Script
            string script = "";

            if (!this.ServiceExists(settings.ServiceName, computer))
            {
                //Create
                script = "& \"sc.exe\" create";
            }
            else
            {
                //Config
                script = "& \"sc.exe\" config";
            }



            //Create Settings
            PowershellSettings powerSettings = new PowershellSettings()
            {
                FormatOutput       = true,
                LogOutput          = true,
                OutputToAppConsole = settings.OutputToAppConsole,

                Arguments = args
            };

            //Remote Connection
            if (!String.IsNullOrEmpty(computer))
            {
                powerSettings.ComputerName = computer;
            }

            this.SetWorkingDirectory(powerSettings);



            //Run Powershell
            _PowershellRunner.Start(script, powerSettings);
        }
示例#13
0
        /// <summary>
        /// Installs a service on a computer
        /// </summary>
        /// <param name="computer">The computer on which the service resides.</param>
        /// <param name="settings">The settings to use when installing the service.</param>
        /// <returns>If the service was installed.</returns>
        /// <inheritdoc />
        public void Install(string computer, InstallSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (String.IsNullOrEmpty(settings.ServiceName))
            {
                throw new ArgumentNullException("settings.ServiceName");
            }
            if (settings.ExecutablePath == null)
            {
                throw new ArgumentNullException("settings.ExecutablePath");
            }



            this.PowershellCreateCommand(computer, settings);

            if (!String.IsNullOrEmpty(settings.Description))
            {
                this.PowershellDescriptionCommand(computer, settings);
            }
        }
示例#14
0
        //Helpers
        private void PowershellCreateCommand(string computer, InstallSettings settings)
        {
            //Get Arguments
            ProcessArgumentBuilder args = new ProcessArgumentBuilder();

            string pathArgs = settings.Arguments.Render();

            this.SetFilePath(computer, settings);



            if (!String.IsNullOrEmpty(settings.ServiceName))
            {
                args.AppendQuoted(settings.ServiceName);
            }

            if (string.IsNullOrEmpty(pathArgs))
            {
                args.AppendQuoted("binPath", settings.ExecutablePath.FullPath);
            }
            else
            {
                args.AppendQuoted("binPath", "\\\"" + settings.ExecutablePath.FullPath + "\\\" " + pathArgs.Replace("\"", "\\\""));
            }



            if (!String.IsNullOrEmpty(settings.DisplayName))
            {
                args.AppendQuoted("DisplayName", settings.DisplayName);
            }

            if (!String.IsNullOrEmpty(settings.Dependencies))
            {
                args.AppendQuoted("depend", settings.Dependencies);
            }

            if (!String.IsNullOrEmpty(settings.StartMode))
            {
                args.AppendQuoted("start", settings.Dependencies);
            }

            if (!String.IsNullOrEmpty(settings.Username))
            {
                args.AppendQuoted("obj", settings.Username);
            }

            if (!String.IsNullOrEmpty(settings.Password))
            {
                args.AppendQuotedSecret("password", settings.Password);
            }



            //Build Script
            string script = "";

            if (!this.ServiceExists(settings.ServiceName, computer))
            {
                //Create
                script = "& \"sc.exe\" create";
            }
            else
            {
                //Config
                script = "& \"sc.exe\" config";
            }



            //Create Settings
            PowershellSettings powerSettings = new PowershellSettings()
            {
                FormatOutput = true,
                LogOutput    = true,

                Arguments = args
            };

            //Remote Connection
            if (!String.IsNullOrEmpty(computer))
            {
                powerSettings.ComputerName = computer;
            }

            this.SetWorkingDirectory(powerSettings);



            //Run Powershell
            _PowershellRunner.Start(script, powerSettings);
        }
示例#15
0
 /// <summary>
 /// Installs a service on a computer
 /// </summary>
 /// <param name="settings">The settings to use when installing the service.</param>
 /// <returns>If the service was installed.</returns>
 public void Install(InstallSettings settings)
 {
     this.Install("", settings);
 }
示例#16
0
 public static void InstallService(this ICakeContext context, string computer, InstallSettings settings)
 {
     context.CreateManager().Install(computer, settings);
 }
示例#17
0
 public static void InstallService(this ICakeContext context, InstallSettings settings)
 {
     context.CreateManager().Install(settings);
 }