/[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 152 - (hide annotations) (download)
Sun Jul 15 13:01:23 2012 UTC (8 years, 7 months ago) by william
File size: 5776 byte(s)
+ successfully install database from installer (if give right server and instance)

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 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 william 149
33     public override void Install(IDictionary stateSaver)
34     {
35     base.Install(stateSaver);
36 william 150 try
37     {
38 william 152
39 william 150 string path = this.Context.Parameters["targetdir"];
40     Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
41     using (log4net.NDC.Push("Logged from ATSAdmin.Installer"))
42     {
43     // setup database
44 william 152 DBServer = this.Context.Parameters["DBSERVER"];
45     DBInstance = this.Context.Parameters["DBINSTANCE"];
46 william 150 // Log the entered data
47     Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance);
48     CreateRegistryConfigKeys();
49     ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
50     ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
51 william 152 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
52     ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
53 william 150 // install the database
54 william 152 Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage));
55     db_installer_thread.IsBackground = true;
56     db_installer_thread.Start();
57     Logging.ATSAdminInstallerLog.DebugFormat(@"Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
58 william 149 AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport();
59     dbsup.SetupDatabase();
60 william 152 dlg.Message = string.Format(@"Successfully installed the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
61     dlg.ForeColor = Color.Green;
62     Thread.Sleep(new TimeSpan(0,0,15));
63     dlg.Close();
64     Logging.ATSAdminInstallerLog.DebugFormat(@"Successfully Installed database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
65 william 149 }
66 william 150 }
67     catch (Exception ex)
68     {
69 william 152 Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
70     dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName);
71     dlg.ForeColor = Color.Red;
72     Thread.Sleep(new TimeSpan(0, 0, 15));
73     dlg.Close();
74 william 150 // database install failed
75     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
76 william 149 {
77 william 150 Logging.ATSAdminInstallerLog.Error("Install() failed.");
78 william 149 }
79 william 150 throw ex;
80 william 149 }
81     }
82    
83     private void CreateRegistryConfigKeys()
84     {
85 william 150 try
86     {
87     Microsoft.Win32.RegistryKey key = null;
88     if (IntPtr.Size == 8)
89     { // 64 bit OS
90     //string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
91     key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true);
92     key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
93     key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
94     }
95     else
96     { // 32 bit OS
97     //strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
98     key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
99     key.CreateSubKey("TFTPD32").CreateSubKey("DHCP");
100     key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config");
101     }
102    
103     // AdminVersion = 2
104     key.SetValue("AdminVersion", 2);
105     // RunFirstTime = 1
106     key.SetValue("RunFirstTime", 1);
107     ATSGlobals.CreateRegistryValues();
108 william 149 }
109 william 150 catch (Exception ex)
110     {
111 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())))
112 william 150 {
113     Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
114     }
115 william 149 }
116     }
117 william 145 }
118     }

  ViewVC Help
Powered by ViewVC 1.1.22