Subversion Repositories DevTools

Rev

Rev 2094 | Rev 2100 | 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
 
171
 
172
      public bool getOptionValue(string s, bool defaultReturnValue)
173
      {
174
         bool returnVal = defaultReturnValue;
175
 
176
         string optionValue = getOptionValueString(s);
177
         if (optionValue != null)
178
         {
179
            try
180
            {
181
               returnVal = Convert.ToBoolean(optionValue);
182
            }
183
            catch(Exception)
184
            {
185
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid boolean" );
186
            }
187
         }   
188
         return returnVal;
189
      }
190
 
191
 
192
      public string getOptionValue(string s, string defaultReturnValue)
193
      {
194
         string returnVal = defaultReturnValue;
195
 
196
         string optionValue = getOptionValueString(s);
197
         if (optionValue != null)
198
         {
199
            returnVal = optionValue;
200
         }   
201
         return returnVal;
202
      }
203
 
204
 
205
      public char getOptionValue(string s, char defaultReturnValue)
206
      {
207
         char returnVal = defaultReturnValue;
208
 
209
         string optionValue = getOptionValueString(s);
210
         if (optionValue != null && optionValue.Length > 0)
211
         {
212
            returnVal = optionValue[0];
213
         }   
214
         return returnVal;
215
      }
216
 
217
 
218
 
219
      /// <summary>
220
      /// Method to extract all the general options from the string array obtained from
221
      /// the EA_DocGen element
222
      /// </summary>
223
      private void extractGeneralOptions()
224
      {
225
         bool parsingGenOpts = false;
226
 
227
         if (options_string != null)
228
         {
229
            // iterate through the string array obtained from the EA_DocGen element
230
            foreach(string s in options_string)
231
            {
2094 ghuddy 232
               if (s.StartsWith(optstr_GeneralOptions))
2088 ghuddy 233
               {
234
                  parsingGenOpts = true;
235
                  continue;
236
               }
237
               else if (   (parsingGenOpts == true) 
238
                        && (s.Length >= 1)
239
                        && (s.Substring(0,1) == "[") )
240
               {
241
                  // we have gone past the general options and reached another section in EA_DocGen
242
                  // so there is no point in continuing. Exit the loop
243
                  break;
244
               }
245
 
246
               if (parsingGenOpts == true)
247
               {
2094 ghuddy 248
                  if (s.StartsWith(optstr_ElementHeadingStyleTransitionsToNumParaAtLevel))
2088 ghuddy 249
                  {
250
                     opt_ElementHeadingTransitionLevel = getOptionValue(s, opt_ElementHeadingTransitionLevel);
251
                  }
2094 ghuddy 252
                  else if (s.StartsWith(optstr_DisplayRequirementElementsAsSections))
2088 ghuddy 253
                  {
254
                     opt_DisplayRequirementElementsAsSections = getOptionValue(s, opt_DisplayRequirementElementsAsSections);
255
                  }
2094 ghuddy 256
                  else if (s.StartsWith(optstr_RequirementElementDisplayFormat))
2088 ghuddy 257
                  {
258
                     opt_RequirementElementDisplayFormat = getOptionValue(s, opt_RequirementElementDisplayFormat);
259
                  }
2094 ghuddy 260
                  else if (s.StartsWith(optstr_DisplayRequirementsWithStatus))
2088 ghuddy 261
                  {
262
                     opt_DisplayRequirementsWithStatus = getOptionValue(s, opt_DisplayRequirementsWithStatus);
263
                  }
2094 ghuddy 264
                  else if (s.StartsWith(optstr_SuppressElementDescriptionMissingWarnings))
265
                  {
266
                     opt_SuppressElementDescriptionMissingWarnings = getOptionValue(s, opt_SuppressElementDescriptionMissingWarnings);
267
                  }
268
                  else if (s.StartsWith(optstr_SuppressPrivateClasses))
269
                  {
270
                     opt_SuppressPrivateClasses = getOptionValue(s, opt_SuppressPrivateClasses);
271
                  }
2096 ghuddy 272
                  else if (s.StartsWith(optstr_SuppressPrivateAttributes))
2094 ghuddy 273
                  {
274
                     opt_SuppressPrivateAttributes = getOptionValue(s, opt_SuppressPrivateAttributes);
275
                  }
276
                  else if (s.StartsWith(optstr_SuppressPrivateMethods))
277
                  {
278
                     opt_SuppressPrivateMethods = getOptionValue(s, opt_SuppressPrivateMethods);
279
                  }
2088 ghuddy 280
 
281
 
282
                  // add others here
283
 
284
               }
285
            }         
286
         }
287
      }
288
 
289
 
290
      private void extractElementTypes()
291
      {
292
         bool parsingElementTypes = false;
293
 
294
         opt_ElementTypes.Clear();
295
 
296
         if (options_string != null)
297
         {
298
            // iterate through the string array obtained from the EA_DocGen element
299
            foreach(string s in options_string)
300
            {
2094 ghuddy 301
               if (s.StartsWith(optstr_ElementTypes))
2088 ghuddy 302
               {
303
                  parsingElementTypes = true;
304
                  continue;
305
               }
306
               else if (   (parsingElementTypes == true) 
307
                        && (s.Length >= 1)
308
                        && (s.Substring(0,1) == "[") )
309
               {
310
                  // we have gone past the element types and reached another section in EA_DocGen
311
                  // so there is no point in continuing. Exit the loop
312
                  break;
313
               }
314
 
315
               if (parsingElementTypes == true)
316
               {
317
                  string trimmed_s = s.Trim();
318
                  if (trimmed_s.Length > 0)
319
                  {
320
                     opt_ElementTypes.Add( s );
321
                  }
322
               }
323
            }
324
         }
325
      }
