Subversion Repositories DevTools

Rev

Rev 2153 | Rev 2157 | 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;
2151 ghuddy 2
using System.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Windows.Forms;
2141 ghuddy 6
using ReqPro40;
7
 
8
 
9
namespace EA_ReqPro
10
{
11
 
12
	/// <summary>
2155 ghuddy 13
   /// ImportReqProDatabase is a specialisation of CopyReqProDatabaseToMemory, designed to copy the 
14
   /// ReqPro database content into an EA database, discarding the structure of and hierarchy of 
15
   /// packages, selecting just the requirements found in the ReqPro database for storage into EA,
16
   /// where they will be used for design traceability purposes.
2141 ghuddy 17
	/// </summary>
2155 ghuddy 18
   public class ImportReqProDatabase : CopyReqProDatabaseToMemory
19
   {
2151 ghuddy 20
      private int totalRequirements = 0;
21
 
2141 ghuddy 22
      /// <summary>
23
      /// Constructor logic
24
      /// </summary>
25
      /// <param name="ea_repository"></param>
2151 ghuddy 26
      public ImportReqProDatabase(): base()
2155 ghuddy 27
      {
2151 ghuddy 28
         totalRequirements = 0;
2155 ghuddy 29
      }
2141 ghuddy 30
 
31
 
32
      /// <summary>
33
      /// Method to parse a ReqPro database using the information in a ReqProDB artifact,
34
      /// assumed to be selected in EA's project browser prior to the method call.
35
      /// </summary>
36
      /// <param name="ea_repository"></param>
37
      /// <returns></returns>
2155 ghuddy 38
      public override bool prompt_and_parse(ReqProDB_Artifact.MODE mode, out bool cancelled)
2151 ghuddy 39
      {
2155 ghuddy 40
         cancelled = false;
41
 
2151 ghuddy 42
         try
43
         {
2155 ghuddy 44
            base.structure_only = false;
45
 
46
            string importDateTime = System.DateTime.Now.ToString();
47
 
48
            Main.WriteOutput("EA Requirement import at " + importDateTime, -1 );
49
            Main.WriteOutput("",-1);
50
 
51
            if (true == base.prompt_and_parse(mode, out cancelled))
2151 ghuddy 52
            {
53
               if (Main.mustAbort)
54
                  return false;
55
 
56
               Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
57
 
58
               // Configure the ReqProDB artifact as a traceability artifact
59
               RQ_Artifact.set_traceability_mode(RQ_Element);
60
 
2155 ghuddy 61
               ImportFromReqPro(importDateTime);
2151 ghuddy 62
 
63
               return true;
64
            }
65
         }
66
         catch (Exception ex)
67
         {
2153 ghuddy 68
            Main.MessageBoxException(ex, "Exception (parse)");
2151 ghuddy 69
         }      
2155 ghuddy 70
 
2151 ghuddy 71
         return false;
72
      }
73
 
2141 ghuddy 74
      /// <summary>
75
      /// Displays the content of the change log element to the output trace display. This method must
76
      /// be kept in sync with the ImportFromReqPro method, obviously.
77
      /// </summary>
78
      /// <param name="ea_repository"></param>
2151 ghuddy 79
      /// <param name="changeLog"></param>
80
      public void displayChangeLog(EA.Element changeLog)
2141 ghuddy 81
      {
82
         // The change log element contains all the log in its notes section. Break it up into
83
         // lines, because each line is a single log entry, so that we can process them one at
84
         // a time.
85
         string delimStr = "\n";
86
         char [] delim = delimStr.ToCharArray();
87
         string[] log_strings = changeLog.Notes.Split(delim,2000);
88
 
89
         // Prepare a string to form an updated change log (needed to support the activity of orphaned 
90
         // requirement deletion).
91
         string newList = "";
92
 
93
         // modify delimiters to : character so that we can extract the parameters for each log entry
94
         delimStr = ":";
95
         delim = delimStr.ToCharArray();
96
 
2155 ghuddy 97
         Main.WriteOutput("Displaying Import Change Log", -1);
2141 ghuddy 98
 
99
         foreach(string s in log_strings)
100
         {
2151 ghuddy 101
            if (Main.mustAbort)
102
               break;
103
 
2141 ghuddy 104
            // over time, users may delete the orphaned requirements from the EA database, but their
105
            // GUIDs will still exist in the change log. Use of such a GUID will cause 
106
            // an exception in the GetElementByGuid() function. What should we do? We can attempt
107
            // to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs
108
            // that is formed from the old list, where only good items from the old list find their 
109
            // way into the new list. Gradually, the list is wittled away as EA users delete orphaned
110
            // requirements having first dealt with the design change impacts that resulted from their
111
            // orphanage.
112
            try
113
            {
114
               if (s.StartsWith("{"))
115
               {
116
                  string trimmed_s = s.Trim();
117
 
118
                  // Get log entry;s parameters.
119
                  string[] parameters = trimmed_s.Split(delim, 10);
120
 
121
                  // The first parameter is the GUID so use it to get the requirement element
2151 ghuddy 122
                  EA.Element ea_req = Main.EA_Repository.GetElementByGuid(parameters[0]);
2141 ghuddy 123
 
124
                  // Now discriminate actions based on the second parameter
125
 
126
                  if (parameters[1].StartsWith("Created"))
127
                  {
2155 ghuddy 128
                     Main.WriteOutput("  Created : " + ea_req.Name, ea_req.ElementID );
2141 ghuddy 129
                  }
2155 ghuddy 130
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 131
                  else if (parameters[1].StartsWith("Orphaned"))
132
                  {
2155 ghuddy 133
                     Main.WriteOutput("  Orphaned : " + ea_req.Name, ea_req.ElementID );
2141 ghuddy 134
 
135
                     foreach (EA.Connector theConnector in ea_req.Connectors)
136
                     {
2151 ghuddy 137
                        EA.Element tgt_ele = (EA.Element)Main.EA_Repository.GetElementByID( theConnector.SupplierID );
2141 ghuddy 138
                        if (tgt_ele != null)
139
                        {
140
                           if (!tgt_ele.Type.StartsWith("Requirement"))
141
                           {
2155 ghuddy 142
                              Main.WriteOutput("     --> " + tgt_ele.Name, tgt_ele.ElementID);
2141 ghuddy 143
                           }
144
                        }
145
                     }
146
                  }
2155 ghuddy 147
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 148
                  else if (parameters[1].StartsWith("Name"))
149
                  {
2155 ghuddy 150
                     Main.WriteOutput("  Modified Name: " + ea_req.Name, ea_req.ElementID );
151
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
152
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 153
                  }
2155 ghuddy 154
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 155
                  else if (parameters[1].StartsWith("Notes"))
156
                  {
2155 ghuddy 157
                     Main.WriteOutput("  Modified Description: " + ea_req.Name, ea_req.ElementID );
158
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
159
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 160
                  }
2155 ghuddy 161
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 162
                  else if (parameters[1].StartsWith("Difficulty"))
163
                  {
2155 ghuddy 164
                     Main.WriteOutput("  Modified Difficulty: " + ea_req.Name, ea_req.ElementID );
165
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
166
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 167
                  }
2155 ghuddy 168
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 169
                  else if (parameters[1].StartsWith("Priority"))
170
                  {
2155 ghuddy 171
                     Main.WriteOutput("  Modified Priority: " + ea_req.Name, ea_req.ElementID );
172
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
173
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 174
                  }
2155 ghuddy 175
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 176
                  else if (parameters[1].StartsWith("Version"))
177
                  {
2155 ghuddy 178
                     Main.WriteOutput("  Modified Version: " + ea_req.Name, ea_req.ElementID );
179
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
180
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 181
                  }
2155 ghuddy 182
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 183
                  else if (parameters[1].StartsWith("Status"))
184
                  {
2155 ghuddy 185
                     Main.WriteOutput("  Modified Status: " + ea_req.Name, ea_req.ElementID );
186
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
187
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 188
                  }
2155 ghuddy 189
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
190
                  else if (parameters[1].StartsWith("Subsystem"))
191
                  {
192
                     Main.WriteOutput("  Modified Subsystem: " + ea_req.Name, ea_req.ElementID );
193
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
194
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
195
                  }
196
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
197
                  else if (parameters[1].StartsWith("Stability"))
198
                  {
199
                     Main.WriteOutput("  Modified Stability: " + ea_req.Name, ea_req.ElementID );
200
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
201
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
202
                  }
203
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
204
                  else if (parameters[1].StartsWith("ReqType"))
205
                  {
206
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
207
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
208
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
209
                  }
210
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
211
                  else if (parameters[1].StartsWith("SourceVersion"))
212
                  {
213
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
214
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
215
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
216
                  }
217
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
218
                  else if (parameters[1].StartsWith("SourceSection"))
219
                  {
220
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
221
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
222
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
223
                  }
224
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
225
                  else if (parameters[1].StartsWith("Source"))
226
                  {
227
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
228
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
229
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
230
                  }
2141 ghuddy 231
 
232
                  // accumulate good item into the newList
233
                  newList += trimmed_s + "\r\n";
234
               }
235
            }
236
            catch
237
            {
238
               // do nothing - the newList accumulator will not have the GUID that caused the exception
239
               // so the next time a display operation is attempted, the exception wont happen.
240
            }
241
         }
242
 
243
         // Update the change log
244
         changeLog.Notes = newList;
245
         changeLog.Update();
246
      }
247
 
2147 ghuddy 248
 
249
      /// <summary>
250
      /// Rid a string of any : char because we use that as a delimiter in the change log and so we 
251
      /// do not want a users use of the character to confuse the change log display mechanism.
252
      /// </summary>
253
      /// <param name="s"></param>
254
      /// <returns></returns>
255
      private string NO_COLONS(string s)
256
      {
257
         string sc =  s.Replace(':', ' ');
258
         sc = sc.Replace('\r' , ' ');
259
         sc = sc.Replace('\n' , ' ');
260
 
261
         return sc;
262
      }
2151 ghuddy 263
 
2155 ghuddy 264
      /// <summary>
265
      /// Get a new import package in which to store change log and new requirements from the import.
266
      /// </summary>
267
      /// <param name="parentPackage"></param>
268
      /// <param name="importDateTime"></param>
269
      /// <returns></returns>
270
      private EA.Package createImportPackage(EA.Package parentPackage, string importDateTime)
271
      {
272
         EA.Package importPackage = null;
273
         string importSubDir = EA_TaggedValues.Read(base.RQ_Element, Constants.TAG_IMPORT_SUB_DIR, "");
274
         if (importSubDir != null && importSubDir.Length > 0)
275
         {
276
            importPackage = (EA.Package)parentPackage.Packages.GetByName(importSubDir);
277
            if (importPackage != null)
278
            {
279
               parentPackage = importPackage;
280
            }
281
            else
282
            {
283
               // create a subdir and use it as the parent
284
               parentPackage = (EA.Package )parentPackage.Packages.AddNew( importSubDir, "Package");
285
               parentPackage.Update();
286
            }
287
         }
2151 ghuddy 288
 
2155 ghuddy 289
         // create the import dir in the parent
290
         importPackage = (EA.Package )parentPackage.Packages.AddNew( "import " + importDateTime, "Package");
291
         importPackage.Update();
292
 
293
         return importPackage;
294
      }
295
 
296
 
297
 
2151 ghuddy 298
      /// <summary>
299
      /// A method that imports requirements from a ReqPro database into EA for the purpose
300
      /// of supporting requirement-to-design traceability.
301
      /// </summary>
302
      /// <param name="repository"></param>
2155 ghuddy 303
      private void ImportFromReqPro(string importDateTime)
2151 ghuddy 304
      {
305
         try
306
         {
307
            // Get a list of EA requirements and their associated ReqPro GUIDs
308
            ArrayList ea_reqs;
309
            ArrayList ea_GUIDs = new ArrayList();
310
            ArrayList ea_req_matched = new ArrayList();
311
 
312
            // Obtain the EA parent package so that we can create under it an import package
313
            // if need be, and scan for existing requirement elements.
314
            EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );
315
 
316
            ArrayList allowedElementTypes = new ArrayList();
317
            allowedElementTypes.Add("Requirement");
318
            allowedElementTypes.Add("UseCase");
319
 
2155 ghuddy 320
            Main.WriteOutput("Acquiring list of elements already in EA", -1);
2151 ghuddy 321
            ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
2153 ghuddy 322
            EA_Utilities.findAndProcessPackageElements( parentPackage, reqLister, true );
2151 ghuddy 323
 
324
            if (Main.mustAbort)
325
               return;
326
 
327
            ea_reqs = reqLister.Elements; 
328
            foreach (EA.Element ea_req in ea_reqs)
329
            {
2155 ghuddy 330
               string GUID = EA_TaggedValues.Read(ea_req, Constants.TAG_GUID);
2151 ghuddy 331
               ea_GUIDs.Add(GUID);
332
               ea_req_matched.Add(false);
333
            }
334
 
335
            if (Main.mustAbort)
336
               return;
337
 
2155 ghuddy 338
            // Create an import package to store new requirements and the change log
339
            EA.Package importPackage = createImportPackage(parentPackage, importDateTime);
2151 ghuddy 340
 
2155 ghuddy 341
            // Create the change log element in the import package
2151 ghuddy 342
            EA.Element changeLog = (EA.Element)importPackage.Elements.AddNew("Change Log","InformationItem");
343
            changeLog.Update();
344
 
345
            // Get a flattened list of requirements from the hierarchical data the user has filtered
346
            ArrayList rq_req_collection = new ArrayList();
347
            get_rq_req_collection(ref rq_req_collection);
348
 
349
            int newRequirementCount = 0;
350
            int modifiedRequirementCount = 0;
351
            int statusUpdatedRequirementCount = 0;
352
            int orphanedCount = 0;
353
 
354
 
2155 ghuddy 355
            Main.WriteOutput("Merging ReqPro content to EA", -1);
2151 ghuddy 356
            // loop through all of the ReqPro requirements
357
            foreach(ReqPro_object rq_obj in rq_req_collection)
358
            {
359
               if (Main.mustAbort)
360
                  break;
361
 
362
               try
363
               {
364
                  // Find which EA requirement element refers to the current ReqPro GUID
365
                  int i_ea_req;
366
                  i_ea_req = ea_GUIDs.IndexOf( rq_obj.guid );
367
 
368
                  // If EA element was found
369
                  if (0 <= i_ea_req)
370
                  {
371
                     ea_req_matched[i_ea_req] = true;
372
 
373
                     EA.Element ea_req = ((EA.Element)ea_reqs[i_ea_req]);
374
 
375
                     rq_obj.ea_element_ID = ea_req.ElementID;
376
 
2155 ghuddy 377
                     // Only update the requirement if it was not mastered in EA, or
378
                     // unrestricted imports have been enabled
379
                     if (  (false == EA_TaggedValues.Read(ea_req, Constants.TAG_CREATED_IN_EA, Constants.DEFAULT_CREATED_IN_EA))
380
                        || (true == EA_TaggedValues.Read(ea_req, Constants.TAG_UNRESTRICTED_IMPORTS, Constants.DEFAULT_UNRESTRICTED_IMPORTS)) )
381
                     {
382
                        // This ReqPro requirement already has a counterpart in EA, so we must simply
383
                        // update the counterpart. But, to aid the designer, we need to try to tell them
384
                        // how the requirement has changed, which could ofcoarse change the meaning 
385
                        // of the requirement and require design changes to be done.
2151 ghuddy 386
 
2155 ghuddy 387
                        bool meaningMayHaveChanged = false;
388
                        bool statusMayHaveChanged = false;
2151 ghuddy 389
 
2155 ghuddy 390
                        string ea_req_name = rq_obj.tag + " " + rq_obj.name;
2151 ghuddy 391
 
2155 ghuddy 392
                        Main.WriteOutput("Updating: " + ea_req_name, rq_obj.ea_element_ID);
2151 ghuddy 393
 
2155 ghuddy 394
                        ea_req.Name       = updated_property_value_if_changed(changeLog, ea_req, ea_req.Name, "Name", ea_req_name, ref meaningMayHaveChanged);
2151 ghuddy 395
 
2155 ghuddy 396
                        ea_req.Notes      = updated_property_value_if_changed(changeLog, ea_req, ea_req.Notes, "Notes", rq_obj.text, ref meaningMayHaveChanged);
2151 ghuddy 397
 
2155 ghuddy 398
                        ea_req.Difficulty = updated_property_value_if_changed(changeLog, ea_req, ea_req.Difficulty, "Difficulty", rq_obj.difficulty, ref statusMayHaveChanged);
2151 ghuddy 399
 
2155 ghuddy 400
                        ea_req.Priority   = updated_property_value_if_changed(changeLog, ea_req, ea_req.Priority, "Priority", rq_obj.priority, ref statusMayHaveChanged);
2151 ghuddy 401
 
2155 ghuddy 402
                        ea_req.Status     = updated_property_value_if_changed(changeLog, ea_req, ea_req.Status, "Status", rq_obj.status, ref statusMayHaveChanged);
403
 
404
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE, "Source", rq_obj.source, ref statusMayHaveChanged);
405
 
406
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_VERSION, "SourceVersion", rq_obj.sourceVersion, ref statusMayHaveChanged);
407
 
408
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_SECTION, "SourceSection", rq_obj.sourceSection, ref statusMayHaveChanged);
409
 
410
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SUBSYSTEM, "Subsystem", rq_obj.subsystem, ref statusMayHaveChanged);
411
 
412
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_STABILITY, "Stability", rq_obj.stability, ref statusMayHaveChanged);
413
 
414
                        // Requirement Types are actually implemented using ordinary EA element stereotypes.
415
                        // Use StereotypeEx field to see if the type already exists, since that field can be a comma
416
                        // seperated list of more than one stereotype, just in case user has added additional stereotypes
417
                        // to the item.
418
                        if (0 > ea_req.StereotypeEx.IndexOf(rq_obj.type))
419
                        {
420
                           changeLog.Notes += ea_req.ElementGUID + ":ReqType:" + ea_req.Stereotype + ":" + rq_obj.type + "\r\n";
421
                           changeLog.Update();
422
                           statusMayHaveChanged = true;
423
                           if (ea_req.StereotypeEx.Length > 0)
424
                              ea_req.StereotypeEx = rq_obj.type + "," + ea_req.StereotypeEx;
425
                           else
426
                              ea_req.StereotypeEx = rq_obj.type;
427
                        }
428
                        if (ea_req.Stereotype.Length == 0)
429
                        {
430
                           ea_req.Stereotype = ea_req.StereotypeEx.Split(",".ToCharArray())[0];
431
                        }
432
 
433
                        ea_req.Update();
434
 
435
                        if (meaningMayHaveChanged)
436
                        {
437
                           modifiedRequirementCount++;
438
                        }
2151 ghuddy 439
 
2155 ghuddy 440
                        if (statusMayHaveChanged)
441
                        {
442
                           statusUpdatedRequirementCount++;
443
                        }
444
 
445
                        totalRequirements++;
2151 ghuddy 446
                     }
447
 
448
                  }
