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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (hide annotations) (download)
Sun Jul 15 13:35:48 2012 UTC (8 years, 7 months ago) by william
File size: 6737 byte(s)

1 william 145 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 william 149 using System.Reflection;
8 william 152 using System.Threading;
9     using System.Windows.Forms;
10     using System.Drawing;
11 william 145
12    
13     namespace AnywhereTS
14     {
15     [RunInstaller(true)]
16     public partial class ATSAmdin : System.Configuration.Install.Installer
17     {
18 william 152 string DBServer;
19     string DBInstance;
20 william 145 public ATSAmdin()
21     {
22     InitializeComponent();
23     }
24 william 152 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 william 149
32 william 153 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 william 155 Logging.ATSAdminInstallerLog.Debug("Configuring AnywhereTS");
53 william 153 frmAdmin atsadmin = new frmAdmin();
54     if (!atsadmin.ConfigureATS())
55     {
56     throw new Exception("AnywhereTS cannot be installed without configuring it first.");
57     }
58 william 155 Logging.ATSAdminInstallerLog.Debug("Successfully Configured AnywhereTS");
59 william 153 }
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 william 149 public override void Install(IDictionary stateSaver)
72     {
73     base.Install(stateSaver);
74 william 150 try
75     {
76 william 152
77 william 150 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 william 152 DBServer = this.Context.Parameters["DBSERVER"];
83     DBInstance = this.Context.Parameters["DBINSTANCE"];
84 william 150 // 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 william 152 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
90     ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
91 william 153
92     InstallDatabase();
93     ConfigureATS();
94 william 149 }
95 william 150 }
96     catch (Exception ex)
97     {
98 william 152 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 william 150 // 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 william 149 {
106 william 150 Logging.ATSAdminInstallerLog.Error("Install() failed.");
107 william 149 }
108 william 150 throw ex;
109 william 149 }
110     }
111    
112     private void CreateRegistryConfigKeys()
113     {
114 william 150 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 william 149 }
138 william 150 catch (Exception ex)
139     {
140 william 152 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
141 william 150 {
142     Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
143     }
144 william 149 }
145     }
146 william 145 }
147     }

  ViewVC Help
Powered by ViewVC 1.1.22