Subversion Repositories DevTools

Rev

Rev 2169 | Rev 2173 | 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
   {
2167 ghuddy 20
      private struct req_lists_t
21
      {
22
         public ArrayList ea_reqs;
23
         public ArrayList ea_GUIDs;
24
         public ArrayList new_ea_reqs;
25
         public ArrayList new_ea_GUIDs;
26
      };
27
 
28
      private req_lists_t req_lists = new req_lists_t();
29
 
2151 ghuddy 30
      private int totalRequirements = 0;
31
 
2167 ghuddy 32
      private EA.Package gCurrentPackage = null;
33
      private EA.Package gNewReqProDBPackage = null;
34
      private EA.Package gChangeHistoryPackage = null;
35
      private EA.Package gOrphansPackage = null;
36
 
37
 
2141 ghuddy 38
      /// <summary>
39
      /// Constructor logic
40
      /// </summary>
41
      /// <param name="ea_repository"></param>
2151 ghuddy 42
      public ImportReqProDatabase(): base()
2155 ghuddy 43
      {
2151 ghuddy 44
         totalRequirements = 0;
2155 ghuddy 45
      }
2141 ghuddy 46
 
47
 
48
      /// <summary>
49
      /// Method to parse a ReqPro database using the information in a ReqProDB artifact,
50
      /// assumed to be selected in EA's project browser prior to the method call.
51
      /// </summary>
52
      /// <param name="ea_repository"></param>
53
      /// <returns></returns>
2155 ghuddy 54
      public override bool prompt_and_parse(ReqProDB_Artifact.MODE mode, out bool cancelled)
2151 ghuddy 55
      {
2155 ghuddy 56
         cancelled = false;
57
 
2151 ghuddy 58
         try
59
         {
2155 ghuddy 60
            base.structure_only = false;
61
 
62
            string importDateTime = System.DateTime.Now.ToString();
63
 
64
            Main.WriteOutput("EA Requirement import at " + importDateTime, -1 );
65
            Main.WriteOutput("",-1);
66
 
67
            if (true == base.prompt_and_parse(mode, out cancelled))
2151 ghuddy 68
            {
69
               if (Main.mustAbort)
70
                  return false;
71
 
72
               Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
73
 
74
               // Configure the ReqProDB artifact as a traceability artifact
75
               RQ_Artifact.set_traceability_mode(RQ_Element);
76
 
2155 ghuddy 77
               ImportFromReqPro(importDateTime);
2151 ghuddy 78
 
79
               return true;
80
            }
81
         }
82
         catch (Exception ex)
83
         {
2153 ghuddy 84
            Main.MessageBoxException(ex, "Exception (parse)");
2151 ghuddy 85
         }      
2155 ghuddy 86
 
2151 ghuddy 87
         return false;
88
      }
89
 
2167 ghuddy 90
 
2141 ghuddy 91
      /// <summary>
92
      /// Displays the content of the change log element to the output trace display. This method must
93
      /// be kept in sync with the ImportFromReqPro method, obviously.
94
      /// </summary>
95
      /// <param name="ea_repository"></param>
2151 ghuddy 96
      /// <param name="changeLog"></param>
97
      public void displayChangeLog(EA.Element changeLog)
2141 ghuddy 98
      {
2167 ghuddy 99
         Main.WriteOutput("Displaying Import Change Log", -1);
2141 ghuddy 100
 
2167 ghuddy 101
         if (changeLog.Notes == null || changeLog.Notes.Length == 0 || changeLog.Notes.Trim().Length == 0)
102
         {
103
            Main.WriteOutput("  No changes", -1);
104
         }
105
         else
106
         {
107
            // The change log element contains all the log in its notes section. Break it up into
108
            // lines, because each line is a single log entry, so that we can process them one at
109
            // a time.
110
            string delimStr = "\n";
111
            char [] delim = delimStr.ToCharArray();
112
            string[] log_strings = changeLog.Notes.Split(delim,2000);
2141 ghuddy 113
 
2167 ghuddy 114
            // Prepare a string to form an updated change log (needed to support the activity of orphaned 
115
            // requirement deletion).
116
            string newList = "";
2141 ghuddy 117
 
2167 ghuddy 118
            // modify delimiters to : character so that we can extract the parameters for each log entry
119
            delimStr = ":";
120
            delim = delimStr.ToCharArray();
2141 ghuddy 121
 
2167 ghuddy 122
            foreach(string s in log_strings)
123
            {
124
               if (Main.mustAbort)
125
                  break;
2151 ghuddy 126
 
2167 ghuddy 127
               // over time, users may delete the orphaned requirements from the EA database, but their
128
               // GUIDs will still exist in the change log. Use of such a GUID will cause 
129
               // an exception in the GetElementByGuid() function. What should we do? We can attempt
130
               // to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs
131
               // that is formed from the old list, where only good items from the old list find their 
132
               // way into the new list. Gradually, the list is wittled away as EA users delete orphaned
133
               // requirements having first dealt with the design change impacts that resulted from their
134
               // orphanage.
135
               try
2141 ghuddy 136
               {
2167 ghuddy 137
                  if (s.StartsWith("{"))
138
                  {
139
                     string trimmed_s = s.Trim();
2141 ghuddy 140
 
2167 ghuddy 141
                     // Get log entry;s parameters.
142
                     string[] parameters = trimmed_s.Split(delim, 10);
2141 ghuddy 143
 
2167 ghuddy 144
                     // The first parameter is the GUID so use it to get the requirement element
145
                     EA.Element ea_req = Main.EA_Repository.GetElementByGuid(parameters[0]);
2141 ghuddy 146
 
2167 ghuddy 147
                     // Now discriminate actions based on the second parameter
2141 ghuddy 148
 
2167 ghuddy 149
                     if (parameters[1].StartsWith("Created"))
2141 ghuddy 150
                     {
2167 ghuddy 151
                        Main.WriteOutput("  Created : " + ea_req.Name, ea_req.ElementID );
152
                     }
153
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
154
                     else if (parameters[1].StartsWith("Orphaned"))
155
                     {
156
                        Main.WriteOutput("  Orphaned : " + ea_req.Name, ea_req.ElementID );
2159 ghuddy 157
 
2167 ghuddy 158
                        foreach (EA.Connector theConnector in ea_req.Connectors)
159
                        {
160
                           int destId = -1;
2159 ghuddy 161
 
2167 ghuddy 162
                           // we dont care about direction of relationship, so test for both
163
                           if (theConnector.ClientID == ea_req.ElementID)
164
                              destId = theConnector.SupplierID;
165
                           else if (theConnector.SupplierID == ea_req.ElementID)
166
                              destId = theConnector.ClientID;
167
                           else 
168
                              destId = theConnector.SupplierID;
169
 
170
                           // and make sure we filter out self-referential connectors
171
                           if (destId != ea_req.ElementID)
2141 ghuddy 172
                           {
2167 ghuddy 173
                              EA.Package tgt_pkg = (EA.Package)Main.EA_Repository.GetPackageByID( destId );
174
                              if (tgt_pkg != null)
2159 ghuddy 175
                              {
2167 ghuddy 176
                                 Main.WriteOutput("     --> " + tgt_pkg.Name, tgt_pkg.PackageID);
2159 ghuddy 177
                              }
2167 ghuddy 178
                              else
179
                              {
180
                                 EA.Element tgt_ele = (EA.Element)Main.EA_Repository.GetElementByID( destId );
181
                                 if (tgt_ele != null)
182
                                 {
183
                                    //if (!tgt_ele.Type.StartsWith("Requirement"))
184
                                    Main.WriteOutput("     --> " + tgt_ele.Name, tgt_ele.ElementID);
185
                                 }
186
                              }
2159 ghuddy 187
                           }
2141 ghuddy 188
                        }
189
                     }
2167 ghuddy 190
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
191
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_NAME))
192
                     {
193
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_NAME, ea_req.Name), ea_req.ElementID );
194
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
195
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
196
                     }
197
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
198
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_NOTES)) // aka Description of the requirement
199
                     {
200
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", "Description", ea_req.Name), ea_req.ElementID );
201
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
202
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
203
                     }
