|
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.IO; |
|
20 using System.Collections.Generic; |
|
21 using CrashItemLib.Crash.Messages; |
|
22 using CrashItemLib.Crash.Container; |
|
23 |
|
24 namespace CrashAnalyserServerExe.Engine |
|
25 { |
|
26 internal class CACmdLineMessageList : IEnumerable<CACmdLineMessage> |
|
27 { |
|
28 #region Constructors |
|
29 public CACmdLineMessageList() |
|
30 { |
|
31 } |
|
32 #endregion |
|
33 |
|
34 #region API |
|
35 public void Clear() |
|
36 { |
|
37 iMessages.Clear(); |
|
38 } |
|
39 |
|
40 public void ClearErrorsAndWarnings() |
|
41 { |
|
42 for( int i=iMessages.Count; i>=0; i-- ) |
|
43 { |
|
44 CACmdLineMessage msg = iMessages[ i ]; |
|
45 // |
|
46 bool remove = true; |
|
47 switch( msg.Type ) |
|
48 { |
|
49 default: |
|
50 case CACmdLineMessage.TType.ETypeError: |
|
51 case CACmdLineMessage.TType.ETypeMessage: |
|
52 case CACmdLineMessage.TType.ETypeWarning: |
|
53 break; |
|
54 case CACmdLineMessage.TType.ETypeDiagnostic: |
|
55 remove = false; |
|
56 break; |
|
57 } |
|
58 // |
|
59 if ( remove ) |
|
60 { |
|
61 iMessages.RemoveAt( i ); |
|
62 } |
|
63 } |
|
64 } |
|
65 |
|
66 public void AddError( string aTitle, string aDescription ) |
|
67 { |
|
68 Add( aTitle, aDescription, CACmdLineMessage.TType.ETypeError ); |
|
69 } |
|
70 |
|
71 public void AddWarning( string aTitle, string aDescription ) |
|
72 { |
|
73 Add( aTitle, aDescription, CACmdLineMessage.TType.ETypeWarning ); |
|
74 } |
|
75 |
|
76 public void AddMessage( string aTitle, string aDescription ) |
|
77 { |
|
78 Add( aTitle, aDescription, CACmdLineMessage.TType.ETypeMessage ); |
|
79 } |
|
80 |
|
81 public void AddDiagnostic( string aTitle, string aDescription ) |
|
82 { |
|
83 Add( aTitle, aDescription, CACmdLineMessage.TType.ETypeDiagnostic ); |
|
84 } |
|
85 |
|
86 public void Add( CACmdLineMessage aMessage ) |
|
87 { |
|
88 iMessages.Add( aMessage ); |
|
89 } |
|
90 |
|
91 public void AddRange( IEnumerable<CACmdLineMessage> aMessages ) |
|
92 { |
|
93 foreach ( CACmdLineMessage msg in aMessages ) |
|
94 { |
|
95 Add( msg ); |
|
96 } |
|
97 } |
|
98 |
|
99 public void AddRange( IEnumerable<CACmdLineMessage> aMessages, CACmdLineMessage.TType aOnlyOfType ) |
|
100 { |
|
101 foreach ( CACmdLineMessage msg in aMessages ) |
|
102 { |
|
103 if ( msg.Type == aOnlyOfType ) |
|
104 { |
|
105 Add( msg ); |
|
106 } |
|
107 } |
|
108 } |
|
109 |
|
110 public void CopyMessagesToContainer( CIContainer aContainer ) |
|
111 { |
|
112 CopyMessagesToContainer( iMessages, aContainer ); |
|
113 } |
|
114 |
|
115 public static void CopyMessagesToContainer( IEnumerable<CACmdLineMessage> aMessages, CIContainer aContainer ) |
|
116 { |
|
117 foreach ( CACmdLineMessage msg in aMessages ) |
|
118 { |
|
119 msg.CopyToContainer( aContainer ); |
|
120 } |
|
121 } |
|
122 |
|
123 public CACmdLineMessage[] ToArray() |
|
124 { |
|
125 return iMessages.ToArray(); |
|
126 } |
|
127 #endregion |
|
128 |
|
129 #region Properties |
|
130 public bool IsEmtpy |
|
131 { |
|
132 get |
|
133 { |
|
134 return iMessages.Count == 0; |
|
135 } |
|
136 } |
|
137 |
|
138 public int Count |
|
139 { |
|
140 get { return iMessages.Count; } |
|
141 } |
|
142 #endregion |
|
143 |
|
144 #region Internal methods |
|
145 private int CountByType( CACmdLineMessage.TType aType ) |
|
146 { |
|
147 int count = 0; |
|
148 // |
|
149 iMessages.ForEach( delegate( CACmdLineMessage aMessage ) |
|
150 { |
|
151 if ( aMessage.Type == CACmdLineMessage.TType.ETypeError ) |
|
152 { |
|
153 ++count; |
|
154 } |
|
155 } |
|
156 ); |
|
157 // |
|
158 return count; |
|
159 } |
|
160 |
|
161 private void Add( string aTitle, string aDescription, CACmdLineMessage.TType aType ) |
|
162 { |
|
163 CACmdLineMessage msg = new CACmdLineMessage( aType, aTitle, aDescription ); |
|
164 Add( msg ); |
|
165 } |
|
166 #endregion |
|
167 |
|
168 #region From IEnumerable<CACmdLineMessage> |
|
169 public IEnumerator<CACmdLineMessage> GetEnumerator() |
|
170 { |
|
171 foreach ( CACmdLineMessage msg in iMessages ) |
|
172 { |
|
173 yield return msg; |
|
174 } |
|
175 } |
|
176 |
|
177 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
178 { |
|
179 foreach ( CACmdLineMessage msg in iMessages ) |
|
180 { |
|
181 yield return msg; |
|
182 } |
|
183 } |
|
184 #endregion |
|
185 |
|
186 #region Data members |
|
187 private List<CACmdLineMessage> iMessages = new List<CACmdLineMessage>(); |
|
188 #endregion |
|
189 } |
|
190 } |