Subversion Repositories DevTools

Rev

Rev 2098 | Rev 2106 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2098 Rev 2104
Line 9... Line 9...
9
	/// </summary>
9
	/// </summary>
10
	public class TextualContent
10
	public class TextualContent
11
	{
11
	{
12
      private Word.Application WordApp = null;
12
      private Word.Application WordApp = null;
13
      private Word.Document WordDocument = null;
13
      private Word.Document WordDocument = null;
-
 
14
      private DocSectionTracking DocSectionTracker = null;
14
 
15
 
15
		public TextualContent(Word.Application wordApp, Word.Document wordDocument)
16
		public TextualContent(Word.Application wordApp, Word.Document wordDocument, DocSectionTracking docSectionTracker)
16
		{
17
		{
17
         WordApp = wordApp;
18
         WordApp = wordApp;
18
         WordDocument = wordDocument;
19
         WordDocument = wordDocument;
-
 
20
         DocSectionTracker = docSectionTracker;
19
		}
21
		}
20
 
22
 
21
 
23
 
22
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
24
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
23
      {
25
      {
Line 108... Line 110...
108
      /// </summary>
110
      /// </summary>
109
      /// <param name="wordText"></param>
111
      /// <param name="wordText"></param>
110
      /// <param name="level"></param>
112
      /// <param name="level"></param>
111
      public void appendAndSelectHeadingText(string wordText, int level)
113
      public void appendAndSelectHeadingText(string wordText, int level)
112
      {
114
      {
-
 
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
 
113
         // Convert level to heading style
120
         // Convert level to heading style
114
         string styleText;
121
         string styleText;
115
         switch(level)
122
         switch(level)
116
         {
123
         {
117
            case 1: styleText = EA_Constants.styleName_Heading1; break;
124
            case 1: styleText = EA_Constants.styleName_Heading1; break;
Line 121... Line 128...
121
            case 5: styleText = EA_Constants.styleName_Heading5; break;
128
            case 5: styleText = EA_Constants.styleName_Heading5; break;
122
            case 6: styleText = EA_Constants.styleName_Heading6; break;
129
            case 6: styleText = EA_Constants.styleName_Heading6; break;
123
            case 7: styleText = EA_Constants.styleName_Heading7; break;
130
            case 7: styleText = EA_Constants.styleName_Heading7; break;
124
            case 8: styleText = EA_Constants.styleName_Heading8; break;
131
            case 8: styleText = EA_Constants.styleName_Heading8; break;
125
            case 9: styleText = EA_Constants.styleName_Heading9; break;
132
            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
 
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)
134
            default: 
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;
135
               // MS-Word cannot produce headings above level 9 and so we have to 
149
            case 5: styleText = EA_Constants.styleName_NumPara5; break;
136
               // fake a heading by constructing it from our document section tracking data.
150
            case 6: styleText = EA_Constants.styleName_NumPara6; break;
-
 
151
            case 7: styleText = EA_Constants.styleName_NumPara7; break;
137
               styleText = EA_Constants.styleName_Heading10OrAbove;
152
            case 8: styleText = EA_Constants.styleName_NumPara8; break;
138
               wordText = DocSectionTracker.formHeadingString(wordText);
153
            case 9: styleText = EA_Constants.styleName_NumPara9; break;
139
               break;
154
            default: styleText = EA_Constants.styleName_NumPara9; break;
-
 
155
         }
140
         }
156
         // append the text as a heading
141
         // append the text as a heading
157
         appendAndSelectText(wordText, styleText);
142
         appendAndSelectText(wordText, styleText);
158
      }
143
      }
159
 
144
 
160
 
145
 
161
      public string testSuiteName(EA.Element theElement)
146
      public string testSuiteName(EA.Element theElement)
162
      {
147
      {
163
         return "Test Suite - " + theElement.Name;
148
         return "Test Suite - " + theElement.Name;
164
      }
149
      }
165
 
150
 
166
 
151
 
167
      public void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList)
152
      public void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList, ref EA_Utilities EA_Utils)
168
      {
153
      {
-
 
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
 
169
         // only feed non-private classes through to the unit test section of a document
160
         // only feed non-private classes through to the unit test section of a document
170
         // NOTE: May need an override option for this filter.
161
         // NOTE: May need an override option for this filter.
171
         if (!theElement.Visibility.StartsWith("Private"))
162
         if (!theElement.Visibility.StartsWith("Private"))
172
         {
163
         {
173
            appendAndSelectHeadingText(testSuiteName(theElement), recurse_level+1);
164
            appendAndSelectHeadingText(testSuiteName(theElement), recurse_level+1);
Line 198... Line 189...
198
            }
189
            }
199
         }
190
         }
200
      }
191
      }
201
 
192
 
202
 
193
 
203
      public void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList)
194
      public void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList, ref EA_Utilities EA_Utils)
