Subversion Repositories DevTools

Rev

Rev 2145 | Rev 2149 | 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.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Collections.Specialized;
6
using System.Windows.Forms;
7
using ReqPro40;
8
 
9
namespace EA_ReqPro
10
{
11
	/// <summary>
12
	/// Summary description for CopyReqProDatabaseToMemory.
13
	/// </summary>
14
	public class CopyReqProDatabaseToMemory : ReqProParser
15
	{
16
      protected bool allowPackageStructureFragments = false;
17
 
18
      protected EA_Utilities EA_Utils;
19
 
2145 ghuddy 20
      // items setup by base class calling into provideReqProDatabaseInfo()
2141 ghuddy 21
      protected ReqPro40.Project RQ_project;
2145 ghuddy 22
      protected ReqPro40.Application RQ_app;
23
      protected ReqProDB_Artifact RQ_Artifact;
24
      protected EA.Element RQ_Element;
2141 ghuddy 25
 
26
      // Where in an EA database, the copy of the ReqPro database content will be written
27
      protected EA.Package ea_rootPackage;
28
 
29
      // Hierarchy tracking data for the parsing of a ReqPro database
30
      protected Stack rq_objs = new Stack();      // Top of stack indicates current parent package
31
      protected Stack ea_treePos = new Stack();   // Top of stack indicates current tree position reflecting object ordering within the parent package
32
      protected int lastLevel;                    // Allows us to determine if we have gone down/up in the hierarchy
33
 
34
      // Collector for the results of the parsing
35
      protected ReqPro_object rq_root_package;
36
 
37
      protected ArrayList rq_req_types;
38
      protected ArrayList rq_req_status_types;
39
 
40
 
41
      /// <summary>
42
      /// Constructor logic
43
      /// </summary>
44
      /// <param name="ea_repository"></param>
45
		public CopyReqProDatabaseToMemory(EA.Repository ea_repository): base()
46
		{
47
         try
48
         {
49
            // create an EA_Utilities object
50
            EA_Utils = new EA_Utilities(ea_repository);
51
 
52
            // figure out where in the EA database we will place the results of parsing
53
            object o;
54
            EA.ObjectType type;
55
            type = ea_repository.GetTreeSelectedItem(out o);
56
            if (type == EA.ObjectType.otElement)
57
            {
58
               ea_rootPackage = ea_repository.GetPackageByID( ((EA.Element)o).PackageID );
59
            }
60
            else if (type == EA.ObjectType.otPackage)
61
            {
62
               ea_rootPackage = (EA.Package)o;
63
            }
64
            else
65
            {
66
               Exception e = new Exception("No Root Package given");
67
               throw e;
68
            }
69
         }
70
         catch (Exception ex)
71
         {
72
            MessageBox.Show(ex.Message, "Error (CopyReqProDatabaseToMemory::CopyReqProDatabaseToMemory)", MessageBoxButtons.OK);
73
         }    
74
		}
75
 
76
 
77
 
78
      #region Requirement Status Type methods
79
 
80
      /// <summary>
81
      /// Get the requirement status types from the ReqPro database, into a simple list, where each element
82
      /// describes the requirement status type and whether it is filtered or not. This list can be given to 
83
      /// the ReqProFilterForm to capture the users requirement status type filtering decisions. 
84
      /// </summary>
85
      private void get_rq_req_status_types_from_database()
86
      {
87
         StringCollection status_values = new StringCollection();
88
 
89
         // Each requirement type can have its own unique list of status attribute values
90
         // so we have to go through each requirement type and find the set of status values
91
         // that each one has and add them to out string collection, if the collection does
92
         // not already have the strings ofcoarse. So, we are merging together all the status
93
         // values in the ReqPro database, into one set.
94
         ReqPro40.ReqTypes rqtypes = RQ_project.ReqTypes;
95
         foreach (ReqPro40.ReqType rq_type in rqtypes)
96
         {
97
            ReqPro40.Attr attr = rq_type.get_Attr("Status", ReqPro40.enumAttrLookups.eAttrLookups_Label);
98
            foreach (ReqPro40.ListItem listItem in attr.ListItems)
99
            {
100
               if (!status_values.Contains(listItem.Text))
101
               {
102
                  status_values.Add(listItem.Text);
103
               }
104
            }
105
         }
106
 
107
         // With our merged set of status values, create a list of ReqPro_ReqStatus objects.
108
         rq_req_status_types = new ArrayList();
109
         foreach (string s in status_values)
110
         {
111
            ReqPro_ReqStatus new_ReqPro_ReqStatus = new ReqPro_ReqStatus();
112
            new_ReqPro_ReqStatus.filtered = false;
113
            new_ReqPro_ReqStatus.status_value = s;
114
            rq_req_status_types.Add(new_ReqPro_ReqStatus);
115
         }
116
      }
117
 
118
      /// <summary>
119
      /// Examine the requirement status type list to see if the requirement status type of 
120
      /// the specified object has been filtered or not.
121
      /// </summary>
122
      /// <param name="rq_obj"></param>
123
      /// <returns></returns>
124
      protected bool reqStatusTypeIsFiltered(ReqPro_object rq_obj)
125
      {
126
         foreach (ReqPro_ReqStatus rqs in rq_req_status_types)
127
         {
128
            if (0 == rqs.status_value.CompareTo(rq_obj.status))
129
            {
130
               return rqs.filtered;
131
            }
132
         }
133
         return false;
134
      }
135
 
136
      #endregion
137
 
138
      #region Requirement Type methods
139
      /// <summary>
140
      /// Recursively set the requirement type enum in each requirement object read
141
      /// from the ReqPro database. The enum give fast indication of the requirement type.
142
      /// If we didnt do this, each time the requirement type needs to be evaluated, a string 
143
      /// compare needs to be done. Here, we do them all up-front so that down the track a simple
144
      /// integer access is all that is required.
145
      /// </summary>
146
      /// <param name="rq_obj"></param>
147
      private void set_rq_req_types_in_copied_data( ReqPro_object rq_obj )
148
         {
149
            if (rq_obj.isRequirement)
150
            {
151
               int i = 0;
152
               foreach (ReqPro_ReqType req_type in rq_req_types)
153
               {
154
                  if (rq_obj.tag.StartsWith(req_type.prefix))
155
                  {
156
                     rq_obj.tag_enum = i;
157
                  }
158
                  i++;
159
               }
160
            }
161
 
162
            foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
163
            {
164
               // recurse
165
               set_rq_req_types_in_copied_data(sub_obj);
166
            }
167
         }
168
 
169
      /// <summary>
170
      /// Get the requirement types from the ReqPro database, into a simple list, where each element
171
      /// describes the requirement type and whether it is filtered or not. This list can be given to 
172
      /// the ReqProFilterForm to capture the users requirement type filtering decisions. 
173
      /// </summary>
174
      private void get_rq_req_types_from_database()
175
      {
176
         rq_req_types = new ArrayList();
177
 
178
         ReqPro40.ReqTypes rqtypes = RQ_project.ReqTypes;
179
         foreach (ReqPro40.ReqType rq_type in rqtypes)
180
         {
181
            ReqPro_ReqType new_req_type = new ReqPro_ReqType();
182
            new_req_type.name     = rq_type.Name;
183
            new_req_type.prefix   = rq_type.ReqPrefix;
184
            new_req_type.filtered = false;
185
            rq_req_types.Add(new_req_type);
186
         }
187
      }
188
 
189
      /// <summary>
190
      /// Examine the requirement type list to see if the requirement type of the specified object
191
      /// has been filtered or not.
192
      /// </summary>
193
      /// <param name="rq_obj"></param>
194
      /// <returns></returns>
195
      protected bool reqTypeIsFiltered(ReqPro_object rq_obj)
196
      {
197
         return ((ReqPro_ReqType)rq_req_types[rq_obj.tag_enum]).filtered;
198
      }
199
 
200
      #endregion
201
 
202
      #region ReqProParser (base class) overrides
203
      /// <summary>
204
      /// This method is designed to prompt the user to select the ReqPro database file
205
      /// before opening and parsing it. Once parsed, the user is offered a chance to setup
206
      /// the filter controls.
207
      /// </summary>
208
      /// <param name="ea_repository"></param>
209
      /// <returns></returns>
2145 ghuddy 210
      public override bool prompt_and_parse(EA.Repository ea_repository, ReqProDB_Artifact.MODE mode)
2141 ghuddy 211
      {
212
         try
213
         {
2145 ghuddy 214
 
2141 ghuddy 215
            pre_parsing();
2145 ghuddy 216
            if (true == base.prompt_and_parse(ea_repository, mode))
2141 ghuddy 217
            {
218
               // obtain the requirement types from the reqpro database (need these for
219
               // the filter dialog)
220
               get_rq_req_types_from_database();
221
               set_rq_req_types_in_copied_data(rq_root_package);
222
 
223
               get_rq_req_status_types_from_database();
224
 
225
               // bring up the filter dialog to allow user to specify exactly what gets copied
2147 ghuddy 226
               ReqProFilterForm rq_filter = new ReqProFilterForm(mode == ReqProDB_Artifact.MODE.TRACEABILITY);
2141 ghuddy 227
               rq_filter.populate(rq_root_package, rq_req_types, rq_req_status_types);
2145 ghuddy 228
 
229
               // Setup the filter based on the saved filter settings in the ReqProDB element (if any)
230
               if (RQ_Element != null)
2141 ghuddy 231
               {
2145 ghuddy 232
                  rq_filter.loadFilterSettings(RQ_Element.Notes);
2141 ghuddy 233
               }
234
 
235
               DialogResult dlgRes = rq_filter.ShowDialog();
236
               if (dlgRes == DialogResult.OK)
237
               {
238
                  allowPackageStructureFragments = rq_filter.allowPackageStructureFragments;
239
                  RQ_project.CloseProject();
2145 ghuddy 240
 
241
                  // Save filter settings to the ReqProDB element if it is available
242
                  if (RQ_Element != null)
243
                  {
244
                     RQ_Element.Notes = rq_filter.saveFilterSettings();
245
                     RQ_Element.Update();
246
                  }
247
 
2141 ghuddy 248
                  return true;
249
               }
250
               RQ_project.CloseProject();
251
            }
252
         }
253
         catch (Exception ex)
254
         {
255
            MessageBox.Show(ex.Message, "Error (CopyReqProDatabaseToMemory::parse)", MessageBoxButtons.OK);
256
         }      
257
         return false;
258
      }
2145 ghuddy 259
 
2141 ghuddy 260
 
261
 
262
      /// <summary>
263
      /// This method will be called by the base class parser when it has obtained a ReqPro
264
      /// project object. We capture that object here so we can interrogate the ReqPro database
265
      /// ourselves, if we need to. We wont do that for package/requirement reading, but we may
266
      /// do it for meta-data such as requirement types, etc.
267
      /// </summary>
268
      /// <param name="reqpro_project"></param>
2145 ghuddy 269
      protected override void provideReqProDatabaseInfo(ReqPro40.Application rq_app, 
270
         ReqPro40.Project rq_project, 
271
         ReqProDB_Artifact rq_artifact,
272
         EA.Element rq_element)
2141 ghuddy 273
      {
2145 ghuddy 274
         RQ_app = rq_app;
2141 ghuddy 275
         RQ_project = rq_project;
2145 ghuddy 276
         RQ_Artifact = rq_artifact;
277
         RQ_Element = rq_element;
2141 ghuddy 278
      }
279
 
280
      /// <summary>
281
      /// This method will be called by the base class parser whenever a package or requirement object
282
      /// is found in the ReqPro database. The method collects important information from the object 
283
      /// into a structure that begins with the ea_rootPackage object. The structure is highly dynamic
284
      /// with each object able to hold a list of other objects. This naturally allows for the ReqPro
285
      /// database hierarchy to be accurately reflected. The hierarchy tracking data maintained within
286
      /// the method allows us to know what object in the structure to hang off any new object derived
287
      /// from info given to us by the base class parser (ie. what object is the parent object at the
288
      /// present time during the parsing).
289
      /// </summary>
290
      /// <param name="level"></param>
291
      /// <param name="ea_repository"></param>
292
      /// <param name="rq_project"></param>
293
      /// <param name="rq_package"></param>
294
      /// <param name="rq_requirement"></param>
295
      protected override void processObject(int level,
296
                                            EA.Repository ea_repository, 
297
                                            ReqPro40.Project rq_project, 
298
                                            ReqPro40.Package rq_package,
299
                                            ReqPro40.Requirement rq_requirement)
300
      {
301
         // If we are still at the same level as the previous package, then pop the previous object 
302
         // in readiness for pushing the one we are now dealing with.
303
         if (level == lastLevel)
304
         {
305
            rq_objs.Pop();
306
            ea_treePos.Pop();
307
         }
308
            // but if we are beneath the previous level, pop all objects that are above us because
309
            // we no longer need them in our hierarchy reference data.
310
         else if (level < lastLevel)
311
         {
312
            while (lastLevel >= level)
313
            {
314
               rq_objs.Pop();
315
               ea_treePos.Pop();
316
               lastLevel--;
317
            }
318
         }
319
 
320
         // bump the tree position at this level (controls display position in the EA project browser)
321
         int treePos = (int)ea_treePos.Pop();
322
         treePos++;
323
         ea_treePos.Push(treePos);
324
 
325
         // create the new requirement or package
326
         ReqPro_object new_rq_obj = new ReqPro_object();
327
         if (rq_requirement != null)
328
         {
329
            new_rq_obj.isRequirement = true;
330
            new_rq_obj.name   = rq_requirement.Name;
331
            new_rq_obj.text   = rq_requirement.Text;
332
            new_rq_obj.guid   = rq_requirement.GUID;
333
            new_rq_obj.tag    = rq_requirement.get_Tag(ReqPro40.enumTagFormat.eTagFormat_FullTag);
334
 
335
            new_rq_obj.status     = rq_requirement.AttrValues["Status", ReqPro40.enumAttrValueLookups.eAttrValueLookup_Label].Text;
336
            new_rq_obj.difficulty = rq_requirement.AttrValues["Difficulty", ReqPro40.enumAttrValueLookups.eAttrValueLookup_Label].Text;
337
            new_rq_obj.priority   = rq_requirement.AttrValues["Priority", ReqPro40.enumAttrValueLookups.eAttrValueLookup_Label].Text;
338
            new_rq_obj.version    = rq_requirement.VersionNumber;
339
            new_rq_obj.versionDateTime = rq_requirement.VersionDateTime;
2143 ghuddy 340
 
341
 
342
            // requirements can trace to other requirements, so we have to find those in order to re-construct
343
            // that traceability later on. Currently, we only process TracesTo relationships from ReqPro.
344
            int limit_numberOfTracesTo = 0;
345
            if (true == rq_requirement.get_HasTracesTo(ref limit_numberOfTracesTo))
346
            {
347
               // scan through the TracesTo relationships
348
               ReqPro40.Relationships theseRelationships = (ReqPro40.Relationships)rq_requirement.TracesTo;
349
 
350
               int i_numberOfTracesTo;
351
               theseRelationships.MoveFirst();
352
               for (i_numberOfTracesTo = 0; i_numberOfTracesTo < limit_numberOfTracesTo; i_numberOfTracesTo++)
353
               {
354
                  // Obtain the traced-to requirement from the relationship, and parse it
355
                  ReqPro40.Relationship thisRelationship = theseRelationships.GetCurrentRelationship();
356
 
357
                  ReqPro40.Requirement tracedToRequirement = 
358
                     thisRelationship.get_DestinationRequirement(ReqPro40.enumRequirementsWeights.eReqWeight_Heavy);
359
 
360
                  if (tracedToRequirement != null)
361
                  {
362
                     // Add the GUID of the traced-to requirement to the relevant list within the
363
                     // object representing the traced-from requirement (ie. parent requirement).
364
                     new_rq_obj.ReqPro_traces.Add(tracedToRequirement.GUID);
365
                  }
366
 
367
                  theseRelationships.MoveNext();
368
               }
369
            }
370
 
2141 ghuddy 371
         }
372
         else if (rq_package != null)
373
         {
374
            new_rq_obj.isPackage = true;
375
 
376
            // Packages in ReqPro may be prefixed by a number to force ReqPro's alphanumeric sorting
377
            // algorithm to order the packages in the way the user wants, as dictated by the actual 
378
            // numbers used. EA does not have this problem because it uses a tree position number to
379
            // control a package/element's position in the project browser. So, strip off any leading
380
            // numeric from the ReqPro packages.
381
            string trimstring = " 0123456789";
382
            char[] trimmer = trimstring.ToCharArray();
383
            string filtered_name = rq_package.Name.TrimStart(trimmer);
384
 
385
            new_rq_obj.name = filtered_name;
386
            new_rq_obj.guid = rq_package.GUID;
387
         }
388
 
389
         new_rq_obj.level = level;
390
         new_rq_obj.treePos = treePos;
391
 
392
         // attach it to its parent object
393
         ReqPro_object parent_rq_obj = (ReqPro_object)rq_objs.Peek();
394
         parent_rq_obj.ReqPro_objects.Add( new_rq_obj );
2143 ghuddy 395
         new_rq_obj.parent = parent_rq_obj;
2141 ghuddy 396
 
397
         // keep a count of the number of requirements the object has beneath it
398
         if (true == new_rq_obj.isRequirement)
399
            parent_rq_obj.numberOfRequirements++;
400
 
401
         // push the new object onto the stack, ready for any sub-objects that may belong to it.
402
         // If, the next time we enter this method, the level is the same, this will get popped off.
403
         // If, the next time we enter this method, the level is lower, this and possibly more will
404
         // get popped off.
405
         rq_objs.Push(new_rq_obj);
406
         ea_treePos.Push(0);
407
 
408
         // capture what the hierarchy level is for the object just processed.
409
         lastLevel = level;
410
      }
411
 
412
      #endregion
413
 
414
 
415
 
416
      /// <summary>
417
      /// A method to contain common pre-parsing steps.
418
      /// </summary>
419
      private void pre_parsing()
420
      {
421
         // create an object to represent the root of the database so that we can collect
422
         // sub-objects (packages or requirements) underneath it.
423
         rq_root_package = new ReqPro_object();
424
         rq_root_package.name = "ROOT";
425
 
426
         // initialise the ReqPro database hierarchy tracking data
427
         rq_objs.Clear();
428
         rq_objs.Push(rq_root_package);
429
         ea_treePos.Clear();
430
         ea_treePos.Push(0);
431
         lastLevel = 0;
432
      }
2143 ghuddy 433
 
434
 
435
 
436
 
2141 ghuddy 437
	}
438
}