Initial project's source code check-in.

This commit is contained in:
ptsurbeleu 2011-07-13 16:07:32 -07:00
commit b03b0b373f
4573 changed files with 981205 additions and 0 deletions

View file

@ -0,0 +1,516 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace WebsitePanel.Setup.Actions
{
public class ActionProgressEventArgs<T> : EventArgs
{
public string StatusMessage { get; set; }
public T EventData { get; set; }
public bool Indeterminate { get; set; }
}
public class ProgressEventArgs : EventArgs
{
public int Value { get; set; }
}
public class ActionErrorEventArgs : EventArgs
{
public string ErrorMessage { get; set; }
public Exception OriginalException { get; set; }
}
public abstract class Action
{
public event EventHandler<ActionProgressEventArgs<int>> ProgressChange;
public event EventHandler<ActionProgressEventArgs<bool>> PrerequisiteComplete;
protected object objectLock = new Object();
public virtual bool Indeterminate
{
get
{
return true;
}
}
protected void Begin(string message)
{
OnInstallProgressChanged(message, 0);
}
protected void Finish(string message)
{
OnInstallProgressChanged(message, 100);
}
protected void OnInstallProgressChanged(string message, int progress)
{
if (ProgressChange == null)
return;
//
ProgressChange(this, new ActionProgressEventArgs<int>
{
StatusMessage = message,
EventData = progress,
Indeterminate = this.Indeterminate
});
}
protected void OnUninstallProgressChanged(string message, int progress)
{
if (ProgressChange == null)
return;
//
ProgressChange(this, new ActionProgressEventArgs<int>
{
StatusMessage = message,
EventData = progress,
Indeterminate = this.Indeterminate
});
}
protected void OnPrerequisiteCompleted(string message, bool result)
{
if (PrerequisiteComplete == null)
return;
//
PrerequisiteComplete(this, new ActionProgressEventArgs<bool>
{
StatusMessage = message,
EventData = result
});
}
}
public interface IActionManager
{
/// <summary>
///
/// </summary>
event EventHandler<ProgressEventArgs> TotalProgressChanged;
/// <summary>
///
/// </summary>
event EventHandler<ActionProgressEventArgs<int>> ActionProgressChanged;
/// <summary>
///
/// </summary>
event EventHandler<ActionProgressEventArgs<bool>> PrerequisiteComplete;
/// <summary>
///
/// </summary>
event EventHandler<ActionErrorEventArgs> ActionError;
/// <summary>
/// Gets current variables available in this session
/// </summary>
SetupVariables SessionVariables { get; }
/// <summary>
///
/// </summary>
/// <param name="action"></param>
void AddAction(Action action);
/// <summary>
/// Triggers manager to run currentScenario specified
/// </summary>
void Start();
/// <summary>
/// Triggers manager to run prerequisites verification procedure
/// </summary>
void VerifyDistributivePrerequisites();
/// <summary>
/// Triggers manager to prepare default parameters for the distributive
/// </summary>
void PrepareDistributiveDefaults();
/// <summary>
/// Initiates rollback procedure from the action specified
/// </summary>
/// <param name="lastSuccessActionIndex"></param>
void Rollback();
}
public class BaseActionManager : IActionManager
{
private List<Action> currentScenario;
//
private int lastSuccessActionIndex = -1;
private SetupVariables sessionVariables;
public SetupVariables SessionVariables
{
get
{
return sessionVariables;
}
}
protected List<Action> CurrentScenario
{
get { return currentScenario; }
set { currentScenario = value; }
}
#region Events
/// <summary>
///
/// </summary>
public event EventHandler<ProgressEventArgs> TotalProgressChanged;
/// <summary>
///
/// </summary>
public event EventHandler<ActionProgressEventArgs<int>> ActionProgressChanged;
/// <summary>
///
/// </summary>
public event EventHandler<ActionProgressEventArgs<bool>> PrerequisiteComplete;
/// <summary>
///
/// </summary>
public event EventHandler<ActionErrorEventArgs> ActionError;
/// <summary>
///
/// </summary>
public event EventHandler Initialize;
#endregion
protected BaseActionManager(SetupVariables sessionVariables)
{
if (sessionVariables == null)
throw new ArgumentNullException("sessionVariables");
//
currentScenario = new List<Action>();
//
this.sessionVariables = sessionVariables;
}
private void OnInitialize()
{
if (Initialize == null)
return;
//
Initialize(this, EventArgs.Empty);
}
/// <summary>
/// Adds action into the list of currentScenario to be executed in the current action manager's session and attaches to its ProgressChange event
/// to track the action's execution progress.
/// </summary>
/// <param name="action">Action to be executed</param>
/// <exception cref="ArgumentNullException"/>
public virtual void AddAction(Action action)
{
if (action == null)
throw new ArgumentNullException("action");
currentScenario.Add(action);
}
private void UpdateActionProgress(string actionText, int actionValue, bool indeterminateAction)
{
OnActionProgressChanged(this, new ActionProgressEventArgs<int>
{
StatusMessage = actionText,
EventData = actionValue,
Indeterminate = indeterminateAction
});
}
private void UpdateTotalProgress(int value)
{
OnTotalProgressChanged(this, new ProgressEventArgs { Value = value });
}
// Fire the Event
private void OnTotalProgressChanged(object sender, ProgressEventArgs args)
{
// Check if there are any Subscribers
if (TotalProgressChanged != null)
{
// Call the Event
TotalProgressChanged(sender, args);
}
}
// Fire the Event
private void OnActionProgressChanged(object sender, ActionProgressEventArgs<int> args)
{
// Check if there are any Subscribers
if (ActionProgressChanged != null)
{
// Call the Event
ActionProgressChanged(sender, args);
}
}
// Fire the Event
private void OnPrerequisiteComplete(object sender, ActionProgressEventArgs<bool> args)
{
// Check if there are any Subscribers
if (PrerequisiteComplete != null)
{
// Call the Event
PrerequisiteComplete(sender, args);
}
}
private void OnActionError(Exception ex)
{
//
if (ActionError == null)
return;
//
var args = new ActionErrorEventArgs
{
ErrorMessage = "An unexpected error has occurred. We apologize for this inconvenience.\n" +
"Please contact Technical Support at support@websitepanel.net.\n\n" +
"Make sure you include a copy of the Installer.log file from the\n" +
"WebsitePanel Installer home directory.",
OriginalException = ex,
};
//
ActionError(this, args);
}
/// <summary>
/// Starts action execution.
/// </summary>
public virtual void Start()
{
var currentActionType = default(Type);
#region Executing the installation session
//
int totalValue = 0;
for (int i = 0, progress = 1; i < currentScenario.Count; i++, progress++)
{
var item = currentScenario[i];
// Get the next action from the queue
var action = item as IInstallAction;
// Take the action's type to log as much information about it as possible
currentActionType = item.GetType();
//
if (action != null)
{
item.ProgressChange += new EventHandler<ActionProgressEventArgs<int>>(action_ProgressChanged);
try
{
// Execute an install action
action.Run(SessionVariables);
}
catch (Exception ex)
{
//
if (currentActionType != default(Type))
{
Log.WriteError(String.Format("Failed to execute '{0}' type of action.", currentActionType));
}
//
Log.WriteError("Here is the original exception...", ex);
//
if (Utils.IsThreadAbortException(ex))
return;
// Notify external clients
OnActionError(ex);
//
Rollback();
//
return;
}
//
item.ProgressChange -= new EventHandler<ActionProgressEventArgs<int>>(action_ProgressChanged);
// Calculate overall current progress status
totalValue = Convert.ToInt32(progress * 100 / currentScenario.Count);
// Update overall progress status
UpdateTotalProgress(totalValue);
}
//
lastSuccessActionIndex = i;
}
//
totalValue = 100;
//
UpdateTotalProgress(totalValue);
//
#endregion
}
void action_ProgressChanged(object sender, ActionProgressEventArgs<int> e)
{
// Action progress has been changed
UpdateActionProgress(e.StatusMessage, e.EventData, e.Indeterminate);
}
public virtual void Rollback()
{
var currentActionType = default(Type);
//
Log.WriteStart("Rolling back");
//
UpdateActionProgress("Rolling back", 0, true);
//
var totalValue = 0;
//
UpdateTotalProgress(totalValue);
//
for (int i = lastSuccessActionIndex, progress = 1; i >= 0; i--, progress++)
{
var action = currentScenario[i] as IUninstallAction;
//
if (action != null)
{
action.ProgressChange += new EventHandler<ActionProgressEventArgs<int>>(action_ProgressChanged);
//
try
{
action.Run(sessionVariables);
}
catch (Exception ex)
{
if (currentActionType != default(Type))
Log.WriteError(String.Format("Failed to rollback '{0}' action.", currentActionType));
//
Log.WriteError("Here is the original exception...", ex);
//
}
//
action.ProgressChange -= new EventHandler<ActionProgressEventArgs<int>>(action_ProgressChanged);
}
//
totalValue = Convert.ToInt32(progress * 100 / (lastSuccessActionIndex + 1));
//
UpdateTotalProgress(totalValue);
}
//
Log.WriteEnd("Rolled back");
}
public void VerifyDistributivePrerequisites()
{
var currentActionType = default(Type);
try
{
//
for (int i = 0; i < currentScenario.Count; i++)
{
var item = currentScenario[i];
// Get the next action from the queue
var action = item as IPrerequisiteAction;
//
currentActionType = item.GetType();
//
if (action != null)
{
//
action.Complete += new EventHandler<ActionProgressEventArgs<bool>>(action_Complete);
// Execute an install action
action.Run(SessionVariables);
//
action.Complete -= new EventHandler<ActionProgressEventArgs<bool>>(action_Complete);
}
}
}
catch (Exception ex)
{
//
if (currentActionType != default(Type))
{
Log.WriteError(String.Format("Failed to execute '{0}' type of action.", currentActionType));
}
//
Log.WriteError("Here is the original exception...", ex);
//
if (Utils.IsThreadAbortException(ex))
return;
// Notify external clients
OnActionError(ex);
//
return;
}
}
void action_Complete(object sender, ActionProgressEventArgs<bool> e)
{
OnPrerequisiteComplete(sender, e);
}
public void PrepareDistributiveDefaults()
{
//
OnInitialize();
//
var currentActionType = default(Type);
try
{
//
for (int i = 0; i < currentScenario.Count; i++)
{
// Get the next action from the queue
var action = currentScenario[i] as IPrepareDefaultsAction;
//
if (action == null)
{
continue;
}
//
currentActionType = action.GetType();
// Execute an install action
action.Run(SessionVariables);
}
}
catch (Exception ex)
{
//
if (currentActionType != default(Type))
{
Log.WriteError(String.Format("Failed to execute '{0}' type of action.", currentActionType));
}
//
Log.WriteError("Here is the original exception...", ex);
//
if (Utils.IsThreadAbortException(ex))
return;
// Notify external clients
OnActionError(ex);
//
return;
}
}
}
}

