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, plus some additional/// modes as required/// </summary>public enum MODE{TRACEABILITY,DOC_MODEL,EXPORT,UNDEFINED}/// <summary>/// Constructor logic/// </summary>public ReqProDB_Artifact(){}/// <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 bool OpenReqProProject(EA.Element rq_artifact, out bool cancelled){cancelled = false;Logon logon = new Logon(EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_USERNAME));DialogResult dlgRes = logon.ShowDialog();if (dlgRes == DialogResult.OK){if (false == ReqProDatabase.open(EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_LOCATION),EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_USERNAME),logon.ebPassword.Text)){MessageBoxEx.Show("Cannot establish connection to ReqPro database.\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.", "Error" );}return ReqProDatabase.opened();}else{cancelled = true;}return false;}/// <summary>/// This method is used to return the ReqProDB artifact. The algorithm searches the areas/// in EA's project browser beginning at where the user selected/highlighted and working/// up through the parent package levels. This gives the best possible chance of finding/// the artifact and allows the user to select anything in a ReqPro import area before/// initiating an import/export. The software automatically finds where the import area/// exists (ie. its parent container package)/// </summary>/// <param name="ea_repository"></param>/// <returns></returns>public EA.Element get_rq_artifact(){object o;EA.ObjectType type;type = Main.EA_Repository.GetTreeSelectedItem(out o);// if user selected the actual ReqProDB element then we can exit straight away with// the object.if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB")){return (EA.Element)o;}else{// Get the package in or under which the EA project browser selection existsEA.Package pkg = EA_Utilities.get_selected_package();// iterate up through the package hiearchywhile (pkg != null){// search for ReqProDB element in the package at the current levelfor(short i=0; i < pkg.Elements.Count; i++){EA.Element ea_ele = (EA.Element)pkg.Elements.GetAt(i);if (ea_ele.Stereotype == "ReqProDB"){return ea_ele;}}// Didnt find ReqProDB element, go up one package level ready for the next loop iterationif (pkg.ParentID > 0){pkg = Main.EA_Repository.GetPackageByID(pkg.ParentID);}else{// force loop termination if cannot go up one more package levelpkg = null;}}}// tell caller we didnt find a ReqProDB stereotyped element.return null;}/// <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.Package package,string name,string description,string reqpro_db_username,string reqpro_db_filename,string reqpro_db_guid){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_TaggedValues.Write( element, Constants.TAG_DB_LOCATION, reqpro_db_filename);EA_TaggedValues.Write( element, Constants.TAG_DB_USERNAME, reqpro_db_username);EA_TaggedValues.Write( element, Constants.TAG_GUID, reqpro_db_guid);element.Update();element.Refresh();element.TaggedValues.Refresh();package.Update();package.Packages.Refresh();package.Elements.Refresh();return element;}return null;}public void set_traceability_mode(EA.Element rq_artifact){EA_TaggedValues.Write( rq_artifact, Constants.TAG_MODE, "Traceability");rq_artifact.Update();}public void set_doc_model_mode(EA.Element rq_artifact){EA_TaggedValues.Write( rq_artifact, Constants.TAG_MODE, "DocModel");rq_artifact.Update();}public MODE get_mode(EA.Element rq_artifact){string mode = EA_TaggedValues.Read(rq_artifact, Constants.TAG_MODE);if (mode.Equals("Traceability"))return MODE.TRACEABILITY;else if (mode.Equals("DocModel"))return MODE.DOC_MODEL;return MODE.UNDEFINED;}}}