/[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 155 - (show annotations) (download)
Sun Jul 15 13:35:48 2012 UTC (8 years, 7 months ago) by william
File size: 6737 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 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 Logging.ATSAdminInstallerLog.Debug("Configuring AnywhereTS");
53 frmAdmin atsadmin = new frmAdmin();
54 if (!atsadmin.ConfigureATS())
55 {
56 throw new Exception("AnywhereTS cannot be installed without configuring it first.");
57 }
58 Logging.ATSAdminInstallerLog.Debug("Successfully Configured AnywhereTS");
59 }
60 catch (Exception ex)
61 {
62 // database install failed
63 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
64 {
65 Logging.ATSAdminInstallerLog.Error("ConfigureATS() failed.");
66 }
67 throw ex;
68 }
69 }
70
71 public override void Install(IDictionary stateSaver)
72 {
73 base.Install(stateSaver);
74 try
75 {
76
77 string path = this.Context.Parameters["targetdir"];
78 Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
79 using (log4net.NDC.Push("Logged from ATSAdmin.Installer"))
80 {
81 // setup database
82 DBServer = this.Context.Parameters["DBSERVER"];
83 DBInstance = this.Context.Parameters["DBINSTANCE"];
84 // Log the entered data
85 Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance);
86 CreateRegistryConfigKeys();
87 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
88 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
89 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
90 ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
91
92 InstallDatabase();
93 ConfigureATS();
94 }
95 }
96 catch (Exception ex)
97 {
98 Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
99 dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
100 dlg.ForeColor = Color.Red;
101 Thread.Sleep(new TimeSpan(0, 0, 15));
102 dlg.Close();
103 // database install failed
104 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
105 {
106 Logging.ATSAdminInstallerLog.Error("Install() failed.");
107 }
108 throw ex;
109 }
110 }
111
112 private void CreateRegistryConfigKeys()
113 {
114 try
115 {
116 Microsoft.Win32.RegistryKey key = null;
117 if (IntPtr.Size == 8)
118 { // 64 bit OS
119 //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
120 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
121 key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
122 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
123 }
124 else
125 { // 32 bit OS
126 //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
127 key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
128 key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
129 key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
130 }
131
132 // AdminVersion = 2
133 key.SetValue("AdminVersion", 2);
134 // RunFirstTime = 1
135 key.SetValue("RunFirstTime", 1);
136 ATSGlobals.CreateRegistryValues();
137 }
138 catch (Exception ex)
139 {
140 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
141 {
142 Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
143 }
144 }
145 }
146 }
147 }

  ViewVC Help
Powered by ViewVC 1.1.22