204
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
205
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_DIFFICULTY))
206
                     {
207
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_DIFFICULTY, ea_req.Name), ea_req.ElementID );
208
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
209
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
210
                     }
211
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
212
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_PRIORITY))
213
                     {
214
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_PRIORITY, ea_req.Name), ea_req.ElementID );
215
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
216
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
217
                     }
218
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
219
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_VERSION))
220
                     {
221
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_VERSION, ea_req.Name), ea_req.ElementID );
222
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
223
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
224
                     }
225
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
226
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_STATUS))
227
                     {
228
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STATUS, ea_req.Name), ea_req.ElementID );
229
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
230
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
231
                     }
232
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
233
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SUBSYSTEM_TYPE))
234
                     {
235
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SUBSYSTEM_TYPE, ea_req.Name), ea_req.ElementID );
236
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
237
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
238
                     }
239
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
240
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_STABILITY))
241
                     {
242
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STABILITY, ea_req.Name), ea_req.ElementID );
243
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
244
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
245
                     }
246
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
247
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_REQ_TYPE))
248
                     {
249
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_REQ_TYPE, ea_req.Name), ea_req.ElementID );
250
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
251
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
252
                     }
253
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
254
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_VERSION))
255
                     {
256
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_VERSION, ea_req.Name), ea_req.ElementID );
257
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
258
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
259
                     }
260
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
261
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_SECTION))
262
                     {
263
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_SECTION, ea_req.Name), ea_req.ElementID );
264
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
265
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
266
                     }
267
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
268
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE))
269
                     {
270
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE, ea_req.Name), ea_req.ElementID );
271
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
272
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
273
                     }
274
 
275
                     // accumulate good item into the newList
276
                     newList += trimmed_s + "\r\n";
2141 ghuddy 277
                  }
278
               }
2167 ghuddy 279
               catch
280
               {
281
                  // do nothing - the newList accumulator will not have the GUID that caused the exception
282
                  // so the next time a display operation is attempted, the exception wont happen.
283
               }
2141 ghuddy 284
            }
2167 ghuddy 285
 
286
            // Update the change log
287
            changeLog.Notes = newList;
288
            changeLog.Update();
2141 ghuddy 289
         }
290
      }
291
 
2147 ghuddy 292
 
293
      /// <summary>
294
      /// Rid a string of any : char because we use that as a delimiter in the change log and so we 
295
      /// do not want a users use of the character to confuse the change log display mechanism.
296
      /// </summary>
297
      /// <param name="s"></param>
298
      /// <returns></returns>
299
      private string NO_COLONS(string s)
300
      {
301
         string sc =  s.Replace(':', ' ');
302
         sc = sc.Replace('\r' , ' ');
303
         sc = sc.Replace('\n' , ' ');
304
 
305
         return sc;
306
      }
2151 ghuddy 307
 
308
 
2155 ghuddy 309
 
310
 
2151 ghuddy 311
      /// <summary>
312
      /// A method that imports requirements from a ReqPro database into EA for the purpose
313
      /// of supporting requirement-to-design traceability.
314
      /// </summary>
315
      /// <param name="repository"></param>
2155 ghuddy 316
      private void ImportFromReqPro(string importDateTime)
