Rev 2141 | Blame | Last modification | View Log | RSS feed
using System;using System.Text;using System.Globalization;using System.Collections;using System.Windows.Forms;using ReqPro40;namespace EA_ReqPro{/// <summary>/// Summary description for EA_Utils./// </summary>public class EA_Utilities{EA.Repository EA_Repository = null;public EA_Utilities(EA.Repository theRepository){EA_Repository = theRepository;}/// <summary>/// This function is designed to parse EA models/packages in a predefined way, whilst allowing/// a user to specify what processing is to be done upon or with each element found./// </summary>/// <param name="thePackage"></param>/// <param name="worker"></param>/// <param name="recurse"></param>public void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse){worker.processPackage( thePackage );foreach (EA.Element theElement in thePackage.Elements){worker.processElement( theElement );}if (recurse == true){foreach (EA.Package subPackage in thePackage.Packages){// RECURSIONfindAndProcessPackageElements( subPackage, worker, true);}}}public string ReadTag(EA.Element theElement, string tagName){string result;EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);if (null != tag){result = tag.Value;}else{result = "";}return result;}public bool WriteTag(EA.Element theElement, string tagName, string value){bool result;EA.TaggedValue tag;tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);if (null != tag){tag.Value = value;}else{tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);}if (tag != null){result = tag.Update();}else{result = false;}return result;}public EA.Package get_selected_package(){object o;EA.ObjectType type;type = EA_Repository.GetTreeSelectedItem(out o);if (type == EA.ObjectType.otElement){return EA_Repository.GetPackageByID( ((EA.Element)o).PackageID );}else if (type == EA.ObjectType.otPackage){return (EA.Package)o;}return null;}/// <summary>/// Creates a package under the specified parent package. the package is given a tree position/// as specified in order for it to be ordered in the model as the caller requires./// </summary>/// <param name="parentPackage"></param>/// <param name="name"></param>/// <param name="treePos"></param>/// <returns></returns>public EA.Package createPackage(EA.Package parentPackage, string name, int treePos){EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");newobj.TreePos = treePos;newobj.Update();return newobj;}public void DumpEAElement(EA.Repository repository){EA.Element ea_ele = (EA.Element)repository.GetTreeSelectedObject();repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Element : " + ea_ele.Name, ea_ele.ElementID);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Author : " + ea_ele.Author, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ClassfierID : " + ea_ele.ClassfierID.ToString(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ClassifierName : " + ea_ele.ClassifierName, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ClassifierType : " + ea_ele.ClassifierType, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Complexity : " + ea_ele.Complexity, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Difficulty : " + ea_ele.Difficulty, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ElementGUID : " + ea_ele.ElementGUID, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ElementID : " + ea_ele.ElementID.ToString(), ea_ele.ElementID);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EventFlags : " + ea_ele.EventFlags, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ExtensionPoints : " + ea_ele.ExtensionPoints, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Genfile : " + ea_ele.Genfile, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Genlinks : " + ea_ele.Genlinks, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Gentype : " + ea_ele.Gentype, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "GetLastError : " + ea_ele.GetLastError(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "GetLinkedDocument : " + ea_ele.GetLinkedDocument(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "GetStereotypeList : " + ea_ele.GetStereotypeList(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "MetaType : " + ea_ele.MetaType, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Multiplicity : " + ea_ele.Multiplicity, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Notes : " + ea_ele.Notes, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "PackageID : " + ea_ele.PackageID.ToString(), ea_ele.PackageID);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ParentID : " + ea_ele.ParentID.ToString(), ea_ele.ParentID);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Persistence : " + ea_ele.Persistence, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Phase : " + ea_ele.Phase, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Priority : " + ea_ele.Priority, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "PropertyType : " + ea_ele.PropertyType.ToString(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "RunState : " + ea_ele.RunState, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Status : " + ea_ele.Status, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Stereotype : " + ea_ele.Stereotype, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "StereotypeEx : " + ea_ele.StereotypeEx, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "StyleEx : " + ea_ele.StyleEx, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Subtype : " + ea_ele.Subtype.ToString(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Tablespace : " + ea_ele.Tablespace, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Tag : " + ea_ele.Tag, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "TreePos : " + ea_ele.TreePos.ToString(), -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Type : " + ea_ele.Type, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Version : " + ea_ele.Version, -1);repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Visibility : " + ea_ele.Visibility, -1);}}/// <summary>/// A Base Class designed to work with the findAndProcessPackageElements method./// Users will normally derive their own classes from this and add real functionality/// to the over-ridable methods the base class provides./// </summary>public class EA_UtilitiesRecursionWorker{public EA_UtilitiesRecursionWorker(){}public virtual void processElement( EA.Element theElement ){}public virtual void processPackage( EA.Package thePackage ){}}/// <summary>/// This class is one derived from the EA_UtilitiesRecursionWorker base class so that/// an instance of it can be used as a parameter in the EA_Utilities.findAndProcessPackageElements/// method which recursively parses a given package. Thus, clients can parse EA model structure but/// specify their own functionality to be carried out on packages and elements found in the/// parsing./// This particular derived class is designed to collect a list of element names from the/// package, from elements that have a type that is acceptable./// </summary>public class ElementAccumulator : EA_UtilitiesRecursionWorker{public ArrayList Elements = null;public ArrayList ElementIDs = null;private ArrayList validElementTypes = null;public ElementAccumulator(ArrayList elementTypeList): base(){validElementTypes = elementTypeList;Elements = new ArrayList();ElementIDs = new ArrayList();}public override void processElement( EA.Element theElement ){if (validElementTypes.Contains( theElement.Type )){Elements.Add( theElement );ElementIDs.Add( theElement.ElementID );}}}}