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

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 public override void Install(IDictionary stateSaver)
34 {
35 base.Install(stateSaver);
36 try
37 {
38
39 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 DBServer = this.Context.Parameters["DBSERVER"];
45 DBInstance = this.Context.Parameters["DBINSTANCE"];
46 // 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 ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer);
52 ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance);
53 // install the database
54 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 AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport();
59 dbsup.SetupDatabase();
60 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 }
66 }
67 catch (Exception ex)
68 {
69 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 // 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 {
77 Logging.ATSAdminInstallerLog.Error("Install() failed.");
78 }
79 throw ex;
80 }
81 }
82
83 private void CreateRegistryConfigKeys()
84 {
85 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 }
109 catch (Exception ex)
110 {
111 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
112 {
113 Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed.");
114 }
115 }
116 }
117 }
118 }

  ViewVC Help
Powered by ViewVC 1.1.22