Rev 2141 | Rev 2153 | 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>/// The ReqProDB_Artifact class contains methods supporting the use of the ReqProDB/// element used to control ReqPro imports for requirement-to-design tracability/// purposes./// </summary>public class ReqProDB_Artifact{/// <summary>/// A ReqProDB artifact can be used for document model (document generation) purposes,/// or requirement-to-design traceability purposes, and this is to be recorded in the element/// as a tagged value. We need an enum to represent the differning modes./// </summary>public enum MODE{TRACEABILITY,DOC_MODEL,UNDEFINED}public ReqPro40.Application RQ_app;/// <summary>/// Constructor logic/// </summary>public ReqProDB_Artifact(){RQ_app = new ReqPro40.ApplicationClass();}/// <summary>/// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact/// element./// </summary>/// <param name="ea_repository"></param>/// <param name="rq_artifact"></param>/// <returns></returns>public ReqPro40.Project OpenReqProProject(EA.Repository ea_repository, EA.Element rq_artifact){EA_Utilities EA_Utils = new EA_Utilities(ea_repository);Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));DialogResult dlgRes = logon.ShowDialog();if (dlgRes == DialogResult.OK){ReqPro40.Project project = RQ_app.OpenProject(EA_Utils.ReadTag(rq_artifact, "Location"),ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,EA_Utils.ReadTag(rq_artifact, "Username"),logon.ebPassword.Text,enumProjectFlags.eProjFlag_Normal,enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);if (project == null){MessageBox.Show("ERROR: Cannot establish connection to ReqPro database.\n\n" +"Check the tagged values in the artifact are correct.\n" +"Check the database still exists or is not locked by\n" +"another user, or has not been password protected." );}return project;}return null;}/// <summary>/// This method is used to return the ReqProDB artifact, on the assumption that it is the/// item the user has highlighted in EA's project browser prior to initiating the process/// leading up to the call to this method. If the user however has selected a package, then/// that package is searched for the first ReqProDB artifact that can be found, and that one/// is returned./// </summary>/// <param name="ea_repository"></param>/// <returns></returns>public EA.Element get_rq_artifact(EA.Repository ea_repository){object o;EA.ObjectType type;type = ea_repository.GetTreeSelectedItem(out o);if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB")){return (EA.Element)o;}else if (type == EA.ObjectType.otPackage){for(short i=0; i < ((EA.Package)o).Elements.Count; i++){EA.Element ea_ele = (EA.Element)((EA.Package)o).Elements.GetAt(i);if (ea_ele.Stereotype == "ReqProDB"){return ea_ele;}}}return null;}/// <summary>/// This method updates a ReqProDB artifact elements internal data. Such an update may be/// needed if the user has deleted requirements from EA that are linked to the specified/// ReqProDB artifact./// </summary>/// <param name="repository"></param>/// <param name="rq_artifact"></param>public void UpdatePackageToReqProDatabaseAssociation(EA.Repository repository, EA.Element rq_artifact){repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Please Wait - Updating ReqProDB element", rq_artifact.ElementID);// Scan EA package to find all requirement elements, and add links to them// from the ReqPro artifact element we have written into the selected package.EA_Utilities EA_Utils = new EA_Utilities(repository);ArrayList allowedElementTypes = new ArrayList();allowedElementTypes.Add("Requirement");allowedElementTypes.Add("UseCase");ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);EA.Package thePackage = repository.GetPackageByID( rq_artifact.PackageID );EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );// Get all existing connectors into a listArrayList connectors = new ArrayList();foreach(EA.Connector theConnector in rq_artifact.Connectors){connectors.Add(theConnector.SupplierID);}// For each element, if it is not already referred to by a connector, add a connector for itforeach (EA.Element theElement in reqLister.Elements){if (!connectors.Contains(theElement.ElementID)){add_connection(repository, rq_artifact, theElement);}}rq_artifact.Connectors.Refresh();// Now remove any connectors that point to element IDs that are no longer in the packageshort i = 0;foreach (EA.Connector theConnector in rq_artifact.Connectors){if (!reqLister.ElementIDs.Contains(theConnector.SupplierID)){rq_artifact.Connectors.Delete(i);rq_artifact.Connectors.Refresh();}else{i++;}}rq_artifact.Update();rq_artifact.Refresh();}/// <summary>/// This method is used to create a ReqProDB element in an EA package./// Do not modify the tag names that are in current use. Only extend with/// additional new tags./// </summary>/// <param name="ea_repository"></param>/// <param name="package"></param>/// <param name="name"></param>/// <param name="description"></param>/// <param name="reqpro_db_username"></param>/// <param name="reqpro_db_filename"></param>/// <param name="reqpro_db_guid"></param>/// <returns></returns>public EA.Element create_rq_artifact( EA.Repository ea_repository,EA.Package package,string name,string description,string reqpro_db_username,string reqpro_db_filename,string reqpro_db_guid){EA_Utilities EA_Utils = new EA_Utilities(ea_repository);package.Notes = description;package.Update();EA.Element element;element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");if (element != null){element.Stereotype = "ReqProDB";element.Notes = description;EA_Utils.WriteTag( element, "Location", reqpro_db_filename);EA_Utils.WriteTag( element, "Username", reqpro_db_username);EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);element.Update();element.Refresh();element.TaggedValues.Refresh();package.Update();package.Packages.Refresh();package.Elements.Refresh();return element;}return null;}/// <summary>/// Adds a connection between a ReqProDB artifact and a requirement element/// </summary>/// <param name="repository"></param>/// <param name="rq_artifact"></param>/// <param name="ea_req"></param>public void add_connection(EA.Repository repository, EA.Element rq_artifact, EA.Element ea_req){// Add the new requirement to the rq_artifactEA.Connector c = (EA.Connector)rq_artifact.Connectors.AddNew("", "Dependency");c.SupplierID = ea_req.ElementID;c.Stereotype = "trace";c.Direction = "Destination -> Source";if (false == c.Update()){repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "New Connector Error : " + c.GetLastError(), ea_req.ElementID );}}public void set_traceability_mode(EA.Repository ea_repository, EA.Element rq_artifact){EA_Utilities EA_Utils = new EA_Utilities(ea_repository);EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");rq_artifact.Update();}public void set_doc_model_mode(EA.Repository ea_repository, EA.Element rq_artifact){EA_Utilities EA_Utils = new EA_Utilities(ea_repository);EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");rq_artifact.Update();}public MODE get_mode(EA.Repository ea_repository, EA.Element rq_artifact){EA_Utilities EA_Utils = new EA_Utilities(ea_repository);string mode = EA_Utils.ReadTag(rq_artifact, "Mode");if (0 == mode.CompareTo("Traceability"))return MODE.TRACEABILITY;else if (0 == mode.CompareTo("DocModel"))return MODE.DOC_MODEL;return MODE.UNDEFINED;}}}