Scheduler moved into windows service.

This commit is contained in:
vfedosevich 2013-05-03 17:29:25 +03:00
parent 5e414136b2
commit ce95326f7d
15 changed files with 219 additions and 86 deletions

View file

@ -28,6 +28,9 @@
using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Xml;
@ -99,6 +102,74 @@ namespace WebsitePanel.Setup.Actions
}
}
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
{
public const string LogStartInstallMessage = "Creating SQL Server database...";
@ -348,6 +419,31 @@ namespace WebsitePanel.Setup.Actions
}
}
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
{
void IInstallAction.Run(SetupVariables vars)
@ -390,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)

View file

@ -77,6 +77,8 @@ namespace WebsitePanel.Setup
public const string ConnectionString = "ConnectionString";
public const string InstallConnectionString = "InstallConnectionString";
public const string Release = "Release";
public const string SchedulerServiceFileName = "WebsitePanel.SchedulerService.exe";
public const string SchedulerServiceName = "WebsitePanel Scheduler";
}
public abstract class Messages

View file

@ -74,6 +74,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Drawing" />

View file

@ -27,11 +27,14 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Configuration.Install;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Windows.Forms;
@ -208,17 +211,19 @@ namespace WebsitePanel.Setup
Log.WriteError("Windows service stop error", ex);
}
int exitCode = Utils.RunProcess(path, "/u");
if (exitCode == 0)
{
Log.WriteEnd("Removed Windows service");
InstallLog.AppendLine(string.Format("- Removed \"{0}\" Windows service", serviceName));
}
else
{
Log.WriteError(string.Format("Unable to remove \"{0}\" Windows service. Error code: {1}", serviceName, exitCode), null);
InstallLog.AppendLine(string.Format("- Failed to remove \"{0}\" Windows service", serviceName));
}
try
{
ManagedInstallerClass.InstallHelper(new[] {"/u", path});
}
catch(Exception)
{
Log.WriteError(string.Format("Unable to remove \"{0}\" Windows service.", serviceName), null);
InstallLog.AppendLine(string.Format("- Failed to remove \"{0}\" Windows service", serviceName));
throw;
}
Log.WriteEnd("Removed Windows service");
InstallLog.AppendLine(string.Format("- Removed \"{0}\" Windows service", serviceName));
}
catch (Exception ex)
{
@ -268,7 +273,7 @@ namespace WebsitePanel.Setup
internal List<InstallAction> GetUninstallActions(string componentId)
{
List<InstallAction> list = new List<InstallAction>();
var list = new List<InstallAction>();
InstallAction action = null;
//windows service
@ -285,6 +290,12 @@ namespace WebsitePanel.Setup
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");