449
                  else
450
                  {
451
                     totalRequirements++;
452
 
453
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
454
                     // a new one.
455
                     newRequirementCount++;
456
 
457
                     // create the new EA requirement in the import package
458
                     EA.Element ea_req = (EA.Element)importPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
459
 
460
                     rq_obj.ea_element_ID = ea_req.ElementID;
461
 
2155 ghuddy 462
                     CopyReqProDatabase.copyReq(ea_req, rq_obj);
2151 ghuddy 463
 
2155 ghuddy 464
                     ea_req.Notes = rq_obj.text;
465
 
2151 ghuddy 466
                     ea_req.Update();
467
 
468
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
469
                     changeLog.Update();
470
 
2155 ghuddy 471
                     Main.WriteOutput("Created: " + ea_req.Name, ea_req.ElementID);
2151 ghuddy 472
                  }
473
 
474
               }
475
               catch (Exception ex)
476
               {
2155 ghuddy 477
                  Main.WriteOutput("Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);
2151 ghuddy 478
               }
479
            }
480
 
481
            if (Main.mustAbort)
482
               return;
483
 
2155 ghuddy 484
            Main.WriteOutput("Checking for orphaned requirements", -1);
2151 ghuddy 485
            // Now check for orphaned EA requirements
486
            for (int i = 0; i < ea_GUIDs.Count; i++)
