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