Subversion Repositories DevTools

Rev

Rev 2153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2151 ghuddy 1
using System;
2
using System.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Windows.Forms;
2141 ghuddy 6
using ReqPro40;
7
 
8
 
9
namespace EA_ReqPro
10
{
2151 ghuddy 11
   /// <summary>
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
14
   /// purposes.
15
   /// </summary>
16
   public class ReqProDB_Artifact
17
   {
2145 ghuddy 18
      /// <summary>
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
2155 ghuddy 21
      /// as a tagged value. We need an enum to represent the differning modes, plus some additional
22
      /// modes as required
2145 ghuddy 23
      /// </summary>
24
      public enum MODE
25
      {
26
         TRACEABILITY,
27
         DOC_MODEL,
2155 ghuddy 28
         EXPORT,
2145 ghuddy 29
         UNDEFINED
30
      }
2141 ghuddy 31
 
2145 ghuddy 32
 
2141 ghuddy 33
      /// <summary>
34
      /// Constructor logic
35
      /// </summary>
2151 ghuddy 36
      public ReqProDB_Artifact()
37
      {
38
      }
2141 ghuddy 39
 
2151 ghuddy 40
 
2141 ghuddy 41
      /// <summary>
42
      /// This method is used to open a ReqPro database file indicated by a given ReqProDB artifact
43
      /// element.
44
      /// </summary>
45
      /// <param name="ea_repository"></param>
46
      /// <param name="rq_artifact"></param>
47
      /// <returns></returns>
2155 ghuddy 48
      public bool OpenReqProProject(EA.Element rq_artifact, out bool cancelled)
2141 ghuddy 49
      {
2155 ghuddy 50
         cancelled = false;
2151 ghuddy 51
 
2155 ghuddy 52
         Logon logon = new Logon(EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_USERNAME));
53
 
2151 ghuddy 54
         DialogResult dlgRes = logon.ShowDialog();
55
         if (dlgRes == DialogResult.OK)
56
         {
2155 ghuddy 57
            if (false == ReqProDatabase.open(EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_LOCATION),
58
               EA_TaggedValues.Read(rq_artifact, Constants.TAG_DB_USERNAME),
59
               logon.ebPassword.Text))
2151 ghuddy 60
            {
2155 ghuddy 61
               MessageBoxEx.Show(
62
                  "Cannot establish connection to ReqPro database.\n" +
63
                  "Check the tagged values in the artifact are correct.\n" +
64
                  "Check the database still exists or is not locked by\n" +
2151 ghuddy 65
                  "another user, or has not been password protected.", "Error" );
66
            }
67
 
2155 ghuddy 68
            return ReqProDatabase.opened();
2151 ghuddy 69
         }
2155 ghuddy 70
         else
71
         {
72
            cancelled = true;
73
         }
74
         return false;
2141 ghuddy 75
      }
76
 
77
 
78
      /// <summary>
2155 ghuddy 79
      /// This method is used to return the ReqProDB artifact. The algorithm searches the areas
80
      /// in EA's project browser beginning at where the user selected/highlighted and working
81
      /// up through the parent package levels. This gives the best possible chance of finding
82
      /// the artifact and allows the user to select anything in a ReqPro import area before
83
      /// initiating an import/export. The software automatically finds where the import area
84
      /// exists (ie. its parent container package)
2141 ghuddy 85
      /// </summary>
86
      /// <param name="ea_repository"></param>
87
      /// <returns></returns>
2151 ghuddy 88
      public EA.Element get_rq_artifact()
2141 ghuddy 89
      {
2151 ghuddy 90
         object o;
91
         EA.ObjectType type;
2141 ghuddy 92
 
2151 ghuddy 93
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
2155 ghuddy 94
 
95
         // if user selected the actual ReqProDB element then we can exit straight away with
96
         // the object.
2151 ghuddy 97
         if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Stereotype == "ReqProDB"))
98
         {
99
            return (EA.Element)o;
2145 ghuddy 100
         }
2155 ghuddy 101
         else
