crashanalysercmd/Libraries/File Formats/Plugins/XmlFilePlugin/PluginImplementations/Sink/CXmlFileSink.cs
changeset 2 0c91f0baec58
equal deleted inserted replaced
1:7a31f7298d8f 2:0c91f0baec58
       
     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 * The class CCrashInfoFileSink is part of CrashAnalyser CrashInfoFile plugin.
       
    16 * Sink output plugin for Crash Info File format.
       
    17 * Implements CISink which is automatically discovered by CISinkManager.
       
    18 * Serialize function produces a Crash Info file formatted text output
       
    19 * 
       
    20 */
       
    21 
       
    22 using System;
       
    23 using System.Collections.Generic;
       
    24 using System.Text;
       
    25 using System.Xml;
       
    26 
       
    27 using CrashItemLib.Sink;
       
    28 
       
    29 //using CrashItemLib.Crash.Symbols;
       
    30 //using CrashItemLib.Crash.CodeSegs;
       
    31 //using CrashItemLib.Crash.Registers;
       
    32 //using CrashItemLib.Crash.Threads;
       
    33 
       
    34 
       
    35 using XmlFilePlugin.PluginImplementations.FileFormat;
       
    36 using System.IO;
       
    37 
       
    38 namespace XmlFilePlugin.PluginImplementations.Sink
       
    39 {
       
    40     public class CXmlFileSink : CISink
       
    41     {
       
    42         #region Constants
       
    43         public const string KCrashInfoSinkName = "XML Crash File";
       
    44         #endregion
       
    45 
       
    46         #region Constructors
       
    47         public CXmlFileSink(CISinkManager aManager)
       
    48             : base(KCrashInfoSinkName, aManager)
       
    49         {
       
    50         }
       
    51         #endregion
       
    52 
       
    53         #region From CISink
       
    54 
       
    55         public override object Serialize(CISinkSerializationParameters aParams)
       
    56         {
       
    57             CXmlFileDocument document = new CXmlFileDocument();
       
    58 
       
    59             //Read information relevant to crash info file from container to internal variables
       
    60             document.ReadDataFromContainer(aParams);
       
    61             string newFileName = "";
       
    62             if (aParams.PlainTextOutput)
       
    63             {
       
    64                 //Override default file extension
       
    65                 aParams.FileExtensionFailed = ".corrupt_txt";
       
    66                 aParams.FileExtensionSuccess = ".txt";
       
    67 
       
    68                 //Write document's internal data to file
       
    69                 newFileName = string.Empty;
       
    70                 using (Stream output = aParams.CreateFile(out newFileName))
       
    71                 {
       
    72                     using (StreamWriter sw = new StreamWriter(output, Encoding.ASCII))
       
    73                     {
       
    74                         document.WriteToPlainTextStream(sw);
       
    75                     }
       
    76                 }
       
    77             }
       
    78             else // XML output
       
    79             {
       
    80                 //Override default file extension
       
    81                 aParams.FileExtensionFailed = ".corrupt_xml";
       
    82                 aParams.FileExtensionSuccess = ".xml";
       
    83 
       
    84                 //Write document's internal data to file
       
    85                 newFileName = string.Empty;
       
    86                 using (Stream output = aParams.CreateFile(out newFileName))
       
    87                 {
       
    88                     XmlWriterSettings settings = new XmlWriterSettings();
       
    89                     settings.Indent = true;
       
    90                     settings.NewLineChars = XmlConsts.Kxml_EOL;
       
    91                     settings.NewLineHandling = NewLineHandling.None;
       
    92                     using (XmlWriter sw = XmlWriter.Create(output, settings))
       
    93                     {
       
    94                         document.WriteToXmlStream(sw);
       
    95                     }
       
    96                 }
       
    97             }
       
    98             return newFileName;
       
    99         }
       
   100 
       
   101         #endregion
       
   102     }
       
   103 }