Subversion Repositories DevTools

Rev

Rev 2145 | Rev 2153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2145 Rev 2151
Line 1... Line 1...
1
using System;
1
using System;
2
using System.Text;
2
using System.Text;
3
using System.Globalization;
3
using System.Globalization;
4
using System.Collections;
4
using System.Collections;
5
using System.Windows.Forms;
5
using System.Windows.Forms;
6
using ReqPro40;
6
using ReqPro40;
7
 
7
 
8
 
8
 
9
namespace EA_ReqPro
9
namespace EA_ReqPro
10
{
10
{
11
	/// <summary>
11
   /// <summary>
12
	/// The ReqProDB_Artifact class contains methods supporting the use of the ReqProDB 
12
   /// The ReqProDB_Artifact class contains methods supporting the use of the ReqProDB
13
	/// element used to control ReqPro imports for requirement-to-design tracability 
13
   /// element used to control ReqPro imports for requirement-to-design tracability
14
	/// purposes. 
14
   /// purposes.
15
	/// </summary>
15
   /// </summary>
16
	public class ReqProDB_Artifact
16
   public class ReqProDB_Artifact
17
	{
17
   {
18
      /// <summary>
18
      /// <summary>
19
      /// A ReqProDB artifact can be used for document model (document generation) purposes,
19
      /// A ReqProDB artifact can be used for document model (document generation) purposes,
20
      /// or requirement-to-design traceability purposes, and this is to be recorded in the element
20
      /// or requirement-to-design traceability purposes, and this is to be recorded in the element
21
      /// as a tagged value. We need an enum to represent the differning modes.
21
      /// as a tagged value. We need an enum to represent the differning modes.
22
      /// </summary>
22
      /// </summary>
Line 30... Line 30...
30
      public ReqPro40.Application RQ_app;
30
      public ReqPro40.Application RQ_app;
31
 
31
 
32
      /// <summary>
32
      /// <summary>
33
      /// Constructor logic
33
      /// Constructor logic
34
      /// </summary>
34
      /// </summary>
35
		public ReqProDB_Artifact()
35
      public ReqProDB_Artifact()
36
		{
36
      {
37
         RQ_app = new ReqPro40.ApplicationClass();
37
         RQ_app = new ReqPro40.ApplicationClass();
-
 
38
      }
38
		}
39
 
39
 
40
 
40
  
-
 
41
      /// <summary>
41
      /// <summary>
42
      /// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact
42
      /// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact
43
      /// element.
43
      /// element.
44
      /// </summary>
44
      /// </summary>
45
      /// <param name="ea_repository"></param>
45
      /// <param name="ea_repository"></param>
46
      /// <param name="rq_artifact"></param>
46
      /// <param name="rq_artifact"></param>
47
      /// <returns></returns>
47
      /// <returns></returns>
48
      public ReqPro40.Project OpenReqProProject(EA.Repository ea_repository, EA.Element rq_artifact)
48
      public ReqPro40.Project OpenReqProProject(EA.Element rq_artifact)
49
      {
49
      {
50
         EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
50
         EA_Utilities EA_Utils = new EA_Utilities();
51
 
51
 
52
         Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));
52
         Logon logon = new Logon(EA_Utils.ReadTag(rq_artifact, "Username"));
53
         
53
 
54
         DialogResult dlgRes = logon.ShowDialog();
54
         DialogResult dlgRes = logon.ShowDialog();
55
         if (dlgRes == DialogResult.OK)
55
         if (dlgRes == DialogResult.OK)
56
         {
56
         {
57
            ReqPro40.Project project = RQ_app.OpenProject(
57
            ReqPro40.Project project = RQ_app.OpenProject(
58
               EA_Utils.ReadTag(rq_artifact, "Location"),
58
               EA_Utils.ReadTag(rq_artifact, "Location"),
59
               ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
59
               ReqPro40.enumOpenProjectOptions.eOpenProjOpt_RQSFile,
60
               EA_Utils.ReadTag(rq_artifact, "Username"),
60
               EA_Utils.ReadTag(rq_artifact, "Username"),
61
               logon.ebPassword.Text, 
61
               logon.ebPassword.Text,
62
               enumProjectFlags.eProjFlag_Normal,
62
               enumProjectFlags.eProjFlag_Normal,
63
               enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
63
               enumRelatedProjectOptions.eRelatedProjOption_ConnectAsSpecified);
64
 
64
 
65
            if (project == null)
65
            if (project == null)
66
            {
66
            {
67
               MessageBox.Show("ERROR: Cannot establish connection to ReqPro database.\n\n" +
67
               MessageBoxEx.Show("Cannot establish connection to ReqPro database. " +
68
                  "Check the tagged values in the artifact are correct.\n" +
68
                  "Check the tagged values in the artifact are correct. " +
69
                  "Check the database still exists or is not locked by\n" +
69
                  "Check the database still exists or is not locked by " +
70
                  "another user, or has not been password protected." );
70
                  "another user, or has not been password protected.", "Error" );
71
            }
71
            }
72
 
72
 
73
            return project;
73
            return project;
74
         }
74
         }
75
         return null;
75
         return null;
76
      }
76
      }
77
 
77
 
78
 
78
 
79
      /// <summary>
79
      /// <summary>
80
      /// This method is used to return the ReqProDB artifact, on the assumption that it is the
80
      /// This method is used to return the ReqProDB artifact, on the assumption that it is the
Line 83... Line 83...
83
      /// that package is searched for the first ReqProDB artifact that can be found, and that one
83
      /// that package is searched for the first ReqProDB artifact that can be found, and that one
84
      /// is returned.
84
      /// is returned.
85
      /// </summary>
85
      /// </summary>
86
      /// <param name="ea_repository"></param>
86
      /// <param name="ea_repository"></param>
87
      /// <returns></returns>
87
      /// <returns></returns>
88
      public EA.Element get_rq_artifact(EA.Repository ea_repository)
88
      public EA.Element get_rq_artifact()
89
      {
89
      {
90
         object o;
90
         object o;
91
         EA.ObjectType type;
91
         EA.ObjectType type;
92
 
92
 
93
         type = ea_repository.GetTreeSelectedItem(out o);
93
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
94
         if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB"))
94
         if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB"))
95
         {
95
         {
96
            return (EA.Element)o;
96
            return (EA.Element)o;
97
         }
97
         }
98
         else if (type == EA.ObjectType.otPackage)
98
         else if (type == EA.ObjectType.otPackage)
99
         {
99
         {
100
            for(short i=0; i < ((EA.Package)o).Elements.Count; i++)
100
            for(short i=0; i < ((EA.Package)o).Elements.Count; i++)
101
            {
101
            {
102
               EA.Element ea_ele = (EA.Element)((EA.Package)o).Elements.GetAt(i);
102
               EA.Element ea_ele = (EA.Element)((EA.Package)o).Elements.GetAt(i);
103
 
103
 
104
               if (ea_ele.Stereotype == "ReqProDB")
104
               if (ea_ele.Stereotype == "ReqProDB")
105
               {
105
               {
106
                  return ea_ele;
106
                  return ea_ele;
107
               }
107
               }
108
            }
108
            }
109
         }
109
         }
110
         return null;
110
         return null;
111
      }
111
      }
112
 
112
 
113
 
113
 
114
 
-
 
115
 
-
 
116
      /// <summary>
-
 
117
      /// This method updates a ReqProDB artifact elements internal data. Such an update may be
-
 
118
      /// needed if the user has deleted requirements from EA that are linked to the specified
-
 
119
      /// ReqProDB artifact.
-
 
120
      /// </summary>
-
 
121
      /// <param name="repository"></param>
-
 
122
      /// <param name="rq_artifact"></param>
-
 
123
      public void UpdatePackageToReqProDatabaseAssociation(EA.Repository repository, EA.Element rq_artifact)
-
 
124
      {
-
 
125
         repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Please Wait - Updating ReqProDB element", rq_artifact.ElementID);
-
 
126
 
-
 
127
         // Scan EA package to find all requirement elements, and add links to them
-
 
128
         // from the ReqPro artifact element we have written into the selected package.
-
 
129
         EA_Utilities EA_Utils = new EA_Utilities(repository);
-
 
130
 
-
 
131
         ArrayList allowedElementTypes = new ArrayList();
-
 
132
         allowedElementTypes.Add("Requirement");
-
 
133
         allowedElementTypes.Add("UseCase");
-
 
134
 
-
 
135
         ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
-
 
136
 
-
 
137
         EA.Package thePackage = repository.GetPackageByID( rq_artifact.PackageID );
-
 
138
         EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );
-
 
139
 
-
 
140
         // Get all existing connectors into a list
-
 
141
         ArrayList connectors = new ArrayList();
-
 
142
         foreach(EA.Connector theConnector in rq_artifact.Connectors)
-
 
143
         {
-
 
144
            connectors.Add(theConnector.SupplierID);
-
 
145
         }
-
 
146
 
-
 
147
         // For each element, if it is not already referred to by a connector, add a connector for it
-
 
148
         foreach (EA.Element theElement in reqLister.Elements)
-
 
149
         {
-
 
150
            if (!connectors.Contains(theElement.ElementID))
-
 
151
            {
-
 
152
               add_connection(repository, rq_artifact, theElement);
-
 
153
            }
-
 
154
         }
-
 
155
         rq_artifact.Connectors.Refresh();
-
 
156
 
-
 
157
 
-
 
158
         // Now remove any connectors that point to element IDs that are no longer in the package
-
 
159
         short i = 0;
-
 
160
         foreach (EA.Connector theConnector in rq_artifact.Connectors)
-
 
161
         {
-
 
162
            if (!reqLister.ElementIDs.Contains(theConnector.SupplierID))
-
 
163
            {
-
 
164
               rq_artifact.Connectors.Delete(i);
-
 
165
               rq_artifact.Connectors.Refresh();
-
 
166
            }
-
 
167
            else
-
 
168
            {
-
 
169
               i++;
-
 
170
            }
-
 
171
         }
-
 
172
         rq_artifact.Update();
-
 
173
         rq_artifact.Refresh();
-
 
174
      }
-
 
175
 
-
 
176
 
-
 
177
      /// <summary>
114
      /// <summary>
178
      /// This method is used to create a ReqProDB element in an EA package.
115
      /// This method is used to create a ReqProDB element in an EA package.
179
      /// Do not modify the tag names that are in current use. Only extend with
116
      /// Do not modify the tag names that are in current use. Only extend with
180
      /// additional new tags.
117
      /// additional new tags.
181
      /// </summary>
118
      /// </summary>
Line 185... Line 122...
185
      /// <param name="description"></param>
122
      /// <param name="description"></param>
186
      /// <param name="reqpro_db_username"></param>
123
      /// <param name="reqpro_db_username"></param>
187
      /// <param name="reqpro_db_filename"></param>
124
      /// <param name="reqpro_db_filename"></param>
188
      /// <param name="reqpro_db_guid"></param>
125
      /// <param name="reqpro_db_guid"></param>
189
      /// <returns></returns>
126
      /// <returns></returns>
190
      public EA.Element create_rq_artifact( EA.Repository ea_repository, 
127
      public EA.Element create_rq_artifact( 
191
         EA.Package package,
128
         EA.Package package,
192
         string name,
129
         string name,
193
         string description,
130
         string description,
194
         string reqpro_db_username,
131
         string reqpro_db_username,
195
         string reqpro_db_filename,
132
         string reqpro_db_filename,
196
         string reqpro_db_guid)
133
         string reqpro_db_guid)
197
      {
134
      {
198
         EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
135
         EA_Utilities EA_Utils = new EA_Utilities();
199
 
136
 
200
         package.Notes = description;
137
         package.Notes = description;
201
         package.Update();
138
         package.Update();
202
            
139
 
203
         EA.Element element;
140
         EA.Element element;
204
         element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
141
         element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
205
         if (element != null)
142
         if (element != null)
206
         {
143
         {
207
            element.Stereotype = "ReqProDB";
144
            element.Stereotype = "ReqProDB";
208
            element.Notes = description;
145
            element.Notes = description;
209
 
146
 
210
            EA_Utils.WriteTag( element, "Location", reqpro_db_filename);
147
            EA_Utils.WriteTag( element, "Location", reqpro_db_filename);
211
            EA_Utils.WriteTag( element, "Username", reqpro_db_username);
148
            EA_Utils.WriteTag( element, "Username", reqpro_db_username);
212
            EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);
149
            EA_Utils.WriteTag( element, "GUID", reqpro_db_guid);
213
 
150
 
214
 
151
 
215
            element.Update();
152
            element.Update();
216
            element.Refresh();
153
            element.Refresh();
217
            element.TaggedValues.Refresh();
154
            element.TaggedValues.Refresh();
218
            package.Update();
155
            package.Update();
219
            package.Packages.Refresh();
156
            package.Packages.Refresh();
220
            package.Elements.Refresh(); 
157
            package.Elements.Refresh();
221
            
158
 
222
            return element;
159
            return element;
223
         }
160
         }
224
         return null;
161
         return null;
225
      }
162
      }
226
 
-
 
227
 
163
 
228
      /// <summary>
-
 
229
      /// Adds a connection between a ReqProDB artifact and a requirement element
-
 
230
      /// </summary>
-
 
231
      /// <param name="repository"></param>
-
 
232
      /// <param name="rq_artifact"></param>
-
 
233
      /// <param name="ea_req"></param>
-
 
234
      public void add_connection(EA.Repository repository, EA.Element rq_artifact, EA.Element ea_req)
-
 
235
      {
-
 
236
         // Add the new requirement to the rq_artifact
-
 
237
         EA.Connector c = (EA.Connector)rq_artifact.Connectors.AddNew("", "Dependency");
-
 
238
         c.SupplierID = ea_req.ElementID;
-
 
239
         c.Stereotype = "trace";
-
 
240
         c.Direction = "Destination -> Source";
-
 
241
         if (false == c.Update())
-
 
242
         {
-
 
243
            repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "New Connector Error : " + c.GetLastError(), ea_req.ElementID );
-
 
244
         }
-
 
245
      }
