-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
851 lines (775 loc) · 34.2 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using Microsoft.Windows.Controls.Ribbon;
using DocScript.Scripts;
namespace DocScript
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : RibbonWindow
{
/// <summary>
/// Background process to run the script file
/// </summary>
public BackgroundWorker ScriptWorker = new BackgroundWorker();
#region | BackgroundWorker |
/// <summary>
/// Run a Documentum script file
///
/// Notes:
/// If you need to run this for below version 6.0 Documentum you need to add idql and iapi to cboType items.
/// Script file must be run from working directory, copy file to working directory (where iapi32.exe/idql32.exe/iapi64.exe/idql64.exe exist)
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void ScriptWorker_DoWork(object sender, DoWorkEventArgs e)
{
Process p = new Process();
string workingDir = Properties.Settings.Default.Script_WorkingDirectory;
string filePath = Properties.Settings.Default.Script_PathCodeFile;
string script = BuildCommandLineScript();
try
{
if (script == string.Empty)
{
MessageBox.Show("Please check the result command line script.", "No action.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string workingFile = System.IO.Path.Combine(workingDir, System.IO.Path.GetFileName(filePath));
File.Copy(filePath, workingFile, true);
string cmdText = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe";
p.StartInfo.FileName = cmdText;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;
p.Start();
p.StandardInput.WriteLine(script);
MessageBox.Show("Script has finished." + Environment.NewLine + Environment.NewLine + "Use [F5] to refresh the result file.", "Done.", MessageBoxButtons.OK, MessageBoxIcon.Information);
p.Close();
}
}
catch (System.IO.FileNotFoundException ex)
{
MessageBox.Show("Script file not found." + Environment.NewLine + filePath, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Console.WriteLine(ex.ToString());
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
finally
{
if ((p != null))
{
p.Dispose();
p = null;
}
}
}
/// <summary>
/// The event for when the script background process changes
/// </summary>
/// <example>
/// <code lang="C#">
/// ScriptWorker.ReportProgress(i);
/// </code>
/// </example>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void ScriptWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//NOTE: Can not track progress of process once it's passed to cmd
try
{
//int totalRows = Data.ScriptTable.Rows.Count;
//double currentFileNbr = e.ProgressPercentage + 1;
//double percentChange = Math.Round((currentFileNbr / totalRows) * 100);
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// The event for when the script background process finishes
/// </summary>
/// <example>
/// <code lang="C#">
/// ScriptWorker.CancelAsync()
///
/// if (ScriptWorker.CancellationPending)
/// {
/// e.Cancel = true;
/// // exit loop here
/// }
/// </code>
/// </example>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void ScriptWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//NOTE: Can not track progress of process once it's passed to cmd
try
{
//this.btnRunCmd.Visibility = System.Windows.Visibility.Visible;
//this.btnCancelCmd.IsEnabled = true;
//this.btnCancelCmd.Visibility = System.Windows.Visibility.Collapsed;
//// <-- [update runtime here]
//if (e.Error != null)
//{
// MessageBox.Show(e.Error.Message);
//}
//else if (e.Cancelled)
//{
// MessageBox.Show("Task cancelled!");
//}
//else
//{
// MessageBox.Show("Task completed!");
//}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
#endregion
#region | Buttons |
/// <summary>
/// Copy the script to the clipboard
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnCopyCommandLine_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Clipboard.SetText(BuildCommandLineScript());
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Delete the script file from the working directory
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnDeleteScriptFile_Click(object sender, System.Windows.RoutedEventArgs e)
{
string workingFile = System.IO.Path.Combine(Properties.Settings.Default.Script_WorkingDirectory, System.IO.Path.GetFileName(Properties.Settings.Default.Script_PathCodeFile));
if (System.IO.File.Exists(workingFile))
{
try
{
System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == System.Windows.MessageBoxResult.Yes)
{
System.IO.File.Delete(workingFile);
MessageBox.Show("Script has been removed from the working directory.", "Done.", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (System.IO.IOException ex) // file already opened by another process.
{
Console.WriteLine(ex.Message);
return;
}
}
}
/// <summary>
/// Toggle full screen mode with the F11 key
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnFullScreen_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (WindowState == System.Windows.WindowState.Maximized)
{
WindowState = System.Windows.WindowState.Normal;
}
else
{
WindowState = System.Windows.WindowState.Maximized;
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Opens the form to edit the code type list
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnOpenFormCodeType_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Data.AppVariables.TableName = "CodeType";
Forms.TableView formCodeType = new Forms.TableView();
formCodeType.ShowDialog();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Opens the form to edit the docbase list
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnOpenFormDocbase_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
string perserveDocbase = Properties.Settings.Default.Script_Docbase;
Data.AppVariables.TableName = "Docbase";
Forms.TableView formDocbase = new Forms.TableView();
Properties.Settings.Default.Script_Docbase = perserveDocbase;
formDocbase.ShowDialog();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Open the results file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnOpenResultsFile_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Process.Start(Properties.Settings.Default.Script_PathResultsFile);
}
catch (System.Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Open the script file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnOpenScriptFile_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Process.Start(Properties.Settings.Default.Script_PathCodeFile);
}
catch (System.Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Open the working directory
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnOpenWorkingDirectory_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (System.IO.Directory.Exists(Properties.Settings.Default.Script_WorkingDirectory))
{
Process.Start(Properties.Settings.Default.Script_WorkingDirectory);
}
}
catch (System.Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Refresh the results of the script in the datagrid
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnRefreshResults_Click(object sender, System.Windows.RoutedEventArgs e)
{
ReadResultsFileToDataTable();
UpdateStatusbarDetails();
}
/// <summary>
/// Run the script file from the working directory
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnRunCmd_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Properties.Settings.Default.Save();
if (ErrorHandler.IsSelectionFilledIn() == true)
{
if (System.IO.File.Exists(Properties.Settings.Default.Script_PathResultsFile))
{
System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("It looks like you have already ran this script.", "Run Script Again?", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question, System.Windows.MessageBoxResult.Cancel);
if (messageBoxResult == System.Windows.MessageBoxResult.Cancel)
{
return;
}
}
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
BuildCommandLineScript();
ScriptWorker.RunWorkerAsync();
ErrorHandler.CreateLogRecord();
}
else
{
MessageBox.Show("Please enter all fields.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (System.Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
finally
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
/// <summary>
/// Save the results to a csv file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnSaveResults_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
string filePath = Properties.Settings.Default.Script_PathResultsFile + ".csv";
SaveFileDialog saveFileDialog = new SaveFileDialog();
{
saveFileDialog.Filter = "CSV File(*.csv)|*.csv|All(*.*)|*";
saveFileDialog.FileName = filePath;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
filePath = saveFileDialog.FileName;
DataTable dtDataTable = Data.ScriptTable;
StreamWriter sw = new StreamWriter(filePath, false);
//headers
for (int i = 0; i < dtDataTable.Columns.Count; i++)
{
sw.Write(dtDataTable.Columns[i]);
if (i < dtDataTable.Columns.Count - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
foreach (DataRow dr in dtDataTable.Rows)
{
for (int i = 0; i < dtDataTable.Columns.Count; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
string value = dr[i].ToString();
if (value.Contains(','))
{
value = String.Format("\"{0}\"", value);
sw.Write(value);
}
else
{
sw.Write(dr[i].ToString());
}
}
if (i < dtDataTable.Columns.Count - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
}
sw.Close();
}
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Select a results file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnSelectResultsFile_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
OpenFileDialog ofdScriptFile = new OpenFileDialog();
ofdScriptFile.Filter = "Result Files|*.txt";
ofdScriptFile.Title = "Select a results file";
ofdScriptFile.InitialDirectory = System.IO.Path.GetDirectoryName(Properties.Settings.Default.Script_PathResultsFile);
System.Windows.Forms.DialogResult result = ofdScriptFile.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.Script_PathResultsFile = System.IO.Path.GetFullPath(ofdScriptFile.FileName);
}
ReadScriptFileToDataTable();
ReadResultsFileToDataTable();
UpdateStatusbarDetails();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Select a script file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void btnSelectScriptFile_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
OpenFileDialog ofdScriptFile = new OpenFileDialog();
ofdScriptFile.Filter = "Script Files|*.api;*.dql;*.txt";
ofdScriptFile.Title = "Select a script file";
ofdScriptFile.InitialDirectory = System.IO.Path.GetDirectoryName(Properties.Settings.Default.Script_PathCodeFile);
System.Windows.Forms.DialogResult result = ofdScriptFile.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.Script_PathCodeFile = System.IO.Path.GetFullPath(ofdScriptFile.FileName);
UpdateResultsFileName();
}
ReadScriptFileToDataTable();
ReadResultsFileToDataTable();
UpdateStatusbarDetails();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Select a working directory
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>>
private void btnSelectWorkingDirectory_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
FolderBrowserDialog fbdWorkingDirectory = new System.Windows.Forms.FolderBrowserDialog();
fbdWorkingDirectory.Description = "Select Working Directory";
System.Windows.Forms.DialogResult result = fbdWorkingDirectory.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.Script_WorkingDirectory = fbdWorkingDirectory.SelectedPath;
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
#endregion
#region | Menu |
/// <summary>
/// Opens the about form
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void mnuAbout_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Forms.About f = new Forms.About();
f.ShowDialog();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Opens a api help file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void mnuApiDoc_Click(object sender, System.Windows.RoutedEventArgs e)
{
string clickOnceLocation = AssemblyInfo.GetClickOnceLocation();
AssemblyInfo.OpenFile(Path.Combine(clickOnceLocation, @"Documentation\\Api Help.chm"));
}
/// <summary>
/// How to file
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void mnuHowTo_Click(object sender, System.Windows.RoutedEventArgs e)
{
string clickOnceLocation = AssemblyInfo.GetClickOnceLocation();
AssemblyInfo.OpenFile(Path.Combine(clickOnceLocation, @"Documentation\\As Built.docx"));
}
/// <summary>
/// Opens the settings form
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void mnuSettings_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Properties.Settings.Default.Save();
Forms.Settings formSettings = new Forms.Settings();
formSettings.ShowDialog();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
#endregion
#region | Form |
/// <summary>
/// This is the main form initialization
/// </summary>
public MainWindow()
{
try
{
InitializeComponent();
this.Title = AssemblyInfo.Description;
this.txtPassword.Password = Scripts.Security.ToInsecureString(Scripts.Security.DecryptString(Properties.Settings.Default.Script_Functional_Password));
Data.CreateCodeTypeTable();
string where = string.Empty;
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
string hostName = System.Net.Dns.GetHostName();
where = " WHERE HostName = '" + hostName + "'";
}
Data.CreateDocbaseTable(where);
Data.CreateScriptTable();
this.cboCodeTypeGalleryCategory.ItemsSource = Data.CodeTypeTable.DefaultView;
this.cboDocbaseGalleryCategory.ItemsSource = Data.DocbaseTable.DefaultView;
this.dgvSourceFiles.ItemsSource = Data.ScriptTable.DefaultView;
ReadScriptFileToDataTable();
ReadResultsFileToDataTable();
UpdateStatusbarDetails();
ScriptWorker.WorkerReportsProgress = true;
ScriptWorker.WorkerSupportsCancellation = true;
ScriptWorker.DoWork += new DoWorkEventHandler(ScriptWorker_DoWork);
ScriptWorker.ProgressChanged += new ProgressChangedEventHandler(ScriptWorker_ProgressChanged);
ScriptWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ScriptWorker_RunWorkerCompleted);
this.StatusBarTextCompanyName.Text = AssemblyInfo.Copyright;
AssemblyInfo.SetAddRemoveProgramsIcon("App.ico");
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// This is the after update event for the textbox
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void BuildScriptTextbox(object sender, System.Windows.RoutedEventArgs e)
{
BuildCommandLineScript();
}
/// <summary>
/// This is the after update event for the combobox
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void BuildScriptCombobox(object sender, EventArgs e)
{
UpdateResultsFileName();
BuildCommandLineScript();
}
/// <summary>
/// This sets the line numbers in the datagrid
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void dgvSourceFiles_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex()).ToString();
}
/// <summary>
/// This is run during the closing of the application
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void DocScript_Closing(object sender, CancelEventArgs e)
{
Properties.Settings.Default.Save();
}
/// <summary>
/// Save the password to application settings
/// </summary>
/// <param name="sender">Represents the control that the action is for. </param>
/// <param name="e">Represents the data related to this event, and can be used to pass parameters. </param>
private void txtPassword_PasswordChanged(object sender, System.Windows.RoutedEventArgs e)
{
try
{
Properties.Settings.Default.Script_Functional_Password = Scripts.Security.EncryptString(Scripts.Security.ToSecureString(this.txtPassword.Password));
Properties.Settings.Default.Save();
BuildCommandLineScript();
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
#endregion
#region | Subroutines |
/// <summary>
/// This builds the command line string
/// </summary>
/// <returns>The command line string</returns>
public string BuildCommandLineScript()
{
try
{
string password = Scripts.Security.ToInsecureString(Scripts.Security.DecryptString(Properties.Settings.Default.Script_Functional_Password));
switch (Properties.Settings.Default.Script_CodeType)
{
case "sqlplus":
return Properties.Settings.Default.Script_CodeType + " " + Properties.Settings.Default.Script_Docbase + " " + Properties.Settings.Default.Script_Functional_UserName + "/" + password + "@" + Properties.Settings.Default.Script_Docbase + " @" + Properties.Settings.Default.Script_PathCodeFile;
default:
return Properties.Settings.Default.Script_CodeType + " " + Properties.Settings.Default.Script_Docbase + " -U" + Properties.Settings.Default.Script_Functional_UserName + " -P" + password + " -R" + System.IO.Path.GetFileName(Properties.Settings.Default.Script_PathCodeFile) + " >\"" + Properties.Settings.Default.Script_PathResultsFile + "\"";
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
return string.Empty;
}
}
/// <summary>
/// Reads the script file to the datagrid
/// </summary>
public void ReadScriptFileToDataTable()
{
try
{
int counter = 0;
string line;
Data.ScriptTable.Clear();
if (File.Exists(Properties.Settings.Default.Script_PathCodeFile))
{
System.IO.StreamReader file = new System.IO.StreamReader(Properties.Settings.Default.Script_PathCodeFile);
while ((line = file.ReadLine()) != null)
{
DataRow scriptRow = Data.ScriptTable.NewRow();
scriptRow["CodeLine"] = line;
Data.ScriptTable.Rows.Add(scriptRow);
counter++;
}
file.Close();
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Updates the datagrid with results from the script file
/// </summary>
public void ReadResultsFileToDataTable()
{
try
{
int rowNum = 0;
string line = string.Empty;
if (File.Exists(Properties.Settings.Default.Script_PathResultsFile))
{
using (FileStream fileStream = new FileStream(Properties.Settings.Default.Script_PathResultsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader file = new StreamReader(fileStream))
{
while ((line = file.ReadLine()) != null)
{
line = line.Trim();
if (int.TryParse(line, out int rowsAffected))
{
Data.ScriptTable.Rows[rowNum]["Status"] = line;
rowNum += Properties.Settings.Default.Script_ResultsFileLineOffset;
}
}
file.Close();
}
}
else
{
foreach (System.Data.DataRowView dr in dgvSourceFiles.ItemsSource)
{
dr["Status"] = null;
}
}
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
/// <summary>
/// Updates the results file name structure
/// </summary>
public void UpdateResultsFileName()
{
Properties.Settings.Default.Script_PathResultsFile = (Properties.Settings.Default.Script_PathCodeFile).Substring(0, Properties.Settings.Default.Script_PathCodeFile.Length - 4) + "_Results_" + Properties.Settings.Default.Script_Docbase + ".txt";
}
/// <summary>
/// Update the details in the main form status bar
/// </summary>
public void UpdateStatusbarDetails()
{
try
{
DataRow[] rows;
rows = Data.ScriptTable.Select("Status = '0'");
double numberOfErrors = rows.Length;
txtErrorLines.Text = numberOfErrors.ToString();
rows = Data.ScriptTable.Select("Status IS NOT NULL");
double numberOfResults = rows.Length;
txtResultLines.Text = numberOfResults.ToString();
rows = Data.ScriptTable.Select();
double numberOfScript = rows.Length / Properties.Settings.Default.Script_ResultsFileLineOffset;
txtScriptLines.Text = numberOfScript.ToString();
double percentChange = 0;
if(numberOfScript == 0)
{
percentChange = 0;
}
else
{
percentChange = Math.Round((numberOfResults / numberOfScript) * 100);
}
this.barBatchProgress.Value = percentChange;
}
catch (Exception ex)
{
ErrorHandler.DisplayMessage(ex);
}
}
#endregion
}
}