コード例 #1
0
        /// <summary>
        /// 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="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings UsePassword(this TopshelfSettings settings, string password)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Password = password;
            return(settings);
        }
コード例 #2
0
        /// <summary>
        /// Sets if the service with run with the local service account
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="localService">Run with the local service account</param>
        /// <returns>The same <see cref="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings UseLocalService(this TopshelfSettings settings, bool localService = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.LocalService = localService;
            return(settings);
        }
コード例 #3
0
        /// <summary>
        /// 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="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings UseUsername(this TopshelfSettings settings, string username)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Username = username;
            return(settings);
        }
コード例 #4
0
        /// <summary>
        /// Specifies the time in milliseconds to wait for the Topshelf executable
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="timeout">The time in milliseconds.</param>
        /// <returns>The same <see cref="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings SetServiceName(this TopshelfSettings settings, int timeout)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Timeout = timeout;
            return(settings);
        }
コード例 #5
0
        /// <summary>
        /// Sets if the service with run with the network service account
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="networkService">Run with the network service account</param>
        /// <returns>The same <see cref="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings UseNetworkService(this TopshelfSettings settings, bool networkService = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.NetworkService = networkService;
            return(settings);
        }
コード例 #6
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="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings SetDescription(this TopshelfSettings settings, string description)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Description = description;
            return(settings);
        }
コード例 #7
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="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings SetDisplayname(this TopshelfSettings settings, string name)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.DisplayName = name;
            return(settings);
        }
コード例 #8
0
        /// <summary>
        /// Sets if the service should start automatically (delayed)
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="delayed">if the service should start delayed</param>
        /// <returns>The same <see cref="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings SetDelayed(this TopshelfSettings settings, bool delayed = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Delayed = delayed;
            return(settings);
        }
コード例 #9
0
        /// <summary>
        /// Sets if the service should automatically start when windows loads
        /// </summary>
        /// <param name="settings">The installation settings.</param>
        /// <param name="autostart">if the service should automatically start when windows loads</param>
        /// <returns>The same <see cref="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings SetAutostart(this TopshelfSettings settings, bool autostart = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Autostart = autostart;
            return(settings);
        }
コード例 #10
0
        private static ProcessArgumentBuilder UseExistingArgumentsIfSupplied(TopshelfSettings settings)
        {
            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

            if ((settings != null) && (settings.Arguments != null))
            {
                builder = settings.Arguments;
            }

            return(builder);
        }
コード例 #11
0
        /// <summary>
        /// Installs a Topshelf windows service
        /// </summary>
        /// <param name="filePath">The file path of the Topshelf executable to install.</param>
        /// <param name="settings">The <see cref="TopshelfSettings"/> used to install the service.</param>
        public void InstallService(FilePath filePath, TopshelfSettings settings = null)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            this.ExecuteProcess(filePath, this.GetInstallArguments(settings), settings.Timeout);

            _Log.Verbose("Topshelf service installed.");
        }
コード例 #12
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="TopshelfSettings"/> instance so that multiple calls can be chained.</returns>
        public static TopshelfSettings WithArguments(this TopshelfSettings settings, Action <ProcessArgumentBuilder> arguments)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

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

            arguments(settings.Arguments);
            return(settings);
        }
コード例 #13
0
        /// <summary>
        /// Installs a Topshelf windows service
        /// </summary>
        /// <param name="filePath">The file path of the Topshelf executable to install.</param>
        /// <param name="settings">The <see cref="TopshelfSettings"/> used to install the service.</param>
        public void InstallService(FilePath filePath, TopshelfSettings settings = null)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            int timeout = TopshelfManager.DefaultTimeoutMs;

            if (settings != null)
            {
                timeout = settings.Timeout;
            }

            this.ExecuteProcess(filePath, settings.GetArguments(), timeout);

            _Log.Verbose("Topshelf service installed.");
        }
コード例 #14
0
        public static ProcessArgumentBuilder GetArguments(this TopshelfSettings settings)
        {
            var builder = UseExistingArgumentsIfSupplied(settings);

            builder.AppendInstall();

            if (settings != null)
            {
                builder.AppendUserName(settings)
                .AppendPassword(settings)
                .AppendInstance(settings)
                .AppendStartupMode(settings)
                .AppendDisabled(settings)
                .AppendDelayed(settings)
                .AppendLocalSystem(settings)
                .AppendLocalService(settings)
                .AppendNetworkService(settings)
                .AppendServiceName(settings)
                .AppendDescription(settings)
                .AppendDisplayname(settings);
            }

            return(builder);
        }
コード例 #15
0
 public static void InstallTopshelf(this ICakeContext context, FilePath filePath, TopshelfSettings settings)
 {
     context.CreateManager().InstallService(filePath, settings);
 }
コード例 #16
0
 public static void InstallTopshelf(this ICakeContext context, FilePath filePath, TopshelfSettings settings)
 {
     context.CreateManager().InstallService(filePath, settings);
 }
コード例 #17
0
        private static ProcessArgumentBuilder AppendStartupMode(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            builder.Append(settings.Autostart
                ? new TextArgument("--autostart")
                : new TextArgument("--manual"));

            return(builder);
        }
