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,100 @@
// 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.Security.Policy;
using System.Diagnostics;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Lifetime;
namespace WebsitePanel.Installer.Common
{
[Serializable]
public class AssemblyLoader : MarshalByRefObject
{
public object RemoteRun(string fileName, string typeName, string methodName, object[] parameters)
{
Assembly assembly = Assembly.LoadFrom(fileName);
Type type = assembly.GetType(typeName);
MethodInfo method = type.GetMethod(methodName);
return method.Invoke(Activator.CreateInstance(type), parameters);
}
public void AddTraceListener(TraceListener traceListener)
{
Trace.Listeners.Add(traceListener);
}
public static object Execute(string fileName, string typeName, string methodName, object[] parameters)
{
AppDomain domain = null;
try
{
Evidence securityInfo = AppDomain.CurrentDomain.Evidence;
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
domain = AppDomain.CreateDomain("Remote Domain", securityInfo, info);
domain.InitializeLifetimeService();
domain.UnhandledException += new UnhandledExceptionEventHandler(OnDomainUnhandledException);
AssemblyLoader loader = (AssemblyLoader)domain.CreateInstanceAndUnwrap(
typeof(AssemblyLoader).Assembly.FullName,
typeof(AssemblyLoader).FullName);
foreach (TraceListener listener in Trace.Listeners)
{
loader.AddTraceListener(listener);
}
object ret = loader.RemoteRun(fileName, typeName, methodName, parameters);
AppDomain.Unload(domain);
return ret;
}
catch (Exception)
{
if (domain != null)
{
AppDomain.Unload(domain);
}
throw;
}
}
static void OnDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.WriteError("Remote domain error", (Exception)e.ExceptionObject);
}
public static string GetShellVersion()
{
return Assembly.GetEntryAssembly().GetName().Version.ToString();
}
}
}

View file

@ -0,0 +1,271 @@
// 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;
namespace WebsitePanel.Installer.Common
{
/// <summary>
/// File utils.
/// </summary>
public sealed class FileUtils
{
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
private FileUtils()
{
}
/// <summary>
/// Creates drectory with the specified directory.
/// </summary>
/// <param name="path">The directory path to create.</param>
public static void CreateDirectory(string path)
{
string dir = Path.GetDirectoryName(path);
if(!Directory.Exists(dir))
{
// create directory structure
Directory.CreateDirectory(dir);
}
}
/// <summary>
/// Saves file content.
/// </summary>
/// <param name="fileName">File name.</param>
/// <param name="content">The array of bytes to write.</param>
public static void SaveFileContent(string fileName, byte[] content)
{
FileStream stream = new FileStream(fileName, FileMode.Create);
stream.Write(content, 0, content.Length);
stream.Close();
}
/// <summary>
/// Saves file content.
/// </summary>
/// <param name="fileName">File name.</param>
/// <param name="content">The array of bytes to write.</param>
public static void AppendFileContent(string fileName, byte[] content)
{
FileStream stream = new FileStream(fileName, FileMode.Append, FileAccess.Write);
stream.Write(content, 0, content.Length);
stream.Close();
}
/// <summary>
/// Deletes the specified file.
/// </summary>
/// <param name="fileName">The name of the file to be deleted.</param>
public static void DeleteFile(string fileName)
{
int attempts = 0;
while (true)
{
try
{
DeleteFileInternal(fileName);
break;
}
catch (Exception)
{
if (attempts > 2)
throw;
attempts++;
System.Threading.Thread.Sleep(1000);
}
}
}
/// <summary>
/// Deletes the specified file.
/// </summary>
/// <param name="fileName">The name of the file to be deleted.</param>
private static void DeleteReadOnlyFile(string fileName)
{
FileInfo info = new FileInfo(fileName);
info.Attributes = FileAttributes.Normal;
info.Delete();
}
/// <summary>
/// Deletes the specified file.
/// </summary>
/// <param name="fileName">The name of the file to be deleted.</param>
private static void DeleteFileInternal(string fileName)
{
try
{
File.Delete(fileName);
}
catch (UnauthorizedAccessException)
{
DeleteReadOnlyFile(fileName);
}
}
/// <summary>
/// Deletes the specified directory.
/// </summary>
/// <param name="directory">The name of the directory to be deleted.</param>
public static void DeleteDirectory(string directory)
{
if (!Directory.Exists(directory))
return;
// iterate through child folders
string[] dirs = Directory.GetDirectories(directory);
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
// iterate through child files
string[] files = Directory.GetFiles(directory);
foreach (string file in files)
{
DeleteFile(file);
}
//try to delete dir for 3 times
int attempts = 0;
while (true)
{
try
{
DeleteDirectoryInternal(directory);
break;
}
catch (Exception)
{
if (attempts > 2)
throw;
attempts++;
System.Threading.Thread.Sleep(1000);
}
}
}
/// <summary>
/// Deletes the specified directory.
/// </summary>
/// <param name="directory">The name of the directory to be deleted.</param>
private static void DeleteDirectoryInternal(string directory)
{
try
{
Directory.Delete(directory);
}
catch (IOException)
{
DeleteReadOnlyDirectory(directory);
}
}
/// <summary>
/// Deletes the specified directory.
/// </summary>
/// <param name="directory">The name of the directory to be deleted.</param>
private static void DeleteReadOnlyDirectory(string directory)
{
DirectoryInfo info = new DirectoryInfo(directory);
info.Attributes = FileAttributes.Normal;
info.Delete();
}
/// <summary>
/// Determines whether the specified file exists.
/// </summary>
/// <param name="fileName">The path to check.</param>
/// <returns></returns>
public static bool FileExists(string fileName)
{
return File.Exists(fileName);
}
/// <summary>
/// Determines whether the given path refers to an existing directory on disk.
/// </summary>
/// <param name="path">The path to test.</param>
/// <returns></returns>
public static bool DirectoryExists(string path)
{
return Directory.Exists(path);
}
/// <summary>
/// Returns current application path.
/// </summary>
/// <returns>Curent application path.</returns>
public static string GetCurrentDirectory()
{
return AppDomain.CurrentDomain.BaseDirectory;
}
/// <summary>
/// Returns application temp directory.
/// </summary>
/// <returns>Application temp directory.</returns>
public static string GetTempDirectory()
{
return Path.Combine(GetCurrentDirectory(), "Tmp");
}
/// <summary>
/// Returns application data directory.
/// </summary>
/// <returns>Application data directory.</returns>
public static string GetDataDirectory()
{
return Path.Combine(GetCurrentDirectory(), "Data");
}
/// <summary>
/// Deletes application temp directory.
/// </summary>
public static void DeleteTempDirectory()
{
try
{
DeleteDirectory(GetTempDirectory());
}
catch (Exception ex)
{
Log.WriteError("IO Error", ex);
}
}
}
}