-
 
246
 
-
 
247
      public void set_traceability_mode(EA.Repository ea_repository, EA.Element rq_artifact)
-
 
248
      {
-
 
249
         EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
-
 
250
         EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");
-
 
251
         rq_artifact.Update();
-
 
252
      }
-
 
253
 
-
 
254
      public void set_doc_model_mode(EA.Repository ea_repository, EA.Element rq_artifact)
-
 
255
      {
-
 
256
         EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
-
 
257
         EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");
-
 
258
         rq_artifact.Update();
-
 
259
      }
-
 
260
 
-
 
261
      public MODE get_mode(EA.Repository ea_repository, EA.Element rq_artifact)
-
 
262
      {
-
 
263
         EA_Utilities EA_Utils = new EA_Utilities(ea_repository);
-
 
264
         string mode = EA_Utils.ReadTag(rq_artifact, "Mode");
-
 
265
                 
-
 
266
         if (0 == mode.CompareTo("Traceability"))
-
 
267
            return MODE.TRACEABILITY;
-
 
268
         else if (0 == mode.CompareTo("DocModel"))
-
 
269
            return MODE.DOC_MODEL;
-
 
270
         
-
 
271
         return MODE.UNDEFINED;
-
 
272
      }
-
 
273
 
164
 
-
 
