From efa7af35a13d62b070db86089eeedbac0c790209 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Tue, 16 Jul 2013 17:45:52 +0300 Subject: [PATCH] Installation of scheduler service added into enterprise server installer --- .../Sources/Setup.SchedulerService/Config.wxi | 2 +- .../Actions/EntServerActionManager.cs | 99 ++++++++++++++++++- .../WebsitePanel.Setup/Common/Global.cs | 4 +- .../Wizard/UninstallPage.cs | 9 +- .../WebsitePanel.SchedulerService.csproj | 2 +- WebsitePanel/build.xml | 21 +--- 6 files changed, 112 insertions(+), 25 deletions(-) diff --git a/WebsitePanel.Installer/Sources/Setup.SchedulerService/Config.wxi b/WebsitePanel.Installer/Sources/Setup.SchedulerService/Config.wxi index 8265cb6f..9883f33b 100644 --- a/WebsitePanel.Installer/Sources/Setup.SchedulerService/Config.wxi +++ b/WebsitePanel.Installer/Sources/Setup.SchedulerService/Config.wxi @@ -1,6 +1,6 @@ - + diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Actions/EntServerActionManager.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Actions/EntServerActionManager.cs index 51032a44..b0e7673a 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Actions/EntServerActionManager.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Actions/EntServerActionManager.cs @@ -100,7 +100,75 @@ namespace WebsitePanel.Setup.Actions throw; } } - } + } + + public class InstallSchedulerServiceAction : Action, IInstallAction, IUninstallAction + { + public const string LogStartInstallMessage = "Installing Scheduler Windows Service..."; + public const string LogStartUninstallMessage = "Uninstalling Scheduler Windows Service..."; + + void IInstallAction.Run(SetupVariables vars) + { + try + { + + Begin(LogStartInstallMessage); + + Log.WriteStart(LogStartInstallMessage); + Log.WriteInfo(String.Format("Scheduler Service Name: \"{0}\"", Global.Parameters.SchedulerServiceName)); + + if (ServiceController.GetServices().Any(s => s.DisplayName.Equals(Global.Parameters.SchedulerServiceName, StringComparison.CurrentCultureIgnoreCase))) + { + Log.WriteEnd("Scheduler Service Already Installed."); + InstallLog.AppendLine(String.Format("- Scheduler Service \"{0}\" Already Installed.", Global.Parameters.SchedulerServiceName)); + return; + } + + ManagedInstallerClass.InstallHelper(new[] { "/i", Path.Combine(vars.InstallationFolder, "bin", Global.Parameters.SchedulerServiceFileName) }); + Utils.StartService(Global.Parameters.SchedulerServiceName); + } + catch (Exception ex) + { + UninstallService(vars); + + if (Utils.IsThreadAbortException(ex)) + { + return; + } + + Log.WriteError("Installing scheduler service error.", ex); + throw; + } + } + + void IUninstallAction.Run(SetupVariables vars) + { + try + { + Log.WriteStart(LogStartUninstallMessage); + UninstallService(vars); + Log.WriteEnd("Scheduler Service Uninstalled."); + } + catch (Exception ex) + { + if (Utils.IsThreadAbortException(ex)) + { + return; + } + + Log.WriteError("Uninstalling scheduler service error.", ex); + throw; + } + } + + private void UninstallService(SetupVariables vars) + { + if (ServiceController.GetServices().Any(s => s.ServiceName.Equals(Global.Parameters.SchedulerServiceName, StringComparison.CurrentCultureIgnoreCase))) + { + ManagedInstallerClass.InstallHelper(new[] { "/u", Path.Combine(vars.InstallationFolder, "bin", Global.Parameters.SchedulerServiceFileName) }); + } + } + } public class CreateDatabaseAction : Action, IInstallAction, IUninstallAction { @@ -350,6 +418,31 @@ namespace WebsitePanel.Setup.Actions Log.WriteEnd(String.Format("Updated {0} file", vars.ConfigurationFile)); } } + + public class SaveSchedulerServiceConnectionStringAction : Action, IInstallAction + { + void IInstallAction.Run(SetupVariables vars) + { + Log.WriteStart(string.Format("Updating {0}.config file (connection string)", Global.Parameters.SchedulerServiceFileName)); + var file = Path.Combine(vars.InstallationFolder, "bin", string.Format("{0}.config", Global.Parameters.SchedulerServiceFileName)); + string content; + + using (var reader = new StreamReader(file)) + { + content = reader.ReadToEnd(); + } + + vars.ConnectionString = String.Format(vars.ConnectionString, vars.DatabaseServer, vars.Database, vars.Database, vars.DatabaseUserPassword); + content = Utils.ReplaceScriptVariable(content, "installer.connectionstring", vars.ConnectionString); + + using (var writer = new StreamWriter(file)) + { + writer.Write(content); + } + + Log.WriteEnd(string.Format("Updated {0}.config file (connection string)", Global.Parameters.SchedulerServiceFileName)); + } + } public class SaveEntServerConfigSettingsAction : Action, IInstallAction { @@ -393,7 +486,9 @@ namespace WebsitePanel.Setup.Actions new UpdateServeradminPasswAction(), new SaveAspNetDbConnectionStringAction(), new SaveComponentConfigSettingsAction(), - new SaveEntServerConfigSettingsAction() + new SaveEntServerConfigSettingsAction(), + new SaveSchedulerServiceConnectionStringAction(), + new InstallSchedulerServiceAction() }; public EntServerActionManager(SetupVariables sessionVars) : base(sessionVars) diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Global.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Global.cs index 819105d6..63112bdc 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Global.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Global.cs @@ -76,7 +76,9 @@ namespace WebsitePanel.Setup public const string DatabaseName = "DatabaseName"; public const string ConnectionString = "ConnectionString"; public const string InstallConnectionString = "InstallConnectionString"; - public const string Release = "Release"; + public const string Release = "Release"; + public const string SchedulerServiceFileName = "WebsitePanel.SchedulerService.exe"; + public const string SchedulerServiceName = "WebsitePanel Scheduler"; } public abstract class Messages diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/UninstallPage.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/UninstallPage.cs index cd65881d..08a97db0 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/UninstallPage.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/UninstallPage.cs @@ -288,7 +288,14 @@ namespace WebsitePanel.Setup action.Description = "Removing Windows service..."; action.Log = string.Format("- Remove {0} Windows service", serviceName); list.Add(action); - } + } + + if (ServiceController.GetServices().Any(s => s.DisplayName.Equals(Global.Parameters.SchedulerServiceName, StringComparison.CurrentCultureIgnoreCase))) + { + action = new InstallAction(ActionTypes.UnregisterWindowsService) { Path = Path.Combine(installFolder, "bin", Global.Parameters.SchedulerServiceFileName), Name = Global.Parameters.SchedulerServiceName, Description = "Removing Windows service..." }; + action.Log = string.Format("- Remove {0} Windows service", action.Name); + list.Add(action); + } //database bool deleteDatabase = AppConfig.GetComponentSettingBooleanValue(componentId, "NewDatabase"); diff --git a/WebsitePanel/Sources/WebsitePanel.SchedulerService/WebsitePanel.SchedulerService.csproj b/WebsitePanel/Sources/WebsitePanel.SchedulerService/WebsitePanel.SchedulerService.csproj index a1501bfa..58dc6bdb 100644 --- a/WebsitePanel/Sources/WebsitePanel.SchedulerService/WebsitePanel.SchedulerService.csproj +++ b/WebsitePanel/Sources/WebsitePanel.SchedulerService/WebsitePanel.SchedulerService.csproj @@ -36,7 +36,7 @@ true - bin\ + ..\WebsitePanel.EnterpriseServer\bin\ DEBUG;TRACE full AnyCPU diff --git a/WebsitePanel/build.xml b/WebsitePanel/build.xml index 4760d0c3..c42ca019 100644 --- a/WebsitePanel/build.xml +++ b/WebsitePanel/build.xml @@ -164,25 +164,7 @@ - - - - - - - - - - - - - - - - - - - + @@ -395,6 +377,7 @@ +