2151 ghuddy 317
      {
318
         try
319
         {
2167 ghuddy 320
            DialogResult dlgres;
321
 
322
            // begin to initialise some of our element lists
323
            req_lists.new_ea_reqs = new ArrayList();
324
            req_lists.new_ea_GUIDs = new ArrayList();
325
            req_lists.ea_GUIDs = new ArrayList();
326
 
2151 ghuddy 327
            ArrayList ea_req_matched = new ArrayList();
328
 
2167 ghuddy 329
            // Obtain the EA parent package so that we can create under it our ReqProDB structure and change history packages
2151 ghuddy 330
            EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );
331
 
2167 ghuddy 332
            // Find or create the change history package in which to store change logs
333
            gChangeHistoryPackage = find_or_create_change_history_package(parentPackage);
334
 
335
            // create the ReqProDB structure package in the parent container package, and attach it to its counterpart
336
            // in the ReqPro_object tree structure (ie. attach it to the root node therein).
337
            gNewReqProDBPackage = (EA.Package)parentPackage.Packages.AddNew( "ReqProDB " + importDateTime, "Package");
338
            gNewReqProDBPackage.Update();
339
            rq_root_package.ea_element_ID = gNewReqProDBPackage.PackageID;
340
 
341
            // Migrate the older form of import directory and change log, into the newer format
342
            migrate_old_import_packages_to_change_history_package(parentPackage);
343
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
344
 
345
            if (Main.mustAbort)
346
               return;
347
 
348
            // Create a package to hold orphans. This will be removed later on if it ends up empty.
349
            gOrphansPackage = find_or_create_orphans_package(parentPackage);
350
 
351
            // Get a list of EA requirements that already exist under the overall ReqProDB container package
2151 ghuddy 352
            ArrayList allowedElementTypes = new ArrayList();
353
            allowedElementTypes.Add("Requirement");
354
            allowedElementTypes.Add("UseCase");
355
 
2155 ghuddy 356
            Main.WriteOutput("Acquiring list of elements already in EA", -1);
2169 ghuddy 357
            EA_ElementAccumulator reqLister = new EA_ElementAccumulator(allowedElementTypes);
358
            EA_Parsing.findAndProcessPackageElements( parentPackage, reqLister, true );
2151 ghuddy 359
 
2167 ghuddy 360
            req_lists.ea_reqs = reqLister.Elements; 
361
 
2151 ghuddy 362
            if (Main.mustAbort)
363
               return;
364
 
2167 ghuddy 365
            // For the lsit we just found, get an adjacent list of the associated ReqPro GUIDs.
366
            // The two lists will be indexable by the same index.
367
            foreach (EA.Element ea_req in req_lists.ea_reqs)
2151 ghuddy 368
            {
2155 ghuddy 369
               string GUID = EA_TaggedValues.Read(ea_req, Constants.TAG_GUID);
2167 ghuddy 370
               req_lists.ea_GUIDs.Add(GUID);
2151 ghuddy 371
               ea_req_matched.Add(false);
372
            }
373
 
374
            if (Main.mustAbort)
375
               return;
376
 
377
 
2167 ghuddy 378
            // Create the change log element in the change history package
379
            EA.Element changeLog = (EA.Element)gChangeHistoryPackage.Elements.AddNew("Change Log" + " - import " + importDateTime, "InformationItem");
380
            changeLog.TreePos = gChangeHistoryPackage.Elements.Count - 1;
2151 ghuddy 381
            changeLog.Update();
382
 
383
            // Get a flattened list of requirements from the hierarchical data the user has filtered
384
            ArrayList rq_req_collection = new ArrayList();
385
            get_rq_req_collection(ref rq_req_collection);
386
 
2167 ghuddy 387
            // initialise some statistical vars
2151 ghuddy 388
            int newRequirementCount = 0;
389
            int modifiedRequirementCount = 0;
390
            int statusUpdatedRequirementCount = 0;
391
            int orphanedCount = 0;
392
 
393
 
2155 ghuddy 394
            Main.WriteOutput("Merging ReqPro content to EA", -1);
2167 ghuddy 395
 
396
            // loop through all of the ReqPro requirements we have captured from the ReqPro database
2151 ghuddy 397
            foreach(ReqPro_object rq_obj in rq_req_collection)
398
            {
399
               if (Main.mustAbort)
400
                  break;
401
 
402
               try
403
               {
404
                  // Find which EA requirement element refers to the current ReqPro GUID
405
                  int i_ea_req;
2167 ghuddy 406
                  i_ea_req = req_lists.ea_GUIDs.IndexOf( rq_obj.guid );
2151 ghuddy 407
 
408
                  // If EA element was found
409
                  if (0 <= i_ea_req)
410
                  {
411
                     ea_req_matched[i_ea_req] = true;
412
 
2167 ghuddy 413
                     EA.Element ea_req = ((EA.Element)req_lists.ea_reqs[i_ea_req]);
2151 ghuddy 414
 
415
                     rq_obj.ea_element_ID = ea_req.ElementID;
416
 
2155 ghuddy 417
                     // Only update the requirement if it was not mastered in EA, or
418
                     // unrestricted imports have been enabled
419
                     if (  (false == EA_TaggedValues.Read(ea_req, Constants.TAG_CREATED_IN_EA, Constants.DEFAULT_CREATED_IN_EA))
420
                        || (true == EA_TaggedValues.Read(ea_req, Constants.TAG_UNRESTRICTED_IMPORTS, Constants.DEFAULT_UNRESTRICTED_IMPORTS)) )
421
                     {
422
                        // This ReqPro requirement already has a counterpart in EA, so we must simply
423
                        // update the counterpart. But, to aid the designer, we need to try to tell them
424
                        // how the requirement has changed, which could ofcoarse change the meaning 
425
                        // of the requirement and require design changes to be done.
2151 ghuddy 426
 
2155 ghuddy 427
                        bool meaningMayHaveChanged = false;
428
                        bool statusMayHaveChanged = false;
2151 ghuddy 429
 
2155 ghuddy 430
                        string ea_req_name = rq_obj.tag + " " + rq_obj.name;
2151 ghuddy 431
 
2155 ghuddy 432
                        Main.WriteOutput("Updating: " + ea_req_name, rq_obj.ea_element_ID);
2151 ghuddy 433
 
2161 ghuddy 434
                        ea_req.Name       = updated_property_value_if_changed(changeLog, ea_req, ea_req.Name, Constants.CHG_LOG_NAME, ea_req_name, ref meaningMayHaveChanged);
2151 ghuddy 435
 
2161 ghuddy 436
                        ea_req.Notes      = updated_property_value_if_changed(changeLog, ea_req, ea_req.Notes, Constants.CHG_LOG_NOTES, rq_obj.text, ref meaningMayHaveChanged);
2151 ghuddy 437
 
2161 ghuddy 438
                        ea_req.Difficulty = updated_property_value_if_changed(changeLog, ea_req, ea_req.Difficulty, Constants.CHG_LOG_DIFFICULTY, rq_obj.difficulty, ref statusMayHaveChanged);
2151 ghuddy 439
 
2161 ghuddy 440
                        ea_req.Priority   = updated_property_value_if_changed(changeLog, ea_req, ea_req.Priority, Constants.CHG_LOG_PRIORITY, rq_obj.priority, ref statusMayHaveChanged);
2151 ghuddy 441
 
2161 ghuddy 442
                        ea_req.Status     = updated_property_value_if_changed(changeLog, ea_req, ea_req.Status, Constants.CHG_LOG_STATUS, rq_obj.status, ref statusMayHaveChanged);
2155 ghuddy 443
 
2161 ghuddy 444
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE, Constants.CHG_LOG_SOURCE, rq_obj.source, ref statusMayHaveChanged);
2155 ghuddy 445
 
2161 ghuddy 446
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_VERSION, Constants.CHG_LOG_SOURCE_VERSION, rq_obj.sourceVersion, ref statusMayHaveChanged);
2155 ghuddy 447
 
2161 ghuddy 448
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_SECTION, Constants.CHG_LOG_SOURCE_SECTION, rq_obj.sourceSection, ref statusMayHaveChanged);
2155 ghuddy 449
 
2161 ghuddy 450
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SUBSYSTEM, Constants.CHG_LOG_SUBSYSTEM_TYPE, rq_obj.subsystem, ref statusMayHaveChanged);
2155 ghuddy 451
 
2161 ghuddy 452
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_STABILITY, Constants.CHG_LOG_STABILITY, rq_obj.stability, ref statusMayHaveChanged);
2155 ghuddy 453
 