165
      public void set_traceability_mode(EA.Element rq_artifact)
-
 
166
      {
-
 
167
         EA_Utilities EA_Utils = new EA_Utilities();
-
 
168
         EA_Utils.WriteTag( rq_artifact, "Mode", "Traceability");
-
 
169
         rq_artifact.Update();
-
 
170
      }
-
 
171
 
-
 
172
      public void set_doc_model_mode(EA.Element rq_artifact)
-
 
173
      {
-
 
174
         EA_Utilities EA_Utils = new EA_Utilities();
-
 
175
         EA_Utils.WriteTag( rq_artifact, "Mode", "DocModel");
-
 
176
         rq_artifact.Update();
-
 
177
      }
-
 
178
 
-
 
179
      public MODE get_mode(EA.Element rq_artifact)
-
 
180
      {
-
 
181
         EA_Utilities EA_Utils = new EA_Utilities();
-
 
182
         string mode = EA_Utils.ReadTag(rq_artifact, "Mode");
-
 
183
 
-
 
184
         if (0 == mode.CompareTo("Traceability"))
-
 
185
            return MODE.TRACEABILITY;
-
 
186
         else if (0 == mode.CompareTo("DocModel"))
-
 
187
            return MODE.DOC_MODEL;
-
 
188
 
-
 
189
         return MODE.UNDEFINED;
-
 
190
      }
274
	}
191
   }
275
}
192
}