コード例 #18
0
        private ProcessArgumentBuilder GetInstallArguments(TopshelfSettings settings)
        {
            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

            if ((settings != null) && (settings.Arguments != null))
            {
                builder = settings.Arguments;
            }

            builder.Append(new TextArgument("install"));



            if (settings != null)
            {
                if (!string.IsNullOrWhiteSpace(settings.Username))
                {
                    builder.Append(new TextArgument("-username"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.Username)));
                }

                if (!string.IsNullOrWhiteSpace(settings.Password))
                {
                    builder.Append(new TextArgument("-password"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.Password)));
                }

                if (!string.IsNullOrWhiteSpace(settings.Instance))
                {
                    builder.Append(new TextArgument("-instance"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.Instance)));
                }

                builder.Append(settings.Autostart
                            ? new TextArgument("--autostart")
                            : new TextArgument("--manual"));

                if (settings.Disabled)
                {
                    builder.Append(new TextArgument("--disabled"));
                }

                if (settings.Delayed)
                {
                    builder.Append(new TextArgument("--delayed"));
                }

                if (settings.LocalSystem)
                {
                    builder.Append(new TextArgument("--localsystem"));
                }

                if (settings.LocalService)
                {
                    builder.Append(new TextArgument("--localservice"));
                }

                if (settings.NetworkService)
                {
                    builder.Append(new TextArgument("--networkservice"));
                }

                if (!string.IsNullOrWhiteSpace(settings.ServiceName))
                {
                    builder.Append(new TextArgument("--servicename"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
                }

                if (!string.IsNullOrWhiteSpace(settings.Description))
                {
                    builder.Append(new TextArgument("--description"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
                }

                if (!string.IsNullOrWhiteSpace(settings.DisplayName))
                {
                    builder.Append(new TextArgument("--displayname"));
                    builder.Append(new QuotedArgument(new TextArgument(settings.DisplayName)));
                }
            }

            return(builder);
        }
コード例 #19
0
        private static ProcessArgumentBuilder AppendDescription(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.Description))
            {
                builder.Append(new TextArgument("-description"));
                builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
            }

            return(builder);
        }
コード例 #20
0
        private static ProcessArgumentBuilder AppendPassword(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.Password))
            {
                builder.Append(new TextArgument("-password"));
                builder.Append(new QuotedArgument(new TextArgument(settings.Password)));
            }

            return(builder);
        }
コード例 #21
0
        private static ProcessArgumentBuilder AppendServiceName(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.ServiceName))
            {
                builder.Append(new TextArgument("-servicename"));
                builder.Append(new QuotedArgument(new TextArgument(settings.ServiceName)));
            }

            return(builder);
        }
コード例 #22
0
        private static ProcessArgumentBuilder AppendLocalService(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (settings.LocalService)
            {
                builder.Append(new TextArgument("--localservice"));
            }

            return(builder);
        }
コード例 #23
0
            /// <summary>
            /// Installs a Topshelf windows service
            /// </summary>
            /// <param name="filePath">The file path of the Topshelf executable to install.</param>
            /// <param name="settings">The <see cref="TopshelfSettings"/> used to install the service.</param>
            public void InstallService(FilePath filePath, TopshelfSettings settings = null)
            {
                if (filePath == null)
                {
                    throw new ArgumentNullException("filePath");
                }

                this.ExecuteProcess(filePath, this.GetInstallArguments(settings), settings.Timeout);

                _Log.Verbose("Topshelf service installed.");
            }
コード例 #24
0
            private ProcessArgumentBuilder GetInstallArguments(TopshelfSettings settings)
            {
                ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

                if ((settings != null) && (settings.Arguments != null))
                {
                    builder = settings.Arguments;
                }

                builder.Append(new TextArgument("install"));



                if (settings != null)
                {
                    if (!string.IsNullOrWhiteSpace(settings.Username))
                    {
                        builder.Append(new TextArgument("-username"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.Username)));
                    }

                    if (!string.IsNullOrWhiteSpace(settings.Password))
                    {
                        builder.Append(new TextArgument("-password"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.Password)));
                    }

                    if (!string.IsNullOrWhiteSpace(settings.Instance))
                    {
                        builder.Append(new TextArgument("-instance"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.Instance)));
                    }

                    builder.Append(settings.Autostart
                            ? new TextArgument("--autostart")
                            : new TextArgument("--manual"));

                    if (settings.Disabled)
                        builder.Append(new TextArgument("--disabled"));

                    if (settings.Delayed)
                        builder.Append(new TextArgument("--delayed"));

                    if (settings.LocalSystem)
                        builder.Append(new TextArgument("--localsystem"));

                    if (settings.LocalService)
                        builder.Append(new TextArgument("--localservice"));

                    if (settings.NetworkService)
                        builder.Append(new TextArgument("--networkservice"));

                    if (!string.IsNullOrWhiteSpace(settings.ServiceName))
                    {
                        builder.Append(new TextArgument("--servicename"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
                    }

                    if (!string.IsNullOrWhiteSpace(settings.Description))
                    {
                        builder.Append(new TextArgument("--description"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
                    }

                    if (!string.IsNullOrWhiteSpace(settings.DisplayName))
                    {
                        builder.Append(new TextArgument("--displayname"));
                        builder.Append(new QuotedArgument(new TextArgument(settings.DisplayName)));
                    }
                }

                return builder;
            }
コード例 #25
0
        private static ProcessArgumentBuilder AppendDisabled(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (settings.Disabled)
            {
                builder.Append(new TextArgument("--disabled"));
            }

            return(builder);
        }