View file

@ -0,0 +1,250 @@
// 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.Xml;
using System.EnterpriseServices;
namespace WebsitePanel.Installer.Common
{
public class Global
{
public const string VisualInstallerShell = "VisualInstallerShell";
public const string SilentInstallerShell = "SilentInstallerShell";
public const string DefaultInstallPathRoot = @"C:\WebsitePanel";
public const string LoopbackIPv4 = "127.0.0.1";
public const string InstallerProductCode = "cfg core";
public abstract class Parameters
{
public const string ComponentId = "ComponentId";
public const string EnterpriseServerUrl = "EnterpriseServerUrl";
public const string ShellMode = "ShellMode";
public const string ShellVersion = "ShellVersion";
public const string IISVersion = "IISVersion";
public const string BaseDirectory = "BaseDirectory";
public const string Installer = "Installer";
public const string InstallerType = "InstallerType";
public const string InstallerPath = "InstallerPath";
public const string InstallerFolder = "InstallerFolder";
public const string Version = "Version";
public const string ComponentDescription = "ComponentDescription";
public const string ComponentCode = "ComponentCode";
public const string ApplicationName = "ApplicationName";
public const string ComponentName = "ComponentName";
public const string WebSiteIP = "WebSiteIP";
public const string WebSitePort = "WebSitePort";
public const string WebSiteDomain = "WebSiteDomain";
public const string ServerPassword = "ServerPassword";
public const string UserDomain = "UserDomain";
public const string UserAccount = "UserAccount";
public const string UserPassword = "UserPassword";
public const string CryptoKey = "CryptoKey";
public const string ServerAdminPassword = "ServerAdminPassword";
public const string SetupXml = "SetupXml";
public const string ParentForm = "ParentForm";
public const string Component = "Component";
public const string FullFilePath = "FullFilePath";
public const string DatabaseServer = "DatabaseServer";
public const string DbServerAdmin = "DbServerAdmin";
public const string DbServerAdminPassword = "DbServerAdminPassword";
public const string DatabaseName = "DatabaseName";
public const string ConnectionString = "ConnectionString";
public const string InstallConnectionString = "InstallConnectionString";
public const string Release = "Release";
}
public abstract class Messages
{
public const string NotEnoughPermissionsError = "You do not have the appropriate permissions to perform this operation. Make sure you are running the application from the local disk and you have local system administrator privileges.";
public const string InstallerVersionIsObsolete = "WebsitePanel Installer {0} or higher required.";
public const string ComponentIsAlreadyInstalled = "Component or its part is already installed.";
public const string AnotherInstanceIsRunning = "Another instance of the installation process is already running.";
public const string NoInputParametersSpecified = "No input parameters specified";
public const int InstallationError = -1000;
public const int UnknownComponentCodeError = -999;
public const int SuccessInstallation = 0;
public const int AnotherInstanceIsRunningError = -998;
public const int NotEnoughPermissionsErrorCode = -997;
public const int NoInputParametersSpecifiedError = -996;
public const int ComponentIsAlreadyInstalledError = -995;
}
public abstract class Server
{
public abstract class CLI
{
public const string ServerPassword = "passw";
};
public const string ComponentName = "Server";
public const string ComponentCode = "server";
public const string ComponentDescription = "WebsitePanel Server is a set of services running on the remote server to be controlled. Server application should be reachable from Enterprise Server one.";
public const string ServiceAccount = "WPServer";
public const string DefaultPort = "9003";
public const string DefaultIP = "127.0.0.1";
public const string SetupController = "Server";
}
public abstract class StandaloneServer
{
public const string SetupController = "StandaloneServerSetup";
public const string ComponentCode = "standalone";
public const string ComponentName = "Standalone Server Setup";
}
public abstract class WebPortal
{
public const string ComponentName = "Portal";
public const string ComponentDescription = "WebsitePanel Portal is a control panel itself with user interface which allows managing user accounts, hosting spaces, web sites, FTP accounts, files, etc.";
public const string ServiceAccount = "WPPortal";
public const string DefaultPort = "9001";
public const string DefaultIP = "";
public const string DefaultEntServURL = "http://127.0.0.1:9002";
public const string ComponentCode = "portal";
public const string SetupController = "Portal";
public static string[] ServiceUserMembership
{
get
{
if (IISVersion.Major == 7)
{
return new string[] { "IIS_IUSRS" };
}
//
return new string[] { "IIS_WPG" };
}
}
public abstract class CLI
{
public const string EnterpriseServerUrl = "esurl";
}
}
public abstract class EntServer
{
public const string ComponentName = "Enterprise Server";
public const string ComponentDescription = "Enterprise Server is the heart of WebsitePanel system. It includes all business logic of the application. Enterprise Server should have access to Server and be accessible from Portal applications.";
public const string ServiceAccount = "WPEnterpriseServer";
public const string DefaultPort = "9002";
public const string DefaultIP = "127.0.0.1";
public const string DefaultDbServer = @"localhost\sqlexpress";
public const string DefaultDatabase = "WebsitePanel";
public const string AspNetConnectionStringFormat = "server={0};database={1};uid={2};pwd={3};";
public const string ComponentCode = "enterprise server";
public const string SetupController = "EnterpriseServer";
public static string[] ServiceUserMembership
{
get
{
if (IISVersion.Major == 7)
{
return new string[] { "IIS_IUSRS" };
}
//
return new string[] { "IIS_WPG" };
}
}
public abstract class CLI
{
public const string ServeradminPassword = "passw";
public const string DatabaseName = "dbname";
public const string DatabaseServer = "dbserver";
public const string DbServerAdmin = "dbadmin";
public const string DbServerAdminPassword = "dbapassw";
}
}
public abstract class CLI
{
public const string WebSiteIP = "webip";
public const string ServiceAccountPassword = "upassw";
public const string ServiceAccountDomain = "udomaim";
public const string ServiceAccountName = "uname";
public const string WebSitePort = "webport";
public const string WebSiteDomain = "webdom";
}
private Global()
{
}
private static Version iisVersion;
//
public static Version IISVersion
{
get
{
if (iisVersion == null)
{
iisVersion = RegistryUtils.GetIISVersion();
}
//
return iisVersion;
}
}
//
private static OS.WindowsVersion osVersion = OS.WindowsVersion.Unknown;
/// <summary>
/// Represents Setup Control Panel Accounts system settings set (SCPA)
/// </summary>
public class SCPA
{
public const string SettingsKeyName = "EnabledSCPA";
}
public static OS.WindowsVersion OSVersion
{
get
{
if (osVersion == OS.WindowsVersion.Unknown)
{
osVersion = OS.GetVersion();
}
//
return osVersion;
}
}
public static XmlDocument SetupXmlDocument { get; set; }
}
public class SetupEventArgs<T> : EventArgs
{
public T EventData { get; set; }
public string EventMessage { get; set; }
}
}

