Subversion Repositories DevTools

Rev

Rev 2141 | Rev 2153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
2141 ghuddy 126
         this.Text = "Export To ReqPro CSV";
2151 ghuddy 127
         this.TopMost = true;
2141 ghuddy 128
         this.ResumeLayout(false);
129
 
130
      }
2151 ghuddy 131
      #endregion
2141 ghuddy 132
 
133
 
134
      /// <summary>
135
      /// Export the requirements found in the selected package to a ReqPro CSV file.
136
      /// </summary>
137
      /// <param name="ea_repository"></param>
2151 ghuddy 138
      public void Export()
2141 ghuddy 139
      {
2151 ghuddy 140
         object o;
2141 ghuddy 141
         EA.ObjectType type;
2151 ghuddy 142
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
2141 ghuddy 143
         if (type == EA.ObjectType.otPackage)
144
         {
145
            EA.Package EA_ParentPackage = (EA.Package)o;
146
 
147
            // Choose CSV file name and location
2151 ghuddy 148
            SaveFileDialog ofd = new SaveFileDialog();
149
            ofd.Title = "Select Name of Export file";
150
            ofd.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
151
            DialogResult dlgRes = ofd.ShowDialog();
2141 ghuddy 152
            if (dlgRes == DialogResult.OK)
153
            {
2151 ghuddy 154
               Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
155
               Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exporting to ReqPro CSV File", -1);
2141 ghuddy 156
 
157
               // Begin to build the CSV file content, starting with the header line ReqPro requires.
158
               csv_text = new StringBuilder();
159
               csv_text.Append( String.Format("\"{0} Tag\",\"Requirement text\",\"Name\"\r\n", textBox_tag.Text));
160
 
161
               // recursively descend the package
2151 ghuddy 162
               parse_package(EA_ParentPackage, 0);
2141 ghuddy 163
 
164
               // write the CSV file content
165
               TextWriter tw = new StreamWriter( ofd.FileName );
166
               tw.WriteLine(csv_text.ToString());
167
               tw.Close();
2151 ghuddy 168
               MessageBoxEx.Show("Export Completed");
2141 ghuddy 169
            }
170
         }
171
      }
172
 
173
      /// <summary>
174
      /// Recursive method to process the EA package and all its sub-packages.
175
      /// For each package found, the method grabs all of the elements in the package and for each
176
      /// one that is a requirement, exports it, dependant upon its tag and the options already set
177
      /// by the user for the export.
178
      /// </summary>
179
      /// <param name="ea_repository"></param>
180
      /// <param name="thePackage"></param>
181
      /// <param name="recurse_level"></param>
2151 ghuddy 182
      private void parse_package(EA.Package thePackage, int recurse_level)
2141 ghuddy 183
      {
184
         // consume elements - we have to use a special sorting class here because of peculiarties
2151 ghuddy 185
         // in the way EA holds the elements in the collections.
2141 ghuddy 186
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
187
         EA.Element theElement = null;
188
         int theElementsRelativeLevel = 0;
189
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
190
         {
191
            do
192
            {
193
               if ( theElement.Type.StartsWith("Requirement"))
194
               {
195
                  int theElementsRecurseLevel = 1 + recurse_level + theElementsRelativeLevel;
196
 
197
                  // If the element has the right tag...
198
                  if (theElement.Name.StartsWith(textBox_tag.Text))
199
                  {
200
                     // Pull out the ID from the name
201
                     int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
202
                     string tag = theElement.Name.Substring( 0, pos );
203
 
204
                     // Pull out the short description from the rest of the name
205
                     string name = theElement.Name.Substring( pos, theElement.Name.Length-pos );
206
                     name = name.Trim();
207
 
208
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", tag, theElement.Notes, name) );
209
 
2151 ghuddy 210
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
2141 ghuddy 211
                  }
212
                  // else if user has asked us to ignore wrong tags...
213
                  else if (false == checkBox_IgnoreWronglyTaggedItems.Checked)
214
                  {
215
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", textBox_tag.Text, theElement.Notes, theElement.Name) );
216
 
2151 ghuddy 217
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
2141 ghuddy 218
                  }
219
                  // else ignore this requirement
220
                  else
221
                  {
2151 ghuddy 222
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Ignored : " + theElement.Name, theElement.ElementID );
2141 ghuddy 223
                  }
224
               }
225
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
226
         }
227
 
228
         // Scan through the packages within this package.
229
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
230
         {
231
            // recurse
2151 ghuddy 232
            parse_package(lowerLevelPackage, recurse_level+1);
2141 ghuddy 233
         }
234
      }
2151 ghuddy 235
   }
2141 ghuddy 236
}