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
 
2145 ghuddy 95
      public EA.Package get_selected_package()
96
      {
97
         object o;
98
         EA.ObjectType type;
99
 
100
         type = EA_Repository.GetTreeSelectedItem(out o);
101
         if (type == EA.ObjectType.otElement)
102
         {
103
            return EA_Repository.GetPackageByID( ((EA.Element)o).PackageID );
104
         }
105
         else if (type == EA.ObjectType.otPackage)
106
         {
107
            return (EA.Package)o;
108
         }
109
         return null;
110
      }
111
 
2141 ghuddy 112
      /// <summary>
113
      /// Creates a package under the specified parent package. the package is given a tree position
114
      /// as specified in order for it to be ordered in the model as the caller requires.
115
      /// </summary>
116
      /// <param name="parentPackage"></param>
117
      /// <param name="name"></param>
118
      /// <param name="treePos"></param>
119
      /// <returns></returns>
120
      public EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
121
      {
122
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
123
         newobj.TreePos = treePos;
124
         newobj.Update();
125
         return newobj;
126
      }
127
 
128
      public void DumpEAElement(EA.Repository repository)
129
      {
130
         EA.Element ea_ele = (EA.Element)repository.GetTreeSelectedObject();
131
 
132
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Element : " + ea_ele.Name, ea_ele.ElementID);
133
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,               "Author : " + ea_ele.Author, -1);
134
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "ClassfierID : " + ea_ele.ClassfierID.ToString(), -1);
135
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,       "ClassifierName : " + ea_ele.ClassifierName, -1);
136
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,       "ClassifierType : " + ea_ele.ClassifierType, -1);
137
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Complexity : " + ea_ele.Complexity, -1);
138
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Difficulty : " + ea_ele.Difficulty, -1);
139
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "ElementGUID : " + ea_ele.ElementGUID, -1);
140
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,            "ElementID : " + ea_ele.ElementID.ToString(), ea_ele.ElementID);
141
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "EventFlags : " + ea_ele.EventFlags, -1);
142
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,      "ExtensionPoints : " + ea_ele.ExtensionPoints, -1);
143
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Genfile : " + ea_ele.Genfile, -1);
144
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "Genlinks : " + ea_ele.Genlinks, -1);
145
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Gentype : " + ea_ele.Gentype, -1);
146
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "GetLastError : " + ea_ele.GetLastError(), -1);
147
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,    "GetLinkedDocument : " + ea_ele.GetLinkedDocument(), -1);
148
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,    "GetStereotypeList : " + ea_ele.GetStereotypeList(), -1);
149
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "MetaType : " + ea_ele.MetaType, -1);
150
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "Multiplicity : " + ea_ele.Multiplicity, -1);
151
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                "Notes : " + ea_ele.Notes, -1);
152
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,            "PackageID : " + ea_ele.PackageID.ToString(), ea_ele.PackageID);
153
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "ParentID : " + ea_ele.ParentID.ToString(), ea_ele.ParentID);
154
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,          "Persistence : " + ea_ele.Persistence, -1);
155
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                "Phase : " + ea_ele.Phase, -1);
156
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "Priority : " + ea_ele.Priority, -1);
157
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "PropertyType : " + ea_ele.PropertyType.ToString(), -1);
158
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,             "RunState : " + ea_ele.RunState, -1);
159
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,               "Status : " + ea_ele.Status, -1);
160
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Stereotype : " + ea_ele.Stereotype, -1);
161
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,         "StereotypeEx : " + ea_ele.StereotypeEx, -1);
162
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "StyleEx : " + ea_ele.StyleEx, -1);
163
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Subtype : " + ea_ele.Subtype.ToString(), -1);
164
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Tablespace : " + ea_ele.Tablespace, -1);
165
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                  "Tag : " + ea_ele.Tag, -1);
166
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "TreePos : " + ea_ele.TreePos.ToString(), -1);
167
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,                 "Type : " + ea_ele.Type, -1);
168
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,              "Version : " + ea_ele.Version, -1);
169
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,           "Visibility : " + ea_ele.Visibility, -1);
170
      }
171
 
172
 
2139 ghuddy 173
	}
174
 
175
 
176
   /// <summary>
177
   /// A Base Class designed to work with the findAndProcessPackageElements method.
178
   /// Users will normally derive their own classes from this and add real functionality
179
   /// to the over-ridable methods the base class provides.
180
   /// </summary>
181
   public class EA_UtilitiesRecursionWorker
182
   {
183
      public EA_UtilitiesRecursionWorker()
184
      {
185
      }
186
 
187
      public virtual void processElement( EA.Element theElement )
188
      {
189
      }
190
      public virtual void processPackage( EA.Package thePackage )
191
      {
192
      }
193
   }
194
 
195
 
2141 ghuddy 196
 
197
   /// <summary>
198
   /// This class is one derived from the EA_UtilitiesRecursionWorker base class so that
199
   /// an instance of it can be used as a parameter in the EA_Utilities.findAndProcessPackageElements
200
   /// method which recursively parses a given package. Thus, clients can parse EA model structure but
201
   /// specify their own functionality to be carried out on packages and elements found in the
202
   /// parsing.
203
   /// This particular derived class is designed to collect a list of element names from the
204
   /// package, from elements that have a type that is acceptable.
205
   /// </summary>
206
   public class ElementAccumulator : EA_UtilitiesRecursionWorker
207
   {
208
      public ArrayList Elements = null;
209
      public ArrayList ElementIDs = null;
210
      private ArrayList validElementTypes = null;
211
 
212
      public ElementAccumulator(ArrayList elementTypeList): base()
213
      {
214
         validElementTypes = elementTypeList;
215
         Elements = new ArrayList();
216
         ElementIDs = new ArrayList();
217
      }
218
 
219
      public override void processElement( EA.Element theElement )
220
      {
221
         if (validElementTypes.Contains( theElement.Type ))
222
         {
223
            Elements.Add( theElement );
224
            ElementIDs.Add( theElement.ElementID );
225
         }
226
      }
227
   }
228
 
2139 ghuddy 229
}