Rev 2147 | Rev 2151 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using System.Text;using System.Globalization;using System.Collections;using System.Windows.Forms;using ReqPro40;namespace EA_ReqPro{/// <summary>/// Summary description for ImportReqProDatabase./// </summary>public class ImportReqProDatabase : CopyReqProDatabaseToMemory{/// <summary>/// Constructor logic/// </summary>/// <param name="ea_repository"></param>public ImportReqProDatabase(EA.Repository ea_repository): base(ea_repository){}/// <summary>/// Method to parse a ReqPro database using the information in a ReqProDB artifact,/// assumed to be selected in EA's project browser prior to the method call./// </summary>/// <param name="ea_repository"></param>/// <returns></returns>public override bool prompt_and_parse(EA.Repository ea_repository, ReqProDB_Artifact.MODE mode){try{if (true == base.prompt_and_parse(ea_repository, mode)){ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);ImportFromReqPro(ea_repository);// Configure the ReqProDB artifact as a traceability artifactRQ_Artifact.set_traceability_mode(ea_repository, RQ_Element);return true;}}catch (Exception ex){MessageBox.Show(ex.Message, "Error (ImportReqProDatabase::parse)", MessageBoxButtons.OK);}return false;}/// <summary>/// Displays the content of the change log element to the output trace display. This method must/// be kept in sync with the ImportFromReqPro method, obviously./// </summary>/// <param name="ea_repository"></param>/// <param name="changeLog"></param>public void displayChangeLog(EA.Repository ea_repository, EA.Element changeLog){// The change log element contains all the log in its notes section. Break it up into// lines, because each line is a single log entry, so that we can process them one at// a time.string delimStr = "\n";char [] delim = delimStr.ToCharArray();string[] log_strings = changeLog.Notes.Split(delim,2000);// Prepare a string to form an updated change log (needed to support the activity of orphaned// requirement deletion).string newList = "";// modify delimiters to : character so that we can extract the parameters for each log entrydelimStr = ":";delim = delimStr.ToCharArray();ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,"Displaying Import Change Log", -1);foreach(string s in log_strings){// over time, users may delete the orphaned requirements from the EA database, but their// GUIDs will still exist in the change log. Use of such a GUID will cause// an exception in the GetElementByGuid() function. What should we do? We can attempt// to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs// that is formed from the old list, where only good items from the old list find their// way into the new list. Gradually, the list is wittled away as EA users delete orphaned// requirements having first dealt with the design change impacts that resulted from their// orphanage.try{if (s.StartsWith("{")){string trimmed_s = s.Trim();// Get log entry;s parameters.string[] parameters = trimmed_s.Split(delim, 10);// The first parameter is the GUID so use it to get the requirement elementEA.Element ea_req = ea_repository.GetElementByGuid(parameters[0]);// Now discriminate actions based on the second parameterif (parameters[1].StartsWith("Created")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME," Created : " + ea_req.Name, ea_req.ElementID );}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Orphaned")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME," Orphaned : " + ea_req.Name, ea_req.ElementID );foreach (EA.Connector theConnector in ea_req.Connectors){EA.Element tgt_ele = (EA.Element)ea_repository.GetElementByID( theConnector.SupplierID );if (tgt_ele != null){if (!tgt_ele.Type.StartsWith("Requirement")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " --> " + tgt_ele.Name, tgt_ele.ElementID);}}}}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Name")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Name: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Notes")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Description: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Difficulty")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Difficulty: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Priority")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Priority: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Version")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Version: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Status")){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Status: " + ea_req.Name, ea_req.ElementID );ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}// accumulate good item into the newListnewList += trimmed_s + "\r\n";}}catch{// do nothing - the newList accumulator will not have the GUID that caused the exception// so the next time a display operation is attempted, the exception wont happen.}}// Update the change logchangeLog.Notes = newList;changeLog.Update();}/// <summary>/// Rid a string of any : char because we use that as a delimiter in the change log and so we/// do not want a users use of the character to confuse the change log display mechanism./// </summary>/// <param name="s"></param>/// <returns></returns>private string NO_COLONS(string s){string sc = s.Replace(':', ' ');sc = sc.Replace('\r' , ' ');sc = sc.Replace('\n' , ' ');return sc;}/// <summary>/// A method that imports requirements from a ReqPro database into EA for the purpose/// of supporting requirement-to-design traceability./// </summary>/// <param name="repository"></param>private void ImportFromReqPro(EA.Repository ea_repository){try{//IFormatProvider cultureInfo = new CultureInfo("en-US", true);string importDateTime = System.TimeZone.CurrentTimeZone.ToUniversalTime( System.DateTime.Now ).ToString();ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Requirement import at " + importDateTime, -1 );// Update the ReqProDB stereotypes element with all the EA requirements in the packagebase.RQ_Artifact.UpdatePackageToReqProDatabaseAssociation(ea_repository, base.RQ_Element);// Get a list of EA requirements and their associated ReqPro GUIDsArrayList ea_reqs = new ArrayList();ArrayList ea_GUIDs = new ArrayList();ArrayList ea_req_matched = new ArrayList();foreach (EA.Connector connector in base.RQ_Element.Connectors){EA.Element ea_req = ea_repository.GetElementByID( connector.SupplierID );if (ea_req != null){ea_reqs.Add(ea_req);string GUID = EA_Utils.ReadTag(ea_req, "GUID");ea_GUIDs.Add(GUID);ea_req_matched.Add(false);}}// Obtain the EA parent package so that we can create under it an import package// if need be.EA.Package parentPackage = ea_repository.GetPackageByID( base.RQ_Element.PackageID );EA.Package importPackage = (EA.Package )parentPackage.Packages.AddNew( "import " + importDateTime, "Package");importPackage.Update();EA.Element changeLog = (EA.Element)importPackage.Elements.AddNew("Change Log","InformationItem");changeLog.Update();// Get a flattened list of requirements from the hierarchical data the user has filteredArrayList rq_req_collection = new ArrayList();get_rq_req_collection(ea_repository, ref rq_req_collection);int newRequirementCount = 0;int modifiedRequirementCount = 0;int statusUpdatedRequirementCount = 0;int orphanedCount = 0;// loop through all of the ReqPro requirementsforeach(ReqPro_object rq_obj in rq_req_collection){try{// Find which EA requirement element refers to the current ReqPro GUIDint i_ea_req;i_ea_req = ea_GUIDs.IndexOf( rq_obj.guid );// If EA element was foundif (0 <= i_ea_req){ea_req_matched[i_ea_req] = true;EA.Element ea_req = ((EA.Element)ea_reqs[i_ea_req]);rq_obj.ea_element_ID = ea_req.ElementID;// This ReqPro requirement already has a counterpart in EA, so we must simply// update the counterpart. But, to aid the designer, we need to try to tell them// how the requirement has changed, which could ofcoarse change the meaning// of the requirement and require design changes to be done.bool meaningMayHaveChanged = false;bool statusMayHaveChanged = false;string ea_req_name = rq_obj.tag + " " + rq_obj.name;if ( ea_req.Name.CompareTo(ea_req_name) != 0 ){changeLog.Notes += ea_req.ElementGUID + ":Name:" + NO_COLONS(ea_req.Name) + ":" + NO_COLONS(ea_req_name) + "\r\n";changeLog.Update();meaningMayHaveChanged = true;ea_req.Name = ea_req_name;}if ( ea_req.Notes.CompareTo(rq_obj.text) != 0 ){changeLog.Notes += ea_req.ElementGUID + ":Notes:" + NO_COLONS(ea_req.Notes) + ":" + NO_COLONS(rq_obj.text) + "\r\n";changeLog.Update();meaningMayHaveChanged = true;ea_req.Notes = rq_obj.text;}if (ea_req.Difficulty != rq_obj.difficulty){changeLog.Notes += ea_req.ElementGUID + ":Difficulty:" + ea_req.Difficulty + ":" + rq_obj.difficulty + "\r\n";changeLog.Update();statusMayHaveChanged = true;ea_req.Difficulty = rq_obj.difficulty;}if (ea_req.Priority != rq_obj.priority){changeLog.Notes += ea_req.ElementGUID + ":Priority:" + ea_req.Priority + ":" + rq_obj.priority + "\r\n";changeLog.Update();statusMayHaveChanged = true;ea_req.Priority = rq_obj.priority;}if (ea_req.Version != rq_obj.version){changeLog.Notes += ea_req.ElementGUID + ":Version:" + ea_req.Version + ":" + rq_obj.version + "\r\n";changeLog.Update();statusMayHaveChanged = true;ea_req.Version = rq_obj.version;}if (ea_req.Status != rq_obj.status){changeLog.Notes += ea_req.ElementGUID + ":Status:" + ea_req.Status + ":" + rq_obj.status + "\r\n";changeLog.Update();statusMayHaveChanged = true;ea_req.Status = rq_obj.status;}ea_req.Update();if (meaningMayHaveChanged){modifiedRequirementCount++;}if (statusMayHaveChanged){statusUpdatedRequirementCount++;}}else{// This ReqPro requirement does not have a counterpart in EA, so we must create// a new one.newRequirementCount++;// create the new EA requirement in the import packageEA.Element ea_req = (EA.Element)importPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");ea_req.Notes = rq_obj.text;rq_obj.ea_element_ID = ea_req.ElementID;ea_req.Difficulty = rq_obj.difficulty;ea_req.Priority = rq_obj.priority;ea_req.Version = rq_obj.version;ea_req.Status = rq_obj.status;EA_Utils.WriteTag(ea_req, "GUID", rq_obj.guid);EA_Utils.WriteTag(ea_req, "TAG", rq_obj.tag);ea_req.Update();// Connect the new requirement to the ea_rq_artifactbase.RQ_Artifact.add_connection(ea_repository, base.RQ_Element, ea_req);changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";changeLog.Update();}}catch (Exception ex){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);}}// Now check for orphaned EA requirementsfor (int i = 0; i < ea_GUIDs.Count; i++){string rq_GUID = (string)ea_GUIDs[i];if (rq_GUID != ""){if ((bool)ea_req_matched[i] == false){EA.Element ea_req = (EA.Element)ea_reqs[i];orphanedCount++;changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";changeLog.Update();}}}displayChangeLog(ea_repository, changeLog);ea_repository.RefreshModelView(parentPackage.PackageID);// Setup the internal requirement to requirement connectivity. This is seperate from the browser// organisation of elements in EA, but since in ReqPro, that organisation tells part of the story// of requirement to requirement connectivity, it is mirrored in the internal connectivity, along// with explicit trace relationships setup in ReqPro.// The purpose of this internal connectivity is to support relationship matrix tables in documentation// generated by EA_DocGen, or to support diagrammatic representations of the requirements in EA,// where the connectivity will become apparent through links ajoining the requirement elements in the// diagram.ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Writing Trace Information", -1);foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects ){write_traces(ea_repository, sub_obj);}// display summary statsea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, newRequirementCount.ToString() + " new requirements", -1);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, modifiedRequirementCount.ToString() + " requirements modified", -1);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, orphanedCount.ToString() + " requirements were orphaned", -1);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Completed import", -1);MessageBox.Show("Import Completed");}catch (Exception ex){MessageBox.Show(ex.Message, "Error (ImportFromReqPro)", MessageBoxButtons.OK);}}/// <summary>/// This method (along with its sibling overload) obtains a flattened view of the/// hierarchical requirements obtained from the ReqPro database. This accumulation/// takes account of the users filtering requests./// </summary>/// <param name="ea_repository"></param>private void get_rq_req_collection(EA.Repository ea_repository, ref ArrayList rq_req_collection){foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects ){get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);}}private void get_rq_req_collection(EA.Repository ea_repository,ref ArrayList rq_req_collection,ReqPro_object rq_obj ){if (rq_obj.isPackage){// if the package is not filtered, or if we are allowed to dig beneath filtered// packages...if (rq_obj.filtered == false || base.allowPackageStructureFragments){// Using recursion, scan this objects sub-objectsforeach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){// if the sub-object is a package, always recurse to process it, else// if the sub-object is a requirement, only recurse if the containing package// is not filtered, so that requirements of filtered packages are themselves// filtered out by virtue of their parent packages filtering state.if ( sub_obj.isPackage|| (sub_obj.isRequirement && rq_obj.filtered == false)){get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);}}}}else if (rq_obj.isRequirement){if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)) ){// Add this requirement to the flattened list we are accumulatingrq_req_collection.Add(rq_obj);// In ReqPro, a requirement can be related to another requirement in several ways:// 1. By virtue of its position relative to another in the browser display. That is,// if you place a requirement beneath a parent requirement, you are establishing a// parent-child relationship.// 2. By virtue of a specific TraceTo relationship being made via the Traceability menu// option.// Interestingly, ReqPro prevents you creating a relationship of one of the above types,// if a relationship of the other type already exists. This implies that the relationship// between a parent and child requirement must be singular and is important regardless// of the manner in which it was created or represented.// The CopyReqProDatabaseToMemory base class will already have taken care of recording// relationships detected from ReqPro made using method 2 above. What we need to do here is// take care of those apparent from the browser based hierarchical organisation (ie. made// in ReqPro using method 1).// All we need to do is grab the parent object (if any) and add the GUID of the child to// its list of trace-to's. Later on, the write_traces() class method will turn these into// EA based connection objects that belong to the parent requirement elements.if (rq_obj.parent != null){rq_obj.parent.ReqPro_traces.Add(rq_obj.guid);}// Using recursion, scan this objects sub-objects, which in practise will all// be requirement objects. At this time requirement objects cannot have packages// as children.foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);}}}}}}