Datei: NDOPackage/ConfigurationDialog.cs
Last Commit (7e08240)
1 | // |
2 | // Copyright (c) 2002-2019 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Linq; |
25 | using System.IO; |
26 | using System.Windows.Forms; |
27 | using MessageBox = System.Windows.Forms.MessageBox; |
28 | using Project = EnvDTE.Project; |
29 | using System.Diagnostics; |
30 | using Microsoft.VisualStudio.ComponentModelHost; |
31 | using NuGet.VisualStudio; |
32 | using NDO.UISupport; |
33 | using System.Drawing; |
34 | |
35 | #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread |
36 | |
37 | namespace NDOVsPackage |
38 | { |
39 | ····/// <summary> |
40 | ····/// Summary description for ConfigurationDialog. |
41 | ····/// </summary> |
42 | ····internal class ConfigurationDialog : System.Windows.Forms.Form |
43 | ····{ |
44 | ········private System.ComponentModel.IContainer components; |
45 | |
46 | ········private Project project; |
47 | ········private System.Windows.Forms.ToolTip toolTip1; |
48 | ········private TabControl tabControl; |
49 | ········private TabPage tabPageGeneral; |
50 | ········private TextBox txtTargetMappingFileName; |
51 | ········private Label label1; |
52 | ········private CheckBox chkVerboseMode; |
53 | ········private TextBox txtSchemaVersion; |
54 | ········private Label label5; |
55 | ········private Button btnNewDatabase; |
56 | ········private Button btnSaveAs; |
57 | ········private Button btnPresetApp; |
58 | ········private TextBox txtDbOwner; |
59 | ········private TextBox txtConnectionString; |
60 | ········private Label label3; |
61 | ········private GroupBox groupBox1; |
62 | ········private CheckBox chkDropExistingElements; |
63 | ········private CheckBox chkGenerateFkConstraints; |
64 | ········private CheckBox chkIncludeTypecodes; |
65 | ········private RadioButton radioDefaultEncoding; |
66 | ········private RadioButton radioUtf8Encoding; |
67 | ········private Label label4; |
68 | ········private ComboBox cbSqlDialect; |
69 | ········private CheckBox chkGenerateSQLScript; |
70 | ········private CheckBox chkUseTimeStamps; |
71 | ········private CheckBox chkChangeEvents; |
72 | ········private Label label2; |
73 | ········private Button btnConnString; |
74 | ········private Button btnOK; |
75 | ········private Button btnPresetLibrary; |
76 | ········private Button btnCancel; |
77 | ········private CheckBox chkMappingNew; |
78 | ········private CheckBox chkActivateEnhancer; |
79 | ········private CheckBox chkActivateAddIn; |
80 | ········private TabPage tabPageAssemblies; |
81 | ········private Label label6; |
82 | ········private CheckedListBox chlbAssemblies; |
83 | ········private ProjectDescription projectDescription; |
84 | ········private Button btnInstallProvider; |
85 | ········private NDOReference[] references; |
86 | |
87 | ········public ConfigurationDialog(Project project, ProjectDescription projectDescription) |
88 | ········{ |
89 | ············try |
90 | ············{ |
91 | ················this.project = project; |
92 | ················this.projectDescription = projectDescription; |
93 | ················this.projectDescription.BuildReferences(); |
94 | ················this.projectDescription.FixDllState(); |
95 | ················InitializeComponent(); |
96 | ················if (Screen.FromControl( this ).Bounds.Width >= 2600) |
97 | ····················Font = new Font( "Segoe UI", 11f, FontStyle.Regular, GraphicsUnit.Point, 0 ); |
98 | ················var lbAssemblies = (ListBox)this.chlbAssemblies; |
99 | ················this.references = projectDescription.References.Values.ToArray(); |
100 | ················lbAssemblies.DataSource = this.references; |
101 | ················lbAssemblies.DisplayMember = nameof( NDOReference.Name ); |
102 | ················lbAssemblies.ValueMember = nameof( NDOReference.CheckState ); |
103 | ················int i = 0; |
104 | ················foreach (var item in this.references) |
105 | ················{ |
106 | ····················this.chlbAssemblies.SetItemCheckState( i++, item.CheckState ); |
107 | ················} |
108 | ············} |
109 | ············catch (Exception ex) |
110 | ············{ |
111 | ················Debug.WriteLine( ex.ToString() ); |
112 | ············} |
113 | ········} |
114 | |
115 | ········void CheckEnabledStateForLoadProviderButton() |
116 | ········{ |
117 | ············string providerName = this.cbSqlDialect.Text; |
118 | |
119 | ············if (string.IsNullOrEmpty( providerName )) |
120 | ············{ |
121 | ················this.btnInstallProvider.Enabled = false; |
122 | ················return; |
123 | ············} |
124 | |
125 | ············if (IsProviderInstalled(providerName)) |
126 | ············{ |
127 | ················this.btnInstallProvider.Enabled = false; |
128 | ················return; |
129 | ············} |
130 | |
131 | ············this.btnInstallProvider.Enabled = true; |
132 | ········} |
133 | |
134 | ········bool IsProviderInstalled(string providerName) |
135 | ········{ |
136 | ············IComponentModel componentModel; |
137 | ············var installerService = GetInstallerService( out componentModel ); |
138 | |
139 | ············string packageName = $"ndo.{providerName.ToLower()}"; |
140 | ············return installerService.IsPackageInstalled( this.project, packageName ); |
141 | ········} |
142 | |
143 | ········/// <summary> |
144 | ········/// Clean up any resources being used. |
145 | ········/// </summary> |
146 | ········protected override void Dispose( bool disposing ) |
147 | ········{ |
148 | ············if( disposing ) |
149 | ············{ |
150 | ················if(components != null) |
151 | ················{ |
152 | ····················components.Dispose(); |
153 | ················} |
154 | ············} |
155 | ············base.Dispose( disposing ); |
156 | ········} |
157 | |
158 | ········#region Windows Form Designer generated code |
159 | ········/// <summary> |
160 | ········/// Required method for Designer support - do not modify |
161 | ········/// the contents of this method with the code editor. |
162 | ········/// </summary> |
163 | ········private void InitializeComponent() |
164 | ········{ |
165 | ············this.components = new System.ComponentModel.Container(); |
166 | ············System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConfigurationDialog)); |
167 | ············this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); |
168 | ············this.chkVerboseMode = new System.Windows.Forms.CheckBox(); |
169 | ············this.btnNewDatabase = new System.Windows.Forms.Button(); |
170 | ············this.btnSaveAs = new System.Windows.Forms.Button(); |
171 | ············this.btnPresetApp = new System.Windows.Forms.Button(); |
172 | ············this.txtDbOwner = new System.Windows.Forms.TextBox(); |
173 | ············this.txtConnectionString = new System.Windows.Forms.TextBox(); |
174 | ············this.chkDropExistingElements = new System.Windows.Forms.CheckBox(); |
175 | ············this.chkGenerateFkConstraints = new System.Windows.Forms.CheckBox(); |
176 | ············this.chkIncludeTypecodes = new System.Windows.Forms.CheckBox(); |
177 | ············this.radioDefaultEncoding = new System.Windows.Forms.RadioButton(); |
178 | ············this.radioUtf8Encoding = new System.Windows.Forms.RadioButton(); |
179 | ············this.cbSqlDialect = new System.Windows.Forms.ComboBox(); |
180 | ············this.chkGenerateSQLScript = new System.Windows.Forms.CheckBox(); |
181 | ············this.chkUseTimeStamps = new System.Windows.Forms.CheckBox(); |
182 | ············this.chkChangeEvents = new System.Windows.Forms.CheckBox(); |
183 | ············this.btnConnString = new System.Windows.Forms.Button(); |
184 | ············this.btnPresetLibrary = new System.Windows.Forms.Button(); |
185 | ············this.chkMappingNew = new System.Windows.Forms.CheckBox(); |
186 | ············this.chkActivateEnhancer = new System.Windows.Forms.CheckBox(); |
187 | ············this.chkActivateAddIn = new System.Windows.Forms.CheckBox(); |
188 | ············this.tabControl = new System.Windows.Forms.TabControl(); |
189 | ············this.tabPageGeneral = new System.Windows.Forms.TabPage(); |
190 | ············this.txtTargetMappingFileName = new System.Windows.Forms.TextBox(); |
191 | ············this.label1 = new System.Windows.Forms.Label(); |
192 | ············this.txtSchemaVersion = new System.Windows.Forms.TextBox(); |
193 | ············this.label5 = new System.Windows.Forms.Label(); |
194 | ············this.label3 = new System.Windows.Forms.Label(); |
195 | ············this.groupBox1 = new System.Windows.Forms.GroupBox(); |
196 | ············this.btnInstallProvider = new System.Windows.Forms.Button(); |
197 | ············this.label4 = new System.Windows.Forms.Label(); |
198 | ············this.label2 = new System.Windows.Forms.Label(); |
199 | ············this.tabPageAssemblies = new System.Windows.Forms.TabPage(); |
200 | ············this.label6 = new System.Windows.Forms.Label(); |
201 | ············this.chlbAssemblies = new System.Windows.Forms.CheckedListBox(); |
202 | ············this.btnOK = new System.Windows.Forms.Button(); |
203 | ············this.btnCancel = new System.Windows.Forms.Button(); |
204 | ············this.tabControl.SuspendLayout(); |
205 | ············this.tabPageGeneral.SuspendLayout(); |
206 | ············this.groupBox1.SuspendLayout(); |
207 | ············this.tabPageAssemblies.SuspendLayout(); |
208 | ············this.SuspendLayout(); |
209 | ············// |
210 | ············// chkVerboseMode |
211 | ············// |
212 | ············this.chkVerboseMode.Location = new System.Drawing.Point(21, 72); |
213 | ············this.chkVerboseMode.Name = "chkVerboseMode"; |
214 | ············this.chkVerboseMode.Size = new System.Drawing.Size(238, 21); |
215 | ············this.chkVerboseMode.TabIndex = 51; |
216 | ············this.chkVerboseMode.Text = "Add-in Verbose Mode"; |
217 | ············this.toolTip1.SetToolTip(this.chkVerboseMode, "Causes the Add-in and the Enhancer to show more information for debugging purpose" + |
218 | ········"s."); |
219 | ············// |
220 | ············// btnNewDatabase |
221 | ············// |
222 | ············this.btnNewDatabase.Location = new System.Drawing.Point(583, 313); |
223 | ············this.btnNewDatabase.Name = "btnNewDatabase"; |
224 | ············this.btnNewDatabase.Size = new System.Drawing.Size(42, 21); |
225 | ············this.btnNewDatabase.TabIndex = 48; |
226 | ············this.btnNewDatabase.Text = "New"; |
227 | ············this.toolTip1.SetToolTip(this.btnNewDatabase, "Create new database"); |
228 | ············this.btnNewDatabase.Click += new System.EventHandler(this.btnNewDatabase_Click); |
229 | ············// |
230 | ············// btnSaveAs |
231 | ············// |
232 | ············this.btnSaveAs.DialogResult = System.Windows.Forms.DialogResult.OK; |
233 | ············this.btnSaveAs.Location = new System.Drawing.Point(249, 385); |
234 | ············this.btnSaveAs.Name = "btnSaveAs"; |
235 | ············this.btnSaveAs.Size = new System.Drawing.Size(100, 39); |
236 | ············this.btnSaveAs.TabIndex = 47; |
237 | ············this.btnSaveAs.Text = "Save as..."; |
238 | ············this.toolTip1.SetToolTip(this.btnSaveAs, "Save the options to be used in unattended builds with the stand-alone enhancer."); |
239 | ············this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click); |
240 | ············// |
241 | ············// btnPresetApp |
242 | ············// |
243 | ············this.btnPresetApp.Location = new System.Drawing.Point(135, 385); |
244 | ············this.btnPresetApp.Name = "btnPresetApp"; |
245 | ············this.btnPresetApp.Size = new System.Drawing.Size(100, 39); |
246 | ············this.btnPresetApp.TabIndex = 46; |
247 | ············this.btnPresetApp.Text = "Preset for Application"; |
248 | ············this.toolTip1.SetToolTip(this.btnPresetApp, "Selects all settings used for applications which don\'t contain but reference pers" + |
249 | ········"istent types."); |
250 | ············this.btnPresetApp.Click += new System.EventHandler(this.btnPresetApp_Click); |
251 | ············// |
252 | ············// txtDbOwner |
253 | ············// |
254 | ············this.txtDbOwner.Location = new System.Drawing.Point(145, 126); |
255 | ············this.txtDbOwner.Name = "txtDbOwner"; |
256 | ············this.txtDbOwner.Size = new System.Drawing.Size(160, 20); |
257 | ············this.txtDbOwner.TabIndex = 45; |
258 | ············this.toolTip1.SetToolTip(this.txtDbOwner, "Enter an owner name, if you like your tables to be written like owner.tablename."); |
259 | ············// |
260 | ············// txtConnectionString |
261 | ············// |
262 | ············this.txtConnectionString.Location = new System.Drawing.Point(18, 313); |
263 | ············this.txtConnectionString.Name = "txtConnectionString"; |
264 | ············this.txtConnectionString.Size = new System.Drawing.Size(514, 20); |
265 | ············this.txtConnectionString.TabIndex = 39; |
266 | ············this.toolTip1.SetToolTip(this.txtConnectionString, "This string will be copied into the mapping file, if there doesn\'t exist a valid " + |
267 | ········"connection string. Otherwise it will be ignored."); |
268 | ············// |
269 | ············// chkDropExistingElements |
270 | ············// |
271 | ············this.chkDropExistingElements.Location = new System.Drawing.Point(13, 202); |
272 | ············this.chkDropExistingElements.Name = "chkDropExistingElements"; |
273 | ············this.chkDropExistingElements.Size = new System.Drawing.Size(235, 21); |
274 | ············this.chkDropExistingElements.TabIndex = 24; |
275 | ············this.chkDropExistingElements.Text = "Insert Drop Statements in the Script"; |
276 | ············this.toolTip1.SetToolTip(this.chkDropExistingElements, "If checked, NDO generates instructions to remove existing tables and constraints." + |
277 | ········""); |
278 | ············// |
279 | ············// chkGenerateFkConstraints |
280 | ············// |
281 | ············this.chkGenerateFkConstraints.Location = new System.Drawing.Point(13, 152); |
282 | ············this.chkGenerateFkConstraints.Name = "chkGenerateFkConstraints"; |
283 | ············this.chkGenerateFkConstraints.Size = new System.Drawing.Size(235, 21); |
284 | ············this.chkGenerateFkConstraints.TabIndex = 23; |
285 | ············this.chkGenerateFkConstraints.Text = "Generate Foreign Key Constraints"; |
286 | ············this.toolTip1.SetToolTip(this.chkGenerateFkConstraints, "If checked, NDO generates foreign key constraints for the relations in the databa" + |
287 | ········"se."); |
288 | ············// |
289 | ············// chkIncludeTypecodes |
290 | ············// |
291 | ············this.chkIncludeTypecodes.Location = new System.Drawing.Point(13, 177); |
292 | ············this.chkIncludeTypecodes.Name = "chkIncludeTypecodes"; |
293 | ············this.chkIncludeTypecodes.Size = new System.Drawing.Size(235, 21); |
294 | ············this.chkIncludeTypecodes.TabIndex = 22; |
295 | ············this.chkIncludeTypecodes.Text = "Include Typecodes in the Script"; |
296 | ············this.toolTip1.SetToolTip(this.chkIncludeTypecodes, "If checked, NDO generates instructions to build an additional table with the type" + |
297 | ········" code information."); |
298 | ············// |
299 | ············// radioDefaultEncoding |
300 | ············// |
301 | ············this.radioDefaultEncoding.Location = new System.Drawing.Point(13, 121); |
302 | ············this.radioDefaultEncoding.Name = "radioDefaultEncoding"; |
303 | ············this.radioDefaultEncoding.Size = new System.Drawing.Size(140, 20); |
304 | ············this.radioDefaultEncoding.TabIndex = 21; |
305 | ············this.radioDefaultEncoding.Text = "Default Encoding"; |
306 | ············this.toolTip1.SetToolTip(this.radioDefaultEncoding, "Check this option, if the script files should use windows encoding."); |
307 | ············// |
308 | ············// radioUtf8Encoding |
309 | ············// |
310 | ············this.radioUtf8Encoding.Checked = true; |
311 | ············this.radioUtf8Encoding.Location = new System.Drawing.Point(13, 99); |
312 | ············this.radioUtf8Encoding.Name = "radioUtf8Encoding"; |
313 | ············this.radioUtf8Encoding.Size = new System.Drawing.Size(140, 21); |
314 | ············this.radioUtf8Encoding.TabIndex = 20; |
315 | ············this.radioUtf8Encoding.TabStop = true; |
316 | ············this.radioUtf8Encoding.Text = "UTF-8 Encoding"; |
317 | ············this.toolTip1.SetToolTip(this.radioUtf8Encoding, "Check this option, if the script files should be UTF-8 encoded."); |
318 | ············// |
319 | ············// cbSqlDialect |
320 | ············// |
321 | ············this.cbSqlDialect.Location = new System.Drawing.Point(13, 70); |
322 | ············this.cbSqlDialect.Name = "cbSqlDialect"; |
323 | ············this.cbSqlDialect.Size = new System.Drawing.Size(220, 21); |
324 | ············this.cbSqlDialect.TabIndex = 18; |
325 | ············this.toolTip1.SetToolTip(this.cbSqlDialect, "Choose an available NDO provider."); |
326 | ············this.cbSqlDialect.SelectedIndexChanged += new System.EventHandler(this.cbSqlDialect_SelectedIndexChanged); |
327 | ············// |
328 | ············// chkGenerateSQLScript |
329 | ············// |
330 | ············this.chkGenerateSQLScript.Location = new System.Drawing.Point(13, 21); |
331 | ············this.chkGenerateSQLScript.Name = "chkGenerateSQLScript"; |
332 | ············this.chkGenerateSQLScript.Size = new System.Drawing.Size(187, 21); |
333 | ············this.chkGenerateSQLScript.TabIndex = 13; |
334 | ············this.chkGenerateSQLScript.Text = "Generate SQL Script"; |
335 | ············this.toolTip1.SetToolTip(this.chkGenerateSQLScript, "If checked, NDO will create a script with DDL code, which can be used to construc" + |
336 | ········"t a database structure."); |
337 | ············this.chkGenerateSQLScript.CheckedChanged += new System.EventHandler(this.chkGenerateSQLScript_CheckedChanged); |
338 | ············// |
339 | ············// chkUseTimeStamps |
340 | ············// |
341 | ············this.chkUseTimeStamps.Location = new System.Drawing.Point(21, 153); |
342 | ············this.chkUseTimeStamps.Name = "chkUseTimeStamps"; |
343 | ············this.chkUseTimeStamps.Size = new System.Drawing.Size(302, 20); |
344 | ············this.chkUseTimeStamps.TabIndex = 42; |
345 | ············this.chkUseTimeStamps.Text = "Generate Time Stamp Columns for each class"; |
346 | ············this.toolTip1.SetToolTip(this.chkUseTimeStamps, "Check this option, if all tables should be protected by collistion detection."); |
347 | ············// |
348 | ············// chkChangeEvents |
349 | ············// |
350 | ············this.chkChangeEvents.Location = new System.Drawing.Point(21, 179); |
351 | ············this.chkChangeEvents.Name = "chkChangeEvents"; |
352 | ············this.chkChangeEvents.Size = new System.Drawing.Size(302, 21); |
353 | ············this.chkChangeEvents.TabIndex = 41; |
354 | ············this.chkChangeEvents.Text = "Generate change events with Add Accessor"; |
355 | ············this.toolTip1.SetToolTip(this.chkChangeEvents, "Check this option, if you intend to bind the UI directly to the accessor properti" + |
356 | ········"es of your persistent classes."); |
357 | ············// |
358 | ············// btnConnString |
359 | ············// |
360 | ············this.btnConnString.Location = new System.Drawing.Point(538, 313); |
361 | ············this.btnConnString.Name = "btnConnString"; |
362 | ············this.btnConnString.Size = new System.Drawing.Size(42, 21); |
363 | ············this.btnConnString.TabIndex = 38; |
364 | ············this.btnConnString.Text = "..."; |
365 | ············this.toolTip1.SetToolTip(this.btnConnString, "Enter existing database connection"); |
366 | ············this.btnConnString.Click += new System.EventHandler(this.btnConnString_Click); |
367 | ············// |
368 | ············// btnPresetLibrary |
369 | ············// |
370 | ············this.btnPresetLibrary.Location = new System.Drawing.Point(21, 385); |
371 | ············this.btnPresetLibrary.Name = "btnPresetLibrary"; |
372 | ············this.btnPresetLibrary.Size = new System.Drawing.Size(100, 39); |
373 | ············this.btnPresetLibrary.TabIndex = 36; |
374 | ············this.btnPresetLibrary.Text = "Preset for Library"; |
375 | ············this.toolTip1.SetToolTip(this.btnPresetLibrary, "Selects all settings necessary for projects containing persistent types."); |
376 | ············this.btnPresetLibrary.Click += new System.EventHandler(this.btnPresetLibrary_Click); |
377 | ············// |
378 | ············// chkMappingNew |
379 | ············// |
380 | ············this.chkMappingNew.Location = new System.Drawing.Point(21, 99); |
381 | ············this.chkMappingNew.Name = "chkMappingNew"; |
382 | ············this.chkMappingNew.Size = new System.Drawing.Size(272, 21); |
383 | ············this.chkMappingNew.TabIndex = 34; |
384 | ············this.chkMappingNew.Text = "Always Generate a new mapping File"; |
385 | ············this.toolTip1.SetToolTip(this.chkMappingNew, "Choose this options, if NDO should discard and rebuild all mapping information."); |
386 | ············// |
387 | ············// chkActivateEnhancer |
388 | ············// |
389 | ············this.chkActivateEnhancer.Location = new System.Drawing.Point(21, 46); |
390 | ············this.chkActivateEnhancer.Name = "chkActivateEnhancer"; |
391 | ············this.chkActivateEnhancer.Size = new System.Drawing.Size(188, 20); |
392 | ············this.chkActivateEnhancer.TabIndex = 33; |
393 | ············this.chkActivateEnhancer.Text = "Activate enhancer"; |
394 | ············this.toolTip1.SetToolTip(this.chkActivateEnhancer, "Choose this option, if your project contains persistent types."); |
395 | ············// |
396 | ············// chkActivateAddIn |
397 | ············// |
398 | ············this.chkActivateAddIn.Location = new System.Drawing.Point(21, 19); |
399 | ············this.chkActivateAddIn.Name = "chkActivateAddIn"; |
400 | ············this.chkActivateAddIn.Size = new System.Drawing.Size(188, 21); |
401 | ············this.chkActivateAddIn.TabIndex = 32; |
402 | ············this.chkActivateAddIn.Text = "Activate NDO AddIn"; |
403 | ············this.toolTip1.SetToolTip(this.chkActivateAddIn, "Choose this options, if your project contains or references persistent types."); |
404 | ············this.chkActivateAddIn.Click += new System.EventHandler(this.chkActivateAddIn_CheckedChanged); |
405 | ············// |
406 | ············// tabControl |
407 | ············// |
408 | ············this.tabControl.Controls.Add(this.tabPageGeneral); |
409 | ············this.tabControl.Controls.Add(this.tabPageAssemblies); |
410 | ············this.tabControl.Dock = System.Windows.Forms.DockStyle.Top; |
411 | ············this.tabControl.Location = new System.Drawing.Point(0, 0); |
412 | ············this.tabControl.Name = "tabControl"; |
413 | ············this.tabControl.SelectedIndex = 0; |
414 | ············this.tabControl.Size = new System.Drawing.Size(661, 374); |
415 | ············this.tabControl.TabIndex = 0; |
416 | ············// |
417 | ············// tabPageGeneral |
418 | ············// |
419 | ············this.tabPageGeneral.Controls.Add(this.txtTargetMappingFileName); |
420 | ············this.tabPageGeneral.Controls.Add(this.label1); |
421 | ············this.tabPageGeneral.Controls.Add(this.chkVerboseMode); |
422 | ············this.tabPageGeneral.Controls.Add(this.txtSchemaVersion); |
423 | ············this.tabPageGeneral.Controls.Add(this.label5); |
424 | ············this.tabPageGeneral.Controls.Add(this.btnNewDatabase); |
425 | ············this.tabPageGeneral.Controls.Add(this.txtDbOwner); |
426 | ············this.tabPageGeneral.Controls.Add(this.txtConnectionString); |
427 | ············this.tabPageGeneral.Controls.Add(this.label3); |
428 | ············this.tabPageGeneral.Controls.Add(this.groupBox1); |
429 | ············this.tabPageGeneral.Controls.Add(this.chkUseTimeStamps); |
430 | ············this.tabPageGeneral.Controls.Add(this.chkChangeEvents); |
431 | ············this.tabPageGeneral.Controls.Add(this.label2); |
432 | ············this.tabPageGeneral.Controls.Add(this.btnConnString); |
433 | ············this.tabPageGeneral.Controls.Add(this.chkMappingNew); |
434 | ············this.tabPageGeneral.Controls.Add(this.chkActivateEnhancer); |
435 | ············this.tabPageGeneral.Controls.Add(this.chkActivateAddIn); |
436 | ············this.tabPageGeneral.Location = new System.Drawing.Point(4, 22); |
437 | ············this.tabPageGeneral.Name = "tabPageGeneral"; |
438 | ············this.tabPageGeneral.Padding = new System.Windows.Forms.Padding(3); |
439 | ············this.tabPageGeneral.Size = new System.Drawing.Size(653, 348); |
440 | ············this.tabPageGeneral.TabIndex = 0; |
441 | ············this.tabPageGeneral.Text = "General"; |
442 | ············this.tabPageGeneral.UseVisualStyleBackColor = true; |
443 | ············// |
444 | ············// txtTargetMappingFileName |
445 | ············// |
446 | ············this.txtTargetMappingFileName.Location = new System.Drawing.Point(145, 245); |
447 | ············this.txtTargetMappingFileName.Name = "txtTargetMappingFileName"; |
448 | ············this.txtTargetMappingFileName.Size = new System.Drawing.Size(160, 20); |
449 | ············this.txtTargetMappingFileName.TabIndex = 53; |
450 | ············// |
451 | ············// label1 |
452 | ············// |
453 | ············this.label1.Location = new System.Drawing.Point(18, 246); |
454 | ············this.label1.Name = "label1"; |
455 | ············this.label1.Size = new System.Drawing.Size(121, 21); |
456 | ············this.label1.TabIndex = 52; |
457 | ············this.label1.Text = "Mapping File Name"; |
458 | ············// |
459 | ············// txtSchemaVersion |
460 | ············// |
461 | ············this.txtSchemaVersion.Location = new System.Drawing.Point(145, 219); |
462 | ············this.txtSchemaVersion.Name = "txtSchemaVersion"; |
463 | ············this.txtSchemaVersion.Size = new System.Drawing.Size(160, 20); |
464 | ············this.txtSchemaVersion.TabIndex = 50; |
465 | ············// |
466 | ············// label5 |
467 | ············// |
468 | ············this.label5.Location = new System.Drawing.Point(18, 220); |
469 | ············this.label5.Name = "label5"; |
470 | ············this.label5.Size = new System.Drawing.Size(121, 21); |
471 | ············this.label5.TabIndex = 49; |
472 | ············this.label5.Text = "Schema Version"; |
473 | ············// |
474 | ············// label3 |
475 | ············// |
476 | ············this.label3.Location = new System.Drawing.Point(18, 128); |
477 | ············this.label3.Name = "label3"; |
478 | ············this.label3.Size = new System.Drawing.Size(127, 21); |
479 | ············this.label3.TabIndex = 44; |
480 | ············this.label3.Text = "Owner / Schema Name"; |
481 | ············// |
482 | ············// groupBox1 |
483 | ············// |
484 | ············this.groupBox1.Controls.Add(this.btnInstallProvider); |
485 | ············this.groupBox1.Controls.Add(this.chkDropExistingElements); |
486 | ············this.groupBox1.Controls.Add(this.chkGenerateFkConstraints); |
487 | ············this.groupBox1.Controls.Add(this.chkIncludeTypecodes); |
488 | ············this.groupBox1.Controls.Add(this.radioDefaultEncoding); |
489 | ············this.groupBox1.Controls.Add(this.radioUtf8Encoding); |
490 | ············this.groupBox1.Controls.Add(this.label4); |
491 | ············this.groupBox1.Controls.Add(this.cbSqlDialect); |
492 | ············this.groupBox1.Controls.Add(this.chkGenerateSQLScript); |
493 | ············this.groupBox1.Location = new System.Drawing.Point(343, 21); |
494 | ············this.groupBox1.Name = "groupBox1"; |
495 | ············this.groupBox1.Size = new System.Drawing.Size(265, 244); |
496 | ············this.groupBox1.TabIndex = 43; |
497 | ············this.groupBox1.TabStop = false; |
498 | ············this.groupBox1.Text = " SQL "; |
499 | ············// |
500 | ············// btnInstallProvider |
501 | ············// |
502 | ············this.btnInstallProvider.Location = new System.Drawing.Point(142, 102); |
503 | ············this.btnInstallProvider.Name = "btnInstallProvider"; |
504 | ············this.btnInstallProvider.Size = new System.Drawing.Size(91, 22); |
505 | ············this.btnInstallProvider.TabIndex = 25; |
506 | ············this.btnInstallProvider.Text = "Install Provider"; |
507 | ············this.btnInstallProvider.UseVisualStyleBackColor = true; |
508 | ············this.btnInstallProvider.Click += new System.EventHandler(this.btnInstallProvider_Click); |
509 | ············// |
510 | ············// label4 |
511 | ············// |
512 | ············this.label4.Location = new System.Drawing.Point(13, 50); |
513 | ············this.label4.Name = "label4"; |
514 | ············this.label4.Size = new System.Drawing.Size(200, 17); |
515 | ············this.label4.TabIndex = 19; |
516 | ············this.label4.Text = "SQL Dialect"; |
517 | ············// |
518 | ············// label2 |
519 | ············// |
520 | ············this.label2.Location = new System.Drawing.Point(18, 292); |
521 | ············this.label2.Name = "label2"; |
522 | ············this.label2.Size = new System.Drawing.Size(360, 21); |
523 | ············this.label2.TabIndex = 40; |
524 | ············this.label2.Text = "Default Connection String"; |
525 | ············// |
526 | ············// tabPageAssemblies |
527 | ············// |
528 | ············this.tabPageAssemblies.Controls.Add(this.label6); |
529 | ············this.tabPageAssemblies.Controls.Add(this.chlbAssemblies); |
530 | ············this.tabPageAssemblies.Location = new System.Drawing.Point(4, 22); |
531 | ············this.tabPageAssemblies.Name = "tabPageAssemblies"; |
532 | ············this.tabPageAssemblies.Padding = new System.Windows.Forms.Padding(3); |
533 | ············this.tabPageAssemblies.Size = new System.Drawing.Size(653, 348); |
534 | ············this.tabPageAssemblies.TabIndex = 1; |
535 | ············this.tabPageAssemblies.Text = "Assemblies"; |
536 | ············this.tabPageAssemblies.UseVisualStyleBackColor = true; |
537 | ············// |
538 | ············// label6 |
539 | ············// |
540 | ············this.label6.AutoSize = true; |
541 | ············this.label6.Location = new System.Drawing.Point(10, 12); |
542 | ············this.label6.Name = "label6"; |
543 | ············this.label6.Size = new System.Drawing.Size(328, 13); |
544 | ············this.label6.TabIndex = 1; |
545 | ············this.label6.Text = "Choose Assemblies which should be analyzed by the NDOEnhancer"; |
546 | ············// |
547 | ············// chlbAssemblies |
548 | ············// |
549 | ············this.chlbAssemblies.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
550 | ············| System.Windows.Forms.AnchorStyles.Left) |
551 | ············| System.Windows.Forms.AnchorStyles.Right))); |
552 | ············this.chlbAssemblies.FormattingEnabled = true; |
553 | ············this.chlbAssemblies.Location = new System.Drawing.Point(10, 39); |
554 | ············this.chlbAssemblies.Name = "chlbAssemblies"; |
555 | ············this.chlbAssemblies.Size = new System.Drawing.Size(631, 289); |
556 | ············this.chlbAssemblies.TabIndex = 0; |
557 | ············this.chlbAssemblies.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.chlbAssemblies_ItemCheck); |
558 | ············// |
559 | ············// btnOK |
560 | ············// |
561 | ············this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; |
562 | ············this.btnOK.Location = new System.Drawing.Point(363, 385); |
563 | ············this.btnOK.Name = "btnOK"; |
564 | ············this.btnOK.Size = new System.Drawing.Size(100, 39); |
565 | ············this.btnOK.TabIndex = 37; |
566 | ············this.btnOK.Text = "OK"; |
567 | ············this.btnOK.Click += new System.EventHandler(this.btnOK_Click); |
568 | ············// |
569 | ············// btnCancel |
570 | ············// |
571 | ············this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; |
572 | ············this.btnCancel.Location = new System.Drawing.Point(477, 385); |
573 | ············this.btnCancel.Name = "btnCancel"; |
574 | ············this.btnCancel.Size = new System.Drawing.Size(100, 39); |
575 | ············this.btnCancel.TabIndex = 35; |
576 | ············this.btnCancel.Text = "Cancel"; |
577 | ············// |
578 | ············// ConfigurationDialog |
579 | ············// |
580 | ············this.AutoScaleMode = AutoScaleMode.Font; |
581 | ············this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
582 | ············this.CancelButton = this.btnCancel; |
583 | ············this.ClientSize = new System.Drawing.Size(661, 439); |
584 | ············this.Controls.Add(this.btnSaveAs); |
585 | ············this.Controls.Add(this.btnPresetApp); |
586 | ············this.Controls.Add(this.btnOK); |
587 | ············this.Controls.Add(this.btnPresetLibrary); |
588 | ············this.Controls.Add(this.btnCancel); |
589 | ············this.Controls.Add(this.tabControl); |
590 | ············this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
591 | ············this.Name = "ConfigurationDialog"; |
592 | ············this.Text = "NDO Configuration"; |
593 | ············this.Load += new System.EventHandler(this.ConfigurationDialog_Load); |
594 | ············this.tabControl.ResumeLayout(false); |
595 | ············this.tabPageGeneral.ResumeLayout(false); |
596 | ············this.tabPageGeneral.PerformLayout(); |
597 | ············this.groupBox1.ResumeLayout(false); |
598 | ············this.tabPageAssemblies.ResumeLayout(false); |
599 | ············this.tabPageAssemblies.PerformLayout(); |
600 | ············this.ResumeLayout(false); |
601 | |
602 | ········} |
603 | ········#endregion |
604 | |
605 | ········private void chkActivateAddIn_CheckedChanged(object sender, System.EventArgs e) |
606 | ········{ |
607 | ············EnableAddin(this.chkActivateAddIn.Checked); |
608 | ········} |
609 | |
610 | |
611 | ········void EnableAddin(bool enabled) |
612 | ········{ |
613 | ············if (project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
614 | ················chkActivateEnhancer.Enabled = false; |
615 | ············else |
616 | ················chkActivateEnhancer.Enabled = enabled; |
617 | ········} |
618 | |
619 | ········private void ConfigurationDialog_Load(object sender, System.EventArgs e) |
620 | ········{ |
621 | ············try |
622 | ············{ |
623 | ················ConfigurationOptions options = new ConfigurationOptions(project); |
624 | ················this.Text = "NDO Configuration - " + project.Name; |
625 | ················chkIncludeTypecodes.Checked = options.IncludeTypecodes; |
626 | ················chkDropExistingElements.Checked = options.DropExistingElements; |
627 | ················chkGenerateFkConstraints.Checked = options.GenerateConstraints; |
628 | ················chkVerboseMode.Checked = options.VerboseMode; |
629 | ················chkChangeEvents.Checked = options.GenerateChangeEvents; |
630 | ················chkActivateAddIn.Checked = options.EnableAddIn; |
631 | ················chkActivateEnhancer.Checked = options.EnableEnhancer; |
632 | ················chkMappingNew.Checked = options.NewMapping; |
633 | ················if (chkActivateAddIn.Checked == false) |
634 | ····················EnableAddin(false); |
635 | ················chkGenerateSQLScript.Checked = options.GenerateSQL; |
636 | ················txtSchemaVersion.Text = options.SchemaVersion; |
637 | ················if (string.IsNullOrEmpty(txtSchemaVersion.Text)) |
638 | ····················txtSchemaVersion.Text = "1.0"; |
639 | ················this.chkUseTimeStamps.Checked = options.UseTimeStamps; |
640 | ················int i = 0; |
641 | ················this.cbSqlDialect.Items.Clear(); |
642 | ················int currentDialectIndex = -1; |
643 | |
644 | ················foreach (string s in NdoUIProviderFactory.Instance.Keys) |
645 | ················{ |
646 | ····················this.cbSqlDialect.Items.Add(s); |
647 | ····················if (options.SQLScriptLanguage == s) |
648 | ························currentDialectIndex = i; |
649 | ····················i++; |
650 | ················} |
651 | ················if (currentDialectIndex > -1) |
652 | ····················cbSqlDialect.SelectedIndex = currentDialectIndex; |
653 | |
654 | ················// Must be initialized after changing the cbSqlDialect index |
655 | ················txtConnectionString.Text = options.DefaultConnection; |
656 | ················txtTargetMappingFileName.Text = options.TargetMappingFileName; |
657 | ················txtDbOwner.Text = options.DatabaseOwner; |
658 | ················chkActivateAddIn_CheckedChanged(null, EventArgs.Empty); |
659 | ················chkGenerateSQLScript_CheckedChanged(null, EventArgs.Empty); |
660 | ················if (options.Utf8Encoding) |
661 | ····················radioUtf8Encoding.Checked = true; |
662 | ················else |
663 | ····················radioDefaultEncoding.Checked = true; |
664 | ················if (project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
665 | ····················this.chkActivateEnhancer.Enabled = false; |
666 | |
667 | ················CheckEnabledStateForLoadProviderButton(); |
668 | ············} |
669 | ············catch (Exception ex) |
670 | ············{ |
671 | #if !DEBUG |
672 | ················MessageBox.Show(ex.Message, "NDO Configuration"); |
673 | #else |
674 | ················MessageBox.Show(ex.ToString(), "NDO Configuration"); |
675 | #endif |
676 | ············} |
677 | ········} |
678 | |
679 | ········private void btnPresetLibrary_Click(object sender, System.EventArgs e) |
680 | ········{ |
681 | //············ConfigurationOptions options = new ConfigurationOptions( project ); |
682 | ············try |
683 | ············{ |
684 | ················EnableCheckBoxes(); |
685 | |
686 | ················this.chkVerboseMode.Checked = false; |
687 | ················this.chkActivateAddIn.Checked = true; |
688 | ················this.chkActivateEnhancer.Checked = true; |
689 | ················this.chkMappingNew.Checked = false; |
690 | ················this.chkChangeEvents.Checked = false; |
691 | ················this.chkIncludeTypecodes.Checked = false; |
692 | ················this.chkGenerateFkConstraints.Checked = false; |
693 | ················this.chkDropExistingElements.Checked = false; |
694 | ················this.chkUseTimeStamps.Checked = false;···· |
695 | ················this.txtDbOwner.Text = ""; |
696 | ················this.chkGenerateSQLScript.Checked = false; |
697 | ················this.txtSchemaVersion.Text = ""; |
698 | ············} |
699 | ············catch (Exception ex) |
700 | ············{ |
701 | ················ShowError(ex); |
702 | ············} |
703 | ········} |
704 | |
705 | |
706 | ········private void btnOK_Click(object sender, System.EventArgs e) |
707 | ········{ |
708 | ············try |
709 | ············{ |
710 | ················ConfigurationOptions options = new ConfigurationOptions( project ); |
711 | |
712 | ················string connType = options.SQLScriptLanguage; |
713 | ················string connName = options.DefaultConnection; |
714 | ················WriteBack(options); |
715 | ················if (options.SQLScriptLanguage != connType || options.DefaultConnection != connName) |
716 | ················{ |
717 | ····················string mappingFileName = this.project.MappingFilePath(); |
718 | ····················if (mappingFileName != null) |
719 | ····················{ |
720 | ························NDOMapping mapping = new NDOMapping(mappingFileName); |
721 | ························bool connectionExists = false; |
722 | ························foreach (Connection conn in mapping.Connections) |
723 | ························{ |
724 | ····························if (conn.Type == options.SQLScriptLanguage && conn.Name == options.DefaultConnection) |
725 | ····························{ |
726 | ································connectionExists = true; |
727 | ································break; |
728 | ····························} |
729 | ························} |
730 | ························if (!connectionExists) |
731 | ························{ |
732 | ····························if (MessageBox.Show("The database connection settings have been changed. Should NDO change the connection settings in the mapping file " + Path.GetFileName(mappingFileName) + " too?", "NDO Configuration", MessageBoxButtons.YesNo) == DialogResult.Yes) |
733 | ····························{ |
734 | ································Connection conn = null; |
735 | ································if (mapping.Connections.Count() == 1) |
736 | ································{ |
737 | ····································conn = (Connection)mapping.Connections.FirstOrDefault(); |
738 | ································} |
739 | ································else |
740 | ································{ |
741 | ····································conn = mapping.NewConnection(String.Empty, String.Empty); |
742 | ····································MessageBox.Show("Added a connection with the ID " + conn.ID, "NDO Configuration"); |
743 | ································} |
744 | ································conn.Type = options.SQLScriptLanguage; |
745 | ································conn.Name = options.DefaultConnection; |
746 | ································mapping.Save(); |
747 | ····························} |
748 | ························} |
749 | ····················} |
750 | ················} |
751 | |
752 | ················if ( options.EnableAddIn ) |
753 | ················{ |
754 | ····················GeneratePackageReference(); |
755 | ················} |
756 | |
757 | ················ThreadHelper.JoinableTaskFactory.Run( async () => await options.SaveAsync( this.projectDescription ) ); |
758 | ················ |
759 | ············} |
760 | ············catch (Exception ex) |
761 | ············{ |
762 | #if DEBUG |
763 | ················MessageBox.Show( "The following error occured while saving your options: " + ex.ToString(), "NDO Add-in" ); |
764 | #else |
765 | ················MessageBox.Show("The following error occured while saving your options: " + ex.Message, "NDO Add-in"); |
766 | #endif |
767 | ············} |
768 | ········} |
769 | |
770 | |
771 | ········void GeneratePackageReference() |
772 | ········{ |
773 | ············try |
774 | ············{ |
775 | ················IComponentModel componentModel; |
776 | ················var installerService = GetInstallerService( out componentModel ); |
777 | |
778 | ················if (!installerService.IsPackageInstalled( this.project, "ndo.dll" )) |
779 | ················{ |
780 | ····················var installer = componentModel.GetService<IVsPackageInstaller>(); |
781 | installer. InstallPackage( null, this. project, "ndo. dll", ( string) null, false ) ; |
782 | ················} |
783 | ············} |
784 | ············catch (Exception ex) |
785 | ············{ |
786 | ················MessageBox.Show( "Error while installing the ndo.dll package: " + ex.ToString() ); |
787 | ············} |
788 | ········} |
789 | |
790 | ········private static IVsPackageInstallerServices GetInstallerService( out IComponentModel componentModel ) |
791 | ········{ |
792 | ············componentModel = (IComponentModel)Package.GetGlobalService( typeof( SComponentModel ) ); |
793 | ············var installerService = componentModel.GetService<IVsPackageInstallerServices>(); |
794 | ············return installerService; |
795 | ········} |
796 | |
797 | ········void ShowError(Exception ex) |
798 | ········{ |
799 | ············MessageBox.Show("The following error occured: " + ex.Message, "NDO Add-in"); |
800 | ········} |
801 | |
802 | ········private void btnConnString_Click(object sender, System.EventArgs e) |
803 | ········{ |
804 | ············try |
805 | ············{ |
806 | ················string connType = cbSqlDialect.Text; |
807 | ················if (connType == string.Empty) |
808 | ····················connType = "SqlServer"; |
809 | ················var provider = NdoUIProviderFactory.Instance[connType]; |
810 | ················if (provider == null) |
811 | ················{ |
812 | ····················MessageBox.Show("Can't find a NDO UI provider for the sql dialect " + connType); |
813 | ····················return; |
814 | ················} |
815 | |
816 | ················string temp = this.txtConnectionString.Text; |
817 | ················NdoDialogResult r = provider.ShowConnectionDialog(ref temp); |
818 | ················if (r == NdoDialogResult.Cancel) |
819 | ····················return; |
820 | ················this.txtConnectionString.Text = temp; |
821 | ············} |
822 | ············catch (Exception ex) |
823 | ············{ |
824 | ················ShowError(ex); |
825 | ············} |
826 | ········} |
827 | |
828 | |
829 | ········private void chkGenerateSQLScript_CheckedChanged(object sender, System.EventArgs e) |
830 | ········{ |
831 | ············bool genSql = this.chkGenerateSQLScript.Checked; |
832 | |
833 | ············this.cbSqlDialect.Enabled = genSql; |
834 | ············this.chkIncludeTypecodes.Enabled = genSql; |
835 | ············this.chkDropExistingElements.Enabled = genSql; |
836 | ············this.chkGenerateFkConstraints.Enabled = genSql; |
837 | ············this.radioUtf8Encoding.Enabled = genSql; |
838 | ············this.radioDefaultEncoding.Enabled = genSql; |
839 | ········} |
840 | |
841 | ········private void EnableCheckBoxes() |
842 | ········{ |
843 | ············foreach(Control c in this.Controls) |
844 | ············{ |
845 | ················CheckBox cb = c as CheckBox; |
846 | ················if (c == null) |
847 | ····················continue; |
848 | ················c.Enabled = true; |
849 | ············} |
850 | ············if (this.project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
851 | ················this.chkActivateEnhancer.Enabled = false; |
852 | ········} |
853 | |
854 | ········private void btnPresetApp_Click(object sender, System.EventArgs e) |
855 | ········{ |
856 | ············try |
857 | ············{ |
858 | ················EnableCheckBoxes(); |
859 | ················this.chkVerboseMode.Checked = false; |
860 | ················this.chkActivateAddIn.Checked = true; |
861 | ················this.chkActivateEnhancer.Checked = false; |
862 | ················this.chkMappingNew.Checked = false; |
863 | ················this.chkGenerateSQLScript.Checked = true; |
864 | ················this.chkChangeEvents.Checked = false; |
865 | ················this.chkIncludeTypecodes.Checked = false; |
866 | ················this.chkDropExistingElements.Checked = false; |
867 | ················this.chkGenerateFkConstraints.Checked = false; |
868 | ················this.txtConnectionString.Text = ""; |
869 | ················this.chkUseTimeStamps.Checked = false; |
870 | ················this.txtDbOwner.Text = ""; |
871 | ················this.txtSchemaVersion.Text = "1.0"; |
872 | ················if (this.txtConnectionString.Text == string.Empty) |
873 | ····················this.btnConnString_Click(null, null); |
874 | ············} |
875 | ············catch (Exception ex) |
876 | ············{ |
877 | ················ShowError(ex); |
878 | ············} |
879 | ········} |
880 | |
881 | //········private void MakeNode(string name, object value, XmlNode parentNode, XmlDocument doc) |
882 | //········{ |
883 | //············XmlElement el = doc.CreateElement(name); |
884 | //············parentNode.AppendChild(el); |
885 | //············if (value != null) |
886 | //················el.InnerText = value.ToString(); |
887 | //········} |
888 | |
889 | ········void WriteBack(ConfigurationOptions options) |
890 | ········{ |
891 | ············options.EnableAddIn = chkActivateAddIn.Checked; |
892 | ············options.EnableEnhancer = chkActivateEnhancer.Checked; |
893 | ············options.IncludeTypecodes = chkIncludeTypecodes.Checked; |
894 | ············options.GenerateConstraints = chkGenerateFkConstraints.Checked; |
895 | ············options.DropExistingElements = chkDropExistingElements.Checked; |
896 | ············options.VerboseMode = chkVerboseMode.Checked; |
897 | ············options.NewMapping = chkMappingNew.Checked; |
898 | ············options.GenerateSQL = chkGenerateSQLScript.Checked; |
899 | ············options.DefaultConnection = txtConnectionString.Text; |
900 | ············options.TargetMappingFileName = txtTargetMappingFileName.Text; |
901 | ············options.GenerateChangeEvents = chkChangeEvents.Checked; |
902 | ············options.UseTimeStamps = chkUseTimeStamps.Checked; |
903 | ············options.SQLScriptLanguage = this.cbSqlDialect.Text; |
904 | ············options.DatabaseOwner = this.txtDbOwner.Text; |
905 | ············options.Utf8Encoding = this.radioUtf8Encoding.Checked; |
906 | ············options.SchemaVersion = this.txtSchemaVersion.Text; |
907 | ········} |
908 | |
909 | ········private void btnSaveAs_Click(object sender, System.EventArgs e) |
910 | ········{ |
911 | ············try |
912 | ············{ |
913 | ················string projDir = Path.GetDirectoryName(project.FullName); |
914 | ················SaveFileDialog sfd = new SaveFileDialog(); |
915 | ················sfd.CheckFileExists = false; |
916 | ················sfd.DefaultExt = "xml"; |
917 | ················sfd.Filter = "NDO Configuration Files (*.ndoproj)|*.ndoproj"; |
918 | ················sfd.FileName = "EnhancerParameters.ndoproj"; |
919 | ················sfd.InitialDirectory = projDir; |
920 | ················if (sfd.ShowDialog(this) != DialogResult.OK) |
921 | ····················return; |
922 | |
923 | ················ConfigurationOptions options = new ConfigurationOptions(project);················ |
924 | ················WriteBack(options); |
925 | ················options.SaveAs(sfd.FileName, this.projectDescription); |
926 | ············} |
927 | ············catch (Exception ex) |
928 | ············{ |
929 | ················ShowError(ex); |
930 | ············}········ |
931 | ········} |
932 | |
933 | ········private void cbSqlDialect_SelectedIndexChanged(object sender, System.EventArgs e) |
934 | ········{ |
935 | ············this.txtConnectionString.Text = string.Empty; |
936 | ············CheckEnabledStateForLoadProviderButton(); |
937 | ········} |
938 | |
939 | ········private void btnNewDatabase_Click(object sender, System.EventArgs e) |
940 | ········{ |
941 | ············string connType = cbSqlDialect.Text; |
942 | ············if (connType == string.Empty) |
943 | ················connType = "SqlServer"; |
944 | ············IDbUISupport provider = NdoUIProviderFactory.Instance[connType]; |
945 | ············if (provider == null) |
946 | ············{ |
947 | ················MessageBox.Show("Can't find a NDO UI provider for the sql dialect " + connType); |
948 | ················return; |
949 | ············} |
950 | ············object necessaryData = null; |
951 | ············try |
952 | ············{ |
953 | ················if (provider.ShowCreateDbDialog(ref necessaryData) == NdoDialogResult.Cancel) |
954 | ····················return; |
955 | ················this.txtConnectionString.Text = provider.CreateDatabase(necessaryData); |
956 | ············} |
957 | ············catch (Exception ex) |
958 | ············{ |
959 | #if !DEBUG |
960 | ················MessageBox.Show("Can't construct the database: " + ex.Message); |
961 | #else |
962 | ················MessageBox.Show("Can't construct the database: " + ex.ToString()); |
963 | #endif |
964 | ············} |
965 | ········} |
966 | |
967 | ········private void chlbAssemblies_ItemCheck( object sender, ItemCheckEventArgs e ) |
968 | ········{ |
969 | ············this.references[e.Index].CheckState = e.NewValue; |
970 | ········} |
971 | |
972 | ········private void btnInstallProvider_Click( object sender, EventArgs e ) |
973 | ········{ |
974 | ············try |
975 | ············{ |
976 | ················string providerName = this.cbSqlDialect.Text; |
977 | |
978 | ················if (string.IsNullOrEmpty( providerName )) |
979 | ················{ |
980 | ····················MessageBox.Show( "Please choose a provider" ); |
981 | ····················return; |
982 | ················} |
983 | |
984 | ················IComponentModel componentModel; |
985 | ················var installerService = GetInstallerService( out componentModel ); |
986 | |
987 | ················string packageName = $"ndo.{providerName.ToLower()}"; |
988 | ················if (!installerService.IsPackageInstalled( this.project, packageName )) |
989 | ················{ |
990 | ····················var installer = componentModel.GetService<IVsPackageInstaller>(); |
991 | ····················installer.InstallPackage( null, this.project, packageName, (string)null, false ); |
992 | ················} |
993 | |
994 | ················this.btnInstallProvider.Enabled = false; |
995 | ············} |
996 | ············catch (Exception ex) |
997 | ············{ |
998 | ················MessageBox.Show( "Error while installing the ndo.dll package: " + ex.ToString() ); |
999 | ············} |
1000 | ········} |
1001 | ····} |
1002 | } |
1003 | |
1004 | #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread |
1005 |
New Commit (0a71280)
1 | // |
2 | // Copyright (c) 2002-2019 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Linq; |
25 | using System.IO; |
26 | using System.Windows.Forms; |
27 | using MessageBox = System.Windows.Forms.MessageBox; |
28 | using Project = EnvDTE.Project; |
29 | using System.Diagnostics; |
30 | using Microsoft.VisualStudio.ComponentModelHost; |
31 | using NuGet.VisualStudio; |
32 | using NDO.UISupport; |
33 | using System.Drawing; |
34 | |
35 | #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread |
36 | |
37 | namespace NDOVsPackage |
38 | { |
39 | ····/// <summary> |
40 | ····/// Summary description for ConfigurationDialog. |
41 | ····/// </summary> |
42 | ····internal class ConfigurationDialog : System.Windows.Forms.Form |
43 | ····{ |
44 | ········private System.ComponentModel.IContainer components; |
45 | |
46 | ········private Project project; |
47 | ········private System.Windows.Forms.ToolTip toolTip1; |
48 | ········private TabControl tabControl; |
49 | ········private TabPage tabPageGeneral; |
50 | ········private TextBox txtTargetMappingFileName; |
51 | ········private Label label1; |
52 | ········private CheckBox chkVerboseMode; |
53 | ········private TextBox txtSchemaVersion; |
54 | ········private Label label5; |
55 | ········private Button btnNewDatabase; |
56 | ········private Button btnSaveAs; |
57 | ········private Button btnPresetApp; |
58 | ········private TextBox txtDbOwner; |
59 | ········private TextBox txtConnectionString; |
60 | ········private Label label3; |
61 | ········private GroupBox groupBox1; |
62 | ········private CheckBox chkDropExistingElements; |
63 | ········private CheckBox chkGenerateFkConstraints; |
64 | ········private CheckBox chkIncludeTypecodes; |
65 | ········private RadioButton radioDefaultEncoding; |
66 | ········private RadioButton radioUtf8Encoding; |
67 | ········private Label label4; |
68 | ········private ComboBox cbSqlDialect; |
69 | ········private CheckBox chkGenerateSQLScript; |
70 | ········private CheckBox chkUseTimeStamps; |
71 | ········private CheckBox chkChangeEvents; |
72 | ········private Label label2; |
73 | ········private Button btnConnString; |
74 | ········private Button btnOK; |
75 | ········private Button btnPresetLibrary; |
76 | ········private Button btnCancel; |
77 | ········private CheckBox chkMappingNew; |
78 | ········private CheckBox chkActivateEnhancer; |
79 | ········private CheckBox chkActivateAddIn; |
80 | ········private TabPage tabPageAssemblies; |
81 | ········private Label label6; |
82 | ········private CheckedListBox chlbAssemblies; |
83 | ········private ProjectDescription projectDescription; |
84 | ········private Button btnInstallProvider; |
85 | ········private NDOReference[] references; |
86 | |
87 | ········public ConfigurationDialog(Project project, ProjectDescription projectDescription) |
88 | ········{ |
89 | ············try |
90 | ············{ |
91 | ················this.project = project; |
92 | ················this.projectDescription = projectDescription; |
93 | ················this.projectDescription.BuildReferences(); |
94 | ················this.projectDescription.FixDllState(); |
95 | ················InitializeComponent(); |
96 | ················if (Screen.FromControl( this ).Bounds.Width >= 2600) |
97 | ····················Font = new Font( "Segoe UI", 11f, FontStyle.Regular, GraphicsUnit.Point, 0 ); |
98 | ················var lbAssemblies = (ListBox)this.chlbAssemblies; |
99 | ················this.references = projectDescription.References.Values.ToArray(); |
100 | ················lbAssemblies.DataSource = this.references; |
101 | ················lbAssemblies.DisplayMember = nameof( NDOReference.Name ); |
102 | ················lbAssemblies.ValueMember = nameof( NDOReference.CheckState ); |
103 | ················int i = 0; |
104 | ················foreach (var item in this.references) |
105 | ················{ |
106 | ····················this.chlbAssemblies.SetItemCheckState( i++, item.CheckState ); |
107 | ················} |
108 | ············} |
109 | ············catch (Exception ex) |
110 | ············{ |
111 | ················Debug.WriteLine( ex.ToString() ); |
112 | ············} |
113 | ········} |
114 | |
115 | ········void CheckEnabledStateForLoadProviderButton() |
116 | ········{ |
117 | ············string providerName = this.cbSqlDialect.Text; |
118 | |
119 | ············if (string.IsNullOrEmpty( providerName )) |
120 | ············{ |
121 | ················this.btnInstallProvider.Enabled = false; |
122 | ················return; |
123 | ············} |
124 | |
125 | ············if (IsProviderInstalled(providerName)) |
126 | ············{ |
127 | ················this.btnInstallProvider.Enabled = false; |
128 | ················return; |
129 | ············} |
130 | |
131 | ············this.btnInstallProvider.Enabled = true; |
132 | ········} |
133 | |
134 | ········bool IsProviderInstalled(string providerName) |
135 | ········{ |
136 | ············IComponentModel componentModel; |
137 | ············var installerService = GetInstallerService( out componentModel ); |
138 | |
139 | ············string packageName = $"ndo.{providerName.ToLower()}"; |
140 | ············return installerService.IsPackageInstalled( this.project, packageName ); |
141 | ········} |
142 | |
143 | ········/// <summary> |
144 | ········/// Clean up any resources being used. |
145 | ········/// </summary> |
146 | ········protected override void Dispose( bool disposing ) |
147 | ········{ |
148 | ············if( disposing ) |
149 | ············{ |
150 | ················if(components != null) |
151 | ················{ |
152 | ····················components.Dispose(); |
153 | ················} |
154 | ············} |
155 | ············base.Dispose( disposing ); |
156 | ········} |
157 | |
158 | ········#region Windows Form Designer generated code |
159 | ········/// <summary> |
160 | ········/// Required method for Designer support - do not modify |
161 | ········/// the contents of this method with the code editor. |
162 | ········/// </summary> |
163 | ········private void InitializeComponent() |
164 | ········{ |
165 | ············this.components = new System.ComponentModel.Container(); |
166 | ············System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConfigurationDialog)); |
167 | ············this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); |
168 | ············this.chkVerboseMode = new System.Windows.Forms.CheckBox(); |
169 | ············this.btnNewDatabase = new System.Windows.Forms.Button(); |
170 | ············this.btnSaveAs = new System.Windows.Forms.Button(); |
171 | ············this.btnPresetApp = new System.Windows.Forms.Button(); |
172 | ············this.txtDbOwner = new System.Windows.Forms.TextBox(); |
173 | ············this.txtConnectionString = new System.Windows.Forms.TextBox(); |
174 | ············this.chkDropExistingElements = new System.Windows.Forms.CheckBox(); |
175 | ············this.chkGenerateFkConstraints = new System.Windows.Forms.CheckBox(); |
176 | ············this.chkIncludeTypecodes = new System.Windows.Forms.CheckBox(); |
177 | ············this.radioDefaultEncoding = new System.Windows.Forms.RadioButton(); |
178 | ············this.radioUtf8Encoding = new System.Windows.Forms.RadioButton(); |
179 | ············this.cbSqlDialect = new System.Windows.Forms.ComboBox(); |
180 | ············this.chkGenerateSQLScript = new System.Windows.Forms.CheckBox(); |
181 | ············this.chkUseTimeStamps = new System.Windows.Forms.CheckBox(); |
182 | ············this.chkChangeEvents = new System.Windows.Forms.CheckBox(); |
183 | ············this.btnConnString = new System.Windows.Forms.Button(); |
184 | ············this.btnPresetLibrary = new System.Windows.Forms.Button(); |
185 | ············this.chkMappingNew = new System.Windows.Forms.CheckBox(); |
186 | ············this.chkActivateEnhancer = new System.Windows.Forms.CheckBox(); |
187 | ············this.chkActivateAddIn = new System.Windows.Forms.CheckBox(); |
188 | ············this.tabControl = new System.Windows.Forms.TabControl(); |
189 | ············this.tabPageGeneral = new System.Windows.Forms.TabPage(); |
190 | ············this.txtTargetMappingFileName = new System.Windows.Forms.TextBox(); |
191 | ············this.label1 = new System.Windows.Forms.Label(); |
192 | ············this.txtSchemaVersion = new System.Windows.Forms.TextBox(); |
193 | ············this.label5 = new System.Windows.Forms.Label(); |
194 | ············this.label3 = new System.Windows.Forms.Label(); |
195 | ············this.groupBox1 = new System.Windows.Forms.GroupBox(); |
196 | ············this.btnInstallProvider = new System.Windows.Forms.Button(); |
197 | ············this.label4 = new System.Windows.Forms.Label(); |
198 | ············this.label2 = new System.Windows.Forms.Label(); |
199 | ············this.tabPageAssemblies = new System.Windows.Forms.TabPage(); |
200 | ············this.label6 = new System.Windows.Forms.Label(); |
201 | ············this.chlbAssemblies = new System.Windows.Forms.CheckedListBox(); |
202 | ············this.btnOK = new System.Windows.Forms.Button(); |
203 | ············this.btnCancel = new System.Windows.Forms.Button(); |
204 | ············this.tabControl.SuspendLayout(); |
205 | ············this.tabPageGeneral.SuspendLayout(); |
206 | ············this.groupBox1.SuspendLayout(); |
207 | ············this.tabPageAssemblies.SuspendLayout(); |
208 | ············this.SuspendLayout(); |
209 | ············// |
210 | ············// chkVerboseMode |
211 | ············// |
212 | ············this.chkVerboseMode.Location = new System.Drawing.Point(21, 72); |
213 | ············this.chkVerboseMode.Name = "chkVerboseMode"; |
214 | ············this.chkVerboseMode.Size = new System.Drawing.Size(238, 21); |
215 | ············this.chkVerboseMode.TabIndex = 51; |
216 | ············this.chkVerboseMode.Text = "Add-in Verbose Mode"; |
217 | ············this.toolTip1.SetToolTip(this.chkVerboseMode, "Causes the Add-in and the Enhancer to show more information for debugging purpose" + |
218 | ········"s."); |
219 | ············// |
220 | ············// btnNewDatabase |
221 | ············// |
222 | ············this.btnNewDatabase.Location = new System.Drawing.Point(583, 313); |
223 | ············this.btnNewDatabase.Name = "btnNewDatabase"; |
224 | ············this.btnNewDatabase.Size = new System.Drawing.Size(42, 21); |
225 | ············this.btnNewDatabase.TabIndex = 48; |
226 | ············this.btnNewDatabase.Text = "New"; |
227 | ············this.toolTip1.SetToolTip(this.btnNewDatabase, "Create new database"); |
228 | ············this.btnNewDatabase.Click += new System.EventHandler(this.btnNewDatabase_Click); |
229 | ············// |
230 | ············// btnSaveAs |
231 | ············// |
232 | ············this.btnSaveAs.DialogResult = System.Windows.Forms.DialogResult.OK; |
233 | ············this.btnSaveAs.Location = new System.Drawing.Point(249, 385); |
234 | ············this.btnSaveAs.Name = "btnSaveAs"; |
235 | ············this.btnSaveAs.Size = new System.Drawing.Size(100, 39); |
236 | ············this.btnSaveAs.TabIndex = 47; |
237 | ············this.btnSaveAs.Text = "Save as..."; |
238 | ············this.toolTip1.SetToolTip(this.btnSaveAs, "Save the options to be used in unattended builds with the stand-alone enhancer."); |
239 | ············this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click); |
240 | ············// |
241 | ············// btnPresetApp |
242 | ············// |
243 | ············this.btnPresetApp.Location = new System.Drawing.Point(135, 385); |
244 | ············this.btnPresetApp.Name = "btnPresetApp"; |
245 | ············this.btnPresetApp.Size = new System.Drawing.Size(100, 39); |
246 | ············this.btnPresetApp.TabIndex = 46; |
247 | ············this.btnPresetApp.Text = "Preset for Application"; |
248 | ············this.toolTip1.SetToolTip(this.btnPresetApp, "Selects all settings used for applications which don\'t contain but reference pers" + |
249 | ········"istent types."); |
250 | ············this.btnPresetApp.Click += new System.EventHandler(this.btnPresetApp_Click); |
251 | ············// |
252 | ············// txtDbOwner |
253 | ············// |
254 | ············this.txtDbOwner.Location = new System.Drawing.Point(145, 126); |
255 | ············this.txtDbOwner.Name = "txtDbOwner"; |
256 | ············this.txtDbOwner.Size = new System.Drawing.Size(160, 20); |
257 | ············this.txtDbOwner.TabIndex = 45; |
258 | ············this.toolTip1.SetToolTip(this.txtDbOwner, "Enter an owner name, if you like your tables to be written like owner.tablename."); |
259 | ············// |
260 | ············// txtConnectionString |
261 | ············// |
262 | ············this.txtConnectionString.Location = new System.Drawing.Point(18, 313); |
263 | ············this.txtConnectionString.Name = "txtConnectionString"; |
264 | ············this.txtConnectionString.Size = new System.Drawing.Size(514, 20); |
265 | ············this.txtConnectionString.TabIndex = 39; |
266 | ············this.toolTip1.SetToolTip(this.txtConnectionString, "This string will be copied into the mapping file, if there doesn\'t exist a valid " + |
267 | ········"connection string. Otherwise it will be ignored."); |
268 | ············// |
269 | ············// chkDropExistingElements |
270 | ············// |
271 | ············this.chkDropExistingElements.Location = new System.Drawing.Point(13, 202); |
272 | ············this.chkDropExistingElements.Name = "chkDropExistingElements"; |
273 | ············this.chkDropExistingElements.Size = new System.Drawing.Size(235, 21); |
274 | ············this.chkDropExistingElements.TabIndex = 24; |
275 | ············this.chkDropExistingElements.Text = "Insert Drop Statements in the Script"; |
276 | ············this.toolTip1.SetToolTip(this.chkDropExistingElements, "If checked, NDO generates instructions to remove existing tables and constraints." + |
277 | ········""); |
278 | ············// |
279 | ············// chkGenerateFkConstraints |
280 | ············// |
281 | ············this.chkGenerateFkConstraints.Location = new System.Drawing.Point(13, 152); |
282 | ············this.chkGenerateFkConstraints.Name = "chkGenerateFkConstraints"; |
283 | ············this.chkGenerateFkConstraints.Size = new System.Drawing.Size(235, 21); |
284 | ············this.chkGenerateFkConstraints.TabIndex = 23; |
285 | ············this.chkGenerateFkConstraints.Text = "Generate Foreign Key Constraints"; |
286 | ············this.toolTip1.SetToolTip(this.chkGenerateFkConstraints, "If checked, NDO generates foreign key constraints for the relations in the databa" + |
287 | ········"se."); |
288 | ············// |
289 | ············// chkIncludeTypecodes |
290 | ············// |
291 | ············this.chkIncludeTypecodes.Location = new System.Drawing.Point(13, 177); |
292 | ············this.chkIncludeTypecodes.Name = "chkIncludeTypecodes"; |
293 | ············this.chkIncludeTypecodes.Size = new System.Drawing.Size(235, 21); |
294 | ············this.chkIncludeTypecodes.TabIndex = 22; |
295 | ············this.chkIncludeTypecodes.Text = "Include Typecodes in the Script"; |
296 | ············this.toolTip1.SetToolTip(this.chkIncludeTypecodes, "If checked, NDO generates instructions to build an additional table with the type" + |
297 | ········" code information."); |
298 | ············// |
299 | ············// radioDefaultEncoding |
300 | ············// |
301 | ············this.radioDefaultEncoding.Location = new System.Drawing.Point(13, 121); |
302 | ············this.radioDefaultEncoding.Name = "radioDefaultEncoding"; |
303 | ············this.radioDefaultEncoding.Size = new System.Drawing.Size(140, 20); |
304 | ············this.radioDefaultEncoding.TabIndex = 21; |
305 | ············this.radioDefaultEncoding.Text = "Default Encoding"; |
306 | ············this.toolTip1.SetToolTip(this.radioDefaultEncoding, "Check this option, if the script files should use windows encoding."); |
307 | ············// |
308 | ············// radioUtf8Encoding |
309 | ············// |
310 | ············this.radioUtf8Encoding.Checked = true; |
311 | ············this.radioUtf8Encoding.Location = new System.Drawing.Point(13, 99); |
312 | ············this.radioUtf8Encoding.Name = "radioUtf8Encoding"; |
313 | ············this.radioUtf8Encoding.Size = new System.Drawing.Size(140, 21); |
314 | ············this.radioUtf8Encoding.TabIndex = 20; |
315 | ············this.radioUtf8Encoding.TabStop = true; |
316 | ············this.radioUtf8Encoding.Text = "UTF-8 Encoding"; |
317 | ············this.toolTip1.SetToolTip(this.radioUtf8Encoding, "Check this option, if the script files should be UTF-8 encoded."); |
318 | ············// |
319 | ············// cbSqlDialect |
320 | ············// |
321 | ············this.cbSqlDialect.Location = new System.Drawing.Point(13, 70); |
322 | ············this.cbSqlDialect.Name = "cbSqlDialect"; |
323 | ············this.cbSqlDialect.Size = new System.Drawing.Size(220, 21); |
324 | ············this.cbSqlDialect.TabIndex = 18; |
325 | ············this.toolTip1.SetToolTip(this.cbSqlDialect, "Choose an available NDO provider."); |
326 | ············this.cbSqlDialect.SelectedIndexChanged += new System.EventHandler(this.cbSqlDialect_SelectedIndexChanged); |
327 | ············// |
328 | ············// chkGenerateSQLScript |
329 | ············// |
330 | ············this.chkGenerateSQLScript.Location = new System.Drawing.Point(13, 21); |
331 | ············this.chkGenerateSQLScript.Name = "chkGenerateSQLScript"; |
332 | ············this.chkGenerateSQLScript.Size = new System.Drawing.Size(187, 21); |
333 | ············this.chkGenerateSQLScript.TabIndex = 13; |
334 | ············this.chkGenerateSQLScript.Text = "Generate SQL Script"; |
335 | ············this.toolTip1.SetToolTip(this.chkGenerateSQLScript, "If checked, NDO will create a script with DDL code, which can be used to construc" + |
336 | ········"t a database structure."); |
337 | ············this.chkGenerateSQLScript.CheckedChanged += new System.EventHandler(this.chkGenerateSQLScript_CheckedChanged); |
338 | ············// |
339 | ············// chkUseTimeStamps |
340 | ············// |
341 | ············this.chkUseTimeStamps.Location = new System.Drawing.Point(21, 153); |
342 | ············this.chkUseTimeStamps.Name = "chkUseTimeStamps"; |
343 | ············this.chkUseTimeStamps.Size = new System.Drawing.Size(302, 20); |
344 | ············this.chkUseTimeStamps.TabIndex = 42; |
345 | ············this.chkUseTimeStamps.Text = "Generate Time Stamp Columns for each class"; |
346 | ············this.toolTip1.SetToolTip(this.chkUseTimeStamps, "Check this option, if all tables should be protected by collistion detection."); |
347 | ············// |
348 | ············// chkChangeEvents |
349 | ············// |
350 | ············this.chkChangeEvents.Location = new System.Drawing.Point(21, 179); |
351 | ············this.chkChangeEvents.Name = "chkChangeEvents"; |
352 | ············this.chkChangeEvents.Size = new System.Drawing.Size(302, 21); |
353 | ············this.chkChangeEvents.TabIndex = 41; |
354 | ············this.chkChangeEvents.Text = "Generate change events with Add Accessor"; |
355 | ············this.toolTip1.SetToolTip(this.chkChangeEvents, "Check this option, if you intend to bind the UI directly to the accessor properti" + |
356 | ········"es of your persistent classes."); |
357 | ············// |
358 | ············// btnConnString |
359 | ············// |
360 | ············this.btnConnString.Location = new System.Drawing.Point(538, 313); |
361 | ············this.btnConnString.Name = "btnConnString"; |
362 | ············this.btnConnString.Size = new System.Drawing.Size(42, 21); |
363 | ············this.btnConnString.TabIndex = 38; |
364 | ············this.btnConnString.Text = "..."; |
365 | ············this.toolTip1.SetToolTip(this.btnConnString, "Enter existing database connection"); |
366 | ············this.btnConnString.Click += new System.EventHandler(this.btnConnString_Click); |
367 | ············// |
368 | ············// btnPresetLibrary |
369 | ············// |
370 | ············this.btnPresetLibrary.Location = new System.Drawing.Point(21, 385); |
371 | ············this.btnPresetLibrary.Name = "btnPresetLibrary"; |
372 | ············this.btnPresetLibrary.Size = new System.Drawing.Size(100, 39); |
373 | ············this.btnPresetLibrary.TabIndex = 36; |
374 | ············this.btnPresetLibrary.Text = "Preset for Library"; |
375 | ············this.toolTip1.SetToolTip(this.btnPresetLibrary, "Selects all settings necessary for projects containing persistent types."); |
376 | ············this.btnPresetLibrary.Click += new System.EventHandler(this.btnPresetLibrary_Click); |
377 | ············// |
378 | ············// chkMappingNew |
379 | ············// |
380 | ············this.chkMappingNew.Location = new System.Drawing.Point(21, 99); |
381 | ············this.chkMappingNew.Name = "chkMappingNew"; |
382 | ············this.chkMappingNew.Size = new System.Drawing.Size(272, 21); |
383 | ············this.chkMappingNew.TabIndex = 34; |
384 | ············this.chkMappingNew.Text = "Always Generate a new mapping File"; |
385 | ············this.toolTip1.SetToolTip(this.chkMappingNew, "Choose this options, if NDO should discard and rebuild all mapping information."); |
386 | ············// |
387 | ············// chkActivateEnhancer |
388 | ············// |
389 | ············this.chkActivateEnhancer.Location = new System.Drawing.Point(21, 46); |
390 | ············this.chkActivateEnhancer.Name = "chkActivateEnhancer"; |
391 | ············this.chkActivateEnhancer.Size = new System.Drawing.Size(188, 20); |
392 | ············this.chkActivateEnhancer.TabIndex = 33; |
393 | ············this.chkActivateEnhancer.Text = "Activate enhancer"; |
394 | ············this.toolTip1.SetToolTip(this.chkActivateEnhancer, "Choose this option, if your project contains persistent types."); |
395 | ············// |
396 | ············// chkActivateAddIn |
397 | ············// |
398 | ············this.chkActivateAddIn.Location = new System.Drawing.Point(21, 19); |
399 | ············this.chkActivateAddIn.Name = "chkActivateAddIn"; |
400 | ············this.chkActivateAddIn.Size = new System.Drawing.Size(188, 21); |
401 | ············this.chkActivateAddIn.TabIndex = 32; |
402 | ············this.chkActivateAddIn.Text = "Activate NDO AddIn"; |
403 | ············this.toolTip1.SetToolTip(this.chkActivateAddIn, "Choose this options, if your project contains or references persistent types."); |
404 | ············this.chkActivateAddIn.Click += new System.EventHandler(this.chkActivateAddIn_CheckedChanged); |
405 | ············// |
406 | ············// tabControl |
407 | ············// |
408 | ············this.tabControl.Controls.Add(this.tabPageGeneral); |
409 | ············this.tabControl.Controls.Add(this.tabPageAssemblies); |
410 | ············this.tabControl.Dock = System.Windows.Forms.DockStyle.Top; |
411 | ············this.tabControl.Location = new System.Drawing.Point(0, 0); |
412 | ············this.tabControl.Name = "tabControl"; |
413 | ············this.tabControl.SelectedIndex = 0; |
414 | ············this.tabControl.Size = new System.Drawing.Size(661, 374); |
415 | ············this.tabControl.TabIndex = 0; |
416 | ············// |
417 | ············// tabPageGeneral |
418 | ············// |
419 | ············this.tabPageGeneral.Controls.Add(this.txtTargetMappingFileName); |
420 | ············this.tabPageGeneral.Controls.Add(this.label1); |
421 | ············this.tabPageGeneral.Controls.Add(this.chkVerboseMode); |
422 | ············this.tabPageGeneral.Controls.Add(this.txtSchemaVersion); |
423 | ············this.tabPageGeneral.Controls.Add(this.label5); |
424 | ············this.tabPageGeneral.Controls.Add(this.btnNewDatabase); |
425 | ············this.tabPageGeneral.Controls.Add(this.txtDbOwner); |
426 | ············this.tabPageGeneral.Controls.Add(this.txtConnectionString); |
427 | ············this.tabPageGeneral.Controls.Add(this.label3); |
428 | ············this.tabPageGeneral.Controls.Add(this.groupBox1); |
429 | ············this.tabPageGeneral.Controls.Add(this.chkUseTimeStamps); |
430 | ············this.tabPageGeneral.Controls.Add(this.chkChangeEvents); |
431 | ············this.tabPageGeneral.Controls.Add(this.label2); |
432 | ············this.tabPageGeneral.Controls.Add(this.btnConnString); |
433 | ············this.tabPageGeneral.Controls.Add(this.chkMappingNew); |
434 | ············this.tabPageGeneral.Controls.Add(this.chkActivateEnhancer); |
435 | ············this.tabPageGeneral.Controls.Add(this.chkActivateAddIn); |
436 | ············this.tabPageGeneral.Location = new System.Drawing.Point(4, 22); |
437 | ············this.tabPageGeneral.Name = "tabPageGeneral"; |
438 | ············this.tabPageGeneral.Padding = new System.Windows.Forms.Padding(3); |
439 | ············this.tabPageGeneral.Size = new System.Drawing.Size(653, 348); |
440 | ············this.tabPageGeneral.TabIndex = 0; |
441 | ············this.tabPageGeneral.Text = "General"; |
442 | ············this.tabPageGeneral.UseVisualStyleBackColor = true; |
443 | ············// |
444 | ············// txtTargetMappingFileName |
445 | ············// |
446 | ············this.txtTargetMappingFileName.Location = new System.Drawing.Point(145, 245); |
447 | ············this.txtTargetMappingFileName.Name = "txtTargetMappingFileName"; |
448 | ············this.txtTargetMappingFileName.Size = new System.Drawing.Size(160, 20); |
449 | ············this.txtTargetMappingFileName.TabIndex = 53; |
450 | ············// |
451 | ············// label1 |
452 | ············// |
453 | ············this.label1.Location = new System.Drawing.Point(18, 246); |
454 | ············this.label1.Name = "label1"; |
455 | ············this.label1.Size = new System.Drawing.Size(121, 21); |
456 | ············this.label1.TabIndex = 52; |
457 | ············this.label1.Text = "Mapping File Name"; |
458 | ············// |
459 | ············// txtSchemaVersion |
460 | ············// |
461 | ············this.txtSchemaVersion.Location = new System.Drawing.Point(145, 219); |
462 | ············this.txtSchemaVersion.Name = "txtSchemaVersion"; |
463 | ············this.txtSchemaVersion.Size = new System.Drawing.Size(160, 20); |
464 | ············this.txtSchemaVersion.TabIndex = 50; |
465 | ············// |
466 | ············// label5 |
467 | ············// |
468 | ············this.label5.Location = new System.Drawing.Point(18, 220); |
469 | ············this.label5.Name = "label5"; |
470 | ············this.label5.Size = new System.Drawing.Size(121, 21); |
471 | ············this.label5.TabIndex = 49; |
472 | ············this.label5.Text = "Schema Version"; |
473 | ············// |
474 | ············// label3 |
475 | ············// |
476 | ············this.label3.Location = new System.Drawing.Point(18, 128); |
477 | ············this.label3.Name = "label3"; |
478 | ············this.label3.Size = new System.Drawing.Size(127, 21); |
479 | ············this.label3.TabIndex = 44; |
480 | ············this.label3.Text = "Owner / Schema Name"; |
481 | ············// |
482 | ············// groupBox1 |
483 | ············// |
484 | ············this.groupBox1.Controls.Add(this.btnInstallProvider); |
485 | ············this.groupBox1.Controls.Add(this.chkDropExistingElements); |
486 | ············this.groupBox1.Controls.Add(this.chkGenerateFkConstraints); |
487 | ············this.groupBox1.Controls.Add(this.chkIncludeTypecodes); |
488 | ············this.groupBox1.Controls.Add(this.radioDefaultEncoding); |
489 | ············this.groupBox1.Controls.Add(this.radioUtf8Encoding); |
490 | ············this.groupBox1.Controls.Add(this.label4); |
491 | ············this.groupBox1.Controls.Add(this.cbSqlDialect); |
492 | ············this.groupBox1.Controls.Add(this.chkGenerateSQLScript); |
493 | ············this.groupBox1.Location = new System.Drawing.Point(343, 21); |
494 | ············this.groupBox1.Name = "groupBox1"; |
495 | ············this.groupBox1.Size = new System.Drawing.Size(265, 244); |
496 | ············this.groupBox1.TabIndex = 43; |
497 | ············this.groupBox1.TabStop = false; |
498 | ············this.groupBox1.Text = " SQL "; |
499 | ············// |
500 | ············// btnInstallProvider |
501 | ············// |
502 | ············this.btnInstallProvider.Location = new System.Drawing.Point(142, 102); |
503 | ············this.btnInstallProvider.Name = "btnInstallProvider"; |
504 | ············this.btnInstallProvider.Size = new System.Drawing.Size(91, 22); |
505 | ············this.btnInstallProvider.TabIndex = 25; |
506 | ············this.btnInstallProvider.Text = "Install Provider"; |
507 | ············this.btnInstallProvider.UseVisualStyleBackColor = true; |
508 | ············this.btnInstallProvider.Click += new System.EventHandler(this.btnInstallProvider_Click); |
509 | ············// |
510 | ············// label4 |
511 | ············// |
512 | ············this.label4.Location = new System.Drawing.Point(13, 50); |
513 | ············this.label4.Name = "label4"; |
514 | ············this.label4.Size = new System.Drawing.Size(200, 17); |
515 | ············this.label4.TabIndex = 19; |
516 | ············this.label4.Text = "SQL Dialect"; |
517 | ············// |
518 | ············// label2 |
519 | ············// |
520 | ············this.label2.Location = new System.Drawing.Point(18, 292); |
521 | ············this.label2.Name = "label2"; |
522 | ············this.label2.Size = new System.Drawing.Size(360, 21); |
523 | ············this.label2.TabIndex = 40; |
524 | ············this.label2.Text = "Default Connection String"; |
525 | ············// |
526 | ············// tabPageAssemblies |
527 | ············// |
528 | ············this.tabPageAssemblies.Controls.Add(this.label6); |
529 | ············this.tabPageAssemblies.Controls.Add(this.chlbAssemblies); |
530 | ············this.tabPageAssemblies.Location = new System.Drawing.Point(4, 22); |
531 | ············this.tabPageAssemblies.Name = "tabPageAssemblies"; |
532 | ············this.tabPageAssemblies.Padding = new System.Windows.Forms.Padding(3); |
533 | ············this.tabPageAssemblies.Size = new System.Drawing.Size(653, 348); |
534 | ············this.tabPageAssemblies.TabIndex = 1; |
535 | ············this.tabPageAssemblies.Text = "Assemblies"; |
536 | ············this.tabPageAssemblies.UseVisualStyleBackColor = true; |
537 | ············// |
538 | ············// label6 |
539 | ············// |
540 | ············this.label6.AutoSize = true; |
541 | ············this.label6.Location = new System.Drawing.Point(10, 12); |
542 | ············this.label6.Name = "label6"; |
543 | ············this.label6.Size = new System.Drawing.Size(328, 13); |
544 | ············this.label6.TabIndex = 1; |
545 | ············this.label6.Text = "Choose Assemblies which should be analyzed by the NDOEnhancer"; |
546 | ············// |
547 | ············// chlbAssemblies |
548 | ············// |
549 | ············this.chlbAssemblies.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
550 | ············| System.Windows.Forms.AnchorStyles.Left) |
551 | ············| System.Windows.Forms.AnchorStyles.Right))); |
552 | ············this.chlbAssemblies.FormattingEnabled = true; |
553 | ············this.chlbAssemblies.Location = new System.Drawing.Point(10, 39); |
554 | ············this.chlbAssemblies.Name = "chlbAssemblies"; |
555 | ············this.chlbAssemblies.Size = new System.Drawing.Size(631, 289); |
556 | ············this.chlbAssemblies.TabIndex = 0; |
557 | ············this.chlbAssemblies.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.chlbAssemblies_ItemCheck); |
558 | ············// |
559 | ············// btnOK |
560 | ············// |
561 | ············this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; |
562 | ············this.btnOK.Location = new System.Drawing.Point(363, 385); |
563 | ············this.btnOK.Name = "btnOK"; |
564 | ············this.btnOK.Size = new System.Drawing.Size(100, 39); |
565 | ············this.btnOK.TabIndex = 37; |
566 | ············this.btnOK.Text = "OK"; |
567 | ············this.btnOK.Click += new System.EventHandler(this.btnOK_Click); |
568 | ············// |
569 | ············// btnCancel |
570 | ············// |
571 | ············this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; |
572 | ············this.btnCancel.Location = new System.Drawing.Point(477, 385); |
573 | ············this.btnCancel.Name = "btnCancel"; |
574 | ············this.btnCancel.Size = new System.Drawing.Size(100, 39); |
575 | ············this.btnCancel.TabIndex = 35; |
576 | ············this.btnCancel.Text = "Cancel"; |
577 | ············// |
578 | ············// ConfigurationDialog |
579 | ············// |
580 | ············this.AutoScaleMode = AutoScaleMode.Font; |
581 | ············this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
582 | ············this.CancelButton = this.btnCancel; |
583 | ············this.ClientSize = new System.Drawing.Size(661, 439); |
584 | ············this.Controls.Add(this.btnSaveAs); |
585 | ············this.Controls.Add(this.btnPresetApp); |
586 | ············this.Controls.Add(this.btnOK); |
587 | ············this.Controls.Add(this.btnPresetLibrary); |
588 | ············this.Controls.Add(this.btnCancel); |
589 | ············this.Controls.Add(this.tabControl); |
590 | ············this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
591 | ············this.Name = "ConfigurationDialog"; |
592 | ············this.Text = "NDO Configuration"; |
593 | ············this.Load += new System.EventHandler(this.ConfigurationDialog_Load); |
594 | ············this.tabControl.ResumeLayout(false); |
595 | ············this.tabPageGeneral.ResumeLayout(false); |
596 | ············this.tabPageGeneral.PerformLayout(); |
597 | ············this.groupBox1.ResumeLayout(false); |
598 | ············this.tabPageAssemblies.ResumeLayout(false); |
599 | ············this.tabPageAssemblies.PerformLayout(); |
600 | ············this.ResumeLayout(false); |
601 | |
602 | ········} |
603 | ········#endregion |
604 | |
605 | ········private void chkActivateAddIn_CheckedChanged(object sender, System.EventArgs e) |
606 | ········{ |
607 | ············EnableAddin(this.chkActivateAddIn.Checked); |
608 | ········} |
609 | |
610 | |
611 | ········void EnableAddin(bool enabled) |
612 | ········{ |
613 | ············if (project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
614 | ················chkActivateEnhancer.Enabled = false; |
615 | ············else |
616 | ················chkActivateEnhancer.Enabled = enabled; |
617 | ········} |
618 | |
619 | ········private void ConfigurationDialog_Load(object sender, System.EventArgs e) |
620 | ········{ |
621 | ············try |
622 | ············{ |
623 | ················ConfigurationOptions options = new ConfigurationOptions(project); |
624 | ················this.Text = "NDO Configuration - " + project.Name; |
625 | ················chkIncludeTypecodes.Checked = options.IncludeTypecodes; |
626 | ················chkDropExistingElements.Checked = options.DropExistingElements; |
627 | ················chkGenerateFkConstraints.Checked = options.GenerateConstraints; |
628 | ················chkVerboseMode.Checked = options.VerboseMode; |
629 | ················chkChangeEvents.Checked = options.GenerateChangeEvents; |
630 | ················chkActivateAddIn.Checked = options.EnableAddIn; |
631 | ················chkActivateEnhancer.Checked = options.EnableEnhancer; |
632 | ················chkMappingNew.Checked = options.NewMapping; |
633 | ················if (chkActivateAddIn.Checked == false) |
634 | ····················EnableAddin(false); |
635 | ················chkGenerateSQLScript.Checked = options.GenerateSQL; |
636 | ················txtSchemaVersion.Text = options.SchemaVersion; |
637 | ················if (string.IsNullOrEmpty(txtSchemaVersion.Text)) |
638 | ····················txtSchemaVersion.Text = "1.0"; |
639 | ················this.chkUseTimeStamps.Checked = options.UseTimeStamps; |
640 | ················int i = 0; |
641 | ················this.cbSqlDialect.Items.Clear(); |
642 | ················int currentDialectIndex = -1; |
643 | |
644 | ················foreach (string s in NdoUIProviderFactory.Instance.Keys) |
645 | ················{ |
646 | ····················this.cbSqlDialect.Items.Add(s); |
647 | ····················if (options.SQLScriptLanguage == s) |
648 | ························currentDialectIndex = i; |
649 | ····················i++; |
650 | ················} |
651 | ················if (currentDialectIndex > -1) |
652 | ····················cbSqlDialect.SelectedIndex = currentDialectIndex; |
653 | |
654 | ················// Must be initialized after changing the cbSqlDialect index |
655 | ················txtConnectionString.Text = options.DefaultConnection; |
656 | ················txtTargetMappingFileName.Text = options.TargetMappingFileName; |
657 | ················txtDbOwner.Text = options.DatabaseOwner; |
658 | ················chkActivateAddIn_CheckedChanged(null, EventArgs.Empty); |
659 | ················chkGenerateSQLScript_CheckedChanged(null, EventArgs.Empty); |
660 | ················if (options.Utf8Encoding) |
661 | ····················radioUtf8Encoding.Checked = true; |
662 | ················else |
663 | ····················radioDefaultEncoding.Checked = true; |
664 | ················if (project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
665 | ····················this.chkActivateEnhancer.Enabled = false; |
666 | |
667 | ················CheckEnabledStateForLoadProviderButton(); |
668 | ············} |
669 | ············catch (Exception ex) |
670 | ············{ |
671 | #if !DEBUG |
672 | ················MessageBox.Show(ex.Message, "NDO Configuration"); |
673 | #else |
674 | ················MessageBox.Show(ex.ToString(), "NDO Configuration"); |
675 | #endif |
676 | ············} |
677 | ········} |
678 | |
679 | ········private void btnPresetLibrary_Click(object sender, System.EventArgs e) |
680 | ········{ |
681 | //············ConfigurationOptions options = new ConfigurationOptions( project ); |
682 | ············try |
683 | ············{ |
684 | ················EnableCheckBoxes(); |
685 | |
686 | ················this.chkVerboseMode.Checked = false; |
687 | ················this.chkActivateAddIn.Checked = true; |
688 | ················this.chkActivateEnhancer.Checked = true; |
689 | ················this.chkMappingNew.Checked = false; |
690 | ················this.chkChangeEvents.Checked = false; |
691 | ················this.chkIncludeTypecodes.Checked = false; |
692 | ················this.chkGenerateFkConstraints.Checked = false; |
693 | ················this.chkDropExistingElements.Checked = false; |
694 | ················this.chkUseTimeStamps.Checked = false;···· |
695 | ················this.txtDbOwner.Text = ""; |
696 | ················this.chkGenerateSQLScript.Checked = false; |
697 | ················this.txtSchemaVersion.Text = ""; |
698 | ············} |
699 | ············catch (Exception ex) |
700 | ············{ |
701 | ················ShowError(ex); |
702 | ············} |
703 | ········} |
704 | |
705 | |
706 | ········private void btnOK_Click(object sender, System.EventArgs e) |
707 | ········{ |
708 | ············try |
709 | ············{ |
710 | ················ConfigurationOptions options = new ConfigurationOptions( project ); |
711 | |
712 | ················string connType = options.SQLScriptLanguage; |
713 | ················string connName = options.DefaultConnection; |
714 | ················WriteBack(options); |
715 | ················if (options.SQLScriptLanguage != connType || options.DefaultConnection != connName) |
716 | ················{ |
717 | ····················string mappingFileName = this.project.MappingFilePath(); |
718 | ····················if (mappingFileName != null) |
719 | ····················{ |
720 | ························NDOMapping mapping = new NDOMapping(mappingFileName); |
721 | ························bool connectionExists = false; |
722 | ························foreach (Connection conn in mapping.Connections) |
723 | ························{ |
724 | ····························if (conn.Type == options.SQLScriptLanguage && conn.Name == options.DefaultConnection) |
725 | ····························{ |
726 | ································connectionExists = true; |
727 | ································break; |
728 | ····························} |
729 | ························} |
730 | ························if (!connectionExists) |
731 | ························{ |
732 | ····························if (MessageBox.Show("The database connection settings have been changed. Should NDO change the connection settings in the mapping file " + Path.GetFileName(mappingFileName) + " too?", "NDO Configuration", MessageBoxButtons.YesNo) == DialogResult.Yes) |
733 | ····························{ |
734 | ································Connection conn = null; |
735 | ································if (mapping.Connections.Count() == 1) |
736 | ································{ |
737 | ····································conn = (Connection)mapping.Connections.FirstOrDefault(); |
738 | ································} |
739 | ································else |
740 | ································{ |
741 | ····································conn = mapping.NewConnection(String.Empty, String.Empty); |
742 | ····································MessageBox.Show("Added a connection with the ID " + conn.ID, "NDO Configuration"); |
743 | ································} |
744 | ································conn.Type = options.SQLScriptLanguage; |
745 | ································conn.Name = options.DefaultConnection; |
746 | ································mapping.Save(); |
747 | ····························} |
748 | ························} |
749 | ····················} |
750 | ················} |
751 | |
752 | ················if ( options.EnableAddIn ) |
753 | ················{ |
754 | ····················GeneratePackageReference(); |
755 | ················} |
756 | |
757 | ················ThreadHelper.JoinableTaskFactory.Run( async () => await options.SaveAsync( this.projectDescription ) ); |
758 | ················ |
759 | ············} |
760 | ············catch (Exception ex) |
761 | ············{ |
762 | #if DEBUG |
763 | ················MessageBox.Show( "The following error occured while saving your options: " + ex.ToString(), "NDO Add-in" ); |
764 | #else |
765 | ················MessageBox.Show("The following error occured while saving your options: " + ex.Message, "NDO Add-in"); |
766 | #endif |
767 | ············} |
768 | ········} |
769 | |
770 | |
771 | ········void GeneratePackageReference() |
772 | ········{ |
773 | ············try |
774 | ············{ |
775 | ················IComponentModel componentModel; |
776 | ················var installerService = GetInstallerService( out componentModel ); |
777 | |
778 | ················if (!installerService.IsPackageInstalled( this.project, "ndo.dll" )) |
779 | ················{ |
780 | ····················var installer = componentModel.GetService<IVsPackageInstaller>(); |
781 | // The newest version of NDO will be v5. x at the time, this package is released. |
782 | ····················// NDO5 needs the NDO.build package in all use cases. |
783 | ····················// If the enhancer is not to be used, uninstalling ndo.build is sufficient |
784 | ····················// because it will only be reinstalled if the NDO.dll package is missing. |
785 | ····················installer.InstallPackage( null, this.project, "NDO.dll", (string)null, false ); |
786 | ····················installer.InstallPackage( null, this.project, "NDO.build", (string) null, false ); |
787 | ················} |
788 | ············} |
789 | ············catch (Exception ex) |
790 | ············{ |
791 | ················MessageBox.Show( "Error while installing the ndo.dll package: " + ex.ToString() ); |
792 | ············} |
793 | ········} |
794 | |
795 | ········private static IVsPackageInstallerServices GetInstallerService( out IComponentModel componentModel ) |
796 | ········{ |
797 | ············componentModel = (IComponentModel)Package.GetGlobalService( typeof( SComponentModel ) ); |
798 | ············var installerService = componentModel.GetService<IVsPackageInstallerServices>(); |
799 | ············return installerService; |
800 | ········} |
801 | |
802 | ········void ShowError(Exception ex) |
803 | ········{ |
804 | ············MessageBox.Show("The following error occured: " + ex.Message, "NDO Add-in"); |
805 | ········} |
806 | |
807 | ········private void btnConnString_Click(object sender, System.EventArgs e) |
808 | ········{ |
809 | ············try |
810 | ············{ |
811 | ················string connType = cbSqlDialect.Text; |
812 | ················if (connType == string.Empty) |
813 | ····················connType = "SqlServer"; |
814 | ················var provider = NdoUIProviderFactory.Instance[connType]; |
815 | ················if (provider == null) |
816 | ················{ |
817 | ····················MessageBox.Show("Can't find a NDO UI provider for the sql dialect " + connType); |
818 | ····················return; |
819 | ················} |
820 | |
821 | ················string temp = this.txtConnectionString.Text; |
822 | ················NdoDialogResult r = provider.ShowConnectionDialog(ref temp); |
823 | ················if (r == NdoDialogResult.Cancel) |
824 | ····················return; |
825 | ················this.txtConnectionString.Text = temp; |
826 | ············} |
827 | ············catch (Exception ex) |
828 | ············{ |
829 | ················ShowError(ex); |
830 | ············} |
831 | ········} |
832 | |
833 | |
834 | ········private void chkGenerateSQLScript_CheckedChanged(object sender, System.EventArgs e) |
835 | ········{ |
836 | ············bool genSql = this.chkGenerateSQLScript.Checked; |
837 | |
838 | ············this.cbSqlDialect.Enabled = genSql; |
839 | ············this.chkIncludeTypecodes.Enabled = genSql; |
840 | ············this.chkDropExistingElements.Enabled = genSql; |
841 | ············this.chkGenerateFkConstraints.Enabled = genSql; |
842 | ············this.radioUtf8Encoding.Enabled = genSql; |
843 | ············this.radioDefaultEncoding.Enabled = genSql; |
844 | ········} |
845 | |
846 | ········private void EnableCheckBoxes() |
847 | ········{ |
848 | ············foreach(Control c in this.Controls) |
849 | ············{ |
850 | ················CheckBox cb = c as CheckBox; |
851 | ················if (c == null) |
852 | ····················continue; |
853 | ················c.Enabled = true; |
854 | ············} |
855 | ············if (this.project.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") |
856 | ················this.chkActivateEnhancer.Enabled = false; |
857 | ········} |
858 | |
859 | ········private void btnPresetApp_Click(object sender, System.EventArgs e) |
860 | ········{ |
861 | ············try |
862 | ············{ |
863 | ················EnableCheckBoxes(); |
864 | ················this.chkVerboseMode.Checked = false; |
865 | ················this.chkActivateAddIn.Checked = true; |
866 | ················this.chkActivateEnhancer.Checked = false; |
867 | ················this.chkMappingNew.Checked = false; |
868 | ················this.chkGenerateSQLScript.Checked = true; |
869 | ················this.chkChangeEvents.Checked = false; |
870 | ················this.chkIncludeTypecodes.Checked = false; |
871 | ················this.chkDropExistingElements.Checked = false; |
872 | ················this.chkGenerateFkConstraints.Checked = false; |
873 | ················this.txtConnectionString.Text = ""; |
874 | ················this.chkUseTimeStamps.Checked = false; |
875 | ················this.txtDbOwner.Text = ""; |
876 | ················this.txtSchemaVersion.Text = "1.0"; |
877 | ················if (this.txtConnectionString.Text == string.Empty) |
878 | ····················this.btnConnString_Click(null, null); |
879 | ············} |
880 | ············catch (Exception ex) |
881 | ············{ |
882 | ················ShowError(ex); |
883 | ············} |
884 | ········} |
885 | |
886 | //········private void MakeNode(string name, object value, XmlNode parentNode, XmlDocument doc) |
887 | //········{ |
888 | //············XmlElement el = doc.CreateElement(name); |
889 | //············parentNode.AppendChild(el); |
890 | //············if (value != null) |
891 | //················el.InnerText = value.ToString(); |
892 | //········} |
893 | |
894 | ········void WriteBack(ConfigurationOptions options) |
895 | ········{ |
896 | ············options.EnableAddIn = chkActivateAddIn.Checked; |
897 | ············options.EnableEnhancer = chkActivateEnhancer.Checked; |
898 | ············options.IncludeTypecodes = chkIncludeTypecodes.Checked; |
899 | ············options.GenerateConstraints = chkGenerateFkConstraints.Checked; |
900 | ············options.DropExistingElements = chkDropExistingElements.Checked; |
901 | ············options.VerboseMode = chkVerboseMode.Checked; |
902 | ············options.NewMapping = chkMappingNew.Checked; |
903 | ············options.GenerateSQL = chkGenerateSQLScript.Checked; |
904 | ············options.DefaultConnection = txtConnectionString.Text; |
905 | ············options.TargetMappingFileName = txtTargetMappingFileName.Text; |
906 | ············options.GenerateChangeEvents = chkChangeEvents.Checked; |
907 | ············options.UseTimeStamps = chkUseTimeStamps.Checked; |
908 | ············options.SQLScriptLanguage = this.cbSqlDialect.Text; |
909 | ············options.DatabaseOwner = this.txtDbOwner.Text; |
910 | ············options.Utf8Encoding = this.radioUtf8Encoding.Checked; |
911 | ············options.SchemaVersion = this.txtSchemaVersion.Text; |
912 | ········} |
913 | |
914 | ········private void btnSaveAs_Click(object sender, System.EventArgs e) |
915 | ········{ |
916 | ············try |
917 | ············{ |
918 | ················string projDir = Path.GetDirectoryName(project.FullName); |
919 | ················SaveFileDialog sfd = new SaveFileDialog(); |
920 | ················sfd.CheckFileExists = false; |
921 | ················sfd.DefaultExt = "xml"; |
922 | ················sfd.Filter = "NDO Configuration Files (*.ndoproj)|*.ndoproj"; |
923 | ················sfd.FileName = "EnhancerParameters.ndoproj"; |
924 | ················sfd.InitialDirectory = projDir; |
925 | ················if (sfd.ShowDialog(this) != DialogResult.OK) |
926 | ····················return; |
927 | |
928 | ················ConfigurationOptions options = new ConfigurationOptions(project);················ |
929 | ················WriteBack(options); |
930 | ················options.SaveAs(sfd.FileName, this.projectDescription); |
931 | ············} |
932 | ············catch (Exception ex) |
933 | ············{ |
934 | ················ShowError(ex); |
935 | ············}········ |
936 | ········} |
937 | |
938 | ········private void cbSqlDialect_SelectedIndexChanged(object sender, System.EventArgs e) |
939 | ········{ |
940 | ············this.txtConnectionString.Text = string.Empty; |
941 | ············CheckEnabledStateForLoadProviderButton(); |
942 | ········} |
943 | |
944 | ········private void btnNewDatabase_Click(object sender, System.EventArgs e) |
945 | ········{ |
946 | ············string connType = cbSqlDialect.Text; |
947 | ············if (connType == string.Empty) |
948 | ················connType = "SqlServer"; |
949 | ············IDbUISupport provider = NdoUIProviderFactory.Instance[connType]; |
950 | ············if (provider == null) |
951 | ············{ |
952 | ················MessageBox.Show("Can't find a NDO UI provider for the sql dialect " + connType); |
953 | ················return; |
954 | ············} |
955 | ············object necessaryData = null; |
956 | ············try |
957 | ············{ |
958 | ················if (provider.ShowCreateDbDialog(ref necessaryData) == NdoDialogResult.Cancel) |
959 | ····················return; |
960 | ················this.txtConnectionString.Text = provider.CreateDatabase(necessaryData); |
961 | ············} |
962 | ············catch (Exception ex) |
963 | ············{ |
964 | #if !DEBUG |
965 | ················MessageBox.Show("Can't construct the database: " + ex.Message); |
966 | #else |
967 | ················MessageBox.Show("Can't construct the database: " + ex.ToString()); |
968 | #endif |
969 | ············} |
970 | ········} |
971 | |
972 | ········private void chlbAssemblies_ItemCheck( object sender, ItemCheckEventArgs e ) |
973 | ········{ |
974 | ············this.references[e.Index].CheckState = e.NewValue; |
975 | ········} |
976 | |
977 | ········private void btnInstallProvider_Click( object sender, EventArgs e ) |
978 | ········{ |
979 | ············try |
980 | ············{ |
981 | ················string providerName = this.cbSqlDialect.Text; |
982 | |
983 | ················if (string.IsNullOrEmpty( providerName )) |
984 | ················{ |
985 | ····················MessageBox.Show( "Please choose a provider" ); |
986 | ····················return; |
987 | ················} |
988 | |
989 | ················IComponentModel componentModel; |
990 | ················var installerService = GetInstallerService( out componentModel ); |
991 | |
992 | ················string packageName = $"ndo.{providerName.ToLower()}"; |
993 | ················if (!installerService.IsPackageInstalled( this.project, packageName )) |
994 | ················{ |
995 | ····················var installer = componentModel.GetService<IVsPackageInstaller>(); |
996 | ····················installer.InstallPackage( null, this.project, packageName, (string)null, false ); |
997 | ················} |
998 | |
999 | ················this.btnInstallProvider.Enabled = false; |
1000 | ············} |
1001 | ············catch (Exception ex) |
1002 | ············{ |
1003 | ················MessageBox.Show( "Error while installing the ndo.dll package: " + ex.ToString() ); |
1004 | ············} |
1005 | ········} |
1006 | ····} |
1007 | } |
1008 | |
1009 | #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread |
1010 |