Rev 2096 | Rev 2104 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using System.Windows.Forms;using System.IO;using System.Collections;using System.Collections.Specialized;using System.Text;namespace EA_DocGen{/// <summary>/// Summary description for EA_DocGenOptions./// </summary>public class EA_DocGenOptions{public const string optstr_GeneralOptions = "[GeneralOptions]";public const string optstr_ElementTypes = "[ElementTypes]";public const string optstr_ElementHeadingStyleTransitionsToNumParaAtLevel = "ElementHeadingStyleTransitionsToNumParaAtLevel";public const string optstr_DisplayRequirementElementsAsSections = "DisplayRequirementElementsAsSections";public const string optstr_RequirementElementDisplayFormat = "RequirementElementDisplayFormat";public const string optstr_DisplayRequirementsWithStatus = "DisplayRequirementsWithStatus";public const string optstr_SuppressElementDescriptionMissingWarnings = "SuppressElementDescriptionMissingWarnings";public const string optstr_SuppressPrivateAttributes = "SuppressPrivateAttributes";public const string optstr_SuppressPrivateMethods = "SuppressPrivateMethods";public const string optstr_SuppressPrivateClasses = "SuppressPrivateClasses";private string [] options_string = null;private bool options_found = false;// General optionspublic int opt_ElementHeadingTransitionLevel;public bool opt_DisplayRequirementElementsAsSections;public string opt_RequirementElementDisplayFormat;public bool opt_SuppressElementDescriptionMissingWarnings;public bool opt_DisplayRequirementsWithStatus;// Visibility optionspublic bool opt_SuppressPrivateAttributes;public bool opt_SuppressPrivateMethods;public bool opt_SuppressPrivateClasses;// Element Types listpublic ArrayList opt_ElementTypes = null;private EA_Utilities EA_Utils = null;public EA_DocGenOptions(EA_Utilities EA_UtilsRef){EA_Utils = EA_UtilsRef;opt_ElementTypes = new ArrayList();setDefaults();}private void setDefaults(){opt_ElementHeadingTransitionLevel = 0;opt_DisplayRequirementElementsAsSections = false;opt_RequirementElementDisplayFormat = "[REQUIREMENT: %s]";opt_DisplayRequirementsWithStatus = true;opt_SuppressElementDescriptionMissingWarnings = false;opt_SuppressPrivateAttributes = true;opt_SuppressPrivateMethods = true;opt_SuppressPrivateClasses = true;}/// <summary>/// Looks for the EA_DocGen element in the selected package. To generate a document/// on a package, the package must contain the EA_DocGen element, even if that elements/// notes are empty. It serves to denote a package as a document model that is allowed/// to be processed by this add-in./// </summary>/// <param name="parentPackage"></param>/// <returns></returns>public bool lookForAndProcess_EA_DocGen_Element( EA.Package parentPackage ){options_found = false;setDefaults();// Look for an EA_DocGen element in this packageforeach(EA.Element theElement in parentPackage.Elements){options_found = lookForAndProcess_EA_DocGen_Element(theElement);if (options_found)break;}return options_found;}public bool lookForAndProcess_EA_DocGen_Element( EA.Element theElement ){options_string = null;options_found = false;setDefaults();// Special handling for the EA_DocGen element designed to control this document// generatorif (0 == theElement.Name.CompareTo(EA_Constants.EA_DocGenBaseName)){options_found = true;// Extract the content of the EA_DocGen element notes section, into a list of// strings.string delimStr = "\n";char [] delim = delimStr.ToCharArray();options_string = theElement.Notes.ToString().Split(delim,200);int i = 0;foreach(string s in options_string){options_string[i] = s.Trim();i++;}// Extract general options from the list of stringsextractGeneralOptions();// Extract element types list from the list of stringsextractElementTypes();}return options_found;}private string getOptionValueString(string optionLine){string delimStr = "=";char [] delim = delimStr.ToCharArray();string [] optionLineParts = optionLine.Split(delim,2);if (optionLineParts.GetLength(0) == 2){return optionLineParts[1];}else{MessageBox.Show( "Error in EA_DocGen option\n\n" + optionLine + "\n\n" + "Missing value" );}return null;}// Overloaded "get option value" methodspublic int getOptionValue(string s, int defaultReturnValue){int returnVal = defaultReturnValue;string optionValue = getOptionValueString(s);if (optionValue != null){try{returnVal = Convert.ToInt32(optionValue);}catch(Exception){MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid integer" );}}return returnVal;}public double getOptionValue(string s, double defaultReturnValue){double returnVal = defaultReturnValue;string optionValue = getOptionValueString(s);if (optionValue != null){try{returnVal = Convert.ToDouble(optionValue);}catch(Exception){MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid double" );}}return returnVal;}public bool getOptionValue(string s, bool defaultReturnValue){bool returnVal = defaultReturnValue;string optionValue = getOptionValueString(s);if (optionValue != null){try{returnVal = Convert.ToBoolean(optionValue);}catch(Exception){MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid boolean" );}}return returnVal;}public string getOptionValue(string s, string defaultReturnValue){string returnVal = defaultReturnValue;string optionValue = getOptionValueString(s);if (optionValue != null){returnVal = optionValue;}return returnVal;}public char getOptionValue(string s, char defaultReturnValue){char returnVal = defaultReturnValue;string optionValue = getOptionValueString(s);if (optionValue != null && optionValue.Length > 0){returnVal = optionValue[0];}return returnVal;}/// <summary>/// Method to extract all the general options from the string array obtained from/// the EA_DocGen element/// </summary>private void extractGeneralOptions(){bool parsingGenOpts = false;if (options_string != null){// iterate through the string array obtained from the EA_DocGen elementforeach(string s in options_string){if (s.StartsWith(optstr_GeneralOptions)){parsingGenOpts = true;continue;}else if ( (parsingGenOpts == true)&& (s.Length >= 1)&& (s.Substring(0,1) == "[") ){// we have gone past the general options and reached another section in EA_DocGen// so there is no point in continuing. Exit the loopbreak;}if (parsingGenOpts == true){if (s.StartsWith(optstr_ElementHeadingStyleTransitionsToNumParaAtLevel)){opt_ElementHeadingTransitionLevel = getOptionValue(s, opt_ElementHeadingTransitionLevel);}else if (s.StartsWith(optstr_DisplayRequirementElementsAsSections)){opt_DisplayRequirementElementsAsSections = getOptionValue(s, opt_DisplayRequirementElementsAsSections);}else if (s.StartsWith(optstr_RequirementElementDisplayFormat)){opt_RequirementElementDisplayFormat = getOptionValue(s, opt_RequirementElementDisplayFormat);}else if (s.StartsWith(optstr_DisplayRequirementsWithStatus)){opt_DisplayRequirementsWithStatus = getOptionValue(s, opt_DisplayRequirementsWithStatus);}else if (s.StartsWith(optstr_SuppressElementDescriptionMissingWarnings)){opt_SuppressElementDescriptionMissingWarnings = getOptionValue(s, opt_SuppressElementDescriptionMissingWarnings);}else if (s.StartsWith(optstr_SuppressPrivateClasses)){opt_SuppressPrivateClasses = getOptionValue(s, opt_SuppressPrivateClasses);}else if (s.StartsWith(optstr_SuppressPrivateAttributes)){opt_SuppressPrivateAttributes = getOptionValue(s, opt_SuppressPrivateAttributes);}else if (s.StartsWith(optstr_SuppressPrivateMethods)){opt_SuppressPrivateMethods = getOptionValue(s, opt_SuppressPrivateMethods);}// add others here}}}}private void extractElementTypes(){bool parsingElementTypes = false;opt_ElementTypes.Clear();if (options_string != null){// iterate through the string array obtained from the EA_DocGen elementforeach(string s in options_string){if (s.StartsWith(optstr_ElementTypes)){parsingElementTypes = true;continue;}else if ( (parsingElementTypes == true)&& (s.Length >= 1)&& (s.Substring(0,1) == "[") ){// we have gone past the element types and reached another section in EA_DocGen// so there is no point in continuing. Exit the loopbreak;}if (parsingElementTypes == true){string trimmed_s = s.Trim();if (trimmed_s.Length > 0){opt_ElementTypes.Add( s );}}}}}/// <summary>/// This method searches the EA_DocGen string list to find the element types the user/// has specified that must be included in the document. If the element type given to/// the function is not in that list then it is excluded from the generated document./// The notes of the EA_DocGen element are formed like a .ini file and contain sections/// and section content along the lines of:////// [sectionName]/// value/// value/// etc/// [anotherSectionName]/// value/// value/// etc////// The [ElementTypes] section is the one this function is interested in////// </summary>/// <param name="elementName"></param>/// <returns></returns>public bool elementTypeFoundInEA_DocGen(string elementType){if (opt_ElementTypes != null && opt_ElementTypes.Count > 0){foreach(string s in opt_ElementTypes){if (s.StartsWith(elementType)){return true;}}// elementType is not in the opt_ElementTypes list, so element is filtered outreturn false;}else{// opt_ElementTypes is empty so no filtering, return truereturn true;}}private void updateEA_DocGen(ref StringBuilder sb, bool bValue, string s){sb.Append( s );sb.Append( "=" );sb.Append( bValue.ToString() );sb.Append( "\r\n" );}private void updateEA_DocGen(ref StringBuilder sb, int iValue, string s){sb.Append( s );sb.Append( "=" );sb.Append( iValue.ToString() );sb.Append( "\r\n" );}public void updateEA_DocGen(EA.Element ele){StringBuilder sb = new StringBuilder();sb.Append( optstr_GeneralOptions );sb.Append( "\r\n" );// Requirement Display optionsif (opt_DisplayRequirementsWithStatus){sb.Append( optstr_DisplayRequirementsWithStatus );sb.Append( "=true\r\n" );sb.Append( optstr_DisplayRequirementElementsAsSections );sb.Append( "=false\r\n" );}else if (opt_DisplayRequirementElementsAsSections){sb.Append( optstr_DisplayRequirementsWithStatus );sb.Append( "=false\r\n" );sb.Append( optstr_DisplayRequirementElementsAsSections );sb.Append( "=true\r\n" );}else{sb.Append( optstr_DisplayRequirementsWithStatus );sb.Append( "=false\r\n" );sb.Append( optstr_DisplayRequirementElementsAsSections );sb.Append( "=false\r\n" );sb.Append( optstr_RequirementElementDisplayFormat );sb.Append( "=" );sb.Append( opt_RequirementElementDisplayFormat );sb.Append( "\r\n" );}// Missing Description handling optionsupdateEA_DocGen(ref sb, opt_SuppressElementDescriptionMissingWarnings, optstr_SuppressElementDescriptionMissingWarnings);// NumPara transition optionupdateEA_DocGen(ref sb, opt_ElementHeadingTransitionLevel, optstr_ElementHeadingStyleTransitionsToNumParaAtLevel);// visibility optionsupdateEA_DocGen(ref sb, opt_SuppressPrivateClasses, optstr_SuppressPrivateClasses);updateEA_DocGen(ref sb, opt_SuppressPrivateAttributes, optstr_SuppressPrivateAttributes);updateEA_DocGen(ref sb, opt_SuppressPrivateMethods, optstr_SuppressPrivateMethods);// Element type filtering optionsif (opt_ElementTypes.Count > 0){sb.Append( "\r\n" );sb.Append( optstr_ElementTypes );sb.Append( "\r\n" );foreach (string s in opt_ElementTypes){sb.Append( s );sb.Append( "\r\n" );}}ele.Notes = sb.ToString();ele.Update();}} // end of class} // end of namespace