View file

@ -0,0 +1,245 @@
// 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.Configuration;
using System.Diagnostics;
using System.IO;
using WebsitePanel.Installer.Configuration;
using System.Security.Principal;
using WebsitePanel.Installer.Core;
using System.Reflection;
namespace WebsitePanel.Installer.Common
{
/// <summary>
/// Installer Log.
/// </summary>
public sealed class Log
{
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
private Log()
{
}
/// <summary>
/// Initializes trace listeners.
/// </summary>
static Log()
{
Initialize();
}
static void Initialize()
{
string fileName = LogFile;
//
Trace.Listeners.Clear();
//
FileStream fileLog = new FileStream(fileName, FileMode.Append);
//
TextWriterTraceListener fileListener = new TextWriterTraceListener(fileLog);
fileListener.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(fileListener);
//
Trace.AutoFlush = true;
}
internal static string LogFile
{
get
{
string fileName = "WebsitePanel.Installer.log";
//
if (string.IsNullOrEmpty(fileName))
{
fileName = "Installer.log";
}
// Ensure the path is correct
if (!Path.IsPathRooted(fileName))
{
fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
}
//
return fileName;
}
}
/// <summary>
/// Write error to the log.
/// </summary>
/// <param name="message">Error message.</param>
/// <param name="ex">Exception.</param>
public static void WriteError(string message, Exception ex)
{
try
{
string line = string.Format("[{0:G}] ERROR: {1}", DateTime.Now, message);
Trace.WriteLine(line);
Trace.WriteLine(ex);
}
catch { }
}
/// <summary>
/// Write error to the log.
/// </summary>
/// <param name="message">Error message.</param>
public static void WriteError(string message)
{
try
{
string line = string.Format("[{0:G}] ERROR: {1}", DateTime.Now, message);
Trace.WriteLine(line);
}
catch { }
}
/// <summary>
/// Write to log
/// </summary>
/// <param name="message"></param>
public static void Write(string message)
{
try
{
string line = string.Format("[{0:G}] {1}", DateTime.Now, message);
Trace.Write(line);
}
catch { }
}
/// <summary>
/// Write line to log
/// </summary>
/// <param name="message"></param>
public static void WriteLine(string message)
{
try
{
string line = string.Format("[{0:G}] {1}", DateTime.Now, message);
Trace.WriteLine(line);
}
catch { }
}
/// <summary>
/// Writes formatted informational message into the log
/// </summary>
/// <param name="format"></param>
/// <param name="args"></param>
public static void WriteInfo(string format, params object[] args)
{
WriteInfo(String.Format(format, args));
}
/// <summary>
/// Write info message to log
/// </summary>
/// <param name="message"></param>
public static void WriteInfo(string message)
{
try
{
string line = string.Format("[{0:G}] INFO: {1}", DateTime.Now, message);
Trace.WriteLine(line);
}
catch { }
}
/// <summary>
/// Write start message to log
/// </summary>
/// <param name="message"></param>
public static void WriteStart(string message)
{
try
{
string line = string.Format("[{0:G}] START: {1}", DateTime.Now, message);
Trace.WriteLine(line);
}
catch { }
}
/// <summary>
/// Write end message to log
/// </summary>
/// <param name="message"></param>
public static void WriteEnd(string message)
{
try
{
string line = string.Format("[{0:G}] END: {1}", DateTime.Now, message);
Trace.WriteLine(line);
}
catch { }
}
public static void WriteApplicationStart()
{
try
{
string name = Assembly.GetEntryAssembly().GetName().Name;
string version = Assembly.GetEntryAssembly().GetName().Version.ToString();
string identity = WindowsIdentity.GetCurrent().Name;
string line = string.Format("[{0:G}] {1} {2} Started by {3}", DateTime.Now, name, version, identity);
Trace.WriteLine(line);
}
catch { }
}
public static void WriteApplicationEnd()
{
try
{
string name = Assembly.GetEntryAssembly().GetName().Name;
string line = string.Format("[{0:G}] {1} Ended", DateTime.Now, name);
Trace.WriteLine(line);
}
catch { }
}
/// <summary>
/// Opens notepad to view log file.
/// </summary>
public static void ShowLogFile()
{
try
{
string path = LogFile;
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
Process.Start("notepad.exe", path);
}
catch { }
}
}
}

