| 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 |
{
|
|
|
18 |
private ReqPro40.Application reqPro;
|
|
|
19 |
|
|
|
20 |
/// <summary>
|
|
|
21 |
/// Constructor logic
|
|
|
22 |
/// </summary>
|
|
|
23 |
public ReqProDB_Artifact()
|
|
|
24 |
{
|
|
|
25 |
reqPro = new ReqPro40.ApplicationClass();
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
/// <summary>
|
|
|
30 |
/// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact
|
|
|
31 |
/// element.
|
|
|
32 |
/// </summary>
|
|
|
33 |
/// <param name="ea_repository"></param>
|
|
|
34 |
/// <param name="rq_artifact"></param>
|
|
|
35 |
/// <returns></returns>
|
|
|
36 |
public ReqPro40.Project OpenReqProProject(EA.Repository ea_repository, EA.Element rq_artifact)
|
|
|
37 |
{
|
|
|
38 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
39 |
|
|
|
40 |
Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));
|
|
|
41 |
|
|
|
42 |
DialogResult dlgRes = logon.ShowDialog();
|
|
|
43 |
if (dlgRes == DialogResult.OK)
|
|
|
44 |
{
|
|
|
45 |
ReqPro40.Project project = reqPro.OpenProject(
|
|
|
46 |
EA_Utils.ReadTag(rq_artifact, "Location"),
|
|
|
47 |
ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
|
|
|
48 |
EA_Utils.ReadTag(rq_artifact, "Username"),
|
|
|
49 |
logon.ebPassword.Text,
|
|
|
50 |
enumProjectFlags.eProjFlag_Normal,
|
|
|
51 |
enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
|
|
|
52 |
|
|
|
53 |
if (project == null)
|
|
|
54 |
{
|
|
|
55 |
MessageBox.Show("ERROR: Cannot establish connection to ReqPro database.\n\n" +
|
|
|
56 |
"Check the tagged values in the artifact are correct.\n" +
|
|
|
57 |
"Check the database still exists or is not locked by\n" +
|
|
|
58 |
"another user, or has not been password protected." );
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
return project;
|
|
|
62 |
}
|
|
|
63 |
return null;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
/// <summary>
|
|
|
68 |
/// This method is used to return the ReqProDB artifact, on the assumption that it is the
|
|
|
69 |
/// item the user has highlighted in EA's project browser prior to initiating the process
|
|
|
70 |
/// leading up to the call to this method.
|
|
|
71 |
/// </summary>
|
|
|
72 |
/// <param name="ea_repository"></param>
|
|
|
73 |
/// <returns></returns>
|
|
|
74 |
public EA.Element get_rq_artifact(EA.Repository ea_repository)
|
|
|
75 |
{
|
|
|
76 |
// assumes this method will only be used when user has selected a ReqProDB element
|
|
|
77 |
// in the project browser.
|
|
|
78 |
return (EA.Element)ea_repository.GetTreeSelectedObject();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
/// <summary>
|
|
|
83 |
///This method is used to associate a package in EA with a specific ReqPro database
|
|
|
84 |
///file.
|
|
|
85 |
/// </summary>
|
|
|
86 |
/// <param name="repository"></param>
|
|
|
87 |
public void AssociatePackageToReqProDatabase(EA.Repository ea_repository)
|
|
|
88 |
{
|
|
|
89 |
object o;
|
|
|
90 |
EA.ObjectType type = ea_repository.GetTreeSelectedItem(out o);
|
|
|
91 |
if (type == EA.ObjectType.otPackage)
|
|
|
92 |
{
|
|
|
93 |
EA.Package package = (EA.Package)o;
|
|
|
94 |
|
|
|
95 |
try
|
|
|
96 |
{
|
|
|
97 |
// Get user to identify the ReqPro database file
|
|
|
98 |
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
99 |
ofd.Title = "Select Requisite Pro project file";
|
|
|
100 |
ofd.Filter = "ReqPro files (*.rqs)|*.rqs|All files (*.*)|*.*";
|
|
|
101 |
DialogResult dlgRes = ofd.ShowDialog();
|
|
|
102 |
|
|
|
103 |
if (dlgRes == DialogResult.OK)
|
|
|
104 |
{
|
|
|
105 |
// Get user to login to the database
|
|
|
106 |
Logon logon = new Logon("");
|
|
|
107 |
dlgRes = logon.ShowDialog();
|
|
|
108 |
|
|
|
109 |
if (dlgRes == DialogResult.OK)
|
|
|
110 |
{
|
|
|
111 |
string username = logon.ebUserName.Text;
|
|
|
112 |
string password = logon.ebPassword.Text;
|
|
|
113 |
|
|
|
114 |
// attempt to test if the database can be opened
|
|
|
115 |
ReqPro40.Project rq_project = reqPro.OpenProject(
|
|
|
116 |
ofd.FileName,
|
|
|
117 |
ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
|
|
|
118 |
logon.ebUserName.Text,
|
|
|
119 |
logon.ebPassword.Text,
|
|
|
120 |
enumProjectFlags.eProjFlag_Normal,
|
|
|
121 |
enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
|
|
|
122 |
|
|
|
123 |
if (rq_project != null)
|
|
|
124 |
{
|
|
|
125 |
// Success - add the RQ project to the EA repository
|
|
|
126 |
EA.Element rq_artifact = create_rq_artifact( ea_repository,
|
|
|
127 |
package,
|
|
|
128 |
rq_project.Name,
|
|
|
129 |
rq_project.Description,
|
|
|
130 |
logon.ebUserName.Text,
|
|
|
131 |
ofd.FileName,
|
|
|
132 |
rq_project.GUID );
|
|
|
133 |
|
|
|
134 |
if (rq_artifact != null)
|
|
|
135 |
{
|
|
|
136 |
UpdatePackageToReqProDatabaseAssociation(ea_repository, rq_artifact);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
rq_project.CloseProject();
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
catch (Exception ex)
|
|
|
145 |
{
|
|
|
146 |
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
/// <summary>
|
|
|
153 |
/// This method updates a ReqProDB artifact elements internal data. Such an update may be
|
|
|
154 |
/// needed if the user has deleted requirements from EA that are linked to the specified
|
|
|
155 |
/// ReqProDB artifact.
|
|
|
156 |
/// </summary>
|
|
|
157 |
/// <param name="repository"></param>
|
|
|
158 |
/// <param name="rq_artifact"></param>
|
|
|
159 |
public void UpdatePackageToReqProDatabaseAssociation(EA.Repository repository, EA.Element rq_artifact)
|
|
|
160 |
{
|
|
|
161 |
repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Please Wait - Updating ReqProDB element", rq_artifact.ElementID);
|
|
|
162 |
|
|
|
163 |
// Scan EA package to find all requirement elements, and add links to them
|
|
|
164 |
// from the ReqPro artifact element we have written into the selected package.
|
|
|
165 |
EA_Utilities EA_Utils = new EA_Utilities(repository);
|
|
|
166 |
|
|
|
167 |
ArrayList allowedElementTypes = new ArrayList();
|
|
|
168 |
allowedElementTypes.Add("Requirement");
|
|
|
169 |
allowedElementTypes.Add("UseCase");
|
|
|
170 |
|
|
|
171 |
ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
|
|
|
172 |
|
|
|
173 |
EA.Package thePackage = repository.GetPackageByID( rq_artifact.PackageID );
|
|
|
174 |
EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );
|
|
|
175 |
|
|
|
176 |
// Get all existing connectors into a list
|
|
|
177 |
ArrayList connectors = new ArrayList();
|
|
|
178 |
foreach(EA.Connector theConnector in rq_artifact.Connectors)
|
|
|
179 |
{
|
|
|
180 |
connectors.Add(theConnector.SupplierID);
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
// For each element, if it is not already referred to by a connector, add a connector for it
|
|
|
184 |
foreach (EA.Element theElement in reqLister.Elements)
|
|
|
185 |
{
|
|
|
186 |
if (!connectors.Contains(theElement.ElementID))
|
|
|
187 |
{
|
|
|
188 |
add_connection(repository, rq_artifact, theElement);
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
rq_artifact.Connectors.Refresh();
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
// Now remove any connectors that point to element IDs that are no longer in the package
|
|
|
195 |
short i = 0;
|
|
|
196 |
foreach (EA.Connector theConnector in rq_artifact.Connectors)
|
|
|
197 |
{
|
|
|
198 |
if (!reqLister.ElementIDs.Contains(theConnector.SupplierID))
|
|
|
199 |
{
|
|
|
200 |
rq_artifact.Connectors.Delete(i);
|
|
|
201 |
rq_artifact.Connectors.Refresh();
|
|
|
202 |
}
|
|
|
203 |
else
|
|
|
204 |
{
|
|
|
205 |
i++;
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
rq_artifact.Update();
|
|
|
209 |
rq_artifact.Refresh();
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
/// <summary>
|
|
|
214 |
/// This method is used to create a ReqProDB element in an EA package.
|
|
|
215 |
/// Do not modify the tag names that are in current use. Only extend with
|
|
|
216 |
/// additional new tags.
|
|
|
217 |
/// </summary>
|
|
|
218 |
/// <param name="ea_repository"></param>
|
|
|
219 |
/// <param name="package"></param>
|
|
|
220 |
/// <param name="name"></param>
|
|
|
221 |
/// <param name="description"></param>
|
|
|
222 |
/// <param name="reqpro_db_username"></param>
|
|
|
223 |
/// <param name="reqpro_db_filename"></param>
|
|
|
224 |
/// <param name="reqpro_db_guid"></param>
|
|
|
225 |
/// <returns></returns>
|
|
|
226 |
private EA.Element create_rq_artifact( EA.Repository ea_repository,
|
|
|
227 |
EA.Package package,
|
|
|
228 |
string name,
|
|
|
229 |
string description,
|
|
|
230 |
string reqpro_db_username,
|
|
|
231 |
string reqpro_db_filename,
|
|
|
232 |
string reqpro_db_guid )
|
|
|
233 |
{
|
|
|
234 |
EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
|
|
|
235 |
|
|
|
236 |
package.Notes = description;
|
|
|
237 |
package.Update();
|
|
|
238 |
|
|
|
239 |
EA.Element element;
|
|
|
240 |
element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
|
|
|
241 |
if (element != null)
|
|
|
242 |
{
|
|
|
243 |
element.Stereotype = "ReqProDB";
|
|
|
244 |
element.Notes = description;
|
|
|
245 |
|
|
|
246 |
EA_Utils.WriteTag( element, "Location", reqpro_db_filename);
|
|
|
247 |
EA_Utils.WriteTag( element, "Username", reqpro_db_username);
|
|
|
248 |
EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);
|
|
|
249 |
EA_Utils.WriteTag( element, "Enable_Update", "false");
|
|
|
250 |
|
|
|
251 |
element.Update();
|
|
|
252 |
element.Refresh();
|
|
|
253 |
element.TaggedValues.Refresh();
|
|
|
254 |
package.Packages.Refresh();
|
|
|
255 |
package.Elements.Refresh();
|
|
|
256 |
|
|
|
257 |
return element;
|
|
|
258 |
}
|
|
|
259 |
return null;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
/// <summary>
|
|
|
264 |
/// Adds a connection between a ReqProDB artifact and a requirement element
|
|
|
265 |
/// </summary>
|
|
|
266 |
/// <param name="repository"></param>
|
|
|
267 |
/// <param name="rq_artifact"></param>
|
|
|
268 |
/// <param name="ea_req"></param>
|
|
|
269 |
public void add_connection(EA.Repository repository, EA.Element rq_artifact, EA.Element ea_req)
|
|
|
270 |
{
|
|
|
271 |
// Add the new requirement to the rq_artifact
|
|
|
272 |
EA.Connector c = (EA.Connector)rq_artifact.Connectors.AddNew("", "Dependency");
|
|
|
273 |
c.SupplierID = ea_req.ElementID;
|
|
|
274 |
c.Stereotype = "trace";
|
|
|
275 |
c.Direction = "Destination -> Source";
|
|
|
276 |
if (false == c.Update())
|
|
|
277 |
{
|
|
|
278 |
repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "New Connector Error : " + c.GetLastError(), ea_req.ElementID );
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
}
|
|
|
285 |
}
|