Subversion Repositories DevTools

Rev

Rev 2145 | Rev 2153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2151 ghuddy 1
using System;
2
using System.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Windows.Forms;
2141 ghuddy 6
using ReqPro40;
7
 
8
 
9
namespace EA_ReqPro
10
{
2151 ghuddy 11
   /// <summary>
12
   /// The ReqProDB_Artifact class contains methods supporting the use of the ReqProDB
13
   /// element used to control ReqPro imports for requirement-to-design tracability
14
   /// purposes.
15
   /// </summary>
16
   public class ReqProDB_Artifact
17
   {
2145 ghuddy 18
      /// <summary>
19
      /// A ReqProDB artifact can be used for document model (document generation) purposes,
20
      /// or requirement-to-design traceability purposes, and this is to be recorded in the element
21
      /// as a tagged value. We need an enum to represent the differning modes.
22
      /// </summary>
23
      public enum MODE
24
      {
25
         TRACEABILITY,
26
         DOC_MODEL,
27
         UNDEFINED
28
      }
2141 ghuddy 29
 
2145 ghuddy 30
      public ReqPro40.Application RQ_app;
31
 
2141 ghuddy 32
      /// <summary>
33
      /// Constructor logic
34
      /// </summary>
2151 ghuddy 35
      public ReqProDB_Artifact()
36
      {
2145 ghuddy 37
         RQ_app = new ReqPro40.ApplicationClass();
2151 ghuddy 38
      }
2141 ghuddy 39
 
2151 ghuddy 40
 
2141 ghuddy 41
      /// <summary>
42
      /// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact
43
      /// element.
44
      /// </summary>
45
      /// <param name="ea_repository"></param>
46
      /// <param name="rq_artifact"></param>
47
      /// <returns></returns>
2151 ghuddy 48
      public ReqPro40.Project OpenReqProProject(EA.Element rq_artifact)
2141 ghuddy 49
      {
2151 ghuddy 50
         EA_Utilities EA_Utils = new EA_Utilities();
51
 
52
         Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));
53
 
54
         DialogResult dlgRes = logon.ShowDialog();
55
         if (dlgRes == DialogResult.OK)
56
         {
57
            ReqPro40.Project project = RQ_app.OpenProject(
58
               EA_Utils.ReadTag(rq_artifact, "Location"),
59
               ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
60
               EA_Utils.ReadTag(rq_artifact, "Username"),
61
               logon.ebPassword.Text,
62
               enumProjectFlags.eProjFlag_Normal,
63
               enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
64
 
65
            if (project == null)
66
            {
67
               MessageBoxEx.Show("Cannot establish connection to ReqPro database. " +
68
                  "Check the tagged values in the artifact are correct. " +
69
                  "Check the database still exists or is not locked by " +
70
                  "another user, or has not been password protected.", "Error" );
71
            }
72
 
73
            return project;
74
         }
75
         return null;
2141 ghuddy 76
      }
77
 
78
 
79
      /// <summary>
80
      /// This method is used to return the ReqProDB artifact, on the assumption that it is the
81
      /// item the user has highlighted in EA's project browser prior to initiating the process
2145 ghuddy 82
      /// leading up to the call to this method. If the user however has selected a package, then
83
      /// that package is searched for the first ReqProDB artifact that can be found, and that one
84
      /// is returned.
2141 ghuddy 85
      /// </summary>
86
      /// <param name="ea_repository"></param>
87
      /// <returns></returns>
2151 ghuddy 88
      public EA.Element get_rq_artifact()
2141 ghuddy 89
      {
2151 ghuddy 90
         object o;
91
         EA.ObjectType type;
2141 ghuddy 92
 
2151 ghuddy 93
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
94
         if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB"))
95
         {
96
            return (EA.Element)o;
2145 ghuddy 97
         }
2151 ghuddy 98
         else if (type == EA.ObjectType.otPackage)
99
         {
100
            for(short i=0; i < ((EA.Package)o).Elements.Count; i++)
101
            {
102
               EA.Element ea_ele = (EA.Element)((EA.Package)o).Elements.GetAt(i);
103
 
104
               if (ea_ele.Stereotype == "ReqProDB")
105
               {
106
                  return ea_ele;
107
               }
108
            }
109
         }
2145 ghuddy 110
         return null;
111
      }
112
 
113
 
2141 ghuddy 114
      /// <summary>
115
      /// This method is used to create a ReqProDB element in an EA package.
116
      /// Do not modify the tag names that are in current use. Only extend with
117
      /// additional new tags.
118
      /// </summary>
119
      /// <param name="ea_repository"></param>
120
      /// <param name="package"></param>
121
      /// <param name="name"></param>
122
      /// <param name="description"></param>
123
      /// <param name="reqpro_db_username"></param>
124
      /// <param name="reqpro_db_filename"></param>
125
      /// <param name="reqpro_db_guid"></param>
126
      /// <returns></returns>
2151 ghuddy 127
      public EA.Element create_rq_artifact( 
128
         EA.Package package,
129
         string name,
130
         string description,
131
         string reqpro_db_username,
132
         string reqpro_db_filename,
133
         string reqpro_db_guid)
134
      {
135
         EA_Utilities EA_Utils = new EA_Utilities();
136
 
137
         package.Notes = description;
138
         package.Update();
139
 
140
         EA.Element element;
141
         element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
142
         if (element != null)
143
         {
144
            element.Stereotype = "ReqProDB";
145
            element.Notes = description;
146
 
147
            EA_Utils.WriteTag( element, "Location", reqpro_db_filename);
148
            EA_Utils.WriteTag( element, "Username", reqpro_db_username);
149
            EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);
150
 
151
 
152
            element.Update();
153
            element.Refresh();
154
            element.TaggedValues.Refresh();
155
            package.Update();
156
            package.Packages.Refresh();
157
            package.Elements.Refresh();
158
 
159
            return element;
160
         }
161
         return null;
2141 ghuddy 162
      }
163
 
164
 
2151 ghuddy 165
      public void set_traceability_mode(EA.Element rq_artifact)
166
      {
167
         EA_Utilities EA_Utils = new EA_Utilities();
168
         EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");
169
         rq_artifact.Update();
170
      }
171
 
172
      public void set_doc_model_mode(EA.Element rq_artifact)
173
      {
174
         EA_Utilities EA_Utils = new EA_Utilities();
175
         EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");
176
         rq_artifact.Update();
177
      }
178
 
179
      public MODE get_mode(EA.Element rq_artifact)
180
      {
181
         EA_Utilities EA_Utils = new EA_Utilities();
182
         string mode = EA_Utils.ReadTag(rq_artifact, "Mode");
183
 
184
         if (0 == mode.CompareTo("Traceability"))
185
            return MODE.TRACEABILITY;
186
         else if (0 == mode.CompareTo("DocModel"))
187
            return MODE.DOC_MODEL;
188
 
189
         return MODE.UNDEFINED;
190
      }
191
   }
2141 ghuddy 192
}