/[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 153 - (show annotations) (download)
Sun Jul 15 13:17:36 2012 UTC (9 years, 4 months ago) by william
File size: 6605 byte(s)

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 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
33 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 public override void Install(IDictionary stateSaver)
71 {
72 base.Install(stateSaver);
73 try
74 {
75
76 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 DBServer = this.Context.Parameters["DBSERVER"];
82 DBInstance = this.Context.Parameters["DBINSTANCE"];
83 // 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 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
89 ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
90
91 InstallDatabase();
92 ConfigureATS();
93 }
94 }
95 catch (Exception ex)
96 {
97 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 // 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 {
105 Logging.ATSAdminInstallerLog.Error("Install() failed.");
106 }
107 throw ex;
108 }
109 }
110
111 private void CreateRegistryConfigKeys()
112 {
113 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 }
137 catch (Exception ex)
138 {
139 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
140 {
141 Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
142 }
143 }
144 }
145 }
146 }

  ViewVC Help
Powered by ViewVC 1.1.22