/[AnywhereTS-MSSQL]/trunk/TSAdminTool/ATSAmdin.Installer.cs
ViewVC logotype

Annotation of /trunk/TSAdminTool/ATSAmdin.Installer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations) (download)
Sun Jul 15 13:17:36 2012 UTC (8 years, 7 months ago) by william
File size: 6605 byte(s)

1 william 145 using System;
2     using System.Collections;
3     using System.Collections.Generic;
4     using System.ComponentModel;
5     using System.Configuration.Install;
6     using System.Linq;
7 william 149 using System.Reflection;
8 william 152 using System.Threading;
9     using System.Windows.Forms;
10     using System.Drawing;
11 william 145
12    
13     namespace AnywhereTS
14     {
15     [RunInstaller(true)]
16     public partial class ATSAmdin : System.Configuration.Install.Installer
17     {
18 william 152 string DBServer;
19     string DBInstance;
20 william 145 public ATSAmdin()
21     {
22     InitializeComponent();
23     }
24 william 152 Exception install_ex = null;
25     DatabaseInstallerWaitDialog dlg;
26     public void InstallDatabaseWaitMessage()
27     {
28     dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName));
29     dlg.ForeColor = Color.Black;
30     dlg.ShowDialog();
31     }
32 william 149
33 william 153 private void InstallDatabase()
34     {
35     // install the database
36     Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage));
37     db_installer_thread.IsBackground = true;
38     db_installer_thread.Start();
39     Logging.ATSAdminInstallerLog.DebugFormat(@"Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
40     AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport();
41     dbsup.SetupDatabase();
42     dlg.Message = string.Format(@"Successfully installed the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
43     dlg.ForeColor = Color.Green;
44     Thread.Sleep(new TimeSpan(0, 0, 15));
45     dlg.Close();
46     Logging.ATSAdminInstallerLog.DebugFormat(@"Successfully Installed database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
47     }
48    
49     private void ConfigureATS()
50     {
51     try
52     {
53     frmAdmin atsadmin = new frmAdmin();
54     if (!atsadmin.ConfigureATS())
55     {
56     throw new Exception("AnywhereTS cannot be installed without configuring it first.");
57     }
58     }
59     catch (Exception ex)
60     {
61     // database install failed
62     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
63     {
64     Logging.ATSAdminInstallerLog.Error("ConfigureATS() failed.");
65     }
66     throw ex;
67     }
68     }
69    
70 william 149 public override void Install(IDictionary stateSaver)
71     {
72     base.Install(stateSaver);
73 william 150 try
74     {
75 william 152
76 william 150 string path = this.Context.Parameters["targetdir"];
77     Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
78     using (log4net.NDC.Push("Logged from ATSAdmin.Installer"))
79     {
80     // setup database
81 william 152 DBServer = this.Context.Parameters["DBSERVER"];
82     DBInstance = this.Context.Parameters["DBINSTANCE"];
83 william 150 // Log the entered data
84     Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance);
85     CreateRegistryConfigKeys();
86     ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
87     ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
88 william 152 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
89     ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
90 william 153
91     InstallDatabase();
92     ConfigureATS();
93 william 149 }
94 william 150 }
95     catch (Exception ex)
96     {
97 william 152 Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
98     dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
99     dlg.ForeColor = Color.Red;
100     Thread.Sleep(new TimeSpan(0, 0, 15));
101     dlg.Close();
102 william 150 // database install failed
103     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
104 william 149 {
105 william 150 Logging.ATSAdminInstallerLog.Error("Install() failed.");
106 william 149 }
107 william 150 throw ex;
108 william 149 }
109     }
110    
111     private void CreateRegistryConfigKeys()
112     {
113 william 150 try
114     {
115     Microsoft.Win32.RegistryKey key = null;
116     if (IntPtr.Size == 8)
117     { // 64 bit OS
118     //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
119     key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
120     key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
121     key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
122     }
123     else
124     { // 32 bit OS
125     //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
126     key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
127     key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
128     key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
129     }
130    
131     // AdminVersion = 2
132     key.SetValue("AdminVersion", 2);
133     // RunFirstTime = 1
134     key.SetValue("RunFirstTime", 1);
135     ATSGlobals.CreateRegistryValues();
136 william 149 }
137 william 150 catch (Exception ex)
138     {
139 william 152 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
140 william 150 {
141     Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
142     }
143 william 149 }
144     }
145 william 145 }
146     }

  ViewVC Help
Powered by ViewVC 1.1.22