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 |
string error = "Error: Unknown mode (84377)"; |
133 |
using (log4net.NDC.Push(string.Format("mode={0}", ATSGlobals.managedMode))) |
134 |
{ |
135 |
Logging.ATSAdminLog.Error(error); |
136 |
} |
137 |
MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("mode={0}", ATSGlobals.managedMode))); |
138 |
return; |
139 |
|
140 |
} |
141 |
//// Save the database directory to registry |
142 |
//ProSupport.strDatabasePath = txtDatabasePath.Text.Trim(); |
143 |
//ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath); |
144 |
|
145 |
// Save mode |
146 |
ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode); |
147 |
|
148 |
// Save destination directory |
149 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDestDir, ProSupport.strDestDir); |
150 |
|
151 |
// Terminate window |
152 |
this.Cursor = Cursors.Default; |
153 |
DialogResult = DialogResult.OK; |
154 |
} |
155 |
|
156 |
private void btnBrowseDatabase_Click(object sender, EventArgs e) |
157 |
{ |
158 |
// Show the FolderBrowserDialog. |
159 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
160 |
if (result == DialogResult.OK) |
161 |
{ |
162 |
txtDatabasePath.Text = folderBrowserDialog.SelectedPath; |
163 |
} |
164 |
} |
165 |
|
166 |
private void radManagedMode_CheckedChanged(object sender, EventArgs e) |
167 |
{ |
168 |
UpdateControls(); |
169 |
} |
170 |
|
171 |
private void radUnmanagedMode_CheckedChanged(object sender, EventArgs e) |
172 |
{ |
173 |
UpdateControls(); |
174 |
} |
175 |
|
176 |
private void UpdateControls() |
177 |
{ |
178 |
if (radManagedMode.Checked) |
179 |
{ // Managed mode |
180 |
//lblDatabasePath.Enabled = true; |
181 |
//txtDatabasePath.Enabled = true; |
182 |
//btnBrowseDatabase.Enabled = true; |
183 |
lblDestinationDir.Enabled = false; |
184 |
txtDestinationDir.Enabled = false; |
185 |
btnBrowseDestinationDir.Enabled = false; |
186 |
btnOK.Text = "Next >"; |
187 |
} |
188 |
else |
189 |
{ // Unmanaged mode |
190 |
//lblDatabasePath.Enabled = false; |
191 |
//txtDatabasePath.Enabled = false; |
192 |
//btnBrowseDatabase.Enabled = false; |
193 |
lblDestinationDir.Enabled = true; |
194 |
txtDestinationDir.Enabled = true; |
195 |
btnBrowseDestinationDir.Enabled = true; |
196 |
btnOK.Text = "Finish"; |
197 |
} |
198 |
|
199 |
} |
200 |
|
201 |
private void btnBrowseDestinationDir_Click(object sender, EventArgs e) |
202 |
{ |
203 |
// Show the FolderBrowserDialog. |
204 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
205 |
if (result == DialogResult.OK) |
206 |
{ |
207 |
txtDestinationDir.Text = folderBrowserDialog.SelectedPath; |
208 |
} |
209 |
} |
210 |
|
211 |
} |
212 |
} |