View file

@ -0,0 +1,386 @@
// 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.Runtime.InteropServices;
namespace WebsitePanel.Installer.Common
{
public sealed class OS
{
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public Int32 dwOSVersionInfoSize;
public Int32 dwMajorVersion;
public Int32 dwMinorVersion;
public Int32 dwBuildNumber;
public Int32 dwPlatformID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFOEX
{
public Int32 dwOSVersionInfoSize;
public Int32 dwMajorVersion;
public Int32 dwMinorVersion;
public Int32 dwBuildNumber;
public Int32 dwPlatformID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
public Int32 dwOemID;
public Int32 dwPageSize;
public Int32 wProcessorArchitecture;
public Int32 lpMinimumApplicationAddress;
public Int32 lpMaximumApplicationAddress;
public Int32 dwActiveProcessorMask;
public Int32 dwNumberOrfProcessors;
public Int32 dwProcessorType;
public Int32 dwAllocationGranularity;
public Int32 dwReserved;
}
public enum WinSuiteMask : int
{
VER_SUITE_SMALLBUSINESS = 1,
VER_SUITE_ENTERPRISE = 2,
VER_SUITE_BACKOFFICE = 4,
VER_SUITE_COMMUNICATIONS = 8,
VER_SUITE_TERMINAL = 16,
VER_SUITE_SMALLBUSINESS_RESTRICTED = 32,
VER_SUITE_EMBEDDEDNT = 64,
VER_SUITE_DATACENTER = 128,
VER_SUITE_SINGLEUSERTS = 256,
VER_SUITE_PERSONAL = 512,
VER_SUITE_BLADE = 1024,
VER_SUITE_STORAGE_SERVER = 8192,
VER_SUITE_COMPUTE_SERVER = 16384
}
public enum WinPlatform : byte
{
VER_NT_WORKSTATION = 1,
VER_NT_DOMAIN_CONTROLLER = 2,
VER_NT_SERVER = 3
}
public enum OSMajorVersion : byte
{
VER_OS_NT4 = 4,
VER_OS_2K_XP_2K3 = 5,
VER_OS_VISTA_LONGHORN = 6
}
private const Int32 SM_SERVERR2 = 89;
private const Int32 SM_MEDIACENTER = 87;
private const Int32 SM_TABLETPC = 86;
[DllImport("kernel32")]
private static extern int GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
[DllImport("user32")]
private static extern int GetSystemMetrics(int nIndex);
[DllImport("kernel32", EntryPoint = "GetVersion")]
private static extern int GetVersionAdv(ref OSVERSIONINFO lpVersionInformation);
[DllImport("kernel32")]
private static extern int GetVersionEx(ref OSVERSIONINFOEX lpVersionInformation);
/*public static string GetVersionEx()
{
OSVERSIONINFO osvi = new OSVERSIONINFO();
OSVERSIONINFOEX xosvi = new OSVERSIONINFOEX();
Int32 iRet = 0;
string strDetails = string.Empty;
osvi.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFO));
xosvi.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
try
{
iRet = (int)System.Environment.OSVersion.Platform;
if (iRet == 1)
{
iRet = GetVersionAdv(ref osvi);
strDetails = Environment.NewLine + "Version: " + osvi.dwMajorVersion + "." + osvi.dwMinorVersion + "." + osvi.dwBuildNumber + Environment.NewLine + osvi.szCSDVersion;
if (Len(osvi) == 0)
{
return "Windows 95" + strDetails;
}
else if (Len(osvi) == 10)
{
return "Windows 98" + strDetails;
}
else if (Len(osvi) == 9)
{
return "Windows ME" + strDetails;
}
}
else
{
iRet = GetVersionEx(xosvi);
strDetails = Environment.NewLine + "Version: " + xosvi.dwMajorVersion + "." + xosvi.dwMinorVersion + "." + xosvi.dwBuildNumber + Environment.NewLine + xosvi.szCSDVersion + " (" + xosvi.wServicePackMajor + "." + xosvi.wServicePackMinor + ")";
if (xosvi.dwMajorVersion == (byte)OSMajorVersion.VER_OS_NT4)
{
return "Windows NT 4" + strDetails;
}
else if (xosvi.dwMajorVersion == OSMajorVersion.VER_OS_2K_XP_2K3)
{
if (xosvi.dwMinorVersion == 0)
{
if (xosvi.wProductType == WinPlatform.VER_NT_WORKSTATION)
{
return "Windows 2000 Pro" + strDetails;
}
else if (xosvi.wProductType == WinPlatform.VER_NT_SERVER)
{
if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_DATACENTER) == WinSuiteMask.VER_SUITE_DATACENTER)
{
return "Windows 2000 Datacenter Server" + strDetails;
}
else if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_ENTERPRISE) == WinSuiteMask.VER_SUITE_ENTERPRISE)
{
return "Windows 2000 Advanced Server" + strDetails;
}
else if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_SMALLBUSINESS) == WinSuiteMask.VER_SUITE_SMALLBUSINESS)
{
return "Windows 2000 Small Business Server" + strDetails;
}
else
{
return "Windows 2000 Server" + strDetails;
}
}
else if (xosvi.wProductType == WinPlatform.VER_NT_DOMAIN_CONTROLLER)
{
if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_DATACENTER) == WinSuiteMask.VER_SUITE_DATACENTER)
{
return "Windows 2000 Datacenter Server Domain Controller" + strDetails;
}
else if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_ENTERPRISE) == WinSuiteMask.VER_SUITE_ENTERPRISE)
{
return "Windows 2000 Advanced Server Domain Controller" + strDetails;
}
else if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_SMALLBUSINESS) == WinSuiteMask.VER_SUITE_SMALLBUSINESS)
{
return "Windows 2000 Small Business Server Domain Controller" + strDetails;
}
else
{
return "Windows 2000 Server Domain Controller" + strDetails;
}
}
}
else if (xosvi.dwMinorVersion == 1)
{
if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_PERSONAL) == WinSuiteMask.VER_SUITE_PERSONAL)
{
return "Windows XP Home Edition" + strDetails;
}
else
{
return "Windows XP Professional Edition" + strDetails;
}
}
else if (xosvi.dwMinorVersion == 2)
{
if (xosvi.wProductType == WinPlatform.VER_NT_WORKSTATION)
{
return "Windows XP Professional x64 Edition" + strDetails;
}
else if (xosvi.wProductType == WinPlatform.VER_NT_SERVER)
{
if (GetSystemMetrics(SM_SERVERR2) == 1)
{
return "Windows Server 2003 R2" + strDetails;
}
else
{
return "Windows Server 2003" + strDetails;
}
}
else if (xosvi.wProductType == WinPlatform.VER_NT_DOMAIN_CONTROLLER)
{
if (GetSystemMetrics(SM_SERVERR2) == 1)
{
return "Windows Server 2003 R2 Domain Controller" + strDetails;
}
else
{
return "Windows Server 2003 Domain Controller" + strDetails;
}
}
}
}
else if (xosvi.dwMajorVersion == OSMajorVersion.VER_OS_VISTA_LONGHORN)
{
if (xosvi.wProductType == WinPlatform.VER_NT_WORKSTATION)
{
if ((xosvi.wSuiteMask & WinSuiteMask.VER_SUITE_PERSONAL) == WinSuiteMask.VER_SUITE_PERSONAL)
{
return "Windows Vista (Home Premium, Home Basic, or Home Ultimate) Edition";
}
else
{
return "Windows Vista (Enterprize or Business)" + strDetails;
}
}
else
{
return "Windows Server (Longhorn)" + strDetails;
}
}
}
}
catch
{
MessageBox.Show(GetLastError.ToString);
return string.Empty;
}
}*/
public enum WindowsVersion
{
Unknown = 0,
Windows95,
Windows98,
WindowsMe,
WindowsNT351,
WindowsNT4,
Windows2000,
WindowsXP,
WindowsServer2003,
Vista,
WindowsServer2008
}
/// <summary>
/// Determine OS version
/// </summary>
/// <returns></returns>
public static WindowsVersion GetVersion()
{
WindowsVersion ret = WindowsVersion.Unknown;
OSVERSIONINFOEX info = new OSVERSIONINFOEX();
info.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
GetVersionEx(ref info);
// Get OperatingSystem information from the system namespace.
System.OperatingSystem osInfo = System.Environment.OSVersion;
// Determine the platform.
switch (osInfo.Platform)
{
// Platform is Windows 95, Windows 98, Windows 98 Second Edition, or Windows Me.
case System.PlatformID.Win32Windows:
switch (osInfo.Version.Minor)
{
case 0:
ret = WindowsVersion.Windows95;
break;
case 10:
ret = WindowsVersion.Windows98;
break;
case 90:
ret = WindowsVersion.WindowsMe;
break;
}
break;
// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000, or Windows XP.
case System.PlatformID.Win32NT:
switch (osInfo.Version.Major)
{
case 3:
ret = WindowsVersion.WindowsNT351;
break;
case 4:
ret = WindowsVersion.WindowsNT4;
break;
case 5:
switch (osInfo.Version.Minor)
{
case 0:
ret = WindowsVersion.Windows2000;
break;
case 1:
ret = WindowsVersion.WindowsXP;
break;
case 2:
int i = GetSystemMetrics(SM_SERVERR2);
if (i != 0)
{
//Server 2003 R2
ret = WindowsVersion.WindowsServer2003;
}
else
{
if (info.wProductType == (byte)WinPlatform.VER_NT_WORKSTATION)
{
//XP Pro x64
ret = WindowsVersion.WindowsXP;
}
else
{
ret = WindowsVersion.WindowsServer2003;
}
break;
}
break;
}
break;
case 6:
if (info.wProductType == (byte)WinPlatform.VER_NT_WORKSTATION)
ret = WindowsVersion.Vista;
else
ret = WindowsVersion.WindowsServer2008;
break;
}
break;
}
return ret;
}
/// <summary>
/// Returns Windows directory
/// </summary>
/// <returns></returns>
public static string GetWindowsDirectory()
{
return Environment.GetEnvironmentVariable("windir");
}
}
}