326
 
327
 
328
      /// <summary>
329
      /// This method searches the EA_DocGen string list to find the element types the user
330
      /// has specified that must be included in the document. If the element type given to
331
      /// the function is not in that list then it is excluded from the generated document.
332
      /// The notes of the EA_DocGen element are formed like a .ini file and contain sections 
333
      /// and section content along the lines of:
334
      /// 
335
      /// [sectionName]
336
      /// value
337
      /// value
338
      /// etc
339
      /// [anotherSectionName]
340
      /// value
341
      /// value
342
      /// etc
343
      /// 
344
      /// The [ElementTypes] section is the one this function is interested in
345
      /// 
346
      /// </summary>
347
      /// <param name="elementName"></param>
348
      /// <returns></returns>
349
      public bool elementTypeFoundInEA_DocGen(string elementType)
350
      {
351
         if (opt_ElementTypes != null && opt_ElementTypes.Count > 0)
352
         {
353
            foreach(string s in opt_ElementTypes)
354
            {
355
               if (s.StartsWith(elementType))
356
               {
357
                  return true;
358
               }
359
            } 
360
            // elementType is not in the opt_ElementTypes list, so element is filtered out
361
            return false;
362
         }
363
         else
364
         {
365
            // opt_ElementTypes is empty so no filtering, return true 
366
            return true;
367
         }
368
      }
369
 
2094 ghuddy 370
      private void updateEA_DocGen(ref StringBuilder sb, bool bValue, string s)
371
      {
372
         sb.Append( s );
373
         sb.Append( "=" );
374
         sb.Append( bValue.ToString() );
375
         sb.Append( "\r\n" );
376
      }
2088 ghuddy 377
 
2094 ghuddy 378
      private void updateEA_DocGen(ref StringBuilder sb, int iValue, string s)
379
      {
380
         sb.Append( s );
381
         sb.Append( "=" );
382
         sb.Append( iValue.ToString() );
383
         sb.Append( "\r\n" );
384
      }
385
 
386
      public void updateEA_DocGen(EA.Element ele)
387
      {
388
         StringBuilder sb = new StringBuilder();
389
 
390
         sb.Append( optstr_GeneralOptions );
391
         sb.Append( "\r\n" );
392
 
393
         // Requirement Display options
394
         if (opt_DisplayRequirementsWithStatus)
395
         {
396
            sb.Append( optstr_DisplayRequirementsWithStatus );
397
            sb.Append( "=true\r\n" );
398
            sb.Append( optstr_DisplayRequirementElementsAsSections );
399
            sb.Append( "=false\r\n" );
400
         }
401
         else if (opt_DisplayRequirementElementsAsSections)
402
         {
403
            sb.Append( optstr_DisplayRequirementsWithStatus );
404
            sb.Append( "=false\r\n" );
405
            sb.Append( optstr_DisplayRequirementElementsAsSections );
406
            sb.Append( "=true\r\n" );
407
         }
408
         else
409
         {
410
            sb.Append( optstr_DisplayRequirementsWithStatus );
411
            sb.Append( "=false\r\n" );
412
            sb.Append( optstr_DisplayRequirementElementsAsSections );
413
            sb.Append( "=false\r\n" );
414
            sb.Append( optstr_RequirementElementDisplayFormat );
415
            sb.Append( "=" );
416
            sb.Append( opt_RequirementElementDisplayFormat );
417
            sb.Append( "\r\n" );
418
         }
419
 
420
         // Missing Description handling options
421
         updateEA_DocGen(ref sb, opt_SuppressElementDescriptionMissingWarnings, optstr_SuppressElementDescriptionMissingWarnings);
422
 
423
         // NumPara transition option
424
         updateEA_DocGen(ref sb, opt_ElementHeadingTransitionLevel, optstr_ElementHeadingStyleTransitionsToNumParaAtLevel);
425
 
426
         // visibility options
427
         updateEA_DocGen(ref sb, opt_SuppressPrivateClasses,    optstr_SuppressPrivateClasses);
2096 ghuddy 428
         updateEA_DocGen(ref sb, opt_SuppressPrivateAttributes, optstr_SuppressPrivateAttributes);
2094 ghuddy 429
         updateEA_DocGen(ref sb, opt_SuppressPrivateMethods,    optstr_SuppressPrivateMethods);
430
 
431
         // Element type filtering options
432
         if (opt_ElementTypes.Count > 0)
433
         {
434
            sb.Append( "\r\n" );
435
            sb.Append( optstr_ElementTypes );
436
            sb.Append( "\r\n" );
437
            foreach (string s in opt_ElementTypes)
438
            {
439
               sb.Append( s );
440
               sb.Append( "\r\n" );
441
            }
442
         }
443
 
444
         ele.Notes = sb.ToString();
445
         ele.Update();
446
 
447
      }
448
 
2088 ghuddy 449
   } // end of class
450
} // end of namespace