Rev 2143 | 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>/// CopyReqProDatabase is a specialisation of ReqProParser, designed to copy the/// ReqPro database content into an EA database, maintaining the structure of/// and hierarchy of packages and requirements found in the ReqPro database./// </summary>public class CopyReqProDatabase : CopyReqProDatabaseToMemory{/// <summary>/// Construct the object/// </summary>/// <param name="ea_repository"></param>public CopyReqProDatabase(EA.Repository ea_repository): base(ea_repository){try{if (ea_rootPackage.Elements.Count > 0|| ea_rootPackage.Packages.Count > 0){DialogResult dlgRes = MessageBox.Show("Package is not empty, delete existing content first?", "Confirm", MessageBoxButtons.YesNo);if (dlgRes == DialogResult.Yes){// Delete packages and requirement elementsshort i;for(i=0; i < ea_rootPackage.Packages.Count; i++){ea_rootPackage.Packages.Delete(i);}for(i=0; i < ea_rootPackage.Elements.Count; i++){if ( ((EA.Element)ea_rootPackage.Elements.GetAt(i)).Type.StartsWith("Requirement") ){ea_rootPackage.Elements.Delete(i);}}ea_rootPackage.Packages.Refresh();// refresh project browser viewea_repository.RefreshModelView(ea_rootPackage.PackageID); }}}catch (Exception ex){MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::CopyReqProDatabase)", MessageBoxButtons.OK);}}/// <summary>/// Method to parse a ReqPro database and copy it into an EA database./// </summary>/// <param name="ea_repository"></param>/// <returns></returns>public override bool prompt_and_parse(EA.Repository ea_repository){try{// use the base classes parser to read the ReqPro database content and allow the user to// filter it.if (true == base.prompt_and_parse(ea_repository)){ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);// write the captured info from reqpro, into the ea database, obeying the filter// settings the user has specified.write_ea_database(ea_repository);return true;}}catch (Exception ex){MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::parse)", MessageBoxButtons.OK);}return false;}/// <summary>/// This method (along with its sibling overloads) perform the copy operation once/// the ReqPro database content has been acquired, and the user has submitted their/// filtering requirements. This method begins the copy operation, but the real nitty/// gritty of it occurs in the other overloaded method./// </summary>/// <param name="ea_repository"></param>private void write_ea_database(EA.Repository ea_repository){ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Copying ReqPro Database Content to EA", -1);foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects ){write_ea_database(ea_repository, ea_rootPackage, null, sub_obj);}ea_rootPackage.Packages.Refresh();// refresh project browser viewea_repository.RefreshModelView(ea_rootPackage.PackageID);}private void write_ea_database(EA.Repository ea_repository,EA.Package ea_parent_package,EA.Element ea_parent_element,ReqPro_object rq_obj ){if (rq_obj.isPackage){if (rq_obj.filtered == false){if (ea_parent_package != null){// create a representative package in EAEA.Package new_ea_package = EA_Utils.createPackage(ea_parent_package, rq_obj.name, rq_obj.treePos);ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Package : " + rq_obj.name, new_ea_package.PackageID );// Using recursion, scan this objects sub-objectsforeach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){write_ea_database(ea_repository, new_ea_package, null, sub_obj);}}else{ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);}}else if (base.allowPackageStructureFragments){// Using recursion, scan this objects sub-objectsforeach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){if (sub_obj.isPackage)write_ea_database(ea_repository, ea_parent_package, null, sub_obj);}}}else if (rq_obj.isRequirement){if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj))){if (ea_parent_element != null){// create a representative element in EAEA.Element new_ea_element = (EA.Element)ea_parent_element.Elements.AddNew(rq_obj.tag + " " + rq_obj.name, "Requirement");ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj.name, new_ea_element.ElementID );// If the ReqPro requirements detailed text is more than what the name already contains (allowing for it// to have a stop character that the name may not have) then copy it over, otherwise ignore it. This// prevents the same text appearing twice in any generated document made using EA_DocGen.if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))new_ea_element.Notes = rq_obj.text;new_ea_element.TreePos = rq_obj.treePos;new_ea_element.Status = rq_obj.status;new_ea_element.Update();// Using recursion, scan this objects sub-objectsforeach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){write_ea_database(ea_repository, null, new_ea_element, sub_obj);}}else if (ea_parent_package != null){// create a representative element in EAEA.Element new_ea_element = (EA.Element)ea_parent_package.Elements.AddNew(rq_obj.tag + " " + rq_obj.name, "Requirement");ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj.name, new_ea_element.ElementID );// If the ReqPro requirements detailed text is more than what the name already contains (allowing for it// to have a stop character that the name may not have) then copy it over, otherwise ignore it. This// prevents the same text appearing twice in any generated document made using EA_DocGen.if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))new_ea_element.Notes = rq_obj.text;new_ea_element.TreePos = rq_obj.treePos;new_ea_element.Status = rq_obj.status;new_ea_element.Update();// Using recursion, scan this objects sub-objectsforeach( ReqPro_object sub_obj in rq_obj.ReqPro_objects ){write_ea_database(ea_repository, null, new_ea_element, sub_obj);}}else{ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);}}}}}}