454
                        // Requirement Types are actually implemented using ordinary EA element stereotypes.
2161 ghuddy 455
                        string[] sar = ea_req.StereotypeEx.Split(",".ToCharArray());
2167 ghuddy 456
 
457
                        // if we didnt get a requirement type from the ReqPro database, set it to an empty string so that it can
458
                        // be compared to the EA stereotype strings.
459
                        if (rq_obj.type == null)
460
                           rq_obj.type = "";
461
 
2161 ghuddy 462
                        if (sar.Length > 0)
2155 ghuddy 463
                        {
2161 ghuddy 464
                           // The first item in the stereotype list is the one on display in the EA element properties and so is the one the user
465
                           // thinks is assigned to the requirement element, so check against that for changes
466
                           string sar0 = sar[0].Trim();
467
 
468
                           if (!sar0.Equals(rq_obj.type))
469
                           {
470
                              changeLog.Notes += ea_req.ElementGUID + ":" + Constants.CHG_LOG_REQ_TYPE + ":" + sar0 + ":" + rq_obj.type + "\r\n";
471
                              changeLog.Update();
472
                              statusMayHaveChanged = true;
473
                              ea_req.StereotypeEx = rq_obj.type;
474
                              ea_req.Stereotype = rq_obj.type;
475
                           }
476
                        }
477
                        else if (!ea_req.Stereotype.Equals(rq_obj.type))
478
                        {
479
                           changeLog.Notes += ea_req.ElementGUID + ":" + Constants.CHG_LOG_REQ_TYPE + ":" + ea_req.Stereotype + ":" + rq_obj.type + "\r\n";
2155 ghuddy 480
                           changeLog.Update();
481
                           statusMayHaveChanged = true;
2157 ghuddy 482
                           ea_req.StereotypeEx = rq_obj.type;
483
                           ea_req.Stereotype = rq_obj.type;
2155 ghuddy 484
                        }
485
 
486
                        ea_req.Update();
487
 
488
                        if (meaningMayHaveChanged)
489
                        {
490
                           modifiedRequirementCount++;
491
                        }
2151 ghuddy 492
 
2155 ghuddy 493
                        if (statusMayHaveChanged)
494
                        {
495
                           statusUpdatedRequirementCount++;
496
                        }
497
 
498
                        totalRequirements++;
2151 ghuddy 499
                     }
500
 
501
                  }
502
                  else
503
                  {
504
                     totalRequirements++;
505
 
506
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
507
                     // a new one.
508
                     newRequirementCount++;
509
 
510
                     // create the new EA requirement in the import package
2167 ghuddy 511
                     EA.Element ea_req = (EA.Element)gChangeHistoryPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
2151 ghuddy 512
 
513
                     rq_obj.ea_element_ID = ea_req.ElementID;
514
 
2155 ghuddy 515
                     CopyReqProDatabase.copyReq(ea_req, rq_obj);
2151 ghuddy 516
 
2155 ghuddy 517
                     ea_req.Notes = rq_obj.text;
518
 
2151 ghuddy 519
                     ea_req.Update();
520
 
2167 ghuddy 521
                     // add the new requirement to our list for later processing
522
                     req_lists.new_ea_reqs.Add(ea_req);
523
                     req_lists.new_ea_GUIDs.Add(rq_obj.guid);
524
 
2151 ghuddy 525
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
526
                     changeLog.Update();
527
 
2155 ghuddy 528
                     Main.WriteOutput("Created: " + ea_req.Name, ea_req.ElementID);
2151 ghuddy 529
                  }
530
 
531
               }
532
               catch (Exception ex)
533
               {
2155 ghuddy 534
                  Main.WriteOutput("Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);
2151 ghuddy 535
               }
536
            }
537
 
538
            if (Main.mustAbort)
539
               return;
540
 
2155 ghuddy 541
            Main.WriteOutput("Checking for orphaned requirements", -1);
