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.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);
            }
        }
        public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall();
                    }
                };

                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 UninstallService(HostSettings settings, Action beforeUninstall, Action afterUninstall)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeUninstall != null)
                    {
                        beforeUninstall();
                    }
                };

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

                installer.UninstallService(before, after);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }