using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Configuration.Install; using System.Linq; using System.Reflection; using System.Threading; using System.Windows.Forms; using System.Drawing; namespace AnywhereTS { [RunInstaller(true)] public partial class ATSAmdin : System.Configuration.Install.Installer { string DBServer; string DBInstance; public ATSAmdin() { InitializeComponent(); } DatabaseInstallerWaitDialog dlg; public void InstallDatabaseWaitMessage() { dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName)); dlg.ForeColor = Color.Black; dlg.ShowDialog(); } private void InstallDatabase() { // install the database Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage)); db_installer_thread.IsBackground = true; db_installer_thread.Start(); Logging.ATSAdminInstallerLog.DebugFormat(@"Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport(); dbsup.SetupDatabase(); dlg.Message = string.Format(@"Successfully installed the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); dlg.ForeColor = Color.Green; Thread.Sleep(new TimeSpan(0, 0, 15)); dlg.Close(); Logging.ATSAdminInstallerLog.DebugFormat(@"Successfully Installed database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); } private void ConfigureATS() { try { Logging.ATSAdminInstallerLog.Debug("Configuring AnywhereTS"); frmAdmin atsadmin = new frmAdmin(); if (!atsadmin.ConfigureATS()) { throw new Exception("AnywhereTS cannot be installed without configuring it first."); } Logging.ATSAdminInstallerLog.Debug("Successfully Configured AnywhereTS"); } catch (Exception ex) { // database install failed using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) { Logging.ATSAdminInstallerLog.Error("ConfigureATS() failed."); } throw ex; } } public override void Install(IDictionary stateSaver) { base.Install(stateSaver); try { string path = this.Context.Parameters["targetdir"]; Logging.UpdateLogPath(string.Format(@"{0}\logs", path)); using (log4net.NDC.Push("Logged from ATSAdmin.Installer")) { // setup database DBServer = this.Context.Parameters["DBSERVER"]; DBInstance = this.Context.Parameters["DBINSTANCE"]; // Log the entered data Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance); CreateRegistryConfigKeys(); ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer); ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance); ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); InstallDatabase(); ConfigureATS(); } } catch (Exception ex) { Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); dlg.ForeColor = Color.Red; Thread.Sleep(new TimeSpan(0, 0, 15)); dlg.Close(); // database install failed using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) { Logging.ATSAdminInstallerLog.Error("Install() failed."); } throw ex; } } private void CreateRegistryConfigKeys() { try { Microsoft.Win32.RegistryKey key = null; if (IntPtr.Size == 8) { // 64 bit OS //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true); key.CreateSubKey("TFTPD32").CreateSubKey("DHCP"); key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config"); } else { // 32 bit OS //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true); key.CreateSubKey("TFTPD32").CreateSubKey("DHCP"); key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config"); } // AdminVersion = 2 key.SetValue("AdminVersion", 2); // RunFirstTime = 1 key.SetValue("RunFirstTime", 1); ATSGlobals.CreateRegistryValues(); } catch (Exception ex) { using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) { Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed."); } } } } }