8 |
using System.Threading; |
using System.Threading; |
9 |
using System.Windows.Forms; |
using System.Windows.Forms; |
10 |
using System.Drawing; |
using System.Drawing; |
11 |
|
using AnywhereTS.DBSupport; |
12 |
|
using System.Data.SqlClient; |
13 |
|
|
14 |
|
|
15 |
namespace AnywhereTS |
namespace AnywhereTS |
23 |
{ |
{ |
24 |
InitializeComponent(); |
InitializeComponent(); |
25 |
} |
} |
26 |
Exception install_ex = null; |
#region Install Members |
27 |
DatabaseInstallerWaitDialog dlg; |
DatabaseInstallerWaitDialog dlg; |
28 |
public void InstallDatabaseWaitMessage() |
public void InstallDatabaseWaitMessage() |
29 |
{ |
{ |
30 |
dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName)); |
dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName)); |
31 |
dlg.ForeColor = Color.Black; |
dlg.ForeColor = Color.Black; |
32 |
dlg.ShowDialog(); |
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) |
public override void Install(IDictionary stateSaver) |
90 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance); |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance); |
91 |
ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); |
ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); |
92 |
ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); |
ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); |
93 |
// install the database |
|
94 |
Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage)); |
InstallDatabase(); |
95 |
db_installer_thread.IsBackground = true; |
ConfigureATS(); |
|
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); |
|
96 |
} |
} |
97 |
} |
} |
98 |
catch (Exception ex) |
catch (Exception ex) |
145 |
} |
} |
146 |
} |
} |
147 |
} |
} |
148 |
|
#endregion |
149 |
|
|
150 |
|
public override void Uninstall(IDictionary savedState) |
151 |
|
{ |
152 |
|
using (log4net.NDC.Push("Logged from ATSAdmin.Installer")) |
153 |
|
{ |
154 |
|
try |
155 |
|
{ |
156 |
|
string path = this.Context.Parameters["targetdir"]; |
157 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Install Dir: {0}", path); |
158 |
|
Logging.UpdateLogPath(string.Format(@"{0}\logs", path)); |
159 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Showing uninstall dialog"); |
160 |
|
UninstallDialog udlg = new UninstallDialog(); |
161 |
|
DialogResult result = udlg.ShowDialog(); |
162 |
|
if (result == DialogResult.Cancel) |
163 |
|
{ |
164 |
|
Logging.ATSAdminInstallerLog.DebugFormat("user aborted uninstall"); |
165 |
|
MessageBox.Show("Uninstall canceled ... nothing was uninstalled", "Uinstall was canceled by user", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
166 |
|
return; |
167 |
|
} |
168 |
|
base.Uninstall(savedState); |
169 |
|
using (log4net.NDC.Push(string.Format("KeepDatabase={0} KeepApplicationSettings={1} KeepClientImages={2}", udlg.KeepDatabase, udlg.KeepApplicationSettings, udlg.KeepClientImages))) |
170 |
|
{ |
171 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Unistall options"); |
172 |
|
} |
173 |
|
string server = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); |
174 |
|
string instance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); |
175 |
|
string database = ATSGlobals.strDatabaseName; |
176 |
|
if (!udlg.KeepDatabase) |
177 |
|
{ |
178 |
|
Exception ErrorInfo = null; |
179 |
|
// delete database |
180 |
|
using (MsSqlConnector conn = new MsSqlConnector(server, instance, "master")) |
181 |
|
{ |
182 |
|
try |
183 |
|
{ |
184 |
|
conn.CreateConnection(out ErrorInfo); |
185 |
|
conn.OpenConnection(out ErrorInfo); |
186 |
|
SqlConnection sqlCon; |
187 |
|
conn.GetConnectionClone(out sqlCon, out ErrorInfo); |
188 |
|
SqlCommand sqlCmd = new SqlCommand(); |
189 |
|
sqlCmd.Connection = sqlCon; |
190 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Removing database: {0}", database); |
191 |
|
sqlCmd.CommandText = string.Format("DROP DATABASE {0};",database); |
192 |
|
sqlCmd.ExecuteNonQuery(); |
193 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed database: {0}", database); |
194 |
|
} |
195 |
|
catch (Exception ex) |
196 |
|
{ |
197 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove database: {0}", database); |
198 |
|
ErrorInfo = ex; |
199 |
|
} |
200 |
|
} |
201 |
|
if (ErrorInfo != null) |
202 |
|
throw ErrorInfo; |
203 |
|
} |
204 |
|
if (!udlg.KeepApplicationSettings) |
205 |
|
{ |
206 |
|
// delete registry settings |
207 |
|
try |
208 |
|
{ |
209 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Removing AnywhereTS Registry settings"); |
210 |
|
Microsoft.Win32.RegistryKey key = null; |
211 |
|
if (IntPtr.Size == 8) |
212 |
|
{ // 64 bit OS |
213 |
|
//string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; |
214 |
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true); |
215 |
|
key.DeleteSubKey("TFTPD32", false); |
216 |
|
key.DeleteSubKey(ATSGlobals.ApplicationName, false); |
217 |
|
} |
218 |
|
else |
219 |
|
{ // 32 bit OS |
220 |
|
//strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; |
221 |
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true); |
222 |
|
key.DeleteSubKey("TFTPD32", false); |
223 |
|
key.DeleteSubKey(ATSGlobals.ApplicationName, false); |
224 |
|
} |
225 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed AnywhereTS Registry settings"); |
226 |
|
} |
227 |
|
catch (Exception ex) |
228 |
|
{ |
229 |
|
Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove AnywhereTS Registry settings"); |
230 |
|
throw ex; |
231 |
|
} |
232 |
|
} |
233 |
|
if (!udlg.KeepClientImages) |
234 |
|
{ |
235 |
|
// delete client images |
236 |
|
try |
237 |
|
{ |
238 |
|
} |
239 |
|
catch (Exception ex) |
240 |
|
{ |
241 |
|
} |
242 |
|
} |
243 |
|
} |
244 |
|
catch (Exception ex) |
245 |
|
{ |
246 |
|
// database install failed |
247 |
|
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
248 |
|
{ |
249 |
|
Logging.ATSAdminInstallerLog.Error("Install() failed."); |
250 |
|
} |
251 |
|
throw ex; |
252 |
|
} |
253 |
|
} |
254 |
|
} |
255 |
} |
} |
256 |
} |
} |