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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (show annotations) (download)
Mon Jul 16 11:38:24 2012 UTC (7 years, 7 months ago) by william
File size: 14055 byte(s)
+ fix install process
* when repairing install get DBServer and DBInstance from registry

1 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 using System.Reflection;
8 using System.Threading;
9 using System.Windows.Forms;
10 using System.Drawing;
11 using AnywhereTS.DBSupport;
12 using System.Data.SqlClient;
13
14
15 namespace AnywhereTS
16 {
17 [RunInstaller(true)]
18 public partial class ATSAmdin : System.Configuration.Install.Installer
19 {
20 string DBServer;
21 string DBInstance;
22 public ATSAmdin()
23 {
24 InitializeComponent();
25 }
26 #region Install Members
27 DatabaseInstallerWaitDialog dlg;
28 public void InstallDatabaseWaitMessage()
29 {
30 dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName));
31 dlg.ForeColor = Color.Black;
32 dlg.ShowDialog();
33 }
34 private void InstallDatabase()
35 {
36 // install the database
37 Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage));
38 db_installer_thread.IsBackground = true;
39 db_installer_thread.Start();
40 Logging.ATSAdminInstallerLog.DebugFormat(@"Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
41 AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport();
42 dbsup.SetupDatabase();
43 dlg.Message = string.Format(@"Successfully installed the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
44 dlg.ForeColor = Color.Green;
45 Thread.Sleep(new TimeSpan(0, 0, 15));
46 dlg.Close();
47 Logging.ATSAdminInstallerLog.DebugFormat(@"Successfully Installed database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
48 }
49
50 private void ConfigureATS()
51 {
52 try
53 {
54 Logging.ATSAdminInstallerLog.Debug("Configuring AnywhereTS");
55 frmAdmin atsadmin = new frmAdmin();
56 if (!atsadmin.ConfigureATS())
57 {
58 throw new Exception("AnywhereTS cannot be installed without configuring it first.");
59 }
60 Logging.ATSAdminInstallerLog.Debug("Successfully Configured AnywhereTS");
61 }
62 catch (Exception ex)
63 {
64 // database install failed
65 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
66 {
67 Logging.ATSAdminInstallerLog.Error("ConfigureATS() failed.");
68 }
69 throw ex;
70 }
71 }
72
73 public override void Install(IDictionary stateSaver)
74 {
75 base.Install(stateSaver);
76 try
77 {
78
79 string path = this.Context.Parameters["targetdir"];
80 Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
81 using (log4net.NDC.Push("Logged from ATSAdmin.Installer"))
82 {
83 // setup database
84 DBServer = this.Context.Parameters["DBSERVER"];
85 DBInstance = this.Context.Parameters["DBINSTANCE"];
86 try
87 {
88 string server = string.Empty;
89 string instance = string.Empty;
90
91 try { server = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); }
92 catch { }
93 try { instance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); }
94 catch { }
95 Logging.ATSAdminInstallerLog.DebugFormat("RegServer={0} RegInstance={1}", server, instance);
96
97 if (!string.IsNullOrEmpty(server))
98 DBServer = server;
99 if (!string.IsNullOrEmpty(instance))
100 DBInstance = instance;
101 }
102 catch
103 {
104 DBServer = this.Context.Parameters["DBSERVER"];
105 DBInstance = this.Context.Parameters["DBINSTANCE"];
106 }
107
108
109 // Log the entered data
110 Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance);
111 CreateRegistryConfigKeys();
112 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
113 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
114 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
115 ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
116
117 InstallDatabase();
118 ConfigureATS();
119 }
120 }
121 catch (Exception ex)
122 {
123 Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
124 dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
125 dlg.ForeColor = Color.Red;
126 Thread.Sleep(new TimeSpan(0, 0, 15));
127 dlg.Close();
128 // database install failed
129 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
130 {
131 Logging.ATSAdminInstallerLog.Error("Install() failed.");
132 }
133 throw ex;
134 }
135 }
136
137 private void CreateRegistryConfigKeys()
138 {
139 try
140 {
141 Microsoft.Win32.RegistryKey key = null;
142 if (IntPtr.Size == 8)
143 { // 64 bit OS
144 //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
145 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
146 key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
147 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
148 }
149 else
150 { // 32 bit OS
151 //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
152 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
153 key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
154 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
155 }
156
157 // AdminVersion = 2
158 key.SetValue("AdminVersion", 2);
159 // RunFirstTime = 1
160 key.SetValue("RunFirstTime", 1);
161 ATSGlobals.CreateRegistryValues();
162 }
163 catch (Exception ex)
164 {
165 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
166 {
167 Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
168 }
169 }
170 }
171 #endregion
172
173 public override void Uninstall(IDictionary savedState)
174 {
175 using (log4net.NDC.Push("Logged from ATSAdmin.Installer"))
176 {
177 try
178 {
179 string path = this.Context.Parameters["targetdir"];
180 Logging.ATSAdminInstallerLog.DebugFormat("Install Dir: {0}", path);
181 Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
182 Logging.ATSAdminInstallerLog.DebugFormat("Showing uninstall dialog");
183 UninstallDialog udlg = new UninstallDialog();
184 DialogResult result = udlg.ShowDialog();
185 if (result == DialogResult.Cancel)
186 {
187 Logging.ATSAdminInstallerLog.DebugFormat("user aborted uninstall");
188 MessageBox.Show("Uninstall canceled ... nothing was uninstalled", "Uinstall was canceled by user", MessageBoxButtons.OK, MessageBoxIcon.Warning);
189 return;
190 }
191 base.Uninstall(savedState);
192 using (log4net.NDC.Push(string.Format("KeepDatabase={0} KeepApplicationSettings={1} KeepClientImages={2}", udlg.KeepDatabase, udlg.KeepApplicationSettings, udlg.KeepClientImages)))
193 {
194 Logging.ATSAdminInstallerLog.DebugFormat("Unistall options");
195 }
196 string server = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
197 string instance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
198 string database = ATSGlobals.strDatabaseName;
199 if (!udlg.KeepDatabase)
200 {
201 Exception ErrorInfo = null;
202 // delete database
203 using (MsSqlConnector conn = new MsSqlConnector(server, instance, "master"))
204 {
205 try
206 {
207 conn.CreateConnection(out ErrorInfo);
208 conn.OpenConnection(out ErrorInfo);
209 SqlConnection sqlCon;
210 conn.GetConnectionClone(out sqlCon, out ErrorInfo);
211 SqlCommand sqlCmd = new SqlCommand();
212 sqlCmd.Connection = sqlCon;
213 Logging.ATSAdminInstallerLog.DebugFormat("Removing database: {0}", database);
214 sqlCmd.CommandText = string.Format("DROP DATABASE {0};",database);
215 sqlCmd.ExecuteNonQuery();
216 Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed database: {0}", database);
217 }
218 catch (Exception ex)
219 {
220 Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove database: {0}", database);
221 ErrorInfo = ex;
222 }
223 }
224 if (ErrorInfo != null)
225 throw ErrorInfo;
226 }
227 if (!udlg.KeepApplicationSettings)
228 {
229 // delete registry settings
230 try
231 {
232 Logging.ATSAdminInstallerLog.DebugFormat("Removing AnywhereTS Registry settings");
233 Microsoft.Win32.RegistryKey key = null;
234 if (IntPtr.Size == 8)
235 { // 64 bit OS
236 //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
237 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
238 key.DeleteSubKeyTree("TFTPD32", false);
239 key.DeleteSubKeyTree(ATSGlobals.ApplicationName, false);
240 }
241 else
242 { // 32 bit OS
243 //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
244 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
245 key.DeleteSubKeyTree("TFTPD32", false);
246 key.DeleteSubKeyTree(ATSGlobals.ApplicationName, false);
247 }
248 Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed AnywhereTS Registry settings");
249 }
250 catch (Exception ex)
251 {
252 Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove AnywhereTS Registry settings");
253 throw ex;
254 }
255 }
256 if (!udlg.KeepClientImages)
257 {
258 // delete client images
259 try
260 {
261 Logging.ATSAdminInstallerLog.Warn("Deleteing Client Images has not been implemented yet.");
262 }
263 catch (Exception ex)
264 {
265 throw ex;
266 }
267 }
268 }
269 catch (Exception ex)
270 {
271 // database install failed
272 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
273 {
274 Logging.ATSAdminInstallerLog.Error("Install() failed.");
275 }
276 throw ex;
277 }
278 }
279 }
280 }
281 }

  ViewVC Help
Powered by ViewVC 1.1.22