Rev 2153 | 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{public EA_Utilities(){}/// <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 static void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse){worker.processPackage( thePackage );foreach (EA.Element theElement in thePackage.Elements){worker.processElement( theElement );if (Main.mustAbort)return;}if (recurse == true){foreach (EA.Package subPackage in thePackage.Packages){// RECURSIONfindAndProcessPackageElements( subPackage, worker, true);if (Main.mustAbort)return;}}}public static void deletePackage(EA.Package packageToDelete){EA.Package parentPackage = Main.EA_Repository.GetPackageByID(packageToDelete.ParentID);if (parentPackage != null){short i = 0;foreach(EA.Package pkg in parentPackage.Packages){if (pkg.PackageID == packageToDelete.PackageID){parentPackage.Packages.Delete(i);break;}i++;}parentPackage.Packages.Refresh();}}public static EA.Element get_selected_element(ArrayList allowedElementTypes){object o;EA.ObjectType type;type = Main.EA_Repository.GetTreeSelectedItem(out o);if (type == EA.ObjectType.otElement){if (allowedElementTypes == null)return (EA.Element)o;if (allowedElementTypes.Contains( ((EA.Element)o).Type ))return (EA.Element)o;}return null;}public static EA.Package get_selected_package(){object o;EA.ObjectType type;type = Main.EA_Repository.GetTreeSelectedItem(out o);if (type == EA.ObjectType.otElement){return Main.EA_Repository.GetPackageByID(((EA.Element)o).PackageID);}else if (type == EA.ObjectType.otDiagram){return Main.EA_Repository.GetPackageByID(((EA.Diagram)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 static 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;}/// <summary>/// Adds a connection between one EA element and another/// </summary>/// <param name="repository"></param>/// <param name="rq_artifact"></param>/// <param name="ea_req"></param>public static void add_connection(EA.Element src_element, EA.Element dest_element){if (false == ea_element_traces_to_or_from(src_element, dest_element)){// Add the new connection between the src_element and dest_elementEA.Connector c = (EA.Connector)src_element.Connectors.AddNew("", "Dependency");c.SupplierID = dest_element.ElementID;c.Direction = "Source -> Destination";c.Update();src_element.Connectors.Refresh();}}private static bool ea_element_traces_to_or_from(EA.Element src_element, EA.Element dest_element){foreach(EA.Connector ea_c in src_element.Connectors){int destId = -1;// we dont care about direction of relationship, so test for bothif (ea_c.ClientID == src_element.ElementID)destId = ea_c.SupplierID;else if (ea_c.SupplierID == src_element.ElementID)destId = ea_c.ClientID;// and make sure we filter out self-referential connectorsif (destId != src_element.ElementID){if (destId == dest_element.ElementID)return true;}}return false;}public static void DumpEAElement(){EA.Element ea_ele = (EA.Element)Main.EA_Repository.GetTreeSelectedObject();Main.WriteOutput("EA Element : " + ea_ele.Name, ea_ele.ElementID);Main.WriteOutput( "Author : " + ea_ele.Author, -1);Main.WriteOutput( "ClassfierID : " + ea_ele.ClassfierID.ToString(), -1);Main.WriteOutput( "ClassifierName : " + ea_ele.ClassifierName, -1);Main.WriteOutput( "ClassifierType : " + ea_ele.ClassifierType, -1);Main.WriteOutput( "Complexity : " + ea_ele.Complexity, -1);Main.WriteOutput( "Difficulty : " + ea_ele.Difficulty, -1);Main.WriteOutput( "ElementGUID : " + ea_ele.ElementGUID, -1);Main.WriteOutput( "ElementID : " + ea_ele.ElementID.ToString(), ea_ele.ElementID);Main.WriteOutput( "EventFlags : " + ea_ele.EventFlags, -1);Main.WriteOutput( "ExtensionPoints : " + ea_ele.ExtensionPoints, -1);Main.WriteOutput( "Genfile : " + ea_ele.Genfile, -1);Main.WriteOutput( "Genlinks : " + ea_ele.Genlinks, -1);Main.WriteOutput( "Gentype : " + ea_ele.Gentype, -1);Main.WriteOutput( "GetLastError : " + ea_ele.GetLastError(), -1);Main.WriteOutput( "GetLinkedDocument : " + ea_ele.GetLinkedDocument(), -1);Main.WriteOutput( "GetStereotypeList : " + ea_ele.GetStereotypeList(), -1);Main.WriteOutput( "MetaType : " + ea_ele.MetaType, -1);Main.WriteOutput( "Multiplicity : " + ea_ele.Multiplicity, -1);Main.WriteOutput( "Notes : " + ea_ele.Notes, -1);Main.WriteOutput( "PackageID : " + ea_ele.PackageID.ToString(), ea_ele.PackageID);Main.WriteOutput( "ParentID : " + ea_ele.ParentID.ToString(), ea_ele.ParentID);Main.WriteOutput( "Persistence : " + ea_ele.Persistence, -1);Main.WriteOutput( "Phase : " + ea_ele.Phase, -1);Main.WriteOutput( "Priority : " + ea_ele.Priority, -1);Main.WriteOutput( "PropertyType : " + ea_ele.PropertyType.ToString(), -1);Main.WriteOutput( "RunState : " + ea_ele.RunState, -1);Main.WriteOutput( "Status : " + ea_ele.Status, -1);Main.WriteOutput( "Stereotype : " + ea_ele.Stereotype, -1);Main.WriteOutput( "StereotypeEx : " + ea_ele.StereotypeEx, -1);Main.WriteOutput( "StyleEx : " + ea_ele.StyleEx, -1);Main.WriteOutput( "Subtype : " + ea_ele.Subtype.ToString(), -1);Main.WriteOutput( "Tablespace : " + ea_ele.Tablespace, -1);Main.WriteOutput( "Tag : " + ea_ele.Tag, -1);Main.WriteOutput( "TreePos : " + ea_ele.TreePos.ToString(), -1);Main.WriteOutput( "Type : " + ea_ele.Type, -1);Main.WriteOutput( "Version : " + ea_ele.Version, -1);Main.WriteOutput( "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 );}}}}