crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/Messages/CIMessage.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.Drawing;
       
    21 using System.Collections.Generic;
       
    22 using CrashItemLib.Crash;
       
    23 using CrashItemLib.Crash.Base;
       
    24 using CrashItemLib.Crash.Base.DataBinding;
       
    25 using CrashItemLib.Crash.Processes;
       
    26 using CrashItemLib.Crash.Container;
       
    27 using System.ComponentModel;
       
    28 using SymbianUtils.Range;
       
    29 using SymbianStructuresLib.Uids;
       
    30 using SymbianUtils.DataBuffer;
       
    31 
       
    32 namespace CrashItemLib.Crash.Messages
       
    33 {
       
    34     [CIDBAttributeColumn( "Type", 0 )]
       
    35     [CIDBAttributeColumn( "Overview", 1, true )]
       
    36     public class CIMessage : CIElement, IEnumerable<string>
       
    37     {
       
    38         #region Enumerations
       
    39         public enum TType
       
    40         {
       
    41             [Description( "Warning" )]
       
    42             ETypeWarning = 0,
       
    43 
       
    44             [Description( "Error" )]
       
    45             ETypeError,
       
    46 
       
    47             [Description( "Message" )]
       
    48             ETypeMessage,
       
    49 
       
    50             [Description( "Other" )]
       
    51             ETypeOther
       
    52         }
       
    53         #endregion
       
    54 
       
    55         #region Static constructors
       
    56         public static CIMessage NewMessage( CIContainer aContainer )
       
    57         {
       
    58             CIMessage ret = new CIMessage( aContainer );
       
    59             ret.Type = TType.ETypeMessage;
       
    60             return ret;
       
    61         }
       
    62 
       
    63         internal static CIMessage Null( CIContainer aContainer )
       
    64         {
       
    65             CIMessage ret = new CIMessage( aContainer );
       
    66             ret.Type = TType.ETypeOther;
       
    67             return ret;
       
    68         }
       
    69         #endregion
       
    70 
       
    71         #region Constructors
       
    72         protected CIMessage( CIContainer aContainer )
       
    73             : this( aContainer, string.Empty )
       
    74         {
       
    75         }
       
    76 
       
    77         protected CIMessage( CIContainer aContainer, string aTitle )
       
    78             : base( aContainer )
       
    79 		{
       
    80             iTitle = aTitle;
       
    81 		}
       
    82 		#endregion
       
    83 
       
    84         #region API
       
    85         public override void Clear()
       
    86         {
       
    87             base.Clear();
       
    88             iLines.Clear();
       
    89         }
       
    90 
       
    91         public void SetLine( string aLine )
       
    92         {
       
    93             iLines.Clear();
       
    94             iLines.Add( aLine );
       
    95         }
       
    96 
       
    97         public void SetLineFormatted( string aFormat, params object[] aArgs )
       
    98         {
       
    99             string line = string.Format( aFormat, aArgs );
       
   100             SetLine( line );
       
   101         }
       
   102 
       
   103         public void AddLine( string aLine )
       
   104         {
       
   105             using ( StringReader reader = new StringReader( aLine ) )
       
   106             {
       
   107                 string line = reader.ReadLine();
       
   108                 while ( line != null )
       
   109                 {
       
   110                     iLines.Add( line );
       
   111                     line = reader.ReadLine();
       
   112                 }
       
   113             }
       
   114         }
       
   115 
       
   116         public void AddLineFormatted( string aFormat, params object[] aArgs )
       
   117         {
       
   118             string line = string.Format( aFormat, aArgs );
       
   119             AddLine( line );
       
   120         }
       
   121 
       
   122         public static string TypeToString( TType aType )
       
   123         {
       
   124             return SymbianUtils.Enum.EnumUtils.ToString( aType );
       
   125         }
       
   126         #endregion
       
   127 
       
   128         #region Properties
       
   129         public override string Name
       
   130         {
       
   131             get { return Title; }
       
   132             set { Title = value; }
       
   133         }
       
   134 
       
   135         [Base.DataBinding.CIDBAttributeCell( "Title", 1 )]
       
   136         public string Title
       
   137         {
       
   138             get { return iTitle; }
       
   139             set { iTitle = value; }
       
   140         }
       
   141 
       
   142         public string Description
       
   143         {
       
   144             get { return ToString(); }
       
   145             set 
       
   146             {
       
   147                 List<string> lines = new List<string>();
       
   148                 //
       
   149                 using ( StringReader reader = new StringReader( value ) )
       
   150                 {
       
   151                     string line = reader.ReadLine();
       
   152                     while ( line != null )
       
   153                     {
       
   154                         lines.Add( line );
       
   155                         line = reader.ReadLine();
       
   156                     }
       
   157                 }
       
   158                 //
       
   159                 iLines = lines;
       
   160             }
       
   161         }
       
   162 
       
   163         public string FullText
       
   164         {
       
   165             get
       
   166             {
       
   167                 StringBuilder ret = new StringBuilder();
       
   168                 //
       
   169                 ret.AppendLine( Title );
       
   170                 ret.Append( System.Environment.NewLine );
       
   171                 ret.Append( Description );
       
   172                 //
       
   173                 return ret.ToString();
       
   174             }
       
   175         }
       
   176 
       
   177         public TType Type
       
   178         {
       
   179             get { return iType; }
       
   180             protected set { iType = value; }
       
   181         }
       
   182 
       
   183         [Base.DataBinding.CIDBAttributeCell( "Type", 0 )]
       
   184         public string TypeName
       
   185         {
       
   186             get { return TypeToString( Type ); }
       
   187         }
       
   188 
       
   189         public virtual Font Font
       
   190         {
       
   191             get { return iFont; }
       
   192             set { iFont = value; }
       
   193         }
       
   194 
       
   195         public virtual Color Color
       
   196         {
       
   197             get { return iColor; }
       
   198             set { iColor = value; }
       
   199         }
       
   200 
       
   201         public int LineCount
       
   202         {
       
   203             get { return iLines.Count; }
       
   204         }
       
   205         #endregion
       
   206 
       
   207         #region Operators
       
   208         public static implicit operator CIDBRow( CIMessage aMessage )
       
   209         {
       
   210             CIDBRow row = new CIDBRow();
       
   211 
       
   212             // To ensure that the register and cells are correctly associated
       
   213             row.Element = aMessage;
       
   214 
       
   215             row.Add( new CIDBCell( aMessage.TypeName ) );
       
   216             row.Add( new CIDBCell( aMessage.Title ) );
       
   217             //
       
   218             return row;
       
   219         }
       
   220         #endregion
       
   221 
       
   222         #region Internal methods
       
   223         #endregion
       
   224 
       
   225         #region From System.Object
       
   226         public override string ToString()
       
   227         {
       
   228             StringBuilder ret = new StringBuilder();
       
   229             for ( int i = 0; i < iLines.Count; i++ )
       
   230             {
       
   231                 ret.Append( iLines[ i ].Trim() );
       
   232                 ret.Append( " " );
       
   233             }
       
   234             return ret.ToString();
       
   235         }
       
   236         #endregion
       
   237 
       
   238         #region From IEnumerable<string>
       
   239         public new IEnumerator<string> GetEnumerator()
       
   240         {
       
   241             foreach ( string s in iLines )
       
   242             {
       
   243                 yield return s;
       
   244             }
       
   245         }
       
   246 
       
   247         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   248         {
       
   249             foreach ( string s in iLines )
       
   250             {
       
   251                 yield return s;
       
   252             }
       
   253         }
       
   254         #endregion
       
   255 
       
   256         #region Data members
       
   257         private TType iType = TType.ETypeWarning;
       
   258         private Font iFont = new Font( "Tahoma", 8.25f );
       
   259         private Color iColor = Color.Black;
       
   260         private string iTitle = string.Empty;
       
   261         private List<string> iLines = new List<string>();
       
   262         #endregion
       
   263     }
       
   264 }