Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2139 ghuddy 1
 
2141 ghuddy 2
using System;
3
using System.Text;
4
using System.Globalization;
5
using System.Collections;
6
using System.Windows.Forms;
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
      EA.Repository EA_Repository = null;
17
 
18
		public EA_Utilities(EA.Repository theRepository)
19
		{
20
         EA_Repository = theRepository;
21
		}
22
 
23
      /// <summary>
24
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
25
      /// a user to specify what processing is to be done upon or with each element found.
26
      /// </summary>
27
      /// <param name="thePackage"></param>
28
      /// <param name="worker"></param>
29
      /// <param name="recurse"></param>
30
      public void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
31
      {
32
         worker.processPackage( thePackage );
33
 
34
         foreach (EA.Element theElement in thePackage.Elements)
35
         {
36
            worker.processElement( theElement );
37
         }
38
 
39
         if (recurse == true)
40
         {
41
            foreach (EA.Package subPackage in thePackage.Packages)
42
            {
43
               // RECURSION
44
               findAndProcessPackageElements( subPackage, worker, true);
45
            }         
46
         }
47
 
48
      }
49
 
50
 
51
      public string ReadTag(EA.Element theElement, string tagName)
52
      {
53
         string result;
54
 
55
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
56
         if (null != tag)
57
         {
58
            result = tag.Value;
59
         }
60
         else
61
         {
62
            result = "";
63
         }
64
         return result;
65
      }
66
 
67
 
68
      public bool WriteTag(EA.Element theElement, string tagName, string value)
69
      {
70
         bool result;
71
         EA.TaggedValue tag;
72
 
73
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
74
         if (null != tag)
75
         {
76
            tag.Value = value;
77
         }
78
         else
79
         {
80
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
81
         }
82
 
83
         if (tag != null)
84
         {
85
            result = tag.Update();
86
         }
87
         else
88
         {
89
            result = false;
90
         }
91
         return result;
92
      }
93
 
94
 
2141 ghuddy 95
      /// <summary>
96
      /// Creates a package under the specified parent package. the package is given a tree position
97
      /// as specified in order for it to be ordered in the model as the caller requires.
98
      /// </summary>
99
      /// <param name="parentPackage"></param>
100
      /// <param name="name"></param>
101
      /// <param name="treePos"></param>
102
      /// <returns></returns>
103
      public EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
104
      {
105
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
106
         newobj.TreePos = treePos;
107
         newobj.Update();
108
         return newobj;
109
      }
110
 
111
      public void DumpEAElement(EA.Repository repository)
112
      {
113
         EA.Element ea_ele = (EA.Element)repository.GetTreeSelectedObject();
114
 
115
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Element : " + ea_ele.Name, ea_ele.ElementID);
116
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,               "Author : " + ea_ele.Author, -1);
117
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "ClassfierID : " + ea_ele.ClassfierID.ToString(), -1);
118
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,       "ClassifierName : " + ea_ele.ClassifierName, -1);
119
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,       "ClassifierType : " + ea_ele.ClassifierType, -1);
120
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Complexity : " + ea_ele.Complexity, -1);
121
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Difficulty : " + ea_ele.Difficulty, -1);
122
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "ElementGUID : " + ea_ele.ElementGUID, -1);
123
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,            "ElementID : " + ea_ele.ElementID.ToString(), ea_ele.ElementID);
124
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "EventFlags : " + ea_ele.EventFlags, -1);
125
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,      "ExtensionPoints : " + ea_ele.ExtensionPoints, -1);
126
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Genfile : " + ea_ele.Genfile, -1);
127
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "Genlinks : " + ea_ele.Genlinks, -1);
128
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Gentype : " + ea_ele.Gentype, -1);
129
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "GetLastError : " + ea_ele.GetLastError(), -1);
130
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,    "GetLinkedDocument : " + ea_ele.GetLinkedDocument(), -1);
131
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,    "GetStereotypeList : " + ea_ele.GetStereotypeList(), -1);
132
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "MetaType : " + ea_ele.MetaType, -1);
133
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "Multiplicity : " + ea_ele.Multiplicity, -1);
134
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                "Notes : " + ea_ele.Notes, -1);
135
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,            "PackageID : " + ea_ele.PackageID.ToString(), ea_ele.PackageID);
136
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "ParentID : " + ea_ele.ParentID.ToString(), ea_ele.ParentID);
137
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "Persistence : " + ea_ele.Persistence, -1);
138
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                "Phase : " + ea_ele.Phase, -1);
139
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "Priority : " + ea_ele.Priority, -1);
140
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "PropertyType : " + ea_ele.PropertyType.ToString(), -1);
141
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "RunState : " + ea_ele.RunState, -1);
142
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,               "Status : " + ea_ele.Status, -1);
143
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Stereotype : " + ea_ele.Stereotype, -1);
144
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "StereotypeEx : " + ea_ele.StereotypeEx, -1);
145
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "StyleEx : " + ea_ele.StyleEx, -1);
146
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Subtype : " + ea_ele.Subtype.ToString(), -1);
147
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Tablespace : " + ea_ele.Tablespace, -1);
148
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                  "Tag : " + ea_ele.Tag, -1);
149
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "TreePos : " + ea_ele.TreePos.ToString(), -1);
150
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                 "Type : " + ea_ele.Type, -1);
151
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Version : " + ea_ele.Version, -1);
152
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Visibility : " + ea_ele.Visibility, -1);
153
      }
154
 
155
 
2139 ghuddy 156
	}
157
 
158
 
159
   /// <summary>
160
   /// A Base Class designed to work with the findAndProcessPackageElements method.
161
   /// Users will normally derive their own classes from this and add real functionality
162
   /// to the over-ridable methods the base class provides.
163
   /// </summary>
164
   public class EA_UtilitiesRecursionWorker
165
   {
166
      public EA_UtilitiesRecursionWorker()
167
      {
168
      }
169
 
170
      public virtual void processElement( EA.Element theElement )
171
      {
172
      }
173
      public virtual void processPackage( EA.Package thePackage )
174
      {
175
      }
176
   }
177
 
178
 
2141 ghuddy 179
 
180
   /// <summary>
181
   /// This class is one derived from the EA_UtilitiesRecursionWorker base class so that
182
   /// an instance of it can be used as a parameter in the EA_Utilities.findAndProcessPackageElements
183
   /// method which recursively parses a given package. Thus, clients can parse EA model structure but
184
   /// specify their own functionality to be carried out on packages and elements found in the
185
   /// parsing.
186
   /// This particular derived class is designed to collect a list of element names from the
187
   /// package, from elements that have a type that is acceptable.
188
   /// </summary>
189
   public class ElementAccumulator : EA_UtilitiesRecursionWorker
190
   {
191
      public ArrayList Elements = null;
192
      public ArrayList ElementIDs = null;
193
      private ArrayList validElementTypes = null;
194
 
195
      public ElementAccumulator(ArrayList elementTypeList): base()
196
      {
197
         validElementTypes = elementTypeList;
198
         Elements = new ArrayList();
199
         ElementIDs = new ArrayList();
200
      }
201
 
202
      public override void processElement( EA.Element theElement )
203
      {
204
         if (validElementTypes.Contains( theElement.Type ))
205
         {
206
            Elements.Add( theElement );
207
            ElementIDs.Add( theElement.ElementID );
208
         }
209
      }
210
   }
211
 
2139 ghuddy 212
}