Subversion Repositories DevTools

Rev

Rev 2145 | 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.Element rq_artifact)
      {
         EA_Utilities EA_Utils = new EA_Utilities();

         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)
            {
               MessageBoxEx.Show("Cannot establish connection to ReqPro database. " +
                  "Check the tagged values in the artifact are correct. " +
                  "Check the database still exists or is not locked by " +
                  "another user, or has not been password protected.", "Error" );
            }

            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()
      {
         object o;
         EA.ObjectType type;

         type = Main.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 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)
      {
         EA_Utilities EA_Utils = new EA_Utilities();

         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;
      }


      public void set_traceability_mode(EA.Element rq_artifact)
      {
         EA_Utilities EA_Utils = new EA_Utilities();
         EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");
         rq_artifact.Update();
      }

      public void set_doc_model_mode(EA.Element rq_artifact)
      {
         EA_Utilities EA_Utils = new EA_Utilities();
         EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");
         rq_artifact.Update();
      }

      public MODE get_mode(EA.Element rq_artifact)
      {
         EA_Utilities EA_Utils = new EA_Utilities();
         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;
      }
   }
}