Installer: old to new update #4

This commit is contained in:
McMak 2015-05-20 16:19:56 +03:00
parent 8219bc32c9
commit b2bb23ea13
7 changed files with 106 additions and 21 deletions

View file

@ -63,6 +63,9 @@ namespace WebsitePanel.Setup.Actions
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
try
{
OnInstallProgressChanged(LogStartInstallMessage, 0);
@ -232,6 +235,9 @@ namespace WebsitePanel.Setup.Actions
{
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
try
{
//
@ -330,6 +336,9 @@ namespace WebsitePanel.Setup.Actions
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
try
{
Log.WriteStart("Updating serveradmin password");
@ -389,6 +398,9 @@ namespace WebsitePanel.Setup.Actions
{
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
Log.WriteStart("Updating web.config file (connection string)");
var file = Path.Combine(vars.InstallationFolder, vars.ConfigurationFile);
vars.ConnectionString = String.Format(vars.ConnectionString, vars.DatabaseServer, vars.Database, vars.Database, vars.DatabaseUserPassword);

View file

@ -151,6 +151,8 @@ namespace WebsitePanel.Setup.Actions
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
// Exit with an error if Windows account with the same name already exists
if (SecurityUtils.UserExists(vars.UserDomain, vars.UserAccount))
throw new Exception(UserAccountExists);
@ -394,7 +396,7 @@ namespace WebsitePanel.Setup.Actions
}
// This flag is the opposite of poolExists flag
vars.NewWebApplicationPool = !poolExists;
vars.NewWebApplicationPool = !poolExists || vars.ComponentExists;
if (poolExists)
{
@ -501,6 +503,9 @@ namespace WebsitePanel.Setup.Actions
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
var siteName = vars.ComponentFullName;
var ip = vars.WebSiteIP;
var port = vars.WebSitePort;
@ -774,6 +779,9 @@ namespace WebsitePanel.Setup.Actions
void IInstallAction.Run(SetupVariables vars)
{
if (vars.ComponentExists)
return;
try
{
Begin(LogStartInstallMessage);

View file

@ -335,10 +335,10 @@ namespace WebsitePanel.Setup
return files;
}
public static void CopyFileToFolder(string sourceFile, string destinationFolder)
public static void CopyFileToFolder(string sourceFile, string destinationFolder, string destinationFileName = "")
{
string fileName = Path.GetFileName(sourceFile);
string destinationFile = Path.Combine(destinationFolder, fileName);
string destinationFile = Path.Combine(destinationFolder, string.IsNullOrWhiteSpace(destinationFileName) ? fileName : destinationFileName);
CopyFile(new FileInfo(sourceFile), destinationFile);
}

View file

@ -249,6 +249,11 @@ namespace WebsitePanel.Setup
public string BaseDirectory { get; set; }
public string SpecialBaseDirectory { get; set; }
public IDictionary<string, string> FileNameMap { get; set; }
public bool ComponentExists { get; set; }
public string UpdateVersion { get; set; }
public string EnterpriseServerURL { get; set; }

View file

@ -163,6 +163,8 @@ namespace WebsitePanel.Setup.Internal
Utils.GetStringSetupParameter(Hash, Global.Parameters.DbServerAdminPassword));
Dst.BaseDirectory = Utils.GetStringSetupParameter(Hash, Global.Parameters.BaseDirectory);
Dst.ComponentId = Utils.GetStringSetupParameter(Hash, Global.Parameters.ComponentId);
Dst.ComponentExists = string.IsNullOrWhiteSpace(Dst.ComponentId) ? false : true;
}
public static string GetFullConfigPath(SetupVariables Ctx)
{
@ -2739,7 +2741,7 @@ namespace WebsitePanel.Setup.Internal
BackupDatabase(action.ConnectionString, action.Name);
break;
case ActionTypes.BackupConfig:
BackupConfig(action.Path, destinationDirectory);
BackupConfig(action.Path, destinationDirectory, action.SetupVariables != null ? action.SetupVariables.FileNameMap : null);
break;
}
}
@ -2755,7 +2757,7 @@ namespace WebsitePanel.Setup.Internal
}
}
private void BackupConfig(string path, string backupDirectory)
private void BackupConfig(string path, string backupDirectory, IDictionary<string, string> NameMap = null)
{
try
{
@ -2772,7 +2774,7 @@ namespace WebsitePanel.Setup.Internal
string[] files = Directory.GetFiles(path, "*.config", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
FileUtils.CopyFileToFolder(file, destination);
FileUtils.CopyFileToFolder(file, destination, GetMappedFileName(file, NameMap));
}
Log.WriteEnd("Backed up system configuration");
InstallLog.AppendLine("- Backed up system configuration");
@ -2786,6 +2788,17 @@ namespace WebsitePanel.Setup.Internal
}
}
private string GetMappedFileName(string FullFileName, IDictionary<string, string> Map)
{
if (Map == null)
return "";
string Key = new FileInfo(FullFileName).Name;
if (Map.Keys.Contains(Key))
return Map[Key];
else
return "";
}
private void BackupDatabase(string connectionString, string database)
{
try
@ -2881,10 +2894,14 @@ namespace WebsitePanel.Setup.Internal
}
//config
action = new InstallAction(ActionTypes.BackupConfig);
action.Description = "Backing up configuration settings...";
action.Path = Context.BaseDirectory;
action.Description = "Backing up configuration settings...";
if (!string.IsNullOrWhiteSpace(Context.SpecialBaseDirectory) )
{
action.Path = Context.SpecialBaseDirectory;
action.SetupVariables = Context;
}
list.Add(action);
return list;
}
private void UpdateWebSiteBindings()
@ -4225,6 +4242,12 @@ namespace WebsitePanel.Setup.Internal
WiXThrow = true;
});
sam.Start();
if (Context.ComponentExists)
{
Context.UpdateVersion = Context.Release;
AppConfig.LoadComponentSettings(Context);
new RestoreScript(Context).Run();
}
}
catch (Exception ex)
{
@ -4303,6 +4326,12 @@ namespace WebsitePanel.Setup.Internal
WiXThrow = true;
});
sam.Start();
if(Context.ComponentExists)
{
Context.UpdateVersion = Context.Release;
AppConfig.LoadComponentSettings(Context);
new RestoreScript(Context).Run();
}
}
catch (Exception ex)
{
@ -4381,6 +4410,12 @@ namespace WebsitePanel.Setup.Internal
WiXThrow = true;
});
sam.Start();
if (Context.ComponentExists)
{
Context.UpdateVersion = Context.Release;
AppConfig.LoadComponentSettings(Context);
new RestoreScript(Context).Run();
}
}
catch (Exception ex)
{