crashanalysercmd/Libraries/File Formats/Plugins/CrashXmlPlugin/FileFormat/Segment/CXmlNodeSegmentTable.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Text;
       
    19 using System.Collections.Generic;
       
    20 using System.IO;
       
    21 using CrashItemLib.Engine;
       
    22 using CrashXmlPlugin.FileFormat.Node;
       
    23 using CrashXmlPlugin.FileFormat.Document;
       
    24 using CrashXmlPlugin.FileFormat.Segment.Entries;
       
    25 using SymbianUtils.PluginManager;
       
    26 
       
    27 namespace CrashXmlPlugin.FileFormat.Segment
       
    28 {
       
    29 	internal class CXmlNodeSegmentTable : CXmlNode, IEnumerable<CXmlSegBase>
       
    30 	{
       
    31 		#region Constructors
       
    32         public CXmlNodeSegmentTable()
       
    33             : base( Constants.SegmentTable )
       
    34 		{
       
    35             AddChildren();
       
    36         }
       
    37 		#endregion
       
    38 
       
    39         #region From CXmlNode
       
    40         public override void XmlSerialize( CXmlDocumentSerializationParameters aParameters )
       
    41         {
       
    42             try
       
    43             {
       
    44                 // Serialize data to string
       
    45                 using ( CXmlDocumentSerializationParameters newParams = new CXmlDocumentSerializationParameters( aParameters, aParameters.Document, iSerializedData ) )
       
    46                 {
       
    47                     base.XmlSerialize( newParams );
       
    48 
       
    49                     // The serialized XML data which is stored to this class' data member will
       
    50                     // be written later on by the segment dictionary.
       
    51                     newParams.Writer.Flush();
       
    52 
       
    53                     // Tidy up head and tail so that it matches the rest of the document.
       
    54                     string indent = aParameters.Writer.Settings.IndentChars;
       
    55                     string text = iSerializedData.ToString();
       
    56                     using ( StringReader reader = new StringReader( text ) )
       
    57                     {
       
    58                         iSerializedData.Length = 0;
       
    59                         string line = reader.ReadLine();
       
    60                         while ( line != null )
       
    61                         {
       
    62                             iSerializedData.AppendLine( indent + line );
       
    63                             line = reader.ReadLine();
       
    64                         }
       
    65                     }
       
    66                     iSerializedData.Insert( 0, System.Environment.NewLine );
       
    67                 }
       
    68             }
       
    69             catch ( Exception )
       
    70             {
       
    71             }
       
    72         }
       
    73         #endregion
       
    74 
       
    75         #region Properties
       
    76         internal string SerializedData
       
    77         {
       
    78             get { return iSerializedData.ToString(); }
       
    79         }
       
    80         #endregion
       
    81 
       
    82         #region Internal methods
       
    83         private void AddChildren()
       
    84         {
       
    85             PluginManager<CXmlSegBase> plugins = new PluginManager<CXmlSegBase>( 1 );
       
    86             plugins.LoadFromCallingAssembly();
       
    87             
       
    88             // Sort them by priority
       
    89             SortedList<int, CXmlSegBase> list = new SortedList<int,CXmlSegBase>();
       
    90             foreach( CXmlSegBase seg in plugins )
       
    91             {
       
    92                 list.Add( seg.SegmentPriority, seg );
       
    93             }
       
    94 
       
    95             // Now they are sorted, add them as children
       
    96             foreach ( KeyValuePair<int, CXmlSegBase> kvp in list )
       
    97             {
       
    98                 base.Add( kvp.Value );
       
    99             }
       
   100         }
       
   101         #endregion
       
   102 
       
   103         #region From IEnumerable<CXmlSegBase>
       
   104         public IEnumerator<CXmlSegBase> GetEnumerator()
       
   105         {
       
   106             foreach ( SymbianTree.SymNode node in base.Children )
       
   107             {
       
   108                 if ( node is CXmlSegBase )
       
   109                 {
       
   110                     CXmlSegBase ret = (CXmlSegBase) node;
       
   111                     yield return ret;
       
   112                 }
       
   113             }
       
   114         }
       
   115 
       
   116         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   117         {
       
   118             foreach ( SymbianTree.SymNode node in base.Children )
       
   119             {
       
   120                 if ( node is CXmlSegBase )
       
   121                 {
       
   122                     CXmlSegBase ret = (CXmlSegBase) node;
       
   123                     yield return ret;
       
   124                 }
       
   125             }
       
   126         }
       
   127         #endregion
       
   128 
       
   129         #region Data members
       
   130         private StringBuilder iSerializedData = new StringBuilder();
       
   131 		#endregion
       
   132     }
       
   133 }