1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Data; |
5 |
using System.Drawing; |
6 |
using System.Text; |
7 |
using System.Windows.Forms; |
8 |
using System.IO; |
9 |
|
10 |
namespace AnywhereTS |
11 |
{ |
12 |
public partial class frmConfigMode : Form |
13 |
{ |
14 |
DatabaseSupport dataSupport; |
15 |
|
16 |
public frmConfigMode() |
17 |
{ |
18 |
InitializeComponent(); |
19 |
} |
20 |
|
21 |
private void Mode_Load(object sender, EventArgs e) |
22 |
{ |
23 |
//this.Cursor = Cursors.WaitCursor; |
24 |
if (ATSGlobals.configured == 0) |
25 |
{ // ATS not configured yet |
26 |
radManagedMode.Checked = true; |
27 |
txtDatabasePath.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS"; |
28 |
txtDestinationDir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\AnywhereTS"; |
29 |
} |
30 |
else |
31 |
{ // ATS already configured |
32 |
txtDatabasePath.Text = ProSupport.strDatabasePath; |
33 |
txtDestinationDir.Text = ProSupport.strDestDir; |
34 |
txtDatabasePath.Enabled = false; |
35 |
btnBrowseDatabase.Enabled = false; |
36 |
// Update radio buttons |
37 |
if (ATSGlobals.managedMode == 1) |
38 |
// We are running in managed mode |
39 |
radManagedMode.Checked = true; |
40 |
|
41 |
else if (ATSGlobals.managedMode == 2) |
42 |
{ // We are running in unmanaged mode |
43 |
radUnmanagedMode.Checked = true; |
44 |
} |
45 |
} |
46 |
|
47 |
this.Cursor = Cursors.Default; |
48 |
|
49 |
} |
50 |
|
51 |
|
52 |
private void btnOK_Click(object sender, EventArgs e) |
53 |
{ |
54 |
if (radManagedMode.Checked) |
55 |
{ // Managed mode is selected |
56 |
// Validate database directory |
57 |
if (txtDatabasePath.Text.Trim().Length == 0) |
58 |
{ |
59 |
MessageBox.Show("You must specifiy a directory for the AnywhereTS database."); |
60 |
txtDatabasePath.Focus(); |
61 |
return; |
62 |
} |
63 |
this.Cursor = Cursors.WaitCursor; |
64 |
|
65 |
// Create Datbase directory |
66 |
try |
67 |
{ |
68 |
Directory.CreateDirectory(txtDatabasePath.Text.Trim()); |
69 |
} |
70 |
catch (Exception ex) |
71 |
{ |
72 |
this.Cursor = Cursors.Default; |
73 |
MessageBox.Show("Could not create directory '" + txtDatabasePath.Text.Trim() + "'. Error: " + ex.Message); |
74 |
using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString()))) |
75 |
{ |
76 |
using (log4net.NDC.Push(string.Format("directory={0}", txtDatabasePath.Text))) |
77 |
{ |
78 |
Logging.ATSAdminLog.Error("Could not create directory."); |
79 |
} |
80 |
} |
81 |
return; |
82 |
} |
83 |
|
84 |
// Save the database directory to registry |
85 |
ProSupport.strDatabasePath = txtDatabasePath.Text.Trim(); |
86 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath); |
87 |
|
88 |
// Set up database |
89 |
dataSupport = new DatabaseSupport(); |
90 |
dataSupport.SetupDatabase(); // Creates updates the database if necessary |
91 |
|
92 |
ATSGlobals.managedMode = 1; // We are running in Managed Mode |
93 |
} |
94 |
else if (radUnmanagedMode.Checked) |
95 |
{ // Unmanaged mode is selected |
96 |
// Validate database dest dir |
97 |
if (txtDestinationDir.Text.Trim().Length == 0) |
98 |
{ |
99 |
MessageBox.Show("You must specifiy a destination directory for the AnywhereTS boot image files."); |
100 |
txtDestinationDir.Focus(); |
101 |
return; |
102 |
} |
103 |
|
104 |
// Create Dest directory |
105 |
try |
106 |
{ |
107 |
Directory.CreateDirectory(txtDestinationDir.Text.Trim()); |
108 |
} |
109 |
catch (Exception ex) |
110 |
{ |
111 |
this.Cursor = Cursors.Default; |
112 |
MessageBox.Show("Could not create directory '" + txtDestinationDir.Text.Trim() + "'. Error: " + ex.Message); |
113 |
using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString()))) |
114 |
{ |
115 |
using (log4net.NDC.Push(string.Format("directory={0}", txtDestinationDir.Text))) |
116 |
{ |
117 |
Logging.ATSAdminLog.Error("Could not create directory."); |
118 |
} |
119 |
} |
120 |
return; |
121 |
} |
122 |
|
123 |
ATSGlobals.managedMode = 2; // We are running in unmanaged mode |
124 |
// No services should be run in unmanaged mode |
125 |
ATSGlobals.dhcpConfig = 1; // Other DHCP |
126 |
ATSGlobals.tftpConfig = 1; // Other TFTP |
127 |
ProSupport.strDestDir = txtDestinationDir.Text.Trim(); |
128 |
|
129 |
} |
130 |
else |
131 |
{ |
132 |
throw new Exception("Error: Unknown mode (84377)"); |
133 |
} |
134 |
// Save the database directory to registry |
135 |
ProSupport.strDatabasePath = txtDatabasePath.Text.Trim(); |
136 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath); |
137 |
|
138 |
// Save mode |
139 |
ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode); |
140 |
|
141 |
// Save destination directory |
142 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDestDir, ProSupport.strDestDir); |
143 |
|
144 |
// Terminate window |
145 |
this.Cursor = Cursors.Default; |
146 |
DialogResult = DialogResult.OK; |
147 |
} |
148 |
|
149 |
private void btnBrowseDatabase_Click(object sender, EventArgs e) |
150 |
{ |
151 |
// Show the FolderBrowserDialog. |
152 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
153 |
if (result == DialogResult.OK) |
154 |
{ |
155 |
txtDatabasePath.Text = folderBrowserDialog.SelectedPath; |
156 |
} |
157 |
} |
158 |
|
159 |
private void radManagedMode_CheckedChanged(object sender, EventArgs e) |
160 |
{ |
161 |
UpdateControls(); |
162 |
} |
163 |
|
164 |
private void radUnmanagedMode_CheckedChanged(object sender, EventArgs e) |
165 |
{ |
166 |
UpdateControls(); |
167 |
} |
168 |
|
169 |
private void UpdateControls() |
170 |
{ |
171 |
if (radManagedMode.Checked) |
172 |
{ // Managed mode |
173 |
lblDatabasePath.Enabled = true; |
174 |
txtDatabasePath.Enabled = true; |
175 |
btnBrowseDatabase.Enabled = true; |
176 |
lblDestinationDir.Enabled = false; |
177 |
txtDestinationDir.Enabled = false; |
178 |
btnBrowseDestinationDir.Enabled = false; |
179 |
btnOK.Text = "Next >"; |
180 |
} |
181 |
else |
182 |
{ // Unmanaged mode |
183 |
lblDatabasePath.Enabled = false; |
184 |
txtDatabasePath.Enabled = false; |
185 |
btnBrowseDatabase.Enabled = false; |
186 |
lblDestinationDir.Enabled = true; |
187 |
txtDestinationDir.Enabled = true; |
188 |
btnBrowseDestinationDir.Enabled = true; |
189 |
btnOK.Text = "Finish"; |
190 |
} |
191 |
|
192 |
} |
193 |
|
194 |
private void btnBrowseDestinationDir_Click(object sender, EventArgs e) |
195 |
{ |
196 |
// Show the FolderBrowserDialog. |
197 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
198 |
if (result == DialogResult.OK) |
199 |
{ |
200 |
txtDestinationDir.Text = folderBrowserDialog.SelectedPath; |
201 |
} |
202 |
} |
203 |
|
204 |
} |
205 |
} |