Rev 2151 | Rev 2155 | 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{private int totalRequirements = 0;/// <summary>/// Constructor logic/// </summary>/// <param name="ea_repository"></param>public ImportReqProDatabase(): base(){totalRequirements = 0;}/// <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(ReqProDB_Artifact.MODE mode){try{if (true == base.prompt_and_parse(mode)){if (Main.mustAbort)return false;Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);// Configure the ReqProDB artifact as a traceability artifactRQ_Artifact.set_traceability_mode(RQ_Element);ImportFromReqPro();return true;}}catch (Exception ex){Main.MessageBoxException(ex, "Exception (parse)");}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.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();Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,"Displaying Import Change Log", -1);foreach(string s in log_strings){if (Main.mustAbort)break;// 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 = Main.EA_Repository.GetElementByGuid(parameters[0]);// Now discriminate actions based on the second parameterif (parameters[1].StartsWith("Created")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME," Created : " + ea_req.Name, ea_req.ElementID );}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Orphaned")){Main.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)Main.EA_Repository.GetElementByID( theConnector.SupplierID );if (tgt_ele != null){if (!tgt_ele.Type.StartsWith("Requirement")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " --> " + tgt_ele.Name, tgt_ele.ElementID);}}}}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Name")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Name: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Notes")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Description: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Difficulty")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Difficulty: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Priority")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Priority: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Version")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Version: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " >>> " + parameters[3], ea_req.ElementID);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////else if (parameters[1].StartsWith("Status")){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " Modified Status: " + ea_req.Name, ea_req.ElementID );Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, " <<< " + parameters[2], ea_req.ElementID);Main.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(){try{//IFormatProvider cultureInfo = new CultureInfo("en-US", true);string importDateTime = System.TimeZone.CurrentTimeZone.ToUniversalTime( System.DateTime.Now ).ToString();Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Requirement import at " + importDateTime, -1 );// Get a list of EA requirements and their associated ReqPro GUIDsArrayList ea_reqs;ArrayList ea_GUIDs = new ArrayList();ArrayList ea_req_matched = new ArrayList();// Obtain the EA parent package so that we can create under it an import package// if need be, and scan for existing requirement elements.EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );ArrayList allowedElementTypes = new ArrayList();allowedElementTypes.Add("Requirement");allowedElementTypes.Add("UseCase");Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "", -1);Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Acquiring list of elements already in EA", -1);ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);EA_Utilities.findAndProcessPackageElements( parentPackage, reqLister, true );if (Main.mustAbort)return;ea_reqs = reqLister.Elements;foreach (EA.Element ea_req in ea_reqs){string GUID = EA_Utilities.ReadTag(ea_req, "GUID");ea_GUIDs.Add(GUID);ea_req_matched.Add(false);}if (Main.mustAbort)return;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(ref rq_req_collection);int newRequirementCount = 0;int modifiedRequirementCount = 0;int statusUpdatedRequirementCount = 0;int orphanedCount = 0;Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Merging ReqPro content to EA", -1);// loop through all of the ReqPro requirementsforeach(ReqPro_object rq_obj in rq_req_collection){if (Main.mustAbort)break;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;Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Updating: " + ea_req_name, rq_obj.ea_element_ID);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++;}totalRequirements++;}else{totalRequirements++;// 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_Utilities.WriteTag(ea_req, "GUID", rq_obj.guid);EA_Utilities.WriteTag(ea_req, "TAG", rq_obj.tag);ea_req.Update();// Connect the new requirement to the ea_rq_artifact//base.RQ_Artifact.add_connection(ea_repository, base.RQ_Element, ea_req);changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";changeLog.Update();Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Created: " + ea_req.Name, ea_req.ElementID);}}catch (Exception ex){Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);}}if (Main.mustAbort)return;Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Checking for orphaned requirements", -1);// Now check for orphaned EA requirementsfor (int i = 0; i < ea_GUIDs.Count; i++){if (Main.mustAbort)break;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();}}}DialogResult dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);if (dlgres == DialogResult.Yes)displayChangeLog(changeLog);Main.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.write_traces(totalRequirements);if (Main.mustAbort)return;// display summary statsMain.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, newRequirementCount.ToString() + " new requirements", -1);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, modifiedRequirementCount.ToString() + " requirements modified", -1);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, orphanedCount.ToString() + " requirements were orphaned", -1);writeDelayedMessages();Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Import Completed", -1);MessageBoxEx.Show("Import Completed", MessageBoxButtons.OK);}catch (Exception ex){Main.MessageBoxException(ex, "Exception (ImportFromReqPro)");}}/// <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(ref ArrayList rq_req_collection){foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects ){get_rq_req_collection(ref rq_req_collection, sub_obj);}}private void get_rq_req_collection(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(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(ref rq_req_collection, sub_obj);}}}}}}