2151 ghuddy 102
         {
2155 ghuddy 103
            // Get the package in or under which the EA project browser selection exists
104
            EA.Package pkg = EA_Utilities.get_selected_package();
105
 
106
            // iterate up through the package hiearchy
107
            while (pkg != null)
2151 ghuddy 108
            {
2155 ghuddy 109
               // search for ReqProDB element in the package at the current level
110
               for(short i=0; i < pkg.Elements.Count; i++)
111
               {
112
                  EA.Element ea_ele = (EA.Element)pkg.Elements.GetAt(i);
2151 ghuddy 113
 
2155 ghuddy 114
                  if (ea_ele.Stereotype == "ReqProDB")
115
                  {
116
                     return ea_ele;
117
                  }
118
               }
119
 
120
               // Didnt find ReqProDB element, go up one package level ready for the next loop iteration
121
               if (pkg.ParentID > 0)
2151 ghuddy 122
               {
2155 ghuddy 123
                  pkg = Main.EA_Repository.GetPackageByID(pkg.ParentID);
2151 ghuddy 124
               }
2155 ghuddy 125
               else
126
               {
127
                  // force loop termination if cannot go up one more package level
128
                  pkg = null;
129
               }
2151 ghuddy 130
            }
131
         }
2155 ghuddy 132
 
133
         // tell caller we didnt find a ReqProDB stereotyped element.
2145 ghuddy 134
         return null;
135
      }
136
 
137
 
2141 ghuddy 138
      /// <summary>
139
      /// This method is used to create a ReqProDB element in an EA package.
140
      /// Do not modify the tag names that are in current use. Only extend with
141
      /// additional new tags.
142
      /// </summary>
143
      /// <param name="ea_repository"></param>
144
      /// <param name="package"></param>
145
      /// <param name="name"></param>
146
      /// <param name="description"></param>
147
      /// <param name="reqpro_db_username"></param>
148
      /// <param name="reqpro_db_filename"></param>
149
      /// <param name="reqpro_db_guid"></param>
150
      /// <returns></returns>
2151 ghuddy 151
      public EA.Element create_rq_artifact( 
152
         EA.Package package,
153
         string name,
154
         string description,
155
         string reqpro_db_username,
156
         string reqpro_db_filename,
157
         string reqpro_db_guid)
158
      {
159
         package.Notes = description;
160
         package.Update();
161
 
162
         EA.Element element;
163
         element = (EA.Element)package.Elements.AddNew(name + " - " + reqpro_db_username, "Artifact");
164
         if (element != null)
165
         {
166
            element.Stereotype = "ReqProDB";
167
            element.Notes = description;
168
 
2155 ghuddy 169
            EA_TaggedValues.Write( element, Constants.TAG_DB_LOCATION, reqpro_db_filename);
170
            EA_TaggedValues.Write( element, Constants.TAG_DB_USERNAME, reqpro_db_username);
171
            EA_TaggedValues.Write( element, Constants.TAG_GUID, reqpro_db_guid);
2151 ghuddy 172
 
173
            element.Update();
174
            element.Refresh();
175
            element.TaggedValues.Refresh();
176
            package.Update();
177
            package.Packages.Refresh();
178
            package.Elements.Refresh();
179
 
180
            return element;
181
         }
182
         return null;
2141 ghuddy 183
      }
184
 
185
 
2151 ghuddy 186
      public void set_traceability_mode(EA.Element rq_artifact)
187
      {
2155 ghuddy 188
         EA_TaggedValues.Write( rq_artifact, Constants.TAG_MODE, "Traceability");
2151 ghuddy 189
         rq_artifact.Update();
190
      }
191
 
192
      public void set_doc_model_mode(EA.Element rq_artifact)
193
      {
2155 ghuddy 194
         EA_TaggedValues.Write( rq_artifact, Constants.TAG_MODE, "DocModel");
2151 ghuddy 195
         rq_artifact.Update();
196
      }
197
 
198
      public MODE get_mode(EA.Element rq_artifact)
199
      {
2155 ghuddy 200
         string mode = EA_TaggedValues.Read(rq_artifact, Constants.TAG_MODE);
2151 ghuddy 201
 
2155 ghuddy 202
         if (mode.Equals("Traceability"))
2151 ghuddy 203
            return MODE.TRACEABILITY;
2155 ghuddy 204
         else if (mode.Equals("DocModel"))
2151 ghuddy 205
            return MODE.DOC_MODEL;
206
 
207
         return MODE.UNDEFINED;
208
      }
209
   }
2141 ghuddy 210
}