/[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 154 - (show annotations) (download)
Sun Jul 15 13:27:58 2012 UTC (7 years, 7 months ago) by william
File size: 6567 byte(s)
+ remove old connection string property

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

  ViewVC Help
Powered by ViewVC 1.1.22