| 2141 |
ghuddy |
1 |
using System;
|
|
|
2 |
using System.Text;
|
|
|
3 |
using System.Globalization;
|
|
|
4 |
using System.Collections;
|
|
|
5 |
using System.Windows.Forms;
|
|
|
6 |
using ReqPro40;
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
namespace EA_ReqPro
|
|
|
10 |
{
|
|
|
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>
|
|
|
35 |
public ReqProDB_Artifact()
|
|
|
36 |
{
|
| 2145 |
ghuddy |
37 |
RQ_app = new ReqPro40.ApplicationClass();
|
| 2141 |
ghuddy |
38 |
}
|
|
|
39 |
|
|
|
40 |
|
|
|
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>
|
|
|
48 |
public ReqPro40.Project OpenReqProProject(EA.Repository ea_repository, EA.Element rq_artifact)
|
|
|
49 |
{
|
|
|
50 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
51 |
|
|
|
52 |
Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));
|
|
|
53 |
|
|
|
54 |
DialogResult dlgRes = logon.ShowDialog();
|
|
|
55 |
if (dlgRes == DialogResult.OK)
|
|
|
56 |
{
|
| 2145 |
ghuddy |
57 |
ReqPro40.Project project = RQ_app.OpenProject(
|
| 2141 |
ghuddy |
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 |
MessageBox.Show("ERROR: Cannot establish connection to ReqPro database.\n\n" +
|
|
|
68 |
"Check the tagged values in the artifact are correct.\n" +
|
|
|
69 |
"Check the database still exists or is not locked by\n" +
|
|
|
70 |
"another user, or has not been password protected." );
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
return project;
|
|
|
74 |
}
|
|
|
75 |
return null;
|
|
|
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>
|
|
|
88 |
public EA.Element get_rq_artifact(EA.Repository ea_repository)
|
|
|
89 |
{
|
| 2145 |
ghuddy |
90 |
object o;
|
|
|
91 |
EA.ObjectType type;
|
| 2141 |
ghuddy |
92 |
|
| 2145 |
ghuddy |
93 |
type = ea_repository.GetTreeSelectedItem(out o);
|
|
|
94 |
if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB"))
|
| 2141 |
ghuddy |
95 |
{
|
| 2145 |
ghuddy |
96 |
return (EA.Element)o;
|
|
|
97 |
}
|
|
|
98 |
else if (type == EA.ObjectType.otPackage)
|
|
|
99 |
{
|
|
|
100 |
for(short i=0; i < ((EA.Package)o).Elements.Count; i++)
|
| 2141 |
ghuddy |
101 |
{
|
| 2145 |
ghuddy |
102 |
EA.Element ea_ele = (EA.Element)((EA.Package)o).Elements.GetAt(i);
|
| 2141 |
ghuddy |
103 |
|
| 2145 |
ghuddy |
104 |
if (ea_ele.Stereotype == "ReqProDB")
|
| 2141 |
ghuddy |
105 |
{
|
| 2145 |
ghuddy |
106 |
return ea_ele;
|
| 2141 |
ghuddy |
107 |
}
|
|
|
108 |
}
|
| 2145 |
ghuddy |
109 |
}
|
|
|
110 |
return null;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
| 2141 |
ghuddy |
115 |
|
|
|
116 |
/// <summary>
|
|
|
117 |
/// This method updates a ReqProDB artifact elements internal data. Such an update may be
|
|
|
118 |
/// needed if the user has deleted requirements from EA that are linked to the specified
|
|
|
119 |
/// ReqProDB artifact.
|
|
|
120 |
/// </summary>
|
|
|
121 |
/// <param name="repository"></param>
|
|
|
122 |
/// <param name="rq_artifact"></param>
|
|
|
123 |
public void UpdatePackageToReqProDatabaseAssociation(EA.Repository repository, EA.Element rq_artifact)
|
|
|
124 |
{
|
|
|
125 |
repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Please Wait - Updating ReqProDB element", rq_artifact.ElementID);
|
|
|
126 |
|
|
|
127 |
// Scan EA package to find all requirement elements, and add links to them
|
|
|
128 |
// from the ReqPro artifact element we have written into the selected package.
|
|
|
129 |
EA_Utilities EA_Utils = new EA_Utilities(repository);
|
|
|
130 |
|
|
|
131 |
ArrayList allowedElementTypes = new ArrayList();
|
|
|
132 |
allowedElementTypes.Add("Requirement");
|
|
|
133 |
allowedElementTypes.Add("UseCase");
|
|
|
134 |
|
|
|
135 |
ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
|
|
|
136 |
|
|
|
137 |
EA.Package thePackage = repository.GetPackageByID( rq_artifact.PackageID );
|
|
|
138 |
EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );
|
|
|
139 |
|
|
|
140 |
// Get all existing connectors into a list
|
|
|
141 |
ArrayList connectors = new ArrayList();
|
|
|
142 |
foreach(EA.Connector theConnector in rq_artifact.Connectors)
|
|
|
143 |
{
|
|
|
144 |
connectors.Add(theConnector.SupplierID);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// For each element, if it is not already referred to by a connector, add a connector for it
|
|
|
148 |
foreach (EA.Element theElement in reqLister.Elements)
|
|
|
149 |
{
|
|
|
150 |
if (!connectors.Contains(theElement.ElementID))
|
|
|
151 |
{
|
|
|
152 |
add_connection(repository, rq_artifact, theElement);
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
rq_artifact.Connectors.Refresh();
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
// Now remove any connectors that point to element IDs that are no longer in the package
|
|
|
159 |
short i = 0;
|
|
|
160 |
foreach (EA.Connector theConnector in rq_artifact.Connectors)
|
|
|
161 |
{
|
|
|
162 |
if (!reqLister.ElementIDs.Contains(theConnector.SupplierID))
|
|
|
163 |
{
|
|
|
164 |
rq_artifact.Connectors.Delete(i);
|
|
|
165 |
rq_artifact.Connectors.Refresh();
|
|
|
166 |
}
|
|
|
167 |
else
|
|
|
168 |
{
|
|
|
169 |
i++;
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
rq_artifact.Update();
|
|
|
173 |
rq_artifact.Refresh();
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
/// <summary>
|
|
|
178 |
/// This method is used to create a ReqProDB element in an EA package.
|
|
|
179 |
/// Do not modify the tag names that are in current use. Only extend with
|
|
|
180 |
/// additional new tags.
|
|
|
181 |
/// </summary>
|
|
|
182 |
/// <param name="ea_repository"></param>
|
|
|
183 |
/// <param name="package"></param>
|
|
|
184 |
/// <param name="name"></param>
|
|
|
185 |
/// <param name="description"></param>
|
|
|
186 |
/// <param name="reqpro_db_username"></param>
|
|
|
187 |
/// <param name="reqpro_db_filename"></param>
|
|
|
188 |
/// <param name="reqpro_db_guid"></param>
|
|
|
189 |
/// <returns></returns>
|
| 2145 |
ghuddy |
190 |
public EA.Element create_rq_artifact( EA.Repository ea_repository,
|
| 2141 |
ghuddy |
191 |
EA.Package package,
|
|
|
192 |
string name,
|
|
|
193 |
string description,
|
|
|
194 |
string reqpro_db_username,
|
|
|
195 |
string reqpro_db_filename,
|
| 2145 |
ghuddy |
196 |
string reqpro_db_guid)
|
| 2141 |
ghuddy |
197 |
{
|
|
|
198 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
199 |
|
|
|
200 |
package.Notes = description;
|
|
|
201 |
package.Update();
|
|
|
202 |
|
|
|
203 |
EA.Element element;
|
|
|
204 |
element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
|
|
|
205 |
if (element != null)
|
|
|
206 |
{
|
|
|
207 |
element.Stereotype = "ReqProDB";
|
|
|
208 |
element.Notes = description;
|
|
|
209 |
|
|
|
210 |
EA_Utils.WriteTag( element, "Location", reqpro_db_filename);
|
|
|
211 |
EA_Utils.WriteTag( element, "Username", reqpro_db_username);
|
|
|
212 |
EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);
|
|
|
213 |
|
| 2145 |
ghuddy |
214 |
|
| 2141 |
ghuddy |
215 |
element.Update();
|
|
|
216 |
element.Refresh();
|
|
|
217 |
element.TaggedValues.Refresh();
|
| 2145 |
ghuddy |
218 |
package.Update();
|
| 2141 |
ghuddy |
219 |
package.Packages.Refresh();
|
|
|
220 |
package.Elements.Refresh();
|
|
|
221 |
|
|
|
222 |
return element;
|
|
|
223 |
}
|
|
|
224 |
return null;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
/// <summary>
|
|
|
229 |
/// Adds a connection between a ReqProDB artifact and a requirement element
|
|
|
230 |
/// </summary>
|
|
|
231 |
/// <param name="repository"></param>
|
|
|
232 |
/// <param name="rq_artifact"></param>
|
|
|
233 |
/// <param name="ea_req"></param>
|
|
|
234 |
public void add_connection(EA.Repository repository, EA.Element rq_artifact, EA.Element ea_req)
|
|
|
235 |
{
|
|
|
236 |
// Add the new requirement to the rq_artifact
|
|
|
237 |
EA.Connector c = (EA.Connector)rq_artifact.Connectors.AddNew("", "Dependency");
|
|
|
238 |
c.SupplierID = ea_req.ElementID;
|
|
|
239 |
c.Stereotype = "trace";
|
|
|
240 |
c.Direction = "Destination -> Source";
|
|
|
241 |
if (false == c.Update())
|
|
|
242 |
{
|
|
|
243 |
repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "New Connector Error : " + c.GetLastError(), ea_req.ElementID );
|
|
|
244 |
}
|
|
|
245 |
}
|
|
|
246 |
|
| 2145 |
ghuddy |
247 |
public void set_traceability_mode(EA.Repository ea_repository, EA.Element rq_artifact)
|
|
|
248 |
{
|
|
|
249 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
250 |
EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");
|
|
|
251 |
rq_artifact.Update();
|
|
|
252 |
}
|
| 2141 |
ghuddy |
253 |
|
| 2145 |
ghuddy |
254 |
public void set_doc_model_mode(EA.Repository ea_repository, EA.Element rq_artifact)
|
|
|
255 |
{
|
|
|
256 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
257 |
EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");
|
|
|
258 |
rq_artifact.Update();
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public MODE get_mode(EA.Repository ea_repository, EA.Element rq_artifact)
|
|
|
262 |
{
|
|
|
263 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
264 |
string mode = EA_Utils.ReadTag(rq_artifact, "Mode");
|
|
|
265 |
|
|
|
266 |
if (0 == mode.CompareTo("Traceability"))
|
|
|
267 |
return MODE.TRACEABILITY;
|
|
|
268 |
else if (0 == mode.CompareTo("DocModel"))
|
|
|
269 |
return MODE.DOC_MODEL;
|
|
|
270 |
|
|
|
271 |
return MODE.UNDEFINED;
|
|
|
272 |
}
|
| 2141 |
ghuddy |
273 |
|
|
|
274 |
}
|
|
|
275 |
}
|