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