2167 ghuddy 542
 
2151 ghuddy 543
            // Now check for orphaned EA requirements
2167 ghuddy 544
            for (int i = 0; i < req_lists.ea_GUIDs.Count; i++)
2151 ghuddy 545
            {
546
               if (Main.mustAbort)
547
                  break;
548
 
2167 ghuddy 549
               string rq_GUID = (string)req_lists.ea_GUIDs[i];
2151 ghuddy 550
               if (rq_GUID != "")
551
               {
552
                  if ((bool)ea_req_matched[i] == false)
553
                  {
2167 ghuddy 554
                     EA.Element ea_req = (EA.Element)req_lists.ea_reqs[i];
2151 ghuddy 555
 
556
                     orphanedCount++;
557
 
558
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
559
                     changeLog.Update();
560
                  }
561
               }
562
            }
563
 
2167 ghuddy 564
            // If there is any change to report, ask user if they want to see it now, and if so, display it
2155 ghuddy 565
            if (changeLog.Notes != null && changeLog.Notes.Length > 0)
566
            {
2167 ghuddy 567
               dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);
2155 ghuddy 568
               if (dlgres == DialogResult.Yes)
569
                  displayChangeLog(changeLog);
570
            }
2151 ghuddy 571
 
2167 ghuddy 572
            if (Main.mustAbort)
573
               return;
574
 
575
            // Now we import the ReqPro database package structure and migrate all of our existing or 
576
            // new requirements into it. We only create the structure we need, ie. empty package structure
577
            // will not be created unecessarily.
578
            Main.WriteOutput("Importing latest ReqPro database package structure", -1);
579
            populate_latest_reqprodb_structure_package(rq_root_package);
580
            gNewReqProDBPackage.Packages.Refresh();
581
            gNewReqProDBPackage.Elements.Refresh();
582
            gNewReqProDBPackage.Diagrams.Refresh();
2151 ghuddy 583
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
584
 
2167 ghuddy 585
            if (Main.mustAbort)
586
               return;
587
 
588
            // Remove the old superseded facsimile of the ReqPro database package structure. At this point,
589
            // orphaned requirements left in these will be moved to the Orphaned package, before the old
590
            // structure package is removed.
591
            Main.WriteOutput("Removing old ReqPro database package structures", -1);
592
 
593
            remove_old_empty_structures(parentPackage, gNewReqProDBPackage);
594
 
595
            if (Main.mustAbort)
596
               return;
597
 
598
            // Remove other empty packages - this tidies up the ReqPro import area so that at the top level
599
            // all a user should see is the Change History package, ReqProDB package, and possibly an Orphans package.
600
            Main.WriteOutput("Pruning empty packages", -1);
601
 
602
            prune_empty_packages(parentPackage);
603
 
604
            // Refresh the project browser
605
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
606
 
2149 ghuddy 607
            // Setup the internal requirement to requirement connectivity. This is seperate from the browser
608
            // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
609
            // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
610
            // with explicit trace relationships setup in ReqPro.
611
            // The purpose of this internal connectivity is to support relationship matrix tables in documentation
612
            // generated by EA_DocGen, or to support diagrammatic representations of the requirements in EA,
613
            // where the connectivity will become apparent through links ajoining the requirement elements in the
614
            // diagram.
2151 ghuddy 615
            write_traces(totalRequirements);
2141 ghuddy 616
 
2151 ghuddy 617
            if (Main.mustAbort)
618
               return;
2141 ghuddy 619
 
2167 ghuddy 620
            // Output any messages the underlying parser may have collected as a result of observations it has made
621
            // regarding the data it has read from the ReqPro database.
2155 ghuddy 622
            writeDelayedMessages();
623
 
2151 ghuddy 624
            // display summary stats
2155 ghuddy 625
            Main.WriteOutput(newRequirementCount.ToString() + " new requirements", -1);
626
            Main.WriteOutput(modifiedRequirementCount.ToString() + " requirements modified", -1);
627
            Main.WriteOutput(statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
628
            Main.WriteOutput(orphanedCount.ToString() + " requirements were orphaned", -1);
2151 ghuddy 629
 
2155 ghuddy 630
            Main.WriteOutput("Import Completed", -1);
631
            MessageBoxEx.Show("Import Completed");
2151 ghuddy 632
         }
633
         catch (Exception ex)
634
         {
2153 ghuddy 635
            Main.MessageBoxException(ex, "Exception (ImportFromReqPro)");
2151 ghuddy 636
         }
637
      }
638
 
2155 ghuddy 639
      private string updated_property_value_if_changed(EA.Element changeLog, 
640
         EA.Element ea_req, 
641
         string dest_value, 
642
         string changeLogName, 
643
         string source_value,
644
         ref bool mayHaveChanged)
645
      {
646
         if (dest_value.CompareTo(source_value) != 0 )
647
         {
648
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName+ ":" + NO_COLONS(dest_value) + ":" + NO_COLONS(source_value) + "\r\n";
649
            changeLog.Update();
650
            mayHaveChanged = true;
651
            return source_value;
652
         }
653
         return dest_value;
654
      }
2151 ghuddy 655
 
2167 ghuddy 656
 
2155 ghuddy 657
      private void if_tagged_value_changed_update_it(EA.Element changeLog, 
658
         EA.Element ea_req, 
659
         string tagname, 
660
         string changeLogName, 
661
         string source_value,
662
         ref bool statusMayHaveChanged)
663
      {
664
         string value = EA_TaggedValues.Read(ea_req, tagname, "");
665
         if ((source_value != null) && (false == source_value.Equals(value)))
666
         {
667
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName + ":" + value + ":" + source_value + "\r\n";
668
            changeLog.Update();
669
            EA_TaggedValues.Write(ea_req, tagname, source_value);
670
            statusMayHaveChanged = true;
671
         }
672
      }
2151 ghuddy 673
 
674
 
2155 ghuddy 675
 
