Subversion Repositories DevTools

Rev

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