| 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 |
namespace EA_ReqPro
|
|
|
9 |
{
|
|
|
10 |
/// <summary>
|
|
|
11 |
/// CopyReqProDatabase is a specialisation of ReqProParser, designed to copy the
|
|
|
12 |
/// ReqPro database content into an EA database, maintaining the structure of
|
|
|
13 |
/// and hierarchy of packages and requirements found in the ReqPro database.
|
|
|
14 |
/// </summary>
|
|
|
15 |
public class CopyReqProDatabase : CopyReqProDatabaseToMemory
|
|
|
16 |
{
|
|
|
17 |
/// <summary>
|
|
|
18 |
/// Construct the object
|
|
|
19 |
/// </summary>
|
|
|
20 |
/// <param name="ea_repository"></param>
|
|
|
21 |
public CopyReqProDatabase(EA.Repository ea_repository): base(ea_repository)
|
|
|
22 |
{
|
|
|
23 |
try
|
|
|
24 |
{
|
|
|
25 |
if (ea_rootPackage.Elements.Count > 0
|
|
|
26 |
|| ea_rootPackage.Packages.Count > 0)
|
|
|
27 |
{
|
|
|
28 |
DialogResult dlgRes = MessageBox.Show("Package is not empty, delete existing content first?", "Confirm", MessageBoxButtons.YesNo);
|
|
|
29 |
if (dlgRes == DialogResult.Yes)
|
|
|
30 |
{
|
|
|
31 |
// Delete packages and requirement elements
|
|
|
32 |
short i;
|
|
|
33 |
for(i=0; i < ea_rootPackage.Packages.Count; i++)
|
|
|
34 |
{
|
|
|
35 |
ea_rootPackage.Packages.Delete(i);
|
|
|
36 |
}
|
|
|
37 |
for(i=0; i < ea_rootPackage.Elements.Count; i++)
|
|
|
38 |
{
|
|
|
39 |
if ( ((EA.Element)ea_rootPackage.Elements.GetAt(i)).Type.StartsWith("Requirement") )
|
|
|
40 |
{
|
|
|
41 |
ea_rootPackage.Elements.Delete(i);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
ea_rootPackage.Packages.Refresh();
|
|
|
45 |
// refresh project browser view
|
|
|
46 |
ea_repository.RefreshModelView(ea_rootPackage.PackageID); }
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
catch (Exception ex)
|
|
|
50 |
{
|
|
|
51 |
MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::CopyReqProDatabase)", MessageBoxButtons.OK);
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
/// <summary>
|
|
|
57 |
/// Method to parse a ReqPro database and copy it into an EA database.
|
|
|
58 |
/// </summary>
|
|
|
59 |
/// <param name="ea_repository"></param>
|
|
|
60 |
/// <returns></returns>
|
|
|
61 |
public override bool prompt_and_parse(EA.Repository ea_repository)
|
|
|
62 |
{
|
|
|
63 |
try
|
|
|
64 |
{
|
|
|
65 |
// use the base classes parser to read the ReqPro database content and allow the user to
|
|
|
66 |
// filter it.
|
|
|
67 |
if (true == base.prompt_and_parse(ea_repository))
|
|
|
68 |
{
|
|
|
69 |
ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
|
|
|
70 |
|
|
|
71 |
// write the captured info from reqpro, into the ea database, obeying the filter
|
|
|
72 |
// settings the user has specified.
|
|
|
73 |
write_ea_database(ea_repository);
|
|
|
74 |
return true;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
catch (Exception ex)
|
|
|
78 |
{
|
|
|
79 |
MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::parse)", MessageBoxButtons.OK);
|
|
|
80 |
}
|
|
|
81 |
return false;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
/// <summary>
|
|
|
90 |
/// This method (along with its sibling overloads) perform the copy operation once
|
|
|
91 |
/// the ReqPro database content has been acquired, and the user has submitted their
|
|
|
92 |
/// filtering requirements. This method begins the copy operation, but the real nitty
|
|
|
93 |
/// gritty of it occurs in the other overloaded method.
|
|
|
94 |
/// </summary>
|
|
|
95 |
/// <param name="ea_repository"></param>
|
|
|
96 |
private void write_ea_database(EA.Repository ea_repository)
|
|
|
97 |
{
|
|
|
98 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Copying ReqPro Database Content to EA", -1);
|
|
|
99 |
|
|
|
100 |
foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
|
|
|
101 |
{
|
|
|
102 |
write_ea_database(ea_repository, ea_rootPackage, null, sub_obj);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
ea_rootPackage.Packages.Refresh();
|
|
|
106 |
// refresh project browser view
|
|
|
107 |
ea_repository.RefreshModelView(ea_rootPackage.PackageID);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
private void write_ea_database(EA.Repository ea_repository,
|
|
|
111 |
EA.Package ea_parent_package,
|
|
|
112 |
EA.Element ea_parent_element,
|
|
|
113 |
ReqPro_object rq_obj )
|
|
|
114 |
{
|
|
|
115 |
if (rq_obj.isPackage)
|
|
|
116 |
{
|
|
|
117 |
if (rq_obj.filtered == false)
|
|
|
118 |
{
|
|
|
119 |
if (ea_parent_package != null)
|
|
|
120 |
{
|
|
|
121 |
// create a representative package in EA
|
|
|
122 |
EA.Package new_ea_package = EA_Utils.createPackage(ea_parent_package, rq_obj.name, rq_obj.treePos);
|
|
|
123 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Package : " + rq_obj.name, new_ea_package.PackageID );
|
|
|
124 |
|
|
|
125 |
// Using recursion, scan this objects sub-objects
|
|
|
126 |
foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
|
|
|
127 |
{
|
|
|
128 |
write_ea_database(ea_repository, new_ea_package, null, sub_obj);
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
else
|
|
|
132 |
{
|
|
|
133 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
else if (base.allowPackageStructureFragments)
|
|
|
137 |
{
|
|
|
138 |
// Using recursion, scan this objects sub-objects
|
|
|
139 |
foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
|
|
|
140 |
{
|
|
|
141 |
if (sub_obj.isPackage)
|
|
|
142 |
write_ea_database(ea_repository, ea_parent_package, null, sub_obj);
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
else if (rq_obj.isRequirement)
|
|
|
147 |
{
|
|
|
148 |
if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)))
|
|
|
149 |
{
|
|
|
150 |
if (ea_parent_element != null)
|
|
|
151 |
{
|
|
|
152 |
// create a representative element in EA
|
|
|
153 |
EA.Element new_ea_element = (EA.Element)ea_parent_element.Elements.AddNew(rq_obj.tag + " " + rq_obj.name, "Requirement");
|
|
|
154 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj.name, new_ea_element.ElementID );
|
|
|
155 |
|
|
|
156 |
// If the ReqPro requirements detailed text is more than what the name already contains (allowing for it
|
|
|
157 |
// to have a stop character that the name may not have) then copy it over, otherwise ignore it. This
|
|
|
158 |
// prevents the same text appearing twice in any generated document made using EA_DocGen.
|
|
|
159 |
if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))
|
|
|
160 |
new_ea_element.Notes = rq_obj.text;
|
|
|
161 |
|
|
|
162 |
new_ea_element.TreePos = rq_obj.treePos;
|
|
|
163 |
new_ea_element.Status = rq_obj.status;
|
|
|
164 |
new_ea_element.Update();
|
|
|
165 |
|
|
|
166 |
// Using recursion, scan this objects sub-objects
|
|
|
167 |
foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
|
|
|
168 |
{
|
|
|
169 |
write_ea_database(ea_repository, null, new_ea_element, sub_obj);
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
else if (ea_parent_package != null)
|
|
|
173 |
{
|
|
|
174 |
// create a representative element in EA
|
|
|
175 |
EA.Element new_ea_element = (EA.Element)ea_parent_package.Elements.AddNew(rq_obj.tag + " " + rq_obj.name, "Requirement");
|
|
|
176 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj.name, new_ea_element.ElementID );
|
|
|
177 |
|
|
|
178 |
// If the ReqPro requirements detailed text is more than what the name already contains (allowing for it
|
|
|
179 |
// to have a stop character that the name may not have) then copy it over, otherwise ignore it. This
|
|
|
180 |
// prevents the same text appearing twice in any generated document made using EA_DocGen.
|
|
|
181 |
if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))
|
|
|
182 |
new_ea_element.Notes = rq_obj.text;
|
|
|
183 |
|
|
|
184 |
new_ea_element.TreePos = rq_obj.treePos;
|
|
|
185 |
new_ea_element.Status = rq_obj.status;
|
|
|
186 |
new_ea_element.Update();
|
|
|
187 |
|
|
|
188 |
// Using recursion, scan this objects sub-objects
|
|
|
189 |
foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
|
|
|
190 |
{
|
|
|
191 |
write_ea_database(ea_repository, null, new_ea_element, sub_obj);
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
else
|
|
|
195 |
{
|
|
|
196 |
ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
}
|