2141 ghuddy 676
      /// <summary>
677
      /// This method (along with its sibling overload) obtains a flattened view of the 
678
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
679
      /// takes account of the users filtering requests.
680
      /// </summary>
681
      /// <param name="ea_repository"></param>
2151 ghuddy 682
      private void get_rq_req_collection(ref ArrayList rq_req_collection)
2141 ghuddy 683
      {
684
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
685
         {
2151 ghuddy 686
            get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 687
         }
688
      }
689
 
2167 ghuddy 690
 
2151 ghuddy 691
      private void get_rq_req_collection(ref ArrayList rq_req_collection,
2141 ghuddy 692
                                         ReqPro_object rq_obj )
693
      {
694
         if (rq_obj.isPackage)
695
         {
2147 ghuddy 696
            // if the package is not filtered, or if we are allowed to dig beneath filtered
697
            // packages...
698
            if (rq_obj.filtered == false || base.allowPackageStructureFragments)
2141 ghuddy 699
            {
700
               // Using recursion, scan this objects sub-objects
701
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
702
               {
2147 ghuddy 703
                  // if the sub-object is a package, always recurse to process it, else
704
                  // if the sub-object is a requirement, only recurse if the containing package
705
                  // is not filtered, so that requirements of filtered packages are themselves
706
                  // filtered out by virtue of their parent packages filtering state.
707
                  if (  sub_obj.isPackage
708
                     || (sub_obj.isRequirement && rq_obj.filtered == false))
709
                  {
2151 ghuddy 710
                     get_rq_req_collection(ref rq_req_collection, sub_obj);
2147 ghuddy 711
                  }
2141 ghuddy 712
               }
713
            }
714
         }
715
         else if (rq_obj.isRequirement)
716
         {
717
            if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)) )
718
            {
719
               // Add this requirement to the flattened list we are accumulating
720
               rq_req_collection.Add(rq_obj);
721
 
2149 ghuddy 722
               // In ReqPro, a requirement can be related to another requirement in several ways:
723
               // 1. By virtue of its position relative to another in the browser display. That is, 
724
               //    if you place a requirement beneath a parent requirement, you are establishing a 
725
               //    parent-child relationship.
726
               // 2. By virtue of a specific TraceTo relationship being made via the Traceability menu
727
               //    option. 
728
               // Interestingly, ReqPro prevents you creating a relationship of one of the above types,
729
               // if a relationship of the other type already exists. This implies that the relationship
730
               // between a parent and child requirement must be singular and is important regardless
731
               // of the manner in which it was created or represented.
732
               // The CopyReqProDatabaseToMemory base class will already have taken care of recording
733
               // relationships detected from ReqPro made using method 2 above. What we need to do here is
734
               // take care of those apparent from the browser based hierarchical organisation (ie. made
735
               // in ReqPro using method 1).
736
               // All we need to do is grab the parent object (if any) and add the GUID of the child to 
737
               // its list of trace-to's. Later on, the write_traces() class method will turn these into
738
               // EA based connection objects that belong to the parent requirement elements.
739
               if (rq_obj.parent != null)
740
               {
741
                  rq_obj.parent.ReqPro_traces.Add(rq_obj.guid);
742
               }
743
 
2147 ghuddy 744
               // Using recursion, scan this objects sub-objects, which in practise will all
745
               // be requirement objects. At this time requirement objects cannot have packages 
746
               // as children.
2141 ghuddy 747
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
748
               {
2151 ghuddy 749
                  get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 750
               }
751
            }
752
         }
753
      }
754
 
755
 
2167 ghuddy 756
 
757
 
758
 
759
 
760
      /// <summary>
761
      /// Populates a ReqProDB structure package to be used as a home for the requirements within the 
762
      /// overall import container, and re-locate requirements into it from wherever they may be elsewhere
763
      /// within and under the import container.
764
      /// </summary>
765
      /// <param name="rq_obj"></param>
766
      private void populate_latest_reqprodb_structure_package(ReqPro_object rq_obj)
767
      {
768
         foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
769
         {
770
            if (Main.mustAbort)
771
               return;
772
 
773
            if (sub_obj.isPackage)
774
            {
775
               populate_latest_reqprodb_structure_package(sub_obj);   // recurse
776
            }
777
            else if (sub_obj.isRequirement)
778
            {
779
               EA.Element ea_req = null;
780
 
781
               // Examine all of our requirement lists to try and re-locate the requirements from
782
               // the old structure(s) to the new one.
783
 
784
               // re-locate existing requirements updated during this import
785
               int i_ea_req;
786
               i_ea_req = req_lists.ea_GUIDs.IndexOf( sub_obj.guid );
787
               if (0 <= i_ea_req)
788
               {
789
                  ea_req = ((EA.Element)req_lists.ea_reqs[i_ea_req]);
790
 
791
                  EA.Package pkg = get_or_create_latest_structure(sub_obj);
792
 
793
                  ea_req.PackageID = pkg.PackageID;   // re-locate
794
                  ea_req.TreePos = sub_obj.treePos;
795
                  ea_req.Update();
796
               }
797
               else
798
               {
799
                  // re-locate new requirements that have come in for the first time on this import.
800
                  i_ea_req = req_lists.new_ea_GUIDs.IndexOf( sub_obj.guid );
801
                  if (0 <= i_ea_req)
802
                  {
803
                     ea_req = ((EA.Element)req_lists.new_ea_reqs[i_ea_req]);
804
 
805
                     EA.Package pkg = get_or_create_latest_structure(sub_obj);
806
 
807
                     ea_req.PackageID = pkg.PackageID;   // re-locate
808
                     ea_req.TreePos = sub_obj.treePos;
809
                     ea_req.Update();
810
                  }
811
               }
812
 
813
               // Re-locate requirement under its parent requirement, if such a relationship exists.
814
               if (ea_req != null && sub_obj.parent.isRequirement)
815
               {
2171 ghuddy 816
                  // Only do this if the parent requirement has not been orphaned
817
                  if (sub_obj.parent.ea_element_ID != -1)
2167 ghuddy 818
                  {
2171 ghuddy 819
                     EA.Element parent_ea_req = Main.EA_Repository.GetElementByID(sub_obj.parent.ea_element_ID);
820
                     if (parent_ea_req != null)
821
                     {
822
                        ea_req.ParentID = parent_ea_req.ElementID;   // re-locate
823
                        ea_req.TreePos = sub_obj.treePos;
824
                        ea_req.Update();
825
                     }
2167 ghuddy 826
                  }
2171 ghuddy 827
                  else
828
                  {
829
                     // TODO: what if the parent requirement has been orphaned, but the child as represented by
830
                     // the current value of sub_obj has not been? Will that have already been taken care of by
831
                     // the code earlier in this function that re-locates existing requirements to the correct
832
                     // parent package?
833
                  }
2167 ghuddy 834
               }
835
 
836
               populate_latest_reqprodb_structure_package(sub_obj);   // recurse
837
            }
838
         }
839
      }
