diff -r 000000000000 -r 818e61de6cd1 crashanalysercmd/Libraries/File Formats/Plugins/CrashXmlPlugin/FileFormat/Segment/CXmlNodeSegmentTable.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crashanalysercmd/Libraries/File Formats/Plugins/CrashXmlPlugin/FileFormat/Segment/CXmlNodeSegmentTable.cs Thu Feb 11 15:50:58 2010 +0200 @@ -0,0 +1,133 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +using System; +using System.Text; +using System.Collections.Generic; +using System.IO; +using CrashItemLib.Engine; +using CrashXmlPlugin.FileFormat.Node; +using CrashXmlPlugin.FileFormat.Document; +using CrashXmlPlugin.FileFormat.Segment.Entries; +using SymbianUtils.PluginManager; + +namespace CrashXmlPlugin.FileFormat.Segment +{ + internal class CXmlNodeSegmentTable : CXmlNode, IEnumerable + { + #region Constructors + public CXmlNodeSegmentTable() + : base( Constants.SegmentTable ) + { + AddChildren(); + } + #endregion + + #region From CXmlNode + public override void XmlSerialize( CXmlDocumentSerializationParameters aParameters ) + { + try + { + // Serialize data to string + using ( CXmlDocumentSerializationParameters newParams = new CXmlDocumentSerializationParameters( aParameters, aParameters.Document, iSerializedData ) ) + { + base.XmlSerialize( newParams ); + + // The serialized XML data which is stored to this class' data member will + // be written later on by the segment dictionary. + newParams.Writer.Flush(); + + // Tidy up head and tail so that it matches the rest of the document. + string indent = aParameters.Writer.Settings.IndentChars; + string text = iSerializedData.ToString(); + using ( StringReader reader = new StringReader( text ) ) + { + iSerializedData.Length = 0; + string line = reader.ReadLine(); + while ( line != null ) + { + iSerializedData.AppendLine( indent + line ); + line = reader.ReadLine(); + } + } + iSerializedData.Insert( 0, System.Environment.NewLine ); + } + } + catch ( Exception ) + { + } + } + #endregion + + #region Properties + internal string SerializedData + { + get { return iSerializedData.ToString(); } + } + #endregion + + #region Internal methods + private void AddChildren() + { + PluginManager plugins = new PluginManager( 1 ); + plugins.LoadFromCallingAssembly(); + + // Sort them by priority + SortedList list = new SortedList(); + foreach( CXmlSegBase seg in plugins ) + { + list.Add( seg.SegmentPriority, seg ); + } + + // Now they are sorted, add them as children + foreach ( KeyValuePair kvp in list ) + { + base.Add( kvp.Value ); + } + } + #endregion + + #region From IEnumerable + public IEnumerator GetEnumerator() + { + foreach ( SymbianTree.SymNode node in base.Children ) + { + if ( node is CXmlSegBase ) + { + CXmlSegBase ret = (CXmlSegBase) node; + yield return ret; + } + } + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + foreach ( SymbianTree.SymNode node in base.Children ) + { + if ( node is CXmlSegBase ) + { + CXmlSegBase ret = (CXmlSegBase) node; + yield return ret; + } + } + } + #endregion + + #region Data members + private StringBuilder iSerializedData = new StringBuilder(); + #endregion + } +}