InstallService() public method

public InstallService ( Action beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback ) : void
beforeInstall Action
afterInstall Action
beforeRollback Action
afterRollback Action
return void
        public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                            beforeInstall();
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                installer.InstallService(before, after);
            }
        }
        public void InstallService(InstallHostSettings settings, Action<InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                        {
                            beforeInstall(settings);
                            installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                            installer.ServiceProcessInstaller.Account = settings.Credentials.Account;

                            // Group Managed Service Account (gMSA) workaround per
                            // https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
                            if (settings.Credentials.Account == ServiceAccount.User &&
                                settings.Credentials.Username != null &&
                                settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture))
                            {
                                _log.InfoFormat("Installing as gMSA {0}.", settings.Credentials.Username);
                                installer.ServiceProcessInstaller.Password = null;
                                installer.ServiceProcessInstaller
                                    .GetType()
                                    .GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
                                    .SetValue(installer.ServiceProcessInstaller, true);
                            }
                            else
                            {
                                installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                            }
                        }
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                Action<InstallEventArgs> before2 = x =>
                    {
                        if (beforeRollback != null)
                            beforeRollback();
                    };

                Action<InstallEventArgs> after2 = x =>
                    {
                        if (afterRollback != null)
                            afterRollback();
                    };

                installer.InstallService(before, after, before2, after2);
            }
        }
        public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall(settings);
                        installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                        installer.ServiceProcessInstaller.Account  = settings.Credentials.Account;

                        bool gMSA = false;
                        // Group Managed Service Account (gMSA) workaround per
                        // https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
                        if (settings.Credentials.Account == ServiceAccount.User &&
                            settings.Credentials.Username != null &&
                            ((gMSA = settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture)) ||
                             string.Equals(settings.Credentials.Username, "NT SERVICE\\" + settings.ServiceName, StringComparison.InvariantCulture)))
                        {
                            _log.InfoFormat(gMSA ? "Installing as gMSA {0}." : "Installing as virtual service account", settings.Credentials.Username);
                            installer.ServiceProcessInstaller.Password = null;
                            installer.ServiceProcessInstaller
                            .GetType()
                            .GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
                            .SetValue(installer.ServiceProcessInstaller, true);
                        }
                        else
                        {
                            installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                        }
                    }
                };

                Action <InstallEventArgs> after = x =>
                {
                    if (afterInstall != null)
                    {
                        afterInstall();
                    }
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    if (beforeRollback != null)
                    {
                        beforeRollback();
                    }
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    if (afterRollback != null)
                    {
                        afterRollback();
                    }
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
        public void InstallService(InstallHostSettings settings, Action<InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                        {
                            beforeInstall(settings);
                            installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                            installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                            installer.ServiceProcessInstaller.Account = settings.Credentials.Account;
                        }
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                Action<InstallEventArgs> before2 = x =>
                    {
                        if (beforeRollback != null)
                            beforeRollback();
                    };

                Action<InstallEventArgs> after2 = x =>
                    {
                        if (afterRollback != null)
                            afterRollback();
                    };

                installer.InstallService(before, after, before2, after2);
            }
        }