Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2139 ghuddy 1
 
2151 ghuddy 2
using System;
3
using System.Text;
4
using System.Globalization;
5
using System.Collections;
6
using System.Windows.Forms;
2141 ghuddy 7
using ReqPro40;
2139 ghuddy 8
 
9
namespace EA_ReqPro
10
{
11
	/// <summary>
12
	/// Summary description for EA_Utils.
13
	/// </summary>
14
	public class EA_Utilities
15
	{
16
 
2151 ghuddy 17
		public EA_Utilities()
2139 ghuddy 18
		{
19
		}
20
 
21
      /// <summary>
22
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
23
      /// a user to specify what processing is to be done upon or with each element found.
24
      /// </summary>
25
      /// <param name="thePackage"></param>
26
      /// <param name="worker"></param>
27
      /// <param name="recurse"></param>
2153 ghuddy 28
      public static void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
2139 ghuddy 29
      {
30
         worker.processPackage( thePackage );
31
 
32
         foreach (EA.Element theElement in thePackage.Elements)
33
         {
34
            worker.processElement( theElement );
2155 ghuddy 35
 
36
            if (Main.mustAbort)
37
               return;
2139 ghuddy 38
         }
39
 
40
         if (recurse == true)
41
         {
42
            foreach (EA.Package subPackage in thePackage.Packages)
43
            {
44
               // RECURSION
45
               findAndProcessPackageElements( subPackage, worker, true);
2155 ghuddy 46
 
47
               if (Main.mustAbort)
48
                  return;
2139 ghuddy 49
            }         
50
         }
51
      }
52
 
2155 ghuddy 53
      public static void deletePackage(EA.Package packageToDelete)
2151 ghuddy 54
      {
2155 ghuddy 55
         EA.Package parentPackage = Main.EA_Repository.GetPackageByID(packageToDelete.ParentID);
56
         if (parentPackage != null)
2151 ghuddy 57
         {
2155 ghuddy 58
            short i = 0;
59
            foreach(EA.Package pkg in parentPackage.Packages)
60
            {
61
               if (pkg.PackageID == packageToDelete.PackageID)
62
               {
63
                  parentPackage.Packages.Delete(i);
64
                  break;
65
               }
66
               i++;
67
            }
68
            parentPackage.Packages.Refresh();
2151 ghuddy 69
         }
70
      }
2139 ghuddy 71
 
2155 ghuddy 72
      public static EA.Element get_selected_element(ArrayList allowedElementTypes)
73
      {
74
         object o;
75
         EA.ObjectType type;
2151 ghuddy 76
 
2155 ghuddy 77
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
78
         if (type == EA.ObjectType.otElement)
2151 ghuddy 79
         {
2155 ghuddy 80
            if (allowedElementTypes == null)
81
               return (EA.Element)o;
2151 ghuddy 82
 
2155 ghuddy 83
            if (allowedElementTypes.Contains( ((EA.Element)o).Type ))
84
               return (EA.Element)o;
2151 ghuddy 85
         }
2155 ghuddy 86
         return null;
2151 ghuddy 87
      }
88
 
2153 ghuddy 89
      public static EA.Package get_selected_package()
2145 ghuddy 90
      {
2151 ghuddy 91
         object o;
92
         EA.ObjectType type;
2145 ghuddy 93
 
2151 ghuddy 94
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
95
         if (type == EA.ObjectType.otElement)
96
         {
2155 ghuddy 97
            return Main.EA_Repository.GetPackageByID(((EA.Element)o).PackageID);
2145 ghuddy 98
         }
2155 ghuddy 99
         else if (type == EA.ObjectType.otDiagram)
100
         {
101
            return Main.EA_Repository.GetPackageByID(((EA.Diagram)o).PackageID);
102
         }
2151 ghuddy 103
         else if (type == EA.ObjectType.otPackage)
104
         {
105
            return (EA.Package)o;
106
         }
2145 ghuddy 107
         return null;
108
      }
109
 
2141 ghuddy 110
      /// <summary>
111
      /// Creates a package under the specified parent package. the package is given a tree position
112
      /// as specified in order for it to be ordered in the model as the caller requires.
113
      /// </summary>
114
      /// <param name="parentPackage"></param>
115
      /// <param name="name"></param>
116
      /// <param name="treePos"></param>
117
      /// <returns></returns>
2153 ghuddy 118
      public static EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
2141 ghuddy 119
      {
120
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
121
         newobj.TreePos = treePos;
122
         newobj.Update();
123
         return newobj;
124
      }
125
 
2155 ghuddy 126
      /// <summary>
127
      /// Adds a connection between one EA element and another
128
      /// </summary>
129
      /// <param name="repository"></param>
130
      /// <param name="rq_artifact"></param>
131
      /// <param name="ea_req"></param>
132
      public static void add_connection(EA.Element src_element, EA.Element dest_element)
133
      {
134
         if (false == ea_element_traces_to_or_from(src_element, dest_element))
135
         {
136
            // Add the new connection between the src_element and dest_element
137
            EA.Connector c = (EA.Connector)src_element.Connectors.AddNew("", "Dependency");
138
            c.SupplierID = dest_element.ElementID;
139
            c.Direction = "Source -> Destination";
140
            c.Update();
141
            src_element.Connectors.Refresh();
142
         }
143
      }
144
 
145
      private static bool ea_element_traces_to_or_from(EA.Element src_element, EA.Element dest_element)
146
      {
147
         foreach(EA.Connector ea_c in src_element.Connectors)
148
         {
149
            int destId = -1;
150
 
151
            // we dont care about direction of relationship, so test for both
152
            if (ea_c.ClientID == src_element.ElementID)
153
               destId = ea_c.SupplierID;
154
            else if (ea_c.SupplierID == src_element.ElementID)
155
               destId = ea_c.ClientID;
156
 
157
            // and make sure we filter out self-referential connectors
158
            if (destId != src_element.ElementID)
159
            {
160
               if (destId == dest_element.ElementID)
161
                  return true;
162
            }
163
         }
164
 
165
         return false;
166
      }
167
 
168
 
169
 
2153 ghuddy 170
      public static void DumpEAElement()
2151 ghuddy 171
      {
172
         EA.Element ea_ele = (EA.Element)Main.EA_Repository.GetTreeSelectedObject();
2141 ghuddy 173
 
2155 ghuddy 174
         Main.WriteOutput("EA Element : " + ea_ele.Name, ea_ele.ElementID);
175
         Main.WriteOutput(              "Author : " + ea_ele.Author, -1);
176
         Main.WriteOutput(         "ClassfierID : " + ea_ele.ClassfierID.ToString(), -1);
177
         Main.WriteOutput(      "ClassifierName : " + ea_ele.ClassifierName, -1);
178
         Main.WriteOutput(      "ClassifierType : " + ea_ele.ClassifierType, -1);
179
         Main.WriteOutput(          "Complexity : " + ea_ele.Complexity, -1);
180
         Main.WriteOutput(          "Difficulty : " + ea_ele.Difficulty, -1);
181
         Main.WriteOutput(         "ElementGUID : " + ea_ele.ElementGUID, -1);
182
         Main.WriteOutput(           "ElementID : " + ea_ele.ElementID.ToString(), ea_ele.ElementID);
183
         Main.WriteOutput(          "EventFlags : " + ea_ele.EventFlags, -1);
184
         Main.WriteOutput(     "ExtensionPoints : " + ea_ele.ExtensionPoints, -1);
185
         Main.WriteOutput(             "Genfile : " + ea_ele.Genfile, -1);
186
         Main.WriteOutput(            "Genlinks : " + ea_ele.Genlinks, -1);
187
         Main.WriteOutput(             "Gentype : " + ea_ele.Gentype, -1);
188
         Main.WriteOutput(        "GetLastError : " + ea_ele.GetLastError(), -1);
189
         Main.WriteOutput(   "GetLinkedDocument : " + ea_ele.GetLinkedDocument(), -1);
190
         Main.WriteOutput(   "GetStereotypeList : " + ea_ele.GetStereotypeList(), -1);
191
         Main.WriteOutput(            "MetaType : " + ea_ele.MetaType, -1);
192
         Main.WriteOutput(        "Multiplicity : " + ea_ele.Multiplicity, -1);
193
         Main.WriteOutput(               "Notes : " + ea_ele.Notes, -1);
194
         Main.WriteOutput(           "PackageID : " + ea_ele.PackageID.ToString(), ea_ele.PackageID);
195
         Main.WriteOutput(            "ParentID : " + ea_ele.ParentID.ToString(), ea_ele.ParentID);
196
         Main.WriteOutput(         "Persistence : " + ea_ele.Persistence, -1);
197
         Main.WriteOutput(               "Phase : " + ea_ele.Phase, -1);
198
         Main.WriteOutput(            "Priority : " + ea_ele.Priority, -1);
199
         Main.WriteOutput(        "PropertyType : " + ea_ele.PropertyType.ToString(), -1);
200
         Main.WriteOutput(            "RunState : " + ea_ele.RunState, -1);
201
         Main.WriteOutput(              "Status : " + ea_ele.Status, -1);
202
         Main.WriteOutput(          "Stereotype : " + ea_ele.Stereotype, -1);
203
         Main.WriteOutput(        "StereotypeEx : " + ea_ele.StereotypeEx, -1);
204
         Main.WriteOutput(             "StyleEx : " + ea_ele.StyleEx, -1);
205
         Main.WriteOutput(             "Subtype : " + ea_ele.Subtype.ToString(), -1);
206
         Main.WriteOutput(          "Tablespace : " + ea_ele.Tablespace, -1);
207
         Main.WriteOutput(                 "Tag : " + ea_ele.Tag, -1);
208
         Main.WriteOutput(             "TreePos : " + ea_ele.TreePos.ToString(), -1);
209
         Main.WriteOutput(                "Type : " + ea_ele.Type, -1);
210
         Main.WriteOutput(             "Version : " + ea_ele.Version, -1);
211
         Main.WriteOutput(          "Visibility : " + ea_ele.Visibility, -1);
2151 ghuddy 212
      }
213
 
2141 ghuddy 214
 
2139 ghuddy 215
	}
216
 
217
 
218
   /// <summary>
219
   /// A Base Class designed to work with the findAndProcessPackageElements method.
220
   /// Users will normally derive their own classes from this and add real functionality
221
   /// to the over-ridable methods the base class provides.
222
   /// </summary>
223
   public class EA_UtilitiesRecursionWorker
224
   {
225
      public EA_UtilitiesRecursionWorker()
226
      {
227
      }
228
 
229
      public virtual void processElement( EA.Element theElement )
230
      {
231
      }
232
      public virtual void processPackage( EA.Package thePackage )
233
      {
234
      }
235
   }
236
 
237
 
2151 ghuddy 238
 
239
   /// <summary>
240
   /// This class is one derived from the EA_UtilitiesRecursionWorker base class so that
241
   /// an instance of it can be used as a parameter in the EA_Utilities.findAndProcessPackageElements
242
   /// method which recursively parses a given package. Thus, clients can parse EA model structure but
243
   /// specify their own functionality to be carried out on packages and elements found in the
244
   /// parsing.
245
   /// This particular derived class is designed to collect a list of element names from the
246
   /// package, from elements that have a type that is acceptable.
247
   /// </summary>
248
   public class ElementAccumulator : EA_UtilitiesRecursionWorker
249
   {
250
      public ArrayList Elements = null;
251
      public ArrayList ElementIDs = null;
252
      private ArrayList validElementTypes = null;
253
 
254
      public ElementAccumulator(ArrayList elementTypeList): base()
255
      {
256
         validElementTypes = elementTypeList;
257
         Elements = new ArrayList();
258
         ElementIDs = new ArrayList();
259
      }
260
 
261
      public override void processElement( EA.Element theElement )
262
      {
263
         if (validElementTypes.Contains( theElement.Type ))
264
         {
265
            Elements.Add( theElement );
266
            ElementIDs.Add( theElement.ElementID );
267
         }
268
      }
2141 ghuddy 269
   }
270
 
2139 ghuddy 271
}