| 2094 |
ghuddy |
1 |
using System;
|
|
|
2 |
using System.Collections;
|
|
|
3 |
using Word;
|
|
|
4 |
|
|
|
5 |
namespace EA_DocGen
|
|
|
6 |
{
|
|
|
7 |
/// <summary>
|
|
|
8 |
/// Summary description for TextualContent.
|
|
|
9 |
/// </summary>
|
|
|
10 |
public class TextualContent
|
|
|
11 |
{
|
|
|
12 |
private Word.Application WordApp = null;
|
|
|
13 |
private Word.Document WordDocument = null;
|
|
|
14 |
|
|
|
15 |
public TextualContent(Word.Application wordApp, Word.Document wordDocument)
|
|
|
16 |
{
|
|
|
17 |
WordApp = wordApp;
|
|
|
18 |
WordDocument = wordDocument;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
|
|
|
23 |
{
|
|
|
24 |
WordApp = wordApp;
|
|
|
25 |
WordDocument = wordDocument;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public Word.Range appendDescription(string wordText, EA_Utilities EA_Utils)
|
|
|
29 |
{
|
| 2098 |
ghuddy |
30 |
return appendDescription(wordText, EA_Utils, false);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public Word.Range appendDescription(string wordText, EA_Utilities EA_Utils, bool continuation)
|
|
|
34 |
{
|
|
|
35 |
return appendDescription(wordText, EA_Constants.styleName_Body1, EA_Utils, continuation);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public Word.Range appendDescription(string wordText, string styleName, EA_Utilities EA_Utils, bool continuation)
|
|
|
39 |
{
|
| 2094 |
ghuddy |
40 |
Word.Range wr = null;
|
|
|
41 |
|
|
|
42 |
if (wordText != null && wordText.Length > 0)
|
| 2098 |
ghuddy |
43 |
wr = appendAndSelectText(wordText, styleName, continuation);
|
| 2094 |
ghuddy |
44 |
else if (!EA_Utils.options.opt_SuppressElementDescriptionMissingWarnings)
|
|
|
45 |
{
|
| 2098 |
ghuddy |
46 |
wr = appendAndSelectText("Description missing!", styleName, continuation);
|
|
|
47 |
// For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
|
|
|
48 |
// otherwise the D of Description, does not get the red color or italic style
|
|
|
49 |
if (continuation)
|
|
|
50 |
wr.Start--;
|
| 2094 |
ghuddy |
51 |
wr.Font.Italic = 1;
|
|
|
52 |
wr.Font.Color = Word.WdColor.wdColorRed;
|
|
|
53 |
}
|
|
|
54 |
return wr;
|
|
|
55 |
}
|
|
|
56 |
|
| 2098 |
ghuddy |
57 |
|
| 2094 |
ghuddy |
58 |
|
|
|
59 |
/// <summary>
|
|
|
60 |
/// Appends a specified text string to the word document, selects the new text, and applies
|
|
|
61 |
/// the specified style formatting to it.
|
|
|
62 |
/// </summary>
|
|
|
63 |
/// <param name="wordText"></param>
|
|
|
64 |
/// <param name="styleText"></param>
|
|
|
65 |
/// <param name="continuation"></param>
|
|
|
66 |
public Word.Range appendAndSelectText(string wordText, string styleText)
|
|
|
67 |
{
|
|
|
68 |
return appendAndSelectText(wordText, styleText, false );
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
public Word.Range appendAndSelectText(string wordText, string styleText, bool continuation )
|
|
|
73 |
{
|
|
|
74 |
if (wordText.Length > 0)
|
|
|
75 |
{
|
|
|
76 |
Word.Range WordRange = null;
|
|
|
77 |
object startLocation;
|
|
|
78 |
object endLocation;
|
|
|
79 |
|
|
|
80 |
object style = styleText;
|
|
|
81 |
int i;
|
|
|
82 |
startLocation = 0;
|
|
|
83 |
endLocation = i = WordDocument.Content.End;
|
|
|
84 |
|
|
|
85 |
WordRange = WordDocument.Range(ref startLocation, ref endLocation);
|
|
|
86 |
|
|
|
87 |
if (!continuation)
|
|
|
88 |
WordRange.InsertAfter( "\n" );
|
|
|
89 |
|
|
|
90 |
WordRange.InsertAfter( wordText );
|
|
|
91 |
|
|
|
92 |
// Make a range out of the pasted text
|
|
|
93 |
startLocation = i;
|
|
|
94 |
endLocation = WordDocument.Content.End;
|
|
|
95 |
WordRange = WordDocument.Range(ref startLocation, ref endLocation);
|
|
|
96 |
|
|
|
97 |
// and set the pasted text style
|
|
|
98 |
WordRange.set_Style(ref style);
|
|
|
99 |
return WordRange;
|
|
|
100 |
}
|
|
|
101 |
return null;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
/// <summary>
|
|
|
106 |
/// Appends a specified text string to the word document, selects the new text, and applies
|
|
|
107 |
/// a heading level style to it.
|
|
|
108 |
/// </summary>
|
|
|
109 |
/// <param name="wordText"></param>
|
|
|
110 |
/// <param name="level"></param>
|
|
|
111 |
public void appendAndSelectHeadingText(string wordText, int level)
|
|
|
112 |
{
|
|
|
113 |
// Convert level to heading style
|
|
|
114 |
string styleText;
|
|
|
115 |
switch(level)
|
|
|
116 |
{
|
|
|
117 |
case 1: styleText = EA_Constants.styleName_Heading1; break;
|
|
|
118 |
case 2: styleText = EA_Constants.styleName_Heading2; break;
|
|
|
119 |
case 3: styleText = EA_Constants.styleName_Heading3; break;
|
|
|
120 |
case 4: styleText = EA_Constants.styleName_Heading4; break;
|
|
|
121 |
case 5: styleText = EA_Constants.styleName_Heading5; break;
|
|
|
122 |
case 6: styleText = EA_Constants.styleName_Heading6; break;
|
|
|
123 |
case 7: styleText = EA_Constants.styleName_Heading7; break;
|
|
|
124 |
case 8: styleText = EA_Constants.styleName_Heading8; break;
|
|
|
125 |
case 9: styleText = EA_Constants.styleName_Heading9; break;
|
|
|
126 |
default: styleText = EA_Constants.styleName_Heading9; break;
|
|
|
127 |
}
|
|
|
128 |
// append the text as a heading
|
|
|
129 |
appendAndSelectText(wordText, styleText);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
/// <summary>
|
|
|
134 |
/// Appends a specified text string to the word document, selects the new text, and applies
|
|
|
135 |
/// a num para heading level style to it.
|
|
|
136 |
/// </summary>
|
|
|
137 |
/// <param name="wordText"></param>
|
|
|
138 |
/// <param name="level"></param>
|
|
|
139 |
public void appendAndSelectNumParaText(string wordText, int level)
|
|
|
140 |
{
|
|
|
141 |
// Convert level to heading style
|
|
|
142 |
string styleText;
|
|
|
143 |
switch(level)
|
|
|
144 |
{
|
|
|
145 |
case 1: styleText = EA_Constants.styleName_NumPara1; break;
|
|
|
146 |
case 2: styleText = EA_Constants.styleName_NumPara2; break;
|
|
|
147 |
case 3: styleText = EA_Constants.styleName_NumPara3; break;
|
|
|
148 |
case 4: styleText = EA_Constants.styleName_NumPara4; break;
|
|
|
149 |
case 5: styleText = EA_Constants.styleName_NumPara5; break;
|
|
|
150 |
case 6: styleText = EA_Constants.styleName_NumPara6; break;
|
|
|
151 |
case 7: styleText = EA_Constants.styleName_NumPara7; break;
|
|
|
152 |
case 8: styleText = EA_Constants.styleName_NumPara8; break;
|
|
|
153 |
case 9: styleText = EA_Constants.styleName_NumPara9; break;
|
|
|
154 |
default: styleText = EA_Constants.styleName_NumPara9; break;
|
|
|
155 |
}
|
|
|
156 |
// append the text as a heading
|
|
|
157 |
appendAndSelectText(wordText, styleText);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
public string testSuiteName(EA.Element theElement)
|
|
|
162 |
{
|
|
|
163 |
return "Test Suite - " + theElement.Name;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
public void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList)
|
|
|
168 |
{
|
|
|
169 |
// only feed non-private classes through to the unit test section of a document
|
|
|
170 |
// NOTE: May need an override option for this filter.
|
|
|
171 |
if (!theElement.Visibility.StartsWith("Private"))
|
|
|
172 |
{
|
|
|
173 |
appendAndSelectHeadingText(testSuiteName(theElement), recurse_level+1);
|
|
|
174 |
|
|
|
175 |
if (theElement.Tests.Count > 0)
|
|
|
176 |
{
|
|
|
177 |
classList.Add( theElement.ElementID );
|
|
|
178 |
|
|
|
179 |
foreach(EA.Test theTest in theElement.Tests)
|
|
|
180 |
{
|
|
|
181 |
appendAndSelectHeadingText("Test Case - " + theTest.Name, recurse_level+2);
|
|
|
182 |
|
|
|
183 |
appendAndSelectHeadingText("Description", recurse_level+3);
|
|
|
184 |
appendAndSelectText(theTest.Notes, EA_Constants.styleName_Body1);
|
|
|
185 |
|
|
|
186 |
appendAndSelectHeadingText("Inputs", recurse_level+3);
|
|
|
187 |
appendAndSelectText(theTest.Input, EA_Constants.styleName_Body1);
|
|
|
188 |
|
|
|
189 |
appendAndSelectHeadingText("Expected Results", recurse_level+3);
|
|
|
190 |
appendAndSelectText(theTest.AcceptanceCriteria, EA_Constants.styleName_Body1);
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
else
|
|
|
194 |
{
|
|
|
195 |
Word.Range wr = appendAndSelectText("Test Cases missing!", EA_Constants.styleName_Body1);
|
|
|
196 |
wr.Font.Italic = 1;
|
|
|
197 |
wr.Font.Color = Word.WdColor.wdColorRed;
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
public void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList)
|
|
|
204 |
{
|
|
|
205 |
EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
|
|
|
206 |
EA.Element theElement = null;
|
|
|
207 |
int theElementsRelativeLevel = 0;
|
|
|
208 |
if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
|
|
|
209 |
{
|
|
|
210 |
do
|
|
|
211 |
{
|
|
|
212 |
if (theElement.Type.StartsWith("Class"))
|
|
|
213 |
{
|
|
|
214 |
appendUnitTestSuite(theElement, recurse_level, ref classList);
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
} while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
// Scan through the packages within this package.
|
|
|
221 |
foreach(EA.Package lowerLevelPackage in thePackage.Packages)
|
|
|
222 |
{
|
|
|
223 |
// recurse
|
|
|
224 |
appendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList);
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
public void SelectInsertionPointAtEndOfDocument()
|
|
|
230 |
{
|
|
|
231 |
object unit;
|
|
|
232 |
object extend;
|
|
|
233 |
|
|
|
234 |
unit = Word.WdUnits.wdStory;
|
|
|
235 |
extend = Word.WdMovementType.wdMove;
|
|
|
236 |
WordApp.Selection.EndKey(ref unit, ref extend);
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
/// <summary>
|
|
|
241 |
/// Generates the text for requirements. This uses custom styles to format the text
|
|
|
242 |
/// rather than formatting it in code.
|
|
|
243 |
/// </summary>
|
|
|
244 |
public bool generateRequirementText( EA.Element theElement, EA_Utilities EA_Utils )
|
|
|
245 |
{
|
|
|
246 |
if ( theElement.Type.StartsWith("Requirement"))
|
|
|
247 |
{
|
|
|
248 |
// Check for Richard Ho's requirement format
|
|
|
249 |
if (EA_Utils.options.opt_DisplayRequirementsWithStatus == true)
|
|
|
250 |
{
|
|
|
251 |
string reqID = "";
|
|
|
252 |
string reqShortDesc = "";
|
|
|
253 |
string reqNotes = "";
|
|
|
254 |
string reqStatusText = "";
|
|
|
255 |
string reqHeadingStyle ="";
|
|
|
256 |
string reqParaStyle = "";
|
|
|
257 |
object reqNameStyle = EA_Constants.styleName_ReqName;
|
|
|
258 |
Word.Range shortDescRange;
|
|
|
259 |
|
|
|
260 |
// Set the style depending on the status
|
|
|
261 |
switch ( theElement.Status )
|
|
|
262 |
{
|
|
|
263 |
case "Proposed":
|
|
|
264 |
reqStatusText = "(Proposed)";
|
|
|
265 |
reqHeadingStyle = EA_Constants.styleName_ReqPropHdr;
|
|
|
266 |
reqParaStyle = EA_Constants.styleName_ReqPropBody;
|
|
|
267 |
break;
|
|
|
268 |
|
|
|
269 |
case "Rejected":
|
|
|
270 |
reqHeadingStyle = EA_Constants.styleName_ReqRejHdr;
|
|
|
271 |
reqParaStyle = EA_Constants.styleName_ReqRejBody;
|
|
|
272 |
break;
|
|
|
273 |
|
|
|
274 |
case "Approved":
|
|
|
275 |
//reqStatusText = "(Approved)";
|
|
|
276 |
//reqStatusText = "(Phase " + theElement.Phase + ")";
|
|
|
277 |
reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
|
|
|
278 |
reqParaStyle = EA_Constants.styleName_ReqAppBody;
|
|
|
279 |
break;
|
|
|
280 |
|
|
|
281 |
default:
|
|
|
282 |
reqStatusText = "(" + theElement.Status + ")";
|
|
|
283 |
//reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";
|
|
|
284 |
reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
|
|
|
285 |
reqParaStyle = EA_Constants.styleName_ReqAppBody;
|
|
|
286 |
break;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
// Pull out the ID from the name
|
|
|
290 |
int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
|
|
|
291 |
reqID = theElement.Name.Substring( 0, pos );
|
|
|
292 |
|
|
|
293 |
// Pull out the short description from the rest of the name
|
|
|
294 |
reqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );
|
|
|
295 |
reqShortDesc = reqShortDesc.Trim();
|
|
|
296 |
|
|
|
297 |
// Pull out the notes
|
|
|
298 |
reqNotes = theElement.Notes.ToString();
|
|
|
299 |
|
|
|
300 |
// Add the text
|
|
|
301 |
appendAndSelectText( reqID + '\t', reqHeadingStyle );
|
|
|
302 |
shortDescRange = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
|
|
|
303 |
Word.Range WordRange = appendAndSelectText( '\t' + reqStatusText, reqHeadingStyle, true );
|
|
|
304 |
|
|
|
305 |
//reapply the name char style to the short desc.
|
|
|
306 |
shortDescRange.Start = shortDescRange.Start-1;
|
|
|
307 |
shortDescRange.End = WordRange.Start-1;
|
|
|
308 |
shortDescRange.set_Style( ref reqNameStyle );
|
|
|
309 |
|
|
|
310 |
appendAndSelectText( reqNotes, reqParaStyle );
|
|
|
311 |
return true;
|
|
|
312 |
}
|
|
|
313 |
//
|
|
|
314 |
else if (EA_Utils.options.opt_DisplayRequirementElementsAsSections == false)
|
|
|
315 |
{
|
|
|
316 |
string s;
|
|
|
317 |
s = EA_Utils.options.opt_RequirementElementDisplayFormat;
|
|
|
318 |
s = s.Replace(@"%s",@"{0}");
|
|
|
319 |
Word.Range WordRange = appendAndSelectText( String.Format( s, theElement.Name ), EA_Constants.styleName_Body1);
|
|
|
320 |
WordRange.Font.Bold = 1;
|
|
|
321 |
|
|
|
322 |
appendAndSelectText( theElement.Notes, EA_Constants.styleName_Body1 );
|
|
|
323 |
return true;
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
return false;
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
}
|
|
|
333 |
}
|