487
            {
488
               if (Main.mustAbort)
489
                  break;
490
 
491
               string rq_GUID = (string)ea_GUIDs[i];
492
               if (rq_GUID != "")
493
               {
494
                  if ((bool)ea_req_matched[i] == false)
495
                  {
496
                     EA.Element ea_req = (EA.Element)ea_reqs[i];
497
 
498
                     orphanedCount++;
499
 
500
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
501
                     changeLog.Update();
502
                  }
503
               }
504
            }
505
 
2155 ghuddy 506
            bool changeLogDeleted = false;
507
            if (changeLog.Notes != null && changeLog.Notes.Length > 0)
508
            {
509
               DialogResult dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);
510
               if (dlgres == DialogResult.Yes)
511
                  displayChangeLog(changeLog);
512
            }
513
            else
514
            {
515
               importPackage.Elements.Refresh();
516
               if (importPackage.Elements.Count == 1)
517
               {
518
                  EA_Utilities.deletePackage(importPackage);
519
                  changeLogDeleted = true;
520
               }
521
            }
2151 ghuddy 522
 
523
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
524
 
2149 ghuddy 525
            // Setup the internal requirement to requirement connectivity. This is seperate from the browser
526
            // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
527
            // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
528
            // with explicit trace relationships setup in ReqPro.
