| 2141 |
ghuddy |
1 |
using System;
|
|
|
2 |
using System.Drawing;
|
|
|
3 |
using System.Collections;
|
|
|
4 |
using System.ComponentModel;
|
|
|
5 |
using System.Windows.Forms;
|
|
|
6 |
using System.Text;
|
|
|
7 |
using System.IO;
|
|
|
8 |
|
|
|
9 |
namespace EA_ReqPro
|
|
|
10 |
{
|
| 2151 |
ghuddy |
11 |
/// <summary>
|
|
|
12 |
/// Summary description for ExportToReqProCSVForm.
|
|
|
13 |
/// </summary>
|
|
|
14 |
public class ExportToReqProCSVForm : System.Windows.Forms.Form
|
|
|
15 |
{
|
| 2141 |
ghuddy |
16 |
private StringBuilder csv_text;
|
|
|
17 |
|
|
|
18 |
private System.Windows.Forms.Button button_ok;
|
|
|
19 |
private System.Windows.Forms.Button button_cancel;
|
|
|
20 |
private System.Windows.Forms.TextBox textBox_tag;
|
|
|
21 |
private System.Windows.Forms.Label label1;
|
|
|
22 |
private System.Windows.Forms.CheckBox checkBox_IgnoreWronglyTaggedItems;
|
|
|
23 |
|
| 2151 |
ghuddy |
24 |
/// <summary>
|
|
|
25 |
/// Required designer variable.
|
|
|
26 |
/// </summary>
|
|
|
27 |
private System.ComponentModel.Container components = null;
|
| 2141 |
ghuddy |
28 |
|
| 2151 |
ghuddy |
29 |
public ExportToReqProCSVForm()
|
|
|
30 |
{
|
|
|
31 |
//
|
|
|
32 |
// Required for Windows Form Designer support
|
|
|
33 |
//
|
|
|
34 |
InitializeComponent();
|
| 2141 |
ghuddy |
35 |
|
| 2151 |
ghuddy |
36 |
//
|
|
|
37 |
// TODO: Add any constructor code after InitializeComponent call
|
|
|
38 |
//
|
|
|
39 |
}
|
| 2141 |
ghuddy |
40 |
|
| 2151 |
ghuddy |
41 |
/// <summary>
|
|
|
42 |
/// Clean up any resources being used.
|
|
|
43 |
/// </summary>
|
|
|
44 |
protected override void Dispose( bool disposing )
|
|
|
45 |
{
|
|
|
46 |
if( disposing )
|
|
|
47 |
{
|
|
|
48 |
if(components != null)
|
|
|
49 |
{
|
|
|
50 |
components.Dispose();
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
base.Dispose( disposing );
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
#region Windows Form Designer generated code
|
|
|
57 |
/// <summary>
|
|
|
58 |
/// Required method for Designer support - do not modify
|
|
|
59 |
/// the contents of this method with the code editor.
|
|
|
60 |
/// </summary>
|
|
|
61 |
private void InitializeComponent()
|
|
|
62 |
{
|
| 2141 |
ghuddy |
63 |
this.button_ok = new System.Windows.Forms.Button();
|
|
|
64 |
this.button_cancel = new System.Windows.Forms.Button();
|
|
|
65 |
this.textBox_tag = new System.Windows.Forms.TextBox();
|
|
|
66 |
this.label1 = new System.Windows.Forms.Label();
|
|
|
67 |
this.checkBox_IgnoreWronglyTaggedItems = new System.Windows.Forms.CheckBox();
|
|
|
68 |
this.SuspendLayout();
|
|
|
69 |
//
|
|
|
70 |
// button_ok
|
|
|
71 |
//
|
|
|
72 |
this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
|
73 |
this.button_ok.Location = new System.Drawing.Point(104, 144);
|
|
|
74 |
this.button_ok.Name = "button_ok";
|
|
|
75 |
this.button_ok.Size = new System.Drawing.Size(88, 32);
|
|
|
76 |
this.button_ok.TabIndex = 0;
|
|
|
77 |
this.button_ok.Text = "OK";
|
|
|
78 |
//
|
|
|
79 |
// button_cancel
|
|
|
80 |
//
|
|
|
81 |
this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
|
82 |
this.button_cancel.Location = new System.Drawing.Point(216, 144);
|
|
|
83 |
this.button_cancel.Name = "button_cancel";
|
|
|
84 |
this.button_cancel.Size = new System.Drawing.Size(88, 32);
|
|
|
85 |
this.button_cancel.TabIndex = 1;
|
|
|
86 |
this.button_cancel.Text = "Cancel";
|
|
|
87 |
//
|
|
|
88 |
// textBox_tag
|
|
|
89 |
//
|
|
|
90 |
this.textBox_tag.Location = new System.Drawing.Point(192, 32);
|
|
|
91 |
this.textBox_tag.Name = "textBox_tag";
|
|
|
92 |
this.textBox_tag.TabIndex = 2;
|
|
|
93 |
this.textBox_tag.Text = "SPR";
|
|
|
94 |
//
|
|
|
95 |
// label1
|
|
|
96 |
//
|
|
|
97 |
this.label1.Location = new System.Drawing.Point(16, 32);
|
|
|
98 |
this.label1.Name = "label1";
|
|
|
99 |
this.label1.Size = new System.Drawing.Size(152, 23);
|
|
|
100 |
this.label1.TabIndex = 3;
|
|
|
101 |
this.label1.Text = "Enter Requirement Tag";
|
|
|
102 |
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
|
|
103 |
//
|
|
|
104 |
// checkBox_IgnoreWronglyTaggedItems
|
|
|
105 |
//
|
|
|
106 |
this.checkBox_IgnoreWronglyTaggedItems.Checked = true;
|
|
|
107 |
this.checkBox_IgnoreWronglyTaggedItems.CheckState = System.Windows.Forms.CheckState.Checked;
|
|
|
108 |
this.checkBox_IgnoreWronglyTaggedItems.Location = new System.Drawing.Point(16, 80);
|
|
|
109 |
this.checkBox_IgnoreWronglyTaggedItems.Name = "checkBox_IgnoreWronglyTaggedItems";
|
|
|
110 |
this.checkBox_IgnoreWronglyTaggedItems.Size = new System.Drawing.Size(272, 24);
|
|
|
111 |
this.checkBox_IgnoreWronglyTaggedItems.TabIndex = 4;
|
|
|
112 |
this.checkBox_IgnoreWronglyTaggedItems.Text = "Ignore wrongly tagged requirements";
|
|
|
113 |
//
|
|
|
114 |
// ExportToReqProCSVForm
|
|
|
115 |
//
|
|
|
116 |
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
|
|
|
117 |
this.ClientSize = new System.Drawing.Size(312, 200);
|
|
|
118 |
this.Controls.Add(this.checkBox_IgnoreWronglyTaggedItems);
|
|
|
119 |
this.Controls.Add(this.textBox_tag);
|
|
|
120 |
this.Controls.Add(this.label1);
|
|
|
121 |
this.Controls.Add(this.button_cancel);
|
|
|
122 |
this.Controls.Add(this.button_ok);
|
| 2151 |
ghuddy |
123 |
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
| 2141 |
ghuddy |
124 |
this.Name = "ExportToReqProCSVForm";
|
| 2151 |
ghuddy |
125 |
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
| 2155 |
ghuddy |
126 |
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
| 2141 |
ghuddy |
127 |
this.Text = "Export To ReqPro CSV";
|
| 2151 |
ghuddy |
128 |
this.TopMost = true;
|
| 2141 |
ghuddy |
129 |
this.ResumeLayout(false);
|
|
|
130 |
|
|
|
131 |
}
|
| 2151 |
ghuddy |
132 |
#endregion
|
| 2141 |
ghuddy |
133 |
|
|
|
134 |
|
|
|
135 |
/// <summary>
|
|
|
136 |
/// Export the requirements found in the selected package to a ReqPro CSV file.
|
|
|
137 |
/// </summary>
|
|
|
138 |
/// <param name="ea_repository"></param>
|
| 2151 |
ghuddy |
139 |
public void Export()
|
| 2141 |
ghuddy |
140 |
{
|
| 2153 |
ghuddy |
141 |
try
|
| 2141 |
ghuddy |
142 |
{
|
| 2153 |
ghuddy |
143 |
object o;
|
|
|
144 |
EA.ObjectType type;
|
|
|
145 |
type = Main.EA_Repository.GetTreeSelectedItem(out o);
|
|
|
146 |
if (type == EA.ObjectType.otPackage)
|
| 2141 |
ghuddy |
147 |
{
|
| 2153 |
ghuddy |
148 |
EA.Package EA_ParentPackage = (EA.Package)o;
|
| 2141 |
ghuddy |
149 |
|
| 2153 |
ghuddy |
150 |
// Choose CSV file name and location
|
|
|
151 |
SaveFileDialog ofd = new SaveFileDialog();
|
|
|
152 |
ofd.Title = "Select Name of Export file";
|
|
|
153 |
ofd.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
|
|
|
154 |
DialogResult dlgRes = ofd.ShowDialog();
|
|
|
155 |
if (dlgRes == DialogResult.OK)
|
|
|
156 |
{
|
|
|
157 |
Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
|
| 2155 |
ghuddy |
158 |
Main.WriteOutput("Exporting to ReqPro CSV File", -1);
|
| 2141 |
ghuddy |
159 |
|
| 2153 |
ghuddy |
160 |
// Begin to build the CSV file content, starting with the header line ReqPro requires.
|
|
|
161 |
csv_text = new StringBuilder();
|
|
|
162 |
csv_text.Append( String.Format("\"{0} Tag\",\"Requirement text\",\"Name\"\r\n", textBox_tag.Text));
|
| 2141 |
ghuddy |
163 |
|
| 2153 |
ghuddy |
164 |
// recursively descend the package
|
|
|
165 |
parse_package(EA_ParentPackage, 0);
|
|
|
166 |
|
|
|
167 |
// write the CSV file content
|
|
|
168 |
TextWriter tw = new StreamWriter( ofd.FileName );
|
|
|
169 |
tw.WriteLine(csv_text.ToString());
|
|
|
170 |
tw.Close();
|
|
|
171 |
MessageBoxEx.Show("Export Completed", "Progress");
|
| 2155 |
ghuddy |
172 |
Main.WriteOutput("Export Completed", -1);
|
| 2153 |
ghuddy |
173 |
}
|
| 2141 |
ghuddy |
174 |
}
|
|
|
175 |
}
|
| 2153 |
ghuddy |
176 |
catch (Exception exc)
|
|
|
177 |
{
|
|
|
178 |
Main.MessageBoxException(exc, "Export Failed");
|
|
|
179 |
}
|
| 2141 |
ghuddy |
180 |
}
|
|
|
181 |
|
|
|
182 |
/// <summary>
|
|
|
183 |
/// Recursive method to process the EA package and all its sub-packages.
|
|
|
184 |
/// For each package found, the method grabs all of the elements in the package and for each
|
|
|
185 |
/// one that is a requirement, exports it, dependant upon its tag and the options already set
|
|
|
186 |
/// by the user for the export.
|
|
|
187 |
/// </summary>
|
|
|
188 |
/// <param name="ea_repository"></param>
|
|
|
189 |
/// <param name="thePackage"></param>
|
|
|
190 |
/// <param name="recurse_level"></param>
|
| 2151 |
ghuddy |
191 |
private void parse_package(EA.Package thePackage, int recurse_level)
|
| 2141 |
ghuddy |
192 |
{
|
|
|
193 |
// consume elements - we have to use a special sorting class here because of peculiarties
|
| 2151 |
ghuddy |
194 |
// in the way EA holds the elements in the collections.
|
| 2141 |
ghuddy |
195 |
EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
|
|
|
196 |
EA.Element theElement = null;
|
|
|
197 |
int theElementsRelativeLevel = 0;
|
|
|
198 |
if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
|
|
|
199 |
{
|
|
|
200 |
do
|
|
|
201 |
{
|
|
|
202 |
if ( theElement.Type.StartsWith("Requirement"))
|
|
|
203 |
{
|
|
|
204 |
int theElementsRecurseLevel = 1 + recurse_level + theElementsRelativeLevel;
|
|
|
205 |
|
|
|
206 |
// If the element has the right tag...
|
|
|
207 |
if (theElement.Name.StartsWith(textBox_tag.Text))
|
|
|
208 |
{
|
|
|
209 |
// Pull out the ID from the name
|
|
|
210 |
int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
|
|
|
211 |
string tag = theElement.Name.Substring( 0, pos );
|
|
|
212 |
|
|
|
213 |
// Pull out the short description from the rest of the name
|
|
|
214 |
string name = theElement.Name.Substring( pos, theElement.Name.Length-pos );
|
|
|
215 |
name = name.Trim();
|
|
|
216 |
|
|
|
217 |
csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", tag, theElement.Notes, name) );
|
|
|
218 |
|
| 2155 |
ghuddy |
219 |
Main.WriteOutput("Exported : " + theElement.Name, theElement.ElementID );
|
| 2141 |
ghuddy |
220 |
}
|
|
|
221 |
// else if user has asked us to ignore wrong tags...
|
|
|
222 |
else if (false == checkBox_IgnoreWronglyTaggedItems.Checked)
|
|
|
223 |
{
|
|
|
224 |
csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", textBox_tag.Text, theElement.Notes, theElement.Name) );
|
|
|
225 |
|
| 2155 |
ghuddy |
226 |
Main.WriteOutput("Exported : " + theElement.Name, theElement.ElementID );
|
| 2141 |
ghuddy |
227 |
}
|
|
|
228 |
// else ignore this requirement
|
|
|
229 |
else
|
|
|
230 |
{
|
| 2155 |
ghuddy |
231 |
Main.WriteOutput("Ignored : " + theElement.Name, theElement.ElementID );
|
| 2141 |
ghuddy |
232 |
}
|
|
|
233 |
}
|
|
|
234 |
} while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
// Scan through the packages within this package.
|
|
|
238 |
foreach(EA.Package lowerLevelPackage in thePackage.Packages)
|
|
|
239 |
{
|
|
|
240 |
// recurse
|
| 2151 |
ghuddy |
241 |
parse_package(lowerLevelPackage, recurse_level+1);
|
| 2141 |
ghuddy |
242 |
}
|
|
|
243 |
}
|
| 2151 |
ghuddy |
244 |
}
|
| 2141 |
ghuddy |
245 |
}
|