Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
2088 ghuddy 1
using System;
2
using System.Windows.Forms;
3
using System.IO;
4
using System.Collections;
2094 ghuddy 5
using System.Collections.Specialized;
6
using System.Text;
2088 ghuddy 7
 
8
namespace EA_DocGen
9
{
10
   /// <summary>
11
   /// Summary description for EA_DocGenOptions.
12
   /// </summary>
13
   public class EA_DocGenOptions
14
   {
2094 ghuddy 15
      public const string optstr_GeneralOptions = "[GeneralOptions]";
16
      public const string optstr_ElementTypes   = "[ElementTypes]";
17
      public const string optstr_SuppressElementDescriptionMissingWarnings = "SuppressElementDescriptionMissingWarnings";
2104 ghuddy 18
      public const string optstr_SuppressUnAllocatedRelationshipWarnings = "SuppressUnAllocatedRelationshipWarnings";
2096 ghuddy 19
      public const string optstr_SuppressPrivateAttributes = "SuppressPrivateAttributes";
2104 ghuddy 20
      public const string optstr_SuppressPrivateMethods    = "SuppressPrivateMethods";
21
      public const string optstr_SuppressPrivateClasses    = "SuppressPrivateClasses";
22
      public const string optstr_ConsiderAPIElementsOnly   = "ConsiderAPIClassesOnly";
23
      public const string optstr_ConsiderAPIPackagesOnly   = "ConsiderAPIPackagesOnly";
24
      public const string optstr_ConsiderAPIDiagramsOnly   = "ConsiderAPIDiagramsOnly";
25
      public const string optstr_RestrictForLinkedPackagesOnly = "APIPackageRestrictionForLinkedPackagesOnly";
2094 ghuddy 26
 
27
 
2088 ghuddy 28
      private string [] options_string = null;
29
      private bool options_found = false;
30
 
31
      // General options
32
 
2094 ghuddy 33
      public bool opt_SuppressElementDescriptionMissingWarnings;
2104 ghuddy 34
      public bool opt_SuppressUnAllocatedRelationshipWarnings;
2094 ghuddy 35
 
2088 ghuddy 36
 
2094 ghuddy 37
      // Visibility options
2096 ghuddy 38
      public bool opt_SuppressPrivateAttributes;
39
      public bool opt_SuppressPrivateMethods;
40
      public bool opt_SuppressPrivateClasses;
2094 ghuddy 41
 
2104 ghuddy 42
      public bool opt_ConsiderAPIElementsOnly;
43
      public bool opt_ConsiderAPIPackagesOnly;
44
      public bool opt_ConsiderAPIDiagramsOnly;
45
      public bool opt_RestrictForLinkedPackagesOnly;
2094 ghuddy 46
 
47
 
2088 ghuddy 48
      // Element Types list
2094 ghuddy 49
      public ArrayList opt_ElementTypes = null;
2088 ghuddy 50
 
51
 
52
      private EA_Utilities EA_Utils = null;
53
 
54
      public EA_DocGenOptions(EA_Utilities EA_UtilsRef)
55
      {
56
         EA_Utils = EA_UtilsRef;
57
         opt_ElementTypes = new ArrayList();
58
         setDefaults();
59
      }
60
 
61
 
62
      private void setDefaults()
63
      {
2094 ghuddy 64
         opt_SuppressElementDescriptionMissingWarnings = false;
2104 ghuddy 65
         opt_SuppressUnAllocatedRelationshipWarnings = false;
66
         opt_SuppressPrivateAttributes = false;
67
         opt_SuppressPrivateMethods    = false;
68
         opt_SuppressPrivateClasses    = false;
69
         opt_ConsiderAPIElementsOnly   = false;
70
         opt_ConsiderAPIDiagramsOnly   = false;
71
         opt_ConsiderAPIPackagesOnly   = false;
72
         opt_RestrictForLinkedPackagesOnly = true;
2088 ghuddy 73
      }
74
 
75
 
76
      /// <summary>
77
      /// Looks for the EA_DocGen element in the selected package. To generate a document
78
      /// on a package, the package must contain the EA_DocGen element, even if that elements
79
      /// notes are empty. It serves to denote a package as a document model that is allowed
80
      /// to be processed by this add-in.
81
      /// </summary>
82
      /// <param name="parentPackage"></param>
83
      /// <returns></returns>
84
      public bool lookForAndProcess_EA_DocGen_Element( EA.Package parentPackage )
85
      {
86
         options_found  = false;
87
         setDefaults();
88
 
89
         // Look for an EA_DocGen element in this package
90
         foreach(EA.Element theElement in parentPackage.Elements)
91
         {
2094 ghuddy 92
            options_found = lookForAndProcess_EA_DocGen_Element(theElement);
93
            if (options_found)
94
               break;
95
         }            
96
         return options_found;
97
      }
2088 ghuddy 98
 
2094 ghuddy 99
      public bool lookForAndProcess_EA_DocGen_Element( EA.Element theElement )
100
      {
101
         options_string = null;
102
         options_found  = false;
103
         setDefaults();
2088 ghuddy 104
 
2094 ghuddy 105
         // Special handling for the EA_DocGen element designed to control this document
106
         // generator
107
         if (0 == theElement.Name.CompareTo(EA_Constants.EA_DocGenBaseName))
108
         {
109
            options_found = true;
2088 ghuddy 110
 
2094 ghuddy 111
            // Extract the content of the EA_DocGen element notes section, into a list of
112
            // strings.
113
            string delimStr = "\n";
114
            char [] delim = delimStr.ToCharArray();
115
            options_string = theElement.Notes.ToString().Split(delim,200);
116
 
117
            int i = 0;
118
            foreach(string s in options_string)
119
            {
120
               options_string[i] = s.Trim();
121
               i++;
2088 ghuddy 122
            }
123
 
2094 ghuddy 124
            // Extract general options from the list of strings
125
            extractGeneralOptions();
126
 
127
            // Extract element types list from the list of strings
128
            extractElementTypes();
129
         }
130
 
2088 ghuddy 131
         return options_found;
132
      }
133
 
134
 
135
      private string getOptionValueString(string optionLine)
136
      {
137
         string delimStr = "=";
138
         char [] delim = delimStr.ToCharArray();
139
         string [] optionLineParts = optionLine.Split(delim,2);
140
         if (optionLineParts.GetLength(0) == 2)
141
         {
142
            return optionLineParts[1];
143
         }
144
         else
145
         {
146
            MessageBox.Show( "Error in EA_DocGen option\n\n" + optionLine + "\n\n" + "Missing value" );
147
         }
148
         return null;
149
      }
150
 
151
 
152
      // Overloaded "get option value" methods
153
      public int getOptionValue(string s, int defaultReturnValue)
154
      {
155
         int returnVal = defaultReturnValue;
156
 
157
         string optionValue = getOptionValueString(s);
158
         if (optionValue != null)
159
         {
160
            try
161
            {
162
               returnVal = Convert.ToInt32(optionValue);
163
            }
164
            catch(Exception)
165
            {
166
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid integer" );
167
            }
168
         }   
169
         return returnVal;
170
      }
171
 
2100 ghuddy 172
      public double getOptionValue(string s, double defaultReturnValue)
173
      {
174
         double returnVal = defaultReturnValue;
175
 
176
         string optionValue = getOptionValueString(s);
177
         if (optionValue != null)
178
         {
179
            try
180
            {
181
               returnVal = Convert.ToDouble(optionValue);
182
            }
183
            catch(Exception)
184
            {
185
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid double" );
186
            }
187
         }   
188
         return returnVal;
189
      }
190
 
2088 ghuddy 191
      public bool getOptionValue(string s, bool defaultReturnValue)
192
      {
193
         bool returnVal = defaultReturnValue;
194
 
195
         string optionValue = getOptionValueString(s);
196
         if (optionValue != null)
197
         {
198
            try
199
            {
200
               returnVal = Convert.ToBoolean(optionValue);
201
            }
202
            catch(Exception)
203
            {
204
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid boolean" );
205
            }
206
         }   
207
         return returnVal;
208
      }
209
 
210
 
211
      public string getOptionValue(string s, string defaultReturnValue)
212
      {
213
         string returnVal = defaultReturnValue;
214
 
215
         string optionValue = getOptionValueString(s);
216
         if (optionValue != null)
217
         {
218
            returnVal = optionValue;
219
         }   
220
         return returnVal;
221
      }
222
 
223
 
224
      public char getOptionValue(string s, char defaultReturnValue)
225
      {
226
         char returnVal = defaultReturnValue;
227
 
228
         string optionValue = getOptionValueString(s);
229
         if (optionValue != null && optionValue.Length > 0)
230
         {
231
            returnVal = optionValue[0];
232
         }   
233
         return returnVal;
234
      }
235
 
236
 
237
 
238
      /// <summary>
239
      /// Method to extract all the general options from the string array obtained from
240
      /// the EA_DocGen element
241
      /// </summary>
242
      private void extractGeneralOptions()
243
      {
244
         bool parsingGenOpts = false;
245
 
246
         if (options_string != null)
247
         {
248
            // iterate through the string array obtained from the EA_DocGen element
249
            foreach(string s in options_string)
250
            {
2094 ghuddy 251
               if (s.StartsWith(optstr_GeneralOptions))
2088 ghuddy 252
               {
253
                  parsingGenOpts = true;
254
                  continue;
255
               }
256
               else if (   (parsingGenOpts == true) 
257
                        && (s.Length >= 1)
258
                        && (s.Substring(0,1) == "[") )
259
               {
260
                  // we have gone past the general options and reached another section in EA_DocGen
261
                  // so there is no point in continuing. Exit the loop
262
                  break;
263
               }
264
 
265
               if (parsingGenOpts == true)
266
               {
2104 ghuddy 267
                  if (s.StartsWith(optstr_SuppressElementDescriptionMissingWarnings))
2088 ghuddy 268
                  {
2104 ghuddy 269
                     opt_SuppressElementDescriptionMissingWarnings = getOptionValue(s, opt_SuppressElementDescriptionMissingWarnings);
2088 ghuddy 270
                  }
2104 ghuddy 271
                  else if (s.StartsWith(optstr_SuppressUnAllocatedRelationshipWarnings))
2088 ghuddy 272
                  {
2104 ghuddy 273
                     opt_SuppressUnAllocatedRelationshipWarnings = getOptionValue(s, opt_SuppressUnAllocatedRelationshipWarnings);
2088 ghuddy 274
                  }
2094 ghuddy 275
                  else if (s.StartsWith(optstr_SuppressPrivateClasses))
276
                  {
277
                     opt_SuppressPrivateClasses = getOptionValue(s, opt_SuppressPrivateClasses);
278
                  }
2096 ghuddy 279
                  else if (s.StartsWith(optstr_SuppressPrivateAttributes))
2094 ghuddy 280
                  {
281
                     opt_SuppressPrivateAttributes = getOptionValue(s, opt_SuppressPrivateAttributes);
282
                  }
283
                  else if (s.StartsWith(optstr_SuppressPrivateMethods))
284
                  {
285
                     opt_SuppressPrivateMethods = getOptionValue(s, opt_SuppressPrivateMethods);
286
                  }
2104 ghuddy 287
                  else if (s.StartsWith(optstr_ConsiderAPIElementsOnly))
288
                  {
289
                     opt_ConsiderAPIElementsOnly = getOptionValue(s, opt_ConsiderAPIElementsOnly);
290
                  }
291
                  else if (s.StartsWith(optstr_ConsiderAPIPackagesOnly))
292
                  {
293
                     opt_ConsiderAPIPackagesOnly = getOptionValue(s, opt_ConsiderAPIPackagesOnly);
294
                  }
295
                  else if (s.StartsWith(optstr_RestrictForLinkedPackagesOnly))
296
                  {
297
                     opt_RestrictForLinkedPackagesOnly = getOptionValue(s, opt_RestrictForLinkedPackagesOnly);
298
                  }
299
                  else if (s.StartsWith(optstr_ConsiderAPIDiagramsOnly))
300
                  {
301
                     opt_ConsiderAPIDiagramsOnly = getOptionValue(s, opt_ConsiderAPIDiagramsOnly);
302
                  }
2088 ghuddy 303
                  // add others here
304
 
305
               }
306
            }         
307
         }
308
      }
309
 
310
 
311
      private void extractElementTypes()
312
      {
313
         bool parsingElementTypes = false;
314
 
315
         opt_ElementTypes.Clear();
316
 
317
         if (options_string != null)
318
         {
319
            // iterate through the string array obtained from the EA_DocGen element
320
            foreach(string s in options_string)
321
            {
2094 ghuddy 322
               if (s.StartsWith(optstr_ElementTypes))
2088 ghuddy 323
               {
324
                  parsingElementTypes = true;
325
                  continue;
326
               }
327
               else if (   (parsingElementTypes == true) 
328
                        && (s.Length >= 1)
329
                        && (s.Substring(0,1) == "[") )
330
               {
331
                  // we have gone past the element types and reached another section in EA_DocGen
332
                  // so there is no point in continuing. Exit the loop
333
                  break;
334
               }
335
 
336
               if (parsingElementTypes == true)
337
               {
338
                  string trimmed_s = s.Trim();
339
                  if (trimmed_s.Length > 0)
340
                  {
341
                     opt_ElementTypes.Add( s );
342
                  }
343
               }
344
            }
345
         }
346
      }
347
 
348
 
349
      /// <summary>
350
      /// This method searches the EA_DocGen string list to find the element types the user
351
      /// has specified that must be included in the document. If the element type given to
352
      /// the function is not in that list then it is excluded from the generated document.
353
      /// The notes of the EA_DocGen element are formed like a .ini file and contain sections 
354
      /// and section content along the lines of:
355
      /// 
356
      /// [sectionName]
357
      /// value
358
      /// value
359
      /// etc
360
      /// [anotherSectionName]
361
      /// value
362
      /// value
363
      /// etc
364
      /// 
365
      /// The [ElementTypes] section is the one this function is interested in
366
      /// 
367
      /// </summary>
368
      /// <param name="elementName"></param>
369
      /// <returns></returns>
370
      public bool elementTypeFoundInEA_DocGen(string elementType)
371
      {
372
         if (opt_ElementTypes != null && opt_ElementTypes.Count > 0)
373
         {
374
            foreach(string s in opt_ElementTypes)
375
            {
376
               if (s.StartsWith(elementType))
377
               {
378
                  return true;
379
               }
380
            } 
381
            // elementType is not in the opt_ElementTypes list, so element is filtered out
382
            return false;
383
         }
384
         else
385
         {
386
            // opt_ElementTypes is empty so no filtering, return true 
387
            return true;
388
         }
389
      }
390
 
2094 ghuddy 391
      private void updateEA_DocGen(ref StringBuilder sb, bool bValue, string s)
392
      {
393
         sb.Append( s );
394
         sb.Append( "=" );
395
         sb.Append( bValue.ToString() );
396
         sb.Append( "\r\n" );
397
      }
2088 ghuddy 398
 
2094 ghuddy 399
      private void updateEA_DocGen(ref StringBuilder sb, int iValue, string s)
400
      {
401
         sb.Append( s );
402
         sb.Append( "=" );
403
         sb.Append( iValue.ToString() );
404
         sb.Append( "\r\n" );
405
      }
406
 
407
      public void updateEA_DocGen(EA.Element ele)
408
      {
409
         StringBuilder sb = new StringBuilder();
410
 
411
         sb.Append( optstr_GeneralOptions );
412
         sb.Append( "\r\n" );
413
 
414
         // Missing Description handling options
415
         updateEA_DocGen(ref sb, opt_SuppressElementDescriptionMissingWarnings, optstr_SuppressElementDescriptionMissingWarnings);
2104 ghuddy 416
         updateEA_DocGen(ref sb, opt_SuppressUnAllocatedRelationshipWarnings, optstr_SuppressUnAllocatedRelationshipWarnings);
2094 ghuddy 417
 
418
         // visibility options
419
         updateEA_DocGen(ref sb, opt_SuppressPrivateClasses,    optstr_SuppressPrivateClasses);
2096 ghuddy 420
         updateEA_DocGen(ref sb, opt_SuppressPrivateAttributes, optstr_SuppressPrivateAttributes);
2094 ghuddy 421
         updateEA_DocGen(ref sb, opt_SuppressPrivateMethods,    optstr_SuppressPrivateMethods);
2104 ghuddy 422
         updateEA_DocGen(ref sb, opt_ConsiderAPIElementsOnly,   optstr_ConsiderAPIElementsOnly);
423
         updateEA_DocGen(ref sb, opt_ConsiderAPIDiagramsOnly,   optstr_ConsiderAPIDiagramsOnly);
424
         updateEA_DocGen(ref sb, opt_ConsiderAPIPackagesOnly,   optstr_ConsiderAPIPackagesOnly);
425
         updateEA_DocGen(ref sb, opt_RestrictForLinkedPackagesOnly, optstr_RestrictForLinkedPackagesOnly);
2094 ghuddy 426
 
2104 ghuddy 427
 
2094 ghuddy 428
         // Element type filtering options
429
         if (opt_ElementTypes.Count > 0)
430
         {
431
            sb.Append( "\r\n" );
432
            sb.Append( optstr_ElementTypes );
433
            sb.Append( "\r\n" );
434
            foreach (string s in opt_ElementTypes)
435
            {
436
               sb.Append( s );
437
               sb.Append( "\r\n" );
438
            }
439
         }
440
 
441
         ele.Notes = sb.ToString();
442
         ele.Update();
443
 
444
      }
445
 
2088 ghuddy 446
   } // end of class
447
} // end of namespace