529
            // The purpose of this internal connectivity is to support relationship matrix tables in documentation
530
            // generated by EA_DocGen, or to support diagrammatic representations of the requirements in EA,
531
            // where the connectivity will become apparent through links ajoining the requirement elements in the
532
            // diagram.
2151 ghuddy 533
            write_traces(totalRequirements);
2141 ghuddy 534
 
2151 ghuddy 535
            if (Main.mustAbort)
536
               return;
2141 ghuddy 537
 
2155 ghuddy 538
            writeDelayedMessages();
539
 
2151 ghuddy 540
            // display summary stats
2155 ghuddy 541
            Main.WriteOutput(newRequirementCount.ToString() + " new requirements", -1);
542
            Main.WriteOutput(modifiedRequirementCount.ToString() + " requirements modified", -1);
543
            Main.WriteOutput(statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
544
            Main.WriteOutput(orphanedCount.ToString() + " requirements were orphaned", -1);
2151 ghuddy 545
 
2155 ghuddy 546
            if (changeLogDeleted)
547
            {
548
               Main.WriteOutput("NOTE: import package and change log deleted, since nothing changed in this import", -1);
549
            }
2151 ghuddy 550
 
2155 ghuddy 551
            Main.WriteOutput("Import Completed", -1);
552
            MessageBoxEx.Show("Import Completed");
2151 ghuddy 553
         }
