Subversion Repositories DevTools

Rev

Rev 2098 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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