View file

@ -0,0 +1,417 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
namespace WebsitePanel.Setup.Actions
{
public class SetEntServerWebSettingsAction : Action, IPrepareDefaultsAction
{
public const string LogStartMessage = "Retrieving default IP address of the component...";
void IPrepareDefaultsAction.Run(SetupVariables vars)
{
//
if (String.IsNullOrEmpty(vars.WebSiteIP))
vars.WebSiteIP = "127.0.0.1";
//
if (String.IsNullOrEmpty(vars.WebSitePort))
vars.WebSitePort = "9002";
//
if (String.IsNullOrEmpty(vars.UserAccount))
vars.UserAccount = "WPEnterpriseServer";
}
}
public class SetEntServerCryptoKeyAction : Action, IInstallAction
{
public const string LogStartInstallMessage = "Updating web.config file (crypto key)";
public const string LogEndInstallMessage = "Updated web.config file";
void IInstallAction.Run(SetupVariables vars)
{
try
{
OnInstallProgressChanged(LogStartInstallMessage, 0);
Log.WriteStart(LogStartInstallMessage);
var file = Path.Combine(vars.InstallationFolder, vars.ConfigurationFile);
vars.CryptoKey = Utils.GetRandomString(20);
// load file
string content = string.Empty;
using (StreamReader reader = new StreamReader(file))
{
content = reader.ReadToEnd();
}
// expand variables
content = Utils.ReplaceScriptVariable(content, "installer.cryptokey", vars.CryptoKey);
//
Log.WriteInfo(String.Format("The following cryptographic key has been generated: '{0}'", vars.CryptoKey));
// save file
using (StreamWriter writer = new StreamWriter(file))
{
writer.Write(content);
}
//update log
Log.WriteEnd(LogEndInstallMessage);
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Update web.config error", ex);
//
throw;
}
}
}
public class CreateDatabaseAction : Action, IInstallAction, IUninstallAction
{
public const string LogStartInstallMessage = "Creating SQL Server database...";
public const string LogStartUninstallMessage = "Deleting database";
void IInstallAction.Run(SetupVariables vars)
{
try
{
Begin(LogStartInstallMessage);
//
var connectionString = vars.DbInstallConnectionString;
var database = vars.Database;
Log.WriteStart(LogStartInstallMessage);
Log.WriteInfo(String.Format("SQL Server Database Name: \"{0}\"", database));
//
if (SqlUtils.DatabaseExists(connectionString, database))
{
throw new Exception(String.Format("SQL Server database \"{0}\" already exists", database));
}
SqlUtils.CreateDatabase(connectionString, database);
//
Log.WriteEnd("Created SQL Server database");
//
InstallLog.AppendLine(String.Format("- Created a new SQL Server database \"{0}\"", database));
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Create database error", ex);
//
throw;
}
}
void IUninstallAction.Run(SetupVariables vars)
{
try
{
Log.WriteStart(LogStartUninstallMessage);
//
Log.WriteInfo(String.Format("Deleting database \"{0}\"", vars.Database));
//
if (SqlUtils.DatabaseExists(vars.DbInstallConnectionString, vars.Database))
{
SqlUtils.DeleteDatabase(vars.DbInstallConnectionString, vars.Database);
//
Log.WriteEnd("Deleted database");
}
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
Log.WriteError("Database delete error", ex);
throw;
}
}
}
public class CreateDatabaseUserAction : Action, IInstallAction, IUninstallAction
{
void IInstallAction.Run(SetupVariables vars)
{
try
{
//
Log.WriteStart(String.Format("Creating database user {0}", vars.Database));
//
vars.DatabaseUserPassword = Utils.GetRandomString(20);
//user name should be the same as database
vars.NewDatabaseUser = SqlUtils.CreateUser(vars.DbInstallConnectionString, vars.Database, vars.DatabaseUserPassword, vars.Database);
//
Log.WriteEnd("Created database user");
InstallLog.AppendLine("- Created database user \"{0}\"", vars.Database);
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
Log.WriteError("Create db user error", ex);
throw;
}
}
void IUninstallAction.Run(SetupVariables vars)
{
try
{
Log.WriteStart("Deleting database user");
Log.WriteInfo(String.Format("Deleting database user \"{0}\"", vars.Database));
//
if (SqlUtils.UserExists(vars.DbInstallConnectionString, vars.Database))
{
SqlUtils.DeleteUser(vars.DbInstallConnectionString, vars.Database);
//
Log.WriteEnd("Deleted database user");
}
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
Log.WriteError("Database user delete error", ex);
throw;
}
}
}
public class ExecuteInstallSqlAction : Action, IInstallAction
{
public const string SqlFilePath = @"Setup\install_db.sql";
public const string ExecuteProgressMessage = "Creating database objects...";
void IInstallAction.Run(SetupVariables vars)
{
try
{
var component = vars.ComponentFullName;
var componentId = vars.ComponentId;
var path = Path.Combine(vars.InstallationFolder, SqlFilePath);
if (!FileUtils.FileExists(path))
{
Log.WriteInfo(String.Format("File {0} not found", path));
return;
}
//
SqlProcess process = new SqlProcess(path, vars.DbInstallConnectionString, vars.Database);
//
process.ProgressChange += new EventHandler<ActionProgressEventArgs<int>>(process_ProgressChange);
//
process.Run();
//
InstallLog.AppendLine(string.Format("- Installed {0} database objects", component));
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Run sql error", ex);
//
throw;
}
}
void process_ProgressChange(object sender, ActionProgressEventArgs<int> e)
{
OnInstallProgressChanged(ExecuteProgressMessage, e.EventData);
}
}
public class UpdateServeradminPasswAction : Action, IInstallAction
{
public const string SqlStatement = @"USE [{0}]; UPDATE [dbo].[Users] SET [Password] = '{1}' WHERE [UserID] = 1;";
void IInstallAction.Run(SetupVariables vars)
{
try
{
Log.WriteStart("Updating serveradmin password");
//
var path = Path.Combine(vars.InstallationFolder, vars.ConfigurationFile);
var password = vars.ServerAdminPassword;
if (!File.Exists(path))
{
Log.WriteInfo(String.Format("File {0} not found", path));
return;
}
//
bool encryptionEnabled = IsEncryptionEnabled(path);
// Encrypt password
if (encryptionEnabled)
{
password = Utils.Encrypt(vars.CryptoKey, password);
}
//
SqlUtils.ExecuteQuery(vars.DbInstallConnectionString, String.Format(SqlStatement, vars.Database, password));
//
Log.WriteEnd("Updated serveradmin password");
//
InstallLog.AppendLine("- Updated password for the serveradmin account");
//
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Update error", ex);
throw;
}
}
private bool IsEncryptionEnabled(string path)
{
var doc = new XmlDocument();
doc.Load(path);
//encryption enabled
string xPath = "configuration/appSettings/add[@key=\"WebsitePanel.EncryptionEnabled\"]";
XmlElement encryptionNode = doc.SelectSingleNode(xPath) as XmlElement;
bool encryptionEnabled = false;
//
if (encryptionNode != null)
{
bool.TryParse(encryptionNode.GetAttribute("value"), out encryptionEnabled);
}
//
return encryptionEnabled;
}
}
public class SaveAspNetDbConnectionStringAction : Action, IInstallAction
{
void IInstallAction.Run(SetupVariables vars)
{
Log.WriteStart("Updating web.config file (connection string)");
//
var file = Path.Combine(vars.InstallationFolder, vars.ConfigurationFile);
//
var content = String.Empty;
// load file
using (StreamReader reader = new StreamReader(file))
{
content = reader.ReadToEnd();
}
// Build connection string
vars.ConnectionString = String.Format(vars.ConnectionString, vars.DatabaseServer, vars.Database, vars.Database, vars.DatabaseUserPassword);
// Expand variables
content = Utils.ReplaceScriptVariable(content, "installer.connectionstring", vars.ConnectionString);
// Save file
using (StreamWriter writer = new StreamWriter(file))
{
writer.Write(content);
}
//
Log.WriteEnd(String.Format("Updated {0} file", vars.ConfigurationFile));
}
}
public class SaveEntServerConfigSettingsAction : Action, IInstallAction
{
void IInstallAction.Run(SetupVariables vars)
{
AppConfig.EnsureComponentConfig(vars.ComponentId);
//
AppConfig.SetComponentSettingStringValue(vars.ComponentId, "Database", vars.Database);
AppConfig.SetComponentSettingBooleanValue(vars.ComponentId, "NewDatabase", true);
//
AppConfig.SetComponentSettingStringValue(vars.ComponentId, "DatabaseUser", vars.Database);
AppConfig.SetComponentSettingBooleanValue(vars.ComponentId, "NewDatabaseUser", vars.NewDatabaseUser);
//
AppConfig.SetComponentSettingStringValue(vars.ComponentId, Global.Parameters.ConnectionString, vars.ConnectionString);
AppConfig.SetComponentSettingStringValue(vars.ComponentId, Global.Parameters.DatabaseServer, vars.DatabaseServer);
AppConfig.SetComponentSettingStringValue(vars.ComponentId, Global.Parameters.InstallConnectionString, vars.DbInstallConnectionString);
AppConfig.SetComponentSettingStringValue(vars.ComponentId, Global.Parameters.CryptoKey, vars.CryptoKey);
//
AppConfig.SaveConfiguration();
}
}
public class EntServerActionManager : BaseActionManager
{
public static readonly List<Action> InstallScenario = new List<Action>
{
new SetCommonDistributiveParamsAction(),
new SetEntServerWebSettingsAction(),
new EnsureServiceAccntSecured(),
new CopyFilesAction(),
new SetEntServerCryptoKeyAction(),
new CreateWindowsAccountAction(),
new ConfigureAspNetTempFolderPermissionsAction(),
new SetNtfsPermissionsAction(),
new CreateWebApplicationPoolAction(),
new CreateWebSiteAction(),
new SwitchAppPoolAspNetVersion(),
new CreateDatabaseAction(),
new CreateDatabaseUserAction(),
new ExecuteInstallSqlAction(),
new UpdateServeradminPasswAction(),
new SaveAspNetDbConnectionStringAction(),
new SaveComponentConfigSettingsAction(),
new SaveEntServerConfigSettingsAction()
};
public EntServerActionManager(SetupVariables sessionVars) : base(sessionVars)
{
Initialize += new EventHandler(EntServerActionManager_PreInit);
}
void EntServerActionManager_PreInit(object sender, EventArgs e)
{
//
switch (SessionVariables.SetupAction)
{
case SetupActions.Install: // Install
LoadInstallationScenario();
break;
}
}
private void LoadInstallationScenario()
{
CurrentScenario.AddRange(InstallScenario);
}
}
}