554
         catch (Exception ex)
555
         {
2153 ghuddy 556
            Main.MessageBoxException(ex, "Exception (ImportFromReqPro)");
2151 ghuddy 557
         }
558
      }
559
 
2155 ghuddy 560
      private string updated_property_value_if_changed(EA.Element changeLog, 
561
         EA.Element ea_req, 
562
         string dest_value, 
563
         string changeLogName, 
564
         string source_value,
565
         ref bool mayHaveChanged)
566
      {
567
         if (dest_value.CompareTo(source_value) != 0 )
568
         {
569
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName+ ":" + NO_COLONS(dest_value) + ":" + NO_COLONS(source_value) + "\r\n";
570
            changeLog.Update();
571
            mayHaveChanged = true;
572
            return source_value;
573
         }
574
         return dest_value;
575
      }
2151 ghuddy 576
 
2155 ghuddy 577
      private void if_tagged_value_changed_update_it(EA.Element changeLog, 
578
         EA.Element ea_req, 
579
         string tagname, 
580
         string changeLogName, 
581
         string source_value,
582
         ref bool statusMayHaveChanged)
583
      {
584
         string value = EA_TaggedValues.Read(ea_req, tagname, "");
585
         if ((source_value != null) && (false == source_value.Equals(value)))
586
         {
587
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName + ":" + value + ":" + source_value + "\r\n";
588
            changeLog.Update();
589
            EA_TaggedValues.Write(ea_req, tagname, source_value);
590
            statusMayHaveChanged = true;
591
         }
592
      }
