Subversion Repositories DevTools

Rev

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