204
      {
195
      {
205
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
196
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
206
         EA.Element theElement = null;
197
         EA.Element theElement = null;
207
         int theElementsRelativeLevel = 0;
198
         int theElementsRelativeLevel = 0;
208
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
199
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
209
         {
200
         {
210
            do
201
            do
211
            {
202
            {
212
               if (theElement.Type.StartsWith("Class"))
203
               if (theElement.Type.StartsWith("Class"))
213
               {
204
               {
214
                  appendUnitTestSuite(theElement, recurse_level, ref classList);
205
                  appendUnitTestSuite(theElement, recurse_level, ref classList, ref EA_Utils);
215
               }
206
               }
216
 
207
 
217
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
208
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
218
         }
209
         }
219
 
210
 
220
         // Scan through the packages within this package.
211
         // Scan through the packages within this package.
221
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
212
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
222
         {
213
         {
223
            // recurse
214
            // recurse
224
            appendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList);
215
            appendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList, ref EA_Utils);
225
         }
216
         }
226
      }
217
      }
227
 
218
 
228
 
219
 
229
      public void SelectInsertionPointAtEndOfDocument()
220
      public void SelectInsertionPointAtEndOfDocument()
Line 243... Line 234...
243
      /// </summary>
234
      /// </summary>
244
      public bool generateRequirementText( EA.Element theElement, EA_Utilities EA_Utils )
235
      public bool generateRequirementText( EA.Element theElement, EA_Utilities EA_Utils )
245
      {
236
      {
246
         if ( theElement.Type.StartsWith("Requirement"))
237
         if ( theElement.Type.StartsWith("Requirement"))
247
         {
238
         {
248
            // Check for Richard Ho's requirement format
-
 
249
            if (EA_Utils.options.opt_DisplayRequirementsWithStatus == true)
-
 
250
            {
-
 
251
               string reqID = "";
239
            string reqID = "";
252
               string reqShortDesc = "";
240
            string reqShortDesc = "";
253
               string reqNotes = "";
241
            string reqNotes = "";
254
               string reqStatusText = "";
242
            string reqStatusText = "";
255
               string reqHeadingStyle ="";
243
            string reqHeadingStyle ="";
256
               string reqParaStyle = "";
244
            string reqParaStyle = "";
257
               object reqNameStyle = EA_Constants.styleName_ReqName;
245
            object reqNameStyle = EA_Constants.styleName_ReqName;
258
               Word.Range shortDescRange;
246
            Word.Range shortDescRange;
259
 
247
 
260
               // Set the style depending on the status
248
            // Set the style depending on the status
261
               switch ( theElement.Status )
249
            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
            {
250
            {
-
 
251
               case "Proposed":
-
 
252
                  reqStatusText = "(Proposed)";
-
 
253
                  reqHeadingStyle = EA_Constants.styleName_ReqPropHdr;
-
 
254
                  reqParaStyle    = EA_Constants.styleName_ReqPropBody;
316
               string s;
255
                  break;
-
 
256
 
-
 
257
               case "Rejected":
317
               s = EA_Utils.options.opt_RequirementElementDisplayFormat;
258
                  reqHeadingStyle = EA_Constants.styleName_ReqRejHdr;
-
 
259
                  reqParaStyle    = EA_Constants.styleName_ReqRejBody;
-
 
260
                  break;
-
 
261
 
-
 
262
               case "Approved":
318
               s = s.Replace(@"%s",@"{0}");
263
                  //reqStatusText = "(Approved)";
-
 
264
                  //reqStatusText = "(Phase " + theElement.Phase + ")";
319
               Word.Range WordRange = appendAndSelectText( String.Format( s, theElement.Name ), EA_Constants.styleName_Body1);
265
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
-
 
266
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
320
               WordRange.Font.Bold = 1;
267
                  break;
321
 
268
 
-
 
269
               default:
-
 
270
                  reqStatusText = "(" + theElement.Status + ")";
-
 
271
                  //reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";
-
 
272
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
322
               appendAndSelectText( theElement.Notes, EA_Constants.styleName_Body1 );
273
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
323
               return true;
274
                  break;
324
            }
275
            }
-
 
276
 
-
 
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 );
-
 
280
 
-
 
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();
-
 
284
 
-
 
285
            // Pull out the notes
-
 
286
            reqNotes = theElement.Notes.ToString();
-
 
287
 
-
 
288
            // Add the text
-
 
289
            appendAndSelectText( reqID + '\t', reqHeadingStyle );
-
 
290
            shortDescRange = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
-
 
291
            Word.Range WordRange = appendAndSelectText( '\t' + reqStatusText, reqHeadingStyle, true );
-
 
292
 
-
 
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 );
-
 
297
 
-
 
298
            appendAndSelectText( reqNotes, reqParaStyle );
-
 
299
            return true;
-
 
300
            
325
         }
301
         }
326
 
302
 
327
         return false;
303
         return false;
328
      }
304
      }
329
 
305