2151 ghuddy 593
 
594
 
2155 ghuddy 595
 
596
 
2141 ghuddy 597
      /// <summary>
598
      /// This method (along with its sibling overload) obtains a flattened view of the 
599
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
600
      /// takes account of the users filtering requests.
601
      /// </summary>
602
      /// <param name="ea_repository"></param>
2151 ghuddy 603
      private void get_rq_req_collection(ref ArrayList rq_req_collection)
2141 ghuddy 604
      {
605
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
606
         {
2151 ghuddy 607
            get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 608
         }
609
      }
610
 
2151 ghuddy 611
      private void get_rq_req_collection(ref ArrayList rq_req_collection,
2141 ghuddy 612
                                         ReqPro_object rq_obj )
613
      {
614
         if (rq_obj.isPackage)
615
         {
2147 ghuddy 616
            // if the package is not filtered, or if we are allowed to dig beneath filtered
617
            // packages...
618
            if (rq_obj.filtered == false || base.allowPackageStructureFragments)
2141 ghuddy 619
            {
620
               // Using recursion, scan this objects sub-objects
621
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
622
               {
2147 ghuddy 623
                  // if the sub-object is a package, always recurse to process it, else
624
                  // if the sub-object is a requirement, only recurse if the containing package
625
                  // is not filtered, so that requirements of filtered packages are themselves
626
                  // filtered out by virtue of their parent packages filtering state.
627
                  if (  sub_obj.isPackage
628
                     || (sub_obj.isRequirement && rq_obj.filtered == false))
629
                  {
2151 ghuddy 630
                     get_rq_req_collection(ref rq_req_collection, sub_obj);
2147 ghuddy 631
                  }
2141 ghuddy 632
               }
633
            }
634
         }
635
         else if (rq_obj.isRequirement)
636
         {
637
            if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)) )
