Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2139 ghuddy 1
 
2
using System;
3
 
4
namespace EA_ReqPro
5
{
6
	/// <summary>
7
	/// Summary description for EA_Utils.
8
	/// </summary>
9
	public class EA_Utilities
10
	{
11
      EA.Repository EA_Repository = null;
12
 
13
		public EA_Utilities(EA.Repository theRepository)
14
		{
15
         EA_Repository = theRepository;
16
		}
17
 
18
      /// <summary>
19
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
20
      /// a user to specify what processing is to be done upon or with each element found.
21
      /// </summary>
22
      /// <param name="thePackage"></param>
23
      /// <param name="worker"></param>
24
      /// <param name="recurse"></param>
25
      public void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
26
      {
27
         worker.processPackage( thePackage );
28
 
29
         foreach (EA.Element theElement in thePackage.Elements)
30
         {
31
            worker.processElement( theElement );
32
         }
33
 
34
         if (recurse == true)
35
         {
36
            foreach (EA.Package subPackage in thePackage.Packages)
37
            {
38
               // RECURSION
39
               findAndProcessPackageElements( subPackage, worker, true);
40
            }         
41
         }
42
 
43
      }
44
 
45
 
46
      public string ReadTag(EA.Element theElement, string tagName)
47
      {
48
         string result;
49
 
50
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
51
         if (null != tag)
52
         {
53
            result = tag.Value;
54
         }
55
         else
56
         {
57
            result = "";
58
         }
59
         return result;
60
      }
61
 
62
 
63
      public bool WriteTag(EA.Element theElement, string tagName, string value)
64
      {
65
         bool result;
66
         EA.TaggedValue tag;
67
 
68
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
69
         if (null != tag)
70
         {
71
            tag.Value = value;
72
         }
73
         else
74
         {
75
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
76
         }
77
 
78
         if (tag != null)
79
         {
80
            result = tag.Update();
81
         }
82
         else
83
         {
84
            result = false;
85
         }
86
         return result;
87
      }
88
 
89
 
90
	}
91
 
92
 
93
   /// <summary>
94
   /// A Base Class designed to work with the findAndProcessPackageElements method.
95
   /// Users will normally derive their own classes from this and add real functionality
96
   /// to the over-ridable methods the base class provides.
97
   /// </summary>
98
   public class EA_UtilitiesRecursionWorker
99
   {
100
      public EA_UtilitiesRecursionWorker()
101
      {
102
      }
103
 
104
      public virtual void processElement( EA.Element theElement )
105
      {
106
      }
107
      public virtual void processPackage( EA.Package thePackage )
108
      {
109
      }
110
   }
111
 
112
 
113
}