View file

@ -0,0 +1,37 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
namespace WebsitePanel.Setup.Actions
{
public interface IInstallAction
{
void Run(WebsitePanel.Setup.SetupVariables vars);
}
}

View file

@ -0,0 +1,39 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Setup.Actions
{
public interface IPrepareDefaultsAction
{
void Run(WebsitePanel.Setup.SetupVariables vars);
}
}

View file

@ -0,0 +1,39 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
namespace WebsitePanel.Setup.Actions
{
public interface IPrerequisiteAction
{
bool Run(WebsitePanel.Setup.SetupVariables vars);
// The event
event EventHandler<ActionProgressEventArgs<bool>> Complete;
}
}

View file

@ -0,0 +1,39 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
namespace WebsitePanel.Setup.Actions
{
public interface IUninstallAction
{
void Run(WebsitePanel.Setup.SetupVariables vars);
//
event EventHandler<ActionProgressEventArgs<int>> ProgressChange;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,282 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
namespace WebsitePanel.Setup.Actions
{
public class SetWebPortalWebSettingsAction : Action, IPrepareDefaultsAction
{
public const string LogStartMessage = "Retrieving default IP address of the component...";
void IPrepareDefaultsAction.Run(SetupVariables vars)
{
//
if (String.IsNullOrEmpty(vars.WebSitePort))
vars.WebSitePort = Global.WebPortal.DefaultPort;
//
if (String.IsNullOrEmpty(vars.UserAccount))
vars.UserAccount = Global.WebPortal.ServiceAccount;
// By default we use public ip for the component
if (String.IsNullOrEmpty(vars.WebSiteIP))
{
var serverIPs = WebUtils.GetIPv4Addresses();
//
if (serverIPs != null && serverIPs.Length > 0)
{
vars.WebSiteIP = serverIPs[0];
}
else
{
vars.WebSiteIP = Global.LoopbackIPv4;
}
}
}
}
public class UpdateEnterpriseServerUrlAction : Action, IInstallAction
{
public const string LogStartInstallMessage = "Updating site settings...";
void IInstallAction.Run(SetupVariables vars)
{
try
{
Begin(LogStartInstallMessage);
//
Log.WriteStart(LogStartInstallMessage);
//
var path = Path.Combine(vars.InstallationFolder, @"App_Data\SiteSettings.config");
//
if (!File.Exists(path))
{
Log.WriteInfo(String.Format("File {0} not found", path));
//
return;
}
//
var doc = new XmlDocument();
doc.Load(path);
//
var urlNode = doc.SelectSingleNode("SiteSettings/EnterpriseServer") as XmlElement;
if (urlNode == null)
{
Log.WriteInfo("EnterpriseServer setting not found");
return;
}
urlNode.InnerText = vars.EnterpriseServerURL;
doc.Save(path);
//
Log.WriteEnd("Updated site settings");
//
InstallLog.AppendLine("- Updated site settings");
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Site settigs error", ex);
//
throw;
}
}
}
public class CreateDesktopShortcutsAction : Action, IInstallAction
{
public const string LogStartInstallMessage = "Creating shortcut...";
public const string ApplicationUrlNotFoundMessage = "Application url not found";
public const string Path2 = "WebsitePanel Software";
void IInstallAction.Run(SetupVariables vars)
{
//
try
{
Begin(LogStartInstallMessage);
//
Log.WriteStart(LogStartInstallMessage);
//
var urls = Utils.GetApplicationUrls(vars.WebSiteIP, vars.WebSiteDomain, vars.WebSitePort, null);
string url = null;
if (urls.Length == 0)
{
Log.WriteInfo(ApplicationUrlNotFoundMessage);
//
return;
}
// Retrieve top-most url from the list
url = "http://" + urls[0];
//
Log.WriteStart("Creating menu shortcut");
//
string programs = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
string fileName = "Login to WebsitePanel.url";
string path = Path.Combine(programs, Path2);
//
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//
WriteShortcutData(Path.Combine(path, fileName), url);
//
Log.WriteEnd("Created menu shortcut");
//
Log.WriteStart("Creating desktop shortcut");
//
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
WriteShortcutData(Path.Combine(desktop, fileName), url);
//
Log.WriteEnd("Created desktop shortcut");
//
InstallLog.AppendLine("- Created application shortcuts");
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Create shortcut error", ex);
}
}
private static void WriteShortcutData(string filePath, string url)
{
string iconFile = Path.Combine(Environment.SystemDirectory, "url.dll");
//
using (StreamWriter sw = File.CreateText(filePath))
{
sw.WriteLine("[InternetShortcut]");
sw.WriteLine("URL=" + url);
sw.WriteLine("IconFile=" + iconFile);
sw.WriteLine("IconIndex=0");
sw.WriteLine("HotKey=0");
//
Log.WriteInfo(String.Format("Shortcut url: {0}", url));
}
}
}
public class CopyWebConfigAction : Action, IInstallAction
{
void IInstallAction.Run(SetupVariables vars)
{
try
{
Log.WriteStart("Copying web.config");
string configPath = Path.Combine(vars.InstallationFolder, "web.config");
string config6Path = Path.Combine(vars.InstallationFolder, "web6.config");
bool iis6 = (vars.IISVersion.Major == 6);
if (!File.Exists(config6Path))
{
Log.WriteInfo(string.Format("File {0} not found", config6Path));
return;
}
if (iis6)
{
if (!File.Exists(configPath))
{
Log.WriteInfo(string.Format("File {0} not found", configPath));
return;
}
FileUtils.DeleteFile(configPath);
File.Move(config6Path, configPath);
}
else
{
FileUtils.DeleteFile(config6Path);
}
Log.WriteEnd("Copied web.config");
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Copy web.config error", ex);
//
throw;
}
}
}
public class WebPortalActionManager : BaseActionManager
{
public static readonly List<Action> InstallScenario = new List<Action>
{
new SetCommonDistributiveParamsAction(),
new SetWebPortalWebSettingsAction(),
new EnsureServiceAccntSecured(),
new CopyFilesAction(),
new CopyWebConfigAction(),
new CreateWindowsAccountAction(),
new ConfigureAspNetTempFolderPermissionsAction(),
new SetNtfsPermissionsAction(),
new CreateWebApplicationPoolAction(),
new CreateWebSiteAction(),
new SwitchAppPoolAspNetVersion(),
new UpdateEnterpriseServerUrlAction(),
new SaveComponentConfigSettingsAction(),
new CreateDesktopShortcutsAction()
};
public WebPortalActionManager(SetupVariables sessionVars)
: base(sessionVars)
{
Initialize += new EventHandler(WebPortalActionManager_Initialize);
}
void WebPortalActionManager_Initialize(object sender, EventArgs e)
{
//
switch (SessionVariables.SetupAction)
{
case SetupActions.Install: // Install
LoadInstallationScenario();
break;
}
}
private void LoadInstallationScenario()
{
CurrentScenario.AddRange(InstallScenario);
}
}
}