|
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.Xml; |
|
20 using System.Collections.Generic; |
|
21 using CrashItemLib.Crash.Container; |
|
22 |
|
23 namespace CAPCrashAnalysis.CommandLine |
|
24 { |
|
25 internal class CACmdLineManifestWriter |
|
26 { |
|
27 #region Constructors |
|
28 public CACmdLineManifestWriter( CACmdLineFSEntityList<CACmdLineFileSource> aSourceFiles ) |
|
29 { |
|
30 iSourceFiles = aSourceFiles; |
|
31 } |
|
32 #endregion |
|
33 |
|
34 #region API |
|
35 public string Create() |
|
36 { |
|
37 // This is where the XML will be stored |
|
38 StringBuilder backBuffer = new StringBuilder(); |
|
39 |
|
40 // Create XML writer |
|
41 XmlWriterSettings settings = new XmlWriterSettings(); |
|
42 settings.Indent = true; |
|
43 settings.IndentChars = " "; |
|
44 settings.NewLineChars = System.Environment.NewLine; |
|
45 settings.NewLineHandling = NewLineHandling.Replace; |
|
46 settings.Encoding = Encoding.UTF8; |
|
47 |
|
48 using ( XmlWriter writer = XmlWriter.Create( backBuffer, settings ) ) |
|
49 { |
|
50 // Serialise manifest for each file |
|
51 writer.WriteStartElement( KXmlRoot ); |
|
52 |
|
53 foreach ( CACmdLineFileSource file in iSourceFiles ) |
|
54 { |
|
55 System.Diagnostics.Debug.Assert( file.ContainerCount >= 1 ); |
|
56 |
|
57 foreach ( CACmdLineFileSource.OutputEntry outputEntry in file.Outputs ) |
|
58 { |
|
59 CIContainer container = outputEntry.Container; |
|
60 string outputFile = outputEntry.OutputFileName; |
|
61 |
|
62 writer.WriteStartElement( KXmlNodeReport ); |
|
63 |
|
64 // Input element |
|
65 writer.WriteStartElement( KXmlNodeReportInput ); |
|
66 writer.WriteAttributeString( KXmlCmnName, file.Name ); |
|
67 writer.WriteEndElement(); |
|
68 |
|
69 // Output element |
|
70 if ( !string.IsNullOrEmpty( outputFile ) ) |
|
71 { |
|
72 writer.WriteStartElement( KXmlNodeReportOutput ); |
|
73 writer.WriteAttributeString( KXmlCmnName, outputEntry.OutputFileName ); |
|
74 writer.WriteEndElement(); |
|
75 } |
|
76 |
|
77 // Status |
|
78 string status = KXmlNodeReportStatusSuccess; |
|
79 if ( outputEntry.Status == TOutputStatus.EFailed ) |
|
80 { |
|
81 status = KXmlNodeReportStatusFailure; |
|
82 } |
|
83 writer.WriteElementString( KXmlNodeReportStatus, status ); |
|
84 |
|
85 // Messages |
|
86 foreach ( CACmdLineMessage msg in outputEntry ) |
|
87 { |
|
88 string typeName = KXmlNodeReportMsgMessage; |
|
89 switch ( msg.Type ) |
|
90 { |
|
91 case CACmdLineMessage.TType.ETypeDiagnostic: |
|
92 typeName = KXmlNodeReportMsgDiagnostic; |
|
93 break; |
|
94 case CACmdLineMessage.TType.ETypeWarning: |
|
95 typeName = KXmlNodeReportMsgWarning; |
|
96 break; |
|
97 case CACmdLineMessage.TType.ETypeError: |
|
98 typeName = KXmlNodeReportMsgError; |
|
99 break; |
|
100 default: |
|
101 break; |
|
102 } |
|
103 writer.WriteStartElement( typeName ); |
|
104 writer.WriteAttributeString( KXmlNodeReportMsgTitle, msg.Title ); |
|
105 writer.WriteString( msg.Description ); |
|
106 writer.WriteEndElement(); |
|
107 } |
|
108 |
|
109 writer.WriteEndElement(); |
|
110 } |
|
111 } |
|
112 |
|
113 writer.WriteEndElement(); |
|
114 } |
|
115 |
|
116 return backBuffer.ToString(); |
|
117 } |
|
118 #endregion |
|
119 |
|
120 #region Properties |
|
121 #endregion |
|
122 |
|
123 #region Internal methods |
|
124 #endregion |
|
125 |
|
126 #region Internal constants |
|
127 private const string KXmlRoot = "summary"; |
|
128 private const string KXmlCmnName = "name"; |
|
129 |
|
130 private const string KXmlNodeReport = "report"; |
|
131 private const string KXmlNodeReportInput = "input"; |
|
132 private const string KXmlNodeReportOutput = "output"; |
|
133 private const string KXmlNodeReportStatus = "status"; |
|
134 private const string KXmlNodeReportStatusSuccess = "OK"; |
|
135 private const string KXmlNodeReportStatusFailure = "ERROR"; |
|
136 private const string KXmlNodeReportMsgTitle = "title"; |
|
137 private const string KXmlNodeReportMsgError = "error"; |
|
138 private const string KXmlNodeReportMsgWarning = "warning"; |
|
139 private const string KXmlNodeReportMsgMessage= "message"; |
|
140 private const string KXmlNodeReportMsgDiagnostic = "diagnostic"; |
|
141 #endregion |
|
142 |
|
143 #region Data members |
|
144 private readonly CACmdLineFSEntityList<CACmdLineFileSource> iSourceFiles; |
|
145 #endregion |
|
146 } |
|
147 } |