840
 
841
 
842
      /// <summary>
843
      /// This is a helper for the populate_latest_reqprodb_structure_package() function. It allows on-the-fly
844
      /// EA package path construction, triggered whenever we find we have a requirement to 
845
      /// re-locate into the latest facsimile of the ReqPro database structure.
846
      /// </summary>
847
      /// <param name="rq_obj"></param>
848
      /// <returns></returns>
849
      private EA.Package get_or_create_latest_structure(ReqPro_object rq_obj)
850
      {
851
         // go up the tree to find the immediate enclosing package of the requirement represented
852
         // by the input parameter. We do this because it is certain that this function will be called
853
         // initially passing a ReqPro_object that has "isRequirement" set to true. The requirement object
854
         // may also be nested within another requirement object, as a result of its parent-child hierarchy
855
         // in ReqPro.
856
         while(rq_obj.isRequirement && rq_obj.parent != null)
857
         {
858
            rq_obj = rq_obj.parent;
859
         }
860
 
861
         // Now that we have reached a package, we can figure out if we need to create its facsimile in EA
862
         // or detect if that has already been done on a previous invocation.
863
         if (rq_obj.isPackage)
864
         {
865
            // if this package has already been related to an EA package, then simply return it. The EA package
866
            // must have been created ona  previous invocation of this function.
867
            if (rq_obj.ea_element_ID != -1)
868
            {
869
               return Main.EA_Repository.GetPackageByID(rq_obj.ea_element_ID);
870
            }
871
            else // need to create this package, and if necessary, its parental line right up to the root package
872
            {
873
               // use recursion to work our way up the package ancestral line until we hit a point where
874
               // we find an EA package, then unwind, creating the sub-packages down to where our requirement
875
               // is to be held.
876
               EA.Package pkg = get_or_create_latest_structure(rq_obj.parent);   // recurse
877
               if (pkg != null)
878
               {
879
                  if (rq_obj.filtered)
880
                  {
881
                     return pkg;
882
                  }
883
                  else
884
                  {
2169 ghuddy 885
                     EA.Package sub_pkg = EA_Package.create(pkg, rq_obj.name, rq_obj.treePos);
2167 ghuddy 886
 
887
                     // attach the EA package to the ReqPro_object so that we do not attempt to create this
888
                     // package again on another call into this function.
889
                     rq_obj.ea_element_ID = sub_pkg.PackageID;
890
 
891
                     return sub_pkg;
892
                  }
893
               }
894
            }
895
         }
896
 
897
         // default to returning the root level package in EA where the requirement structure begins.
898
         // This will always be valid and available, but hopefully, the execution path wont drop down
899
         // to here.
900
         return Main.EA_Repository.GetPackageByID(rq_root_package.ea_element_ID);
901
      }
902
 
903
      /// <summary>
904
      /// Remove the old ReqProDB structure packages if they are now empty of requirements. IF some 
905
      /// requirements remain in them, they are moved to the orphaned package so that the old ReqProDB
906
      /// packages can be removed.
907
      /// </summary>
908
      /// <param name="parentPackage"></param>
909
      /// <param name="new_structure_pkg"></param>
910
      private void remove_old_empty_structures(EA.Package parentPackage, EA.Package new_structure_pkg)
911
      {
912
         // NOTE: The parentPackage is the container of the ReqProDB element
913
         short i;
914
         for(i=0; i<parentPackage.Packages.Count; i++)
915
         {
916
            gCurrentPackage = (EA.Package)parentPackage.Packages.GetAt(i);
917
 
918
            // dont do anything to the new structure package that has been created on the current import cycle.
919
            if (new_structure_pkg != null && gCurrentPackage.PackageID == new_structure_pkg.PackageID)
920
            {
921
               continue;
922
            }
923
 
924
            // skip any packages that are not ReqProDB structure packages
925
            if (!gCurrentPackage.Name.StartsWith("ReqProDB"))
926
            {
927
               continue;
928
            }
929
 
930
            // re-locate all elements to the orphans package
931
            relocate_elements_to_orphans_package(gCurrentPackage);
932
 
933
            // Now delete the old ReqProDB structure package
934
            parentPackage.Packages.DeleteAt(i, false);
935
         }
936
 
937
         parentPackage.Packages.Refresh();
938
         Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
939
      }
940
 
941
 
942
      /// <summary>
943
      /// Re-locate all requirements that remain under a ReqProDB structure package, to its 
944
      /// top level, so that later on, the package hierarchy within it can be removed.
945
      /// </summary>
946
      /// <param name="parentPackage"></param>
947
      private void relocate_elements_to_orphans_package(EA.Package parentPackage)