View file

@ -0,0 +1,212 @@
// 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 Microsoft.Win32;
namespace WebsitePanel.Installer.Common
{
/// <summary>
/// Registry helper class.
/// </summary>
public sealed class RegistryUtils
{
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
private RegistryUtils()
{
}
/// <summary>
/// Retrieves the specified value from the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to retrieve.</param>
/// <returns>The data associated with name.</returns>
public static string GetRegistryKeyStringValue(string subkey, string name)
{
string ret = null;
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if ( rk != null )
{
ret = (string)rk.GetValue(name, string.Empty);
}
return ret;
}
/// <summary>
/// Retrieves the specified value from the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to retrieve.</param>
/// <returns>The data associated with name.</returns>
public static int GetRegistryKeyInt32Value(string subkey, string name)
{
int ret = 0;
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if ( rk != null )
{
ret = (int)rk.GetValue(name, 0);
}
return ret;
}
/// <summary>
/// Retrieves an array of strings that contains all the value names associated with this key.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <returns>An array of strings that contains the value names for the current key.</returns>
public static string[] GetRegistryKeyValues(string subkey)
{
string[] ret = null;
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if (rk != null)
{
ret = rk.GetValueNames();
}
return ret;
}
public static RegistryValueKind GetRegistryKeyValueKind(string subkey, string name)
{
RegistryValueKind ret = RegistryValueKind.Unknown;
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if (rk != null)
{
ret = rk.GetValueKind(name);
}
return ret;
}
/// <summary>
/// Retrieves the specified value from the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to retrieve.</param>
/// <returns>The data associated with name.</returns>
public static bool GetRegistryKeyBooleanValue(string subkey, string name)
{
bool ret = false;
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if ( rk != null )
{
string strValue = (string)rk.GetValue(name, "False");
ret = Boolean.Parse(strValue);
}
return ret;
}
/// <summary>
/// Deletes a registry subkey and any child subkeys.
/// </summary>
/// <param name="subkey">Subkey to delete.</param>
public static void DeleteRegistryKey(string subkey)
{
RegistryKey root = Registry.LocalMachine;
root.DeleteSubKeyTree(subkey);
}
/// <summary>
/// Sets the specified value to the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to store data in.</param>
/// <param name="value">Data to store. </param>
public static void SetRegistryKeyStringValue(string subkey, string name, string value)
{
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.CreateSubKey(subkey);
if ( rk != null )
{
rk.SetValue(name, value);
}
}
/// <summary>
/// Sets the specified value to the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to store data in.</param>
/// <param name="value">Data to store. </param>
public static void SetRegistryKeyInt32Value(string subkey, string name, int value)
{
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.CreateSubKey(subkey);
if ( rk != null )
{
rk.SetValue(name, value);
}
}
/// <summary>
/// Sets the specified value to the subkey.
/// </summary>
/// <param name="subkey">Subkey.</param>
/// <param name="name">Name of value to store data in.</param>
/// <param name="value">Data to store. </param>
public static void SetRegistryKeyBooleanValue(string subkey, string name, bool value)
{
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.CreateSubKey(subkey);
if ( rk != null )
{
rk.SetValue(name, value);
}
}
/// <summary>
/// Return the list of sub keys for the specified registry key.
/// </summary>
/// <param name="subkey">The name of the registry key</param>
/// <returns>The array of subkey names.</returns>
public static string[] GetRegistrySubKeys(string subkey)
{
string[] ret = new string[0];
RegistryKey root = Registry.LocalMachine;
RegistryKey rk = root.OpenSubKey(subkey);
if (rk != null)
ret = rk.GetSubKeyNames();
return ret;
}
public static Version GetIISVersion()
{
int major = GetRegistryKeyInt32Value("SOFTWARE\\Microsoft\\InetStp", "MajorVersion");
int minor = GetRegistryKeyInt32Value("SOFTWARE\\Microsoft\\InetStp", "MinorVersion");
return new Version(major, minor);
}
}
}

