Rev 2098 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using System.Collections;using Word;namespace EA_DocGen{/// <summary>/// Summary description for TextualContent./// </summary>public class TextualContent{private Word.Application WordApp = null;private Word.Document WordDocument = null;public TextualContent(Word.Application wordApp, Word.Document wordDocument){WordApp = wordApp;WordDocument = wordDocument;}public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument){WordApp = wordApp;WordDocument = wordDocument;}public Word.Range appendDescription(string wordText, EA_Utilities EA_Utils){Word.Range wr = null;if (wordText != null && wordText.Length > 0)wr = appendAndSelectText(wordText, EA_Constants.styleName_Body1);else if (!EA_Utils.options.opt_SuppressElementDescriptionMissingWarnings){wr = appendAndSelectText("Description missing!", EA_Constants.styleName_Body1);wr.Font.Italic = 1;wr.Font.Color = Word.WdColor.wdColorRed;}return wr;}/// <summary>/// Appends a specified text string to the word document, selects the new text, and applies/// the specified style formatting to it./// </summary>/// <param name="wordText"></param>/// <param name="styleText"></param>/// <param name="continuation"></param>public Word.Range appendAndSelectText(string wordText, string styleText){return appendAndSelectText(wordText, styleText, false );}public Word.Range appendAndSelectText(string wordText, string styleText, bool continuation ){if (wordText.Length > 0){Word.Range WordRange = null;object startLocation;object endLocation;object style = styleText;int i;startLocation = 0;endLocation = i = WordDocument.Content.End;WordRange = WordDocument.Range(ref startLocation, ref endLocation);if (!continuation)WordRange.InsertAfter( "\n" );WordRange.InsertAfter( wordText );// Make a range out of the pasted textstartLocation = i;endLocation = WordDocument.Content.End;WordRange = WordDocument.Range(ref startLocation, ref endLocation);// and set the pasted text styleWordRange.set_Style(ref style);return WordRange;}return null;}/// <summary>/// Appends a specified text string to the word document, selects the new text, and applies/// a heading level style to it./// </summary>/// <param name="wordText"></param>/// <param name="level"></param>public void appendAndSelectHeadingText(string wordText, int level){// Convert level to heading stylestring styleText;switch(level){case 1: styleText = EA_Constants.styleName_Heading1; break;case 2: styleText = EA_Constants.styleName_Heading2; break;case 3: styleText = EA_Constants.styleName_Heading3; break;case 4: styleText = EA_Constants.styleName_Heading4; break;case 5: styleText = EA_Constants.styleName_Heading5; break;case 6: styleText = EA_Constants.styleName_Heading6; break;case 7: styleText = EA_Constants.styleName_Heading7; break;case 8: styleText = EA_Constants.styleName_Heading8; break;case 9: styleText = EA_Constants.styleName_Heading9; break;default: styleText = EA_Constants.styleName_Heading9; break;}// append the text as a headingappendAndSelectText(wordText, styleText);}/// <summary>/// Appends a specified text string to the word document, selects the new text, and applies/// a num para heading level style to it./// </summary>/// <param name="wordText"></param>/// <param name="level"></param>public void appendAndSelectNumParaText(string wordText, int level){// Convert level to heading stylestring styleText;switch(level){case 1: styleText = EA_Constants.styleName_NumPara1; break;case 2: styleText = EA_Constants.styleName_NumPara2; break;case 3: styleText = EA_Constants.styleName_NumPara3; break;case 4: styleText = EA_Constants.styleName_NumPara4; break;case 5: styleText = EA_Constants.styleName_NumPara5; break;case 6: styleText = EA_Constants.styleName_NumPara6; break;case 7: styleText = EA_Constants.styleName_NumPara7; break;case 8: styleText = EA_Constants.styleName_NumPara8; break;case 9: styleText = EA_Constants.styleName_NumPara9; break;default: styleText = EA_Constants.styleName_NumPara9; break;}// append the text as a headingappendAndSelectText(wordText, styleText);}public string testSuiteName(EA.Element theElement){return "Test Suite - " + theElement.Name;}public void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList){// only feed non-private classes through to the unit test section of a document// NOTE: May need an override option for this filter.if (!theElement.Visibility.StartsWith("Private")){appendAndSelectHeadingText(testSuiteName(theElement), recurse_level+1);if (theElement.Tests.Count > 0){classList.Add( theElement.ElementID );foreach(EA.Test theTest in theElement.Tests){appendAndSelectHeadingText("Test Case - " + theTest.Name, recurse_level+2);appendAndSelectHeadingText("Description", recurse_level+3);appendAndSelectText(theTest.Notes, EA_Constants.styleName_Body1);appendAndSelectHeadingText("Inputs", recurse_level+3);appendAndSelectText(theTest.Input, EA_Constants.styleName_Body1);appendAndSelectHeadingText("Expected Results", recurse_level+3);appendAndSelectText(theTest.AcceptanceCriteria, EA_Constants.styleName_Body1);}}else{Word.Range wr = appendAndSelectText("Test Cases missing!", EA_Constants.styleName_Body1);wr.Font.Italic = 1;wr.Font.Color = Word.WdColor.wdColorRed;}}}public void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList){EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);EA.Element theElement = null;int theElementsRelativeLevel = 0;if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel)){do{if (theElement.Type.StartsWith("Class")){appendUnitTestSuite(theElement, recurse_level, ref classList);}} while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));}// Scan through the packages within this package.foreach(EA.Package lowerLevelPackage in thePackage.Packages){// recurseappendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList);}}public void SelectInsertionPointAtEndOfDocument(){object unit;object extend;unit = Word.WdUnits.wdStory;extend = Word.WdMovementType.wdMove;WordApp.Selection.EndKey(ref unit, ref extend);}/// <summary>/// Generates the text for requirements. This uses custom styles to format the text/// rather than formatting it in code./// </summary>public bool generateRequirementText( EA.Element theElement, EA_Utilities EA_Utils ){if ( theElement.Type.StartsWith("Requirement")){// Check for Richard Ho's requirement formatif (EA_Utils.options.opt_DisplayRequirementsWithStatus == true){string reqID = "";string reqShortDesc = "";string reqNotes = "";string reqStatusText = "";string reqHeadingStyle ="";string reqParaStyle = "";object reqNameStyle = EA_Constants.styleName_ReqName;Word.Range shortDescRange;// Set the style depending on the statusswitch ( theElement.Status ){case "Proposed":reqStatusText = "(Proposed)";reqHeadingStyle = EA_Constants.styleName_ReqPropHdr;reqParaStyle = EA_Constants.styleName_ReqPropBody;break;case "Rejected":reqHeadingStyle = EA_Constants.styleName_ReqRejHdr;reqParaStyle = EA_Constants.styleName_ReqRejBody;break;case "Approved"://reqStatusText = "(Approved)";//reqStatusText = "(Phase " + theElement.Phase + ")";reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;reqParaStyle = EA_Constants.styleName_ReqAppBody;break;default:reqStatusText = "(" + theElement.Status + ")";//reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;reqParaStyle = EA_Constants.styleName_ReqAppBody;break;}// Pull out the ID from the nameint pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );reqID = theElement.Name.Substring( 0, pos );// Pull out the short description from the rest of the namereqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );reqShortDesc = reqShortDesc.Trim();// Pull out the notesreqNotes = theElement.Notes.ToString();// Add the textappendAndSelectText( reqID + '\t', reqHeadingStyle );shortDescRange = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );Word.Range WordRange = appendAndSelectText( '\t' + reqStatusText, reqHeadingStyle, true );//reapply the name char style to the short desc.shortDescRange.Start = shortDescRange.Start-1;shortDescRange.End = WordRange.Start-1;shortDescRange.set_Style( ref reqNameStyle );appendAndSelectText( reqNotes, reqParaStyle );return true;}//else if (EA_Utils.options.opt_DisplayRequirementElementsAsSections == false){string s;s = EA_Utils.options.opt_RequirementElementDisplayFormat;s = s.Replace(@"%s",@"{0}");Word.Range WordRange = appendAndSelectText( String.Format( s, theElement.Name ), EA_Constants.styleName_Body1);WordRange.Font.Bold = 1;appendAndSelectText( theElement.Notes, EA_Constants.styleName_Body1 );return true;}}return false;}}}