948
      {
949
         if (parentPackage.PackageID != gOrphansPackage.PackageID)
950
         {
951
            // relocate elements and diagrams to the top level of the orphans package
952
            foreach(EA.Element ele in parentPackage.Elements)
953
            {
954
               ele.PackageID = gOrphansPackage.PackageID;
955
               ele.Update();
956
            }
957
            foreach(EA.Diagram diag in parentPackage.Diagrams)
958
            {
959
               diag.PackageID = gOrphansPackage.PackageID;
960
               diag.Update();
961
            }
962
 
963
            // now parse lower level packages in the tree
964
            foreach(EA.Package sub_pkg in parentPackage.Packages)
965
            {
966
               relocate_elements_to_orphans_package(sub_pkg);  // recurse
967
            }
968
         }
969
      }
970
 
971
 
972
      /// <summary>
973
      /// This function migrates the older form of import package and its change log file into the newer
974
      /// Change History package, and deletes the old import package. In doing this, it will move any
975
      /// requirements still remaining in the import package to the top level of the new ReqProDB structure
976
      /// package.
977
      /// </summary>
978
      /// <param name="parentPackage"></param>
979
      private void migrate_old_import_packages_to_change_history_package(EA.Package parentPackage)
980
      {
981
         if (gNewReqProDBPackage != null && gChangeHistoryPackage != null)
982
         {
983
            bool found = false;
984
            short i;
985
            for(i=0; i<parentPackage.Packages.Count; i++)
986
            {
987
               EA.Package sub_pkg = (EA.Package)parentPackage.Packages.GetAt(i);
988
 
989
               if (sub_pkg.Name.StartsWith("import"))
990
               {
991
                  if (!found)
992
                  {
993
                     found = true;
994
                     Main.WriteOutput("Migrating old import package contents to Change History and ReqProDB packages", -1);
995
                  }
996
 
997
                  // re-locate all elements from the old import package to the new ReqProDB structure package.
998
                  migrate_old_import_packages_to_change_history_package_recurser(sub_pkg);
999
 
1000
                  // delete the old import package
1001
                  parentPackage.Packages.DeleteAt(i, false);
1002
               }
1003
            }
1004
            parentPackage.Packages.Refresh();
1005
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
1006
         }
1007
      }
1008
 
1009
      /// <summary>
1010
      /// Moves all elements out of an old-style import package, and into the new ReqProDB structure package.
1011
      /// Change Log elements are handled in a special way such that they are renamed from plain "Change Log" 
1012
      /// to the new style "Change Log - import <date> <time>" format, and are moved into the new "Change History"
1013
      /// package.
1014
      /// </summary>
1015
      /// <param name="parentPackage"></param>
1016
      private void migrate_old_import_packages_to_change_history_package_recurser(EA.Package parentPackage)
1017
      {
1018
         foreach(EA.Element ele in parentPackage.Elements)
1019
         {
1020
            if (ele.Name.StartsWith("Change Log"))
1021
            {
1022
               ele.Name = ele.Name + " - " + parentPackage.Name;
1023
               ele.PackageID = gChangeHistoryPackage.PackageID;
1024
               ele.Update();
1025
               gChangeHistoryPackage.Elements.Refresh();
1026
            }
1027
            else
1028
            {
1029
               ele.PackageID = gNewReqProDBPackage.PackageID;
1030
               ele.Update();
1031
            }
1032
         }
1033
 
1034
         foreach(EA.Diagram diag in parentPackage.Diagrams)
1035
         {
1036
            diag.PackageID = gNewReqProDBPackage.PackageID;
1037
            diag.Update();
1038
         }
1039
 
1040
         foreach(EA.Package sub_pkg in parentPackage.Packages)
1041
         {
1042
            migrate_old_import_packages_to_change_history_package_recurser(sub_pkg);   // recurse
1043
         }
1044
      }
1045
 
1046
 
1047
      private EA.Package find_or_create_change_history_package(EA.Package parentPackage)
1048
      {
1049
         foreach(EA.Package sub_pkg in parentPackage.Packages)
1050
         {
1051
            if (sub_pkg.Name.StartsWith("Change History"))
1052
            {
1053
               return sub_pkg;
1054
            }
1055
         }
2169 ghuddy 1056
         EA.Package pkg = EA_Package.create(parentPackage, "Change History", 1);
2167 ghuddy 1057
         return pkg;
1058
      }
1059
 
1060
      private EA.Package find_or_create_orphans_package(EA.Package parentPackage)
1061
      {
1062
         foreach(EA.Package sub_pkg in parentPackage.Packages)
1063
         {
1064
            if (sub_pkg.Name.StartsWith("Orphaned Requirements"))
1065
            {
1066
               return sub_pkg;
1067
            }
1068
         }
2169 ghuddy 1069
         EA.Package pkg = EA_Package.create(parentPackage, "Orphaned Requirements", 1);
2167 ghuddy 1070
         return pkg;
1071
      }
1072
 
1073
 
1074
      /// <summary>
1075
      /// This function removes any empty packages it can find in the ReqPro import area. This is 
1076
      /// a tidying up operation.
1077
      /// </summary>
1078
      /// <param name="parentPackage"></param>
1079
      /// <returns></returns>
1080
      private bool prune_empty_packages(EA.Package parentPackage)
1081
      {
1082
         bool retVal = false;
1083
         bool needRefresh = false;
1084
         short i;
1085
         for(i=0; i<parentPackage.Packages.Count; i++)
1086
         {
1087
            EA.Package sub_pkg = (EA.Package)parentPackage.Packages.GetAt(i);
1088
 
1089
            if (true == prune_empty_packages(sub_pkg))   // recurse
1090
            {
1091
               parentPackage.Packages.DeleteAt(i, false);
1092
               needRefresh = true;
1093
            }
1094
         }
1095
 
1096
         if (needRefresh)
1097
         {
1098
            parentPackage.Packages.Refresh();
1099
         }
1100
 
1101
         if (parentPackage.Packages.Count == 0 
1102
            && parentPackage.Elements.Count == 0
1103
            && parentPackage.Diagrams.Count == 0)
1104
         {
1105
            retVal = true;
1106
         }
1107
 
1108
         return retVal;
1109
      }
2141 ghuddy 1110
	}
1111
}