View file

@ -0,0 +1,393 @@
// 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.IO;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.Security.Principal;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Threading;
using WebsitePanel.Installer.Core;
using WebsitePanel.Installer.Configuration;
using System.Xml;
namespace WebsitePanel.Installer.Common
{
public class UserDecisionEventArgs : EventArgs
{
public bool Accepted { get; set; }
public string UserMessage { get; set; }
}
public static class Utils
{
public static void FixConfigurationSectionDefinition()
{
var appConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, String.Concat(AppConfigManager.AppConfigFileNameWithoutExtension, ".config"));
//
try
{
var configXmlDoc = new XmlDocument();
//
configXmlDoc.Load(appConfigPath);
//
var sectionDef = configXmlDoc.SelectSingleNode("//configSections/section[@name='installer']");
//
if (sectionDef == null)
{
return;
}
//
var typeDefString = sectionDef.Attributes["type"].Value;
//
if (typeDefString.EndsWith("WebsitePanel.Installer.Core") == false)
{
sectionDef.Attributes["type"].Value = "WebsitePanel.Installer.Configuration.InstallerSection, WebsitePanel.Installer.Core";
//
configXmlDoc.Save(appConfigPath);
}
}
catch (Exception ex)
{
Trace.TraceError("Failed to fix configuration section definition. Exception: {0}", ex);
}
}
#region DB
/// <summary>
/// Converts db value to string
/// </summary>
/// <param name="val">Value</param>
/// <returns>string</returns>
public static string GetDbString(object val)
{
string ret = string.Empty;
if ((val != null) && (val != DBNull.Value))
ret = (string)val;
return ret;
}
/// <summary>
/// Converts db value to short
/// </summary>
/// <param name="val">Value</param>
/// <returns>short</returns>
public static short GetDbShort(object val)
{
short ret = 0;
if ((val != null) && (val != DBNull.Value))
ret = (short)val;
return ret;
}
/// <summary>
/// Converts db value to int
/// </summary>
/// <param name="val">Value</param>
/// <returns>int</returns>
public static int GetDbInt32(object val)
{
int ret = 0;
if ((val != null) && (val != DBNull.Value))
ret = (int)val;
return ret;
}
/// <summary>
/// Converts db value to bool
/// </summary>
/// <param name="val">Value</param>
/// <returns>bool</returns>
public static bool GetDbBool(object val)
{
bool ret = false;
if ((val != null) && (val != DBNull.Value))
ret = Convert.ToBoolean(val);
return ret;
}
/// <summary>
/// Converts db value to decimal
/// </summary>
/// <param name="val">Value</param>
/// <returns>decimal</returns>
public static decimal GetDbDecimal(object val)
{
decimal ret = 0;
if ((val != null) && (val != DBNull.Value))
ret = (decimal)val;
return ret;
}
/// <summary>
/// Converts db value to datetime
/// </summary>
/// <param name="val">Value</param>
/// <returns>DateTime</returns>
public static DateTime GetDbDateTime(object val)
{
DateTime ret = DateTime.MinValue;
if ((val != null) && (val != DBNull.Value))
ret = (DateTime)val;
return ret;
}
#endregion
public static void ShowConsoleErrorMessage(string format, params object[] args)
{
Console.WriteLine(String.Format(format, args));
}
public static bool CheckForInstalledComponent(string componentCode)
{
bool ret = false;
List<string> installedComponents = new List<string>();
foreach (ComponentConfigElement componentConfig in AppConfigManager.AppConfiguration.Components)
{
string code = componentConfig.Settings[Global.Parameters.ComponentCode].Value;
installedComponents.Add(code);
if (code == componentCode)
{
ret = true;
break;
}
}
//
if (componentCode == "standalone")
{
if (installedComponents.Contains("server") ||
installedComponents.Contains("enterprise server") ||
installedComponents.Contains("portal"))
ret = true;
}
//
return ret;
}
public static bool IsThreadAbortException(Exception ex)
{
Exception innerException = ex;
while (innerException != null)
{
if (innerException is System.Threading.ThreadAbortException)
return true;
innerException = innerException.InnerException;
}
string str = ex.ToString();
return str.Contains("System.Threading.ThreadAbortException");
}
public static bool IsSecurityException(Exception ex)
{
if (ex is System.Security.SecurityException)
return true;
Exception innerException = ex;
while (innerException != null)
{
if (innerException is System.Security.SecurityException)
return true;
innerException = innerException.InnerException;
}
string str = ex.ToString();
return str.Contains("System.Security.SecurityException");
}
public static bool IsWin64()
{
return (IntPtr.Size == 8);
}
public static void SetObjectProperty(DirectoryEntry oDE, string name, object value)
{
if (value != null)
{
if (oDE.Properties.Contains(name))
{
oDE.Properties[name][0] = value;
}
else
{
oDE.Properties[name].Add(value);
}
}
}
public static object GetObjectProperty(DirectoryEntry entry, string name)
{
if (entry.Properties.Contains(name))
return entry.Properties[name][0];
else
return null;
}
public static bool IIS32Enabled()
{
bool enabled = false;
DirectoryEntry obj = new DirectoryEntry("IIS://LocalHost/W3SVC/AppPools");
object objProperty = GetObjectProperty(obj, "Enable32bitAppOnWin64");
if (objProperty != null)
{
enabled = (bool)objProperty;
}
return enabled;
}
public static void CheckWin64(EventHandler<UserDecisionEventArgs> callback)
{
if (IsWin64())
{
Log.WriteInfo("x64 detected");
string check = AppConfigManager.AppConfiguration.GetStringSetting(ConfigKeys.Settings_IIS64);
if (check == "False")
return;
//ignore win64 check on IIS7
if (Global.IISVersion.Major == 7)
return;
if (!IIS32Enabled())
{
Log.WriteInfo("IIS 32-bit mode disabled");
var args = new UserDecisionEventArgs
{
UserMessage = "WebsitePanel Installer has detected that Microsoft Internet Information Services (IIS) " +
"are running in 64-bit mode. It is recommended to switch IIS to 32-bit mode to " +
"enable compatibility with 32-bit applications. " +
"Please note that 64-bit web applications will not work in 32-bit mode.\n" +
"Do you want WebsitePanel Installer to switch IIS to 32-bit mode?"
};
if (callback != null)
{
callback(null, args);
}
if (AppConfigManager.AppConfiguration.Settings[ConfigKeys.Settings_IIS64] != null)
AppConfigManager.AppConfiguration.Settings[ConfigKeys.Settings_IIS64].Value = "False";
else
AppConfigManager.AppConfiguration.Settings.Add(ConfigKeys.Settings_IIS64, "False");
//
AppConfigManager.SaveConfiguration(false);
if (args.Accepted)
{
EnableIIS32();
}
}
else
{
Log.WriteInfo("IIS 32-bit mode enabled");
}
}
else
{
Log.WriteInfo("x86 detected");
}
}
private static void EnableIIS32()
{
Log.WriteStart("Enabling IIS 32-bit mode");
DirectoryEntry obj = new DirectoryEntry("IIS://LocalHost/W3SVC/AppPools");
SetObjectProperty(obj, "Enable32bitAppOnWin64", true);
obj.CommitChanges();
Log.WriteEnd("Enabled IIS 32-bit mode");
Log.WriteStart("Starting aspnet_regiis -i");
string path = Path.Combine(OS.GetWindowsDirectory(), @"Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe");
ProcessStartInfo info = new ProcessStartInfo(path, "-i");
//info.WindowStyle = ProcessWindowStyle.Minimized;
Process process = Process.Start(info);
process.WaitForExit();
Log.WriteEnd("Finished aspnet_regiis -i");
Log.WriteStart("Enabling Web Service Extension");
DirectoryEntry iis = new DirectoryEntry("IIS://LocalHost/W3SVC");
iis.Invoke("EnableWebServiceExtension", "ASP.NET v2.0.50727 (32-bit)");
iis.CommitChanges();
Log.WriteEnd("Enabled Web Service Extension");
}
/// <summary>
/// Check security permissions
/// </summary>
public static bool CheckSecurity()
{
try
{
PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
set.Demand();
}
catch
{
return false;
}
return true;
}
public static bool IsAdministrator()
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private static Mutex mutex = null;
public static void SaveMutex()
{
GC.KeepAlive(mutex);
}
public static bool IsNewInstance()
{
//check only one instance
bool createdNew = true;
mutex = new Mutex(true, "WebsitePanel Installer", out createdNew);
return createdNew;
}
}
}