638
            {
639
               // Add this requirement to the flattened list we are accumulating
640
               rq_req_collection.Add(rq_obj);
641
 
2149 ghuddy 642
               // In ReqPro, a requirement can be related to another requirement in several ways:
643
               // 1. By virtue of its position relative to another in the browser display. That is, 
644
               //    if you place a requirement beneath a parent requirement, you are establishing a 
645
               //    parent-child relationship.
646
               // 2. By virtue of a specific TraceTo relationship being made via the Traceability menu
647
               //    option. 
648
               // Interestingly, ReqPro prevents you creating a relationship of one of the above types,
649
               // if a relationship of the other type already exists. This implies that the relationship
650
               // between a parent and child requirement must be singular and is important regardless
651
               // of the manner in which it was created or represented.
652
               // The CopyReqProDatabaseToMemory base class will already have taken care of recording
653
               // relationships detected from ReqPro made using method 2 above. What we need to do here is
654
               // take care of those apparent from the browser based hierarchical organisation (ie. made
655
               // in ReqPro using method 1).
656
               // All we need to do is grab the parent object (if any) and add the GUID of the child to 
657
               // its list of trace-to's. Later on, the write_traces() class method will turn these into
658
               // EA based connection objects that belong to the parent requirement elements.
659
               if (rq_obj.parent != null)
660
               {
661
                  rq_obj.parent.ReqPro_traces.Add(rq_obj.guid);
662
               }
663
 
2147 ghuddy 664
               // Using recursion, scan this objects sub-objects, which in practise will all
665
               // be requirement objects. At this time requirement objects cannot have packages 
666
               // as children.
2141 ghuddy 667
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
668
               {
2151 ghuddy 669
                  get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 670
               }
671
            }
672
         }
673
      }
674
 
675
 
676
	}
677
}