Subversion Repositories DevTools

Rev

Rev 2155 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2155 ghuddy 1
using System;
2
using ReqPro40;
3
 
4
namespace EA_ReqPro
5
{
6
	/// <summary>
7
	/// This class is a rather unsuccessful attempt to encapsulate ReqPro automation interface
8
	/// dependencies but unfortunately, outside of this class, many other classes still know about
9
	/// ReqPro types. A gradual movement of functionality into this class should be attempted over 
10
	/// time. Return of types objects should be altered to returning simple system.object values, etc.
11
	/// A series of collection parsing functions that use delegate callbacks could be written to pull
12
	/// in the functionality that exists outside of this class that depends on ReqPro types.
13
	/// </summary>
14
	public class ReqProDatabase
15
	{
16
      private static ReqPro40.Application RQ_app = null;
17
      private static ReqPro40.Project RQ_project = null;
18
 
19
      private static bool gotApplication()
20
      {
21
         if (RQ_app == null)
22
         {
23
            RQ_app = new ReqPro40.ApplicationClass();
24
         }
25
         if (RQ_app == null)
26
            return false;
27
         else
28
            return true;
29
      }
30
 
31
      private static bool gotProject()
32
      {
33
         if (RQ_project == null)
34
            return false;
35
         else
36
            return true;
37
      }
38
 
39
 
40
      public static bool opened()
41
      {
42
         return gotProject();
43
      }
44
 
45
      public static string name()
46
      {
47
         if (RQ_project != null)
48
            return RQ_project.Name;
49
         else
50
            return "";
51
      }
52
 
53
      public static string description()
54
      {
55
         if (RQ_project != null)
56
            return RQ_project.Description;
57
         else
58
            return "";
59
      }
60
 
61
      public static string guid()
62
      {
63
         if (RQ_project != null)
64
            return RQ_project.GUID;
65
         else
66
            return "";
67
      }
68
 
69
      public static ReqPro40.RootPackage get_root_package()
70
      {
71
         if (gotProject())
72
         {
73
            return RQ_project.GetRootPackage(true);
74
         }
75
         return null;
76
      }
77
 
78
      public static ReqPro40.Package get_package(int iKey)
79
      {
80
         if (gotProject())
81
         {
82
            return RQ_project.GetPackage(iKey, ReqPro40.enumPackageWeights.ePackageWeight_Empty);
83
         }
84
         return null;
85
      }
86
 
87
      public static ReqPro40.Requirement get_requirement_by_guid(string guid)
88
      {
89
         if (gotProject())
90
         {
91
            return RQ_project.GetRequirement(guid, ReqPro40.enumRequirementLookups.eReqLookup_GUID,
92
               ReqPro40.enumRequirementsWeights.eReqWeight_Heavy, 
93
               ReqPro40.enumRequirementFlags.eReqFlag_Empty);
94
         }
95
         return null;
96
      }
97
 
98
      public static ReqPro40.Requirement get_requirement_by_key(object key)
99
      {
100
         if (gotProject())
101
         {
102
            return 
103
               RQ_project.GetRequirement(key,
104
               ReqPro40.enumRequirementLookups.eReqLookup_Key,
105
               ReqPro40.enumRequirementsWeights.eReqWeight_Heavy,
106
               ReqPro40.enumRequirementFlags.eReqFlag_RetainHierarchy);
107
         }
108
         return null;
109
      }
110
 
111
      public static ReqPro40.ReqTypes get_requirement_types()
112
      {
113
         if (gotProject())
114
         {
115
            return RQ_project.ReqTypes;
116
         }
117
         return null;
118
      }
119
 
120
      public static ReqPro40.Requirements get_requirements()
121
      {
122
         if (gotProject())
123
         {
124
            return RQ_project.GetRequirements(
125
               null,
126
               ReqPro40.enumRequirementsLookups.eReqsLookup_All,
127
               ReqPro40.enumRequirementsWeights.eReqWeight_Heavy,
128
               ReqPro40.enumRequirementFlags.eReqFlag_Empty, 1000, 4);
129
         }
130
         return null;
131
      }
132
 
133
 
134
 
135
      public static bool open(string location, string user_name, string password)
136
      {
137
         if (gotApplication())
138
         {
139
            RQ_project = RQ_app.OpenProject(
140
               location,
141
               ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
142
               user_name,
143
               password,
144
               enumProjectFlags.eProjFlag_Normal,
145
               enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
146
            if (RQ_project != null)
147
               return true;
148
         }
149
         return false;
150
      }
151
 
152
      public static void close()
153
      {
154
         if (RQ_project != null)
155
         {
156
            RQ_project.CloseProject();
157
            RQ_project = null;
158
            RQ_app = null;
159
         }
160
         else
161
         {
162
            RQ_app = null;
163
         }
164
      }
165
 
166
 
167
      public static ReqPro40.Package create_package(string name, string description)
168
      {
169
         ReqPro40.RootPackage rp_root_pkg = ReqProDatabase.get_root_package();
170
         if (rp_root_pkg != null)
171
         {
172
            return rp_root_pkg.CreatePackage(name, description, ReqPro40.enumPackageTypes.ePackageType_Empty);
173
         }
174
         return null;
175
      }
176
 
177
      public static ReqPro40.Package create_sub_package(ReqPro40.Package parent_pkg, string sub_pkg_name, string sub_pkg_description)
178
      {
179
         ReqPro40.Package sub_pkg = create_package(sub_pkg_name, sub_pkg_description);
180
         if (sub_pkg != null)
181
         {
182
            parent_pkg.AddElement(sub_pkg, 
183
               ReqPro40.enumPackageLookups.ePackageLookup_Object, 
184
               ReqPro40.enumElementTypes.eElemType_Package);
185
 
186
            return sub_pkg;
187
         }
188
 
189
         return null;
190
      }
191
 
192
 
193
      public static ReqPro40.Requirement add_requirement(object req_collection, string name, string description, string type)
194
      {
195
         return ((ReqPro40.Requirements)req_collection).Add(name, description, type,
196
            ReqPro40.enumReqTypesLookups.eReqTypesLookups_Prefix, 
197
            "1.0", "Version 1.0", 
198
            null, ReqPro40.enumRequirementLookups.eReqLookup_Empty);
199
      }
200
 
2169 ghuddy 201
      public static ReqPro40.Requirement add_requirement(object req_collection, string name, string description, string type, ReqPro40.Requirement parent_rp_req)
202
      {
203
         return ((ReqPro40.Requirements)req_collection).Add(name, description, type,
204
            ReqPro40.enumReqTypesLookups.eReqTypesLookups_Prefix, 
205
            "1.0", "Version 1.0", 
206
            parent_rp_req, ReqPro40.enumRequirementLookups.eReqLookup_Object);
207
      }
2155 ghuddy 208
 
209
      public static bool any_relationship_exists(ReqPro40.Requirement rp_req, string guid)
210
      {
211
         return (  traces_to_relationship_exists(rp_req, guid)
212
                || traces_from_relationship_exists(rp_req, guid)
213
                || child_relationship_exists(rp_req, guid));
214
      }
215
 
216
      public static bool child_relationship_exists(ReqPro40.Requirement rp_req, string guid)
217
      {
218
         int number_of_rels = 0;
219
         if (true == rp_req.get_HasChildren(ref number_of_rels))
220
         {
221
            ReqPro40.Relationships rp_req_c = (ReqPro40.Relationships)rp_req.Children;
222
            if (rp_req_c != null)
223
            {
224
               return relationship_exists(rp_req_c, number_of_rels, guid);
225
            }
226
         }
227
         return false;
228
      }
229
 
230
      public static bool traces_to_relationship_exists(ReqPro40.Requirement rp_req, string guid)
231
      {
232
         int number_of_rels = 0;
233
         if (true == rp_req.get_HasTracesTo(ref number_of_rels))
234
         {
235
            ReqPro40.Relationships rp_req_c = (ReqPro40.Relationships)rp_req.TracesTo;
236
            if (rp_req_c != null)
237
            {
238
               return relationship_exists(rp_req_c, number_of_rels, guid);
239
            }
240
         }
241
         return false;
242
      }
243
 
244
      public static bool traces_from_relationship_exists(ReqPro40.Requirement rp_req, string guid)
245
      {
246
         int number_of_rels = 0;
247
         if (true == rp_req.get_HasTracesFrom(ref number_of_rels))
248
         {
249
            ReqPro40.Relationships rp_req_c = (ReqPro40.Relationships)rp_req.TracesFrom;
250
            if (rp_req_c != null)
251
            {
252
               return relationship_exists(rp_req_c, number_of_rels, guid);
253
            }
254
         }
255
         return false;
256
      }
257
 
258
      private static bool relationship_exists(ReqPro40.Relationships rq_rels, int number_of_rels, string guid)
259
      {
260
         int i;
261
         rq_rels.MoveFirst();
262
         for (i = 0; i < number_of_rels; i++)
263
         {
264
            if (Main.mustAbort)
265
               break;
266
 
267
            ReqPro40.Relationship thisRelationship = rq_rels.GetCurrentRelationship();
268
 
269
            ReqPro40.Requirement subRequirement = 
270
               thisRelationship.get_DestinationRequirement(ReqPro40.enumRequirementsWeights.eReqWeight_Heavy);
271
 
272
            if (subRequirement != null)
273
            {
274
               if (subRequirement.GUID.Equals(guid))
275
               {
276
                  return true;
277
               }
278
            }
279
 
280
            rq_rels.MoveNext();
281
         }
282
         return false;
283
      }
284
 
285
	}
286
}