|
| 1 | +using BIDSHelper.Core; |
| 2 | +using Microsoft.SqlServer.Dts.Runtime; |
| 3 | +using System; |
| 4 | +using System.ComponentModel; |
| 5 | +using System.Drawing; |
| 6 | +using System.Windows.Forms; |
| 7 | + |
| 8 | +namespace BIDSHelper.SSIS |
| 9 | +{ |
| 10 | + public partial class FindVariableReferences : Form |
| 11 | + { |
| 12 | + private BackgroundWorker processPackage = null; |
| 13 | + private System.Diagnostics.Stopwatch stopwatch; |
| 14 | + private FindVariables finder = new FindVariables(); |
| 15 | + private Package package; |
| 16 | + private Variable variable; |
| 17 | + |
| 18 | + public FindVariableReferences() |
| 19 | + { |
| 20 | + InitializeComponent(); |
| 21 | + |
| 22 | + processPackage = new BackgroundWorker(); |
| 23 | + processPackage.WorkerReportsProgress = true; |
| 24 | + processPackage.WorkerSupportsCancellation = true; |
| 25 | + processPackage.DoWork += new DoWorkEventHandler(processPackage_DoWork); |
| 26 | + processPackage.RunWorkerCompleted += new RunWorkerCompletedEventHandler(processPackage_RunWorkerCompleted); |
| 27 | + |
| 28 | + this.Icon = BIDSHelper.Resources.Versioned.VariableFindReferences; |
| 29 | + } |
| 30 | + |
| 31 | + public void Show(Package package, Variable variable) |
| 32 | + { |
| 33 | + this.progressBar.Visible = true; |
| 34 | + |
| 35 | + this.package = package; |
| 36 | + this.variable = variable; |
| 37 | + |
| 38 | + InitializeTreeView(); |
| 39 | + |
| 40 | + stopwatch = new System.Diagnostics.Stopwatch(); |
| 41 | + processPackage.RunWorkerAsync(); |
| 42 | + |
| 43 | + this.Show(); |
| 44 | + } |
| 45 | + |
| 46 | + public void Show(Package package, Parameter parameter) |
| 47 | + { |
| 48 | + // Get the Variable object that is the same as the Parameter. A parameter is also an item in the Variables collection. |
| 49 | + Variable variable = package.Variables[parameter.ID]; |
| 50 | + this.Show(package, variable); |
| 51 | + } |
| 52 | + |
| 53 | + private void InitializeTreeView() |
| 54 | + { |
| 55 | + this.treeView.Nodes.Clear(); |
| 56 | + this.treeView.SuspendLayout(); |
| 57 | + this.treeView.Enabled = false; |
| 58 | + } |
| 59 | + |
| 60 | + private void VariableFound(object sender, VariableFoundEventArgs e) |
| 61 | + { |
| 62 | + // Report variable found via BackGroundWorker to ensure we are thread safe when accessing the form control later on |
| 63 | + this.processPackage.ReportProgress(0, e); |
| 64 | + } |
| 65 | + |
| 66 | + private void PruneNodes(TreeNode parent) |
| 67 | + { |
| 68 | + for (int index = parent.Nodes.Count -1; index >= 0; index--) |
| 69 | + { |
| 70 | + TreeNode node = parent.Nodes[index]; |
| 71 | + |
| 72 | + if (node.IsExpanded || node.Checked) |
| 73 | + { |
| 74 | + PruneNodes(node); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + node.Remove(); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + #region BackgroundWorker Events |
| 84 | + |
| 85 | + private void processPackage_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
| 86 | + { |
| 87 | + TreeNode parent = this.treeView.Nodes[0]; |
| 88 | + PruneNodes(parent); |
| 89 | + |
| 90 | + stopwatch.Stop(); |
| 91 | + this.Text += (" " + stopwatch.ElapsedMilliseconds.ToString()); |
| 92 | + |
| 93 | + this.treeView.Enabled = true; |
| 94 | + this.treeView.ResumeLayout(); |
| 95 | + |
| 96 | + this.progressBar.Visible = false; |
| 97 | + } |
| 98 | + |
| 99 | + private void processPackage_DoWork(object sender, DoWorkEventArgs e) |
| 100 | + { |
| 101 | + stopwatch.Start(); |
| 102 | + finder.FindReferences(this.package, this.variable, this.treeView); |
| 103 | + } |
| 104 | + #endregion |
| 105 | + |
| 106 | + private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
| 107 | + { |
| 108 | + SetPropertyGrid(e.Node); |
| 109 | + } |
| 110 | + |
| 111 | + private void SetPropertyGrid(TreeNode node) |
| 112 | + { |
| 113 | + propertyGrid.SelectedObject = node.Tag; |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments