crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/Source/CISource.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;
       
    21 using System.Collections.Generic;
       
    22 using CrashItemLib.Crash;
       
    23 using CrashItemLib.Crash.Base;
       
    24 
       
    25 namespace CrashItemLib.Crash.Source
       
    26 {
       
    27     /// <summary>
       
    28     /// Base class for all crash sources
       
    29     /// </summary>
       
    30     public abstract class CISource : IEnumerable<FileInfo>
       
    31     {
       
    32         #region Constructors
       
    33         protected CISource( FileInfo aFile )
       
    34 		{
       
    35             iFile = aFile;
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region Constants
       
    40         public static readonly string[] KExtensionsTrace = new string[] { ".txt", ".log", ".trace" };
       
    41         #endregion
       
    42 
       
    43         #region API
       
    44         public void AddAdditionalFile( FileInfo aFile )
       
    45         {
       
    46             iAdditionalFiles.Add( aFile );
       
    47         }
       
    48 
       
    49         public static bool SubstringMatch( string aText, string[] aCandidates )
       
    50         {
       
    51             string text = aText.ToUpper();
       
    52             foreach ( string candidate in aCandidates )
       
    53             {
       
    54                 if ( text.Contains( candidate.ToUpper() ) )
       
    55                 {
       
    56                     return true;
       
    57                 }
       
    58             }
       
    59 
       
    60             return false;
       
    61         }
       
    62         #endregion
       
    63 
       
    64         #region Properties
       
    65         /// <summary>
       
    66         /// The primary file which essentially describes the crash.
       
    67         /// </summary>
       
    68         public FileInfo MasterFile
       
    69         {
       
    70             get { return iFile; }
       
    71         }
       
    72 
       
    73         public string MasterFileName
       
    74         {
       
    75             get
       
    76             {
       
    77                 string ret = string.Empty;
       
    78                 //
       
    79                 if ( MasterFile != null )
       
    80                 {
       
    81                     ret = MasterFile.FullName;
       
    82                 }
       
    83                 //
       
    84                 return ret; 
       
    85             }
       
    86         }
       
    87 
       
    88         /// <summary>
       
    89         /// Get other files which may be related to the master file.
       
    90         /// For example, D_EXC stores it stack file separately to
       
    91         /// the main text file, therefore the STK file would be present
       
    92         /// only within the 'all files' array.
       
    93         /// </summary>
       
    94         public FileInfo[] AllFiles
       
    95         {
       
    96             get
       
    97             {
       
    98                 List<FileInfo> ret = new List<FileInfo>( this.iAdditionalFiles );
       
    99                 ret.Insert( 0, MasterFile );
       
   100                 return ret.ToArray();
       
   101             }
       
   102         }
       
   103 
       
   104         public string Extension
       
   105         {
       
   106             get { return Path.GetExtension( MasterFileName ).ToLower(); }
       
   107         }
       
   108 
       
   109         public int AdditionalFileCount
       
   110         {
       
   111             get { return iAdditionalFiles.Count; }
       
   112         }
       
   113 
       
   114         public long LineNumber
       
   115         {
       
   116             get { return iLineNumber; }
       
   117             set { iLineNumber = value; }
       
   118         }
       
   119 
       
   120         public bool Exists
       
   121         {
       
   122             get { return File.Exists( MasterFileName ); }
       
   123         }
       
   124 
       
   125         public bool IsTraceExtension
       
   126         {
       
   127             get
       
   128             {
       
   129                 string extn = Extension;
       
   130                 bool ret = SubstringMatch( extn, KExtensionsTrace );
       
   131                 return ret;
       
   132             }
       
   133         }
       
   134 
       
   135         public bool IsLineNumberAvailable
       
   136         {
       
   137             get { return iLineNumber != KLineNumberNotApplicable; }
       
   138         }
       
   139         #endregion
       
   140 
       
   141         #region Framework properties
       
   142         public abstract Version ImplementorVersion
       
   143         {
       
   144             get;
       
   145         }
       
   146 
       
   147         public abstract string ImplementorName
       
   148         {
       
   149             get;
       
   150         }
       
   151         #endregion
       
   152         
       
   153         #region Internal constants
       
   154         private const long KLineNumberNotApplicable = -1;
       
   155         #endregion
       
   156 
       
   157         #region Internal methods
       
   158         internal void RawDataClear()
       
   159         {
       
   160             iRawData.Clear();
       
   161         }
       
   162 
       
   163         internal byte[] RawData
       
   164         {
       
   165             get { return iRawData.ToArray(); }
       
   166         }
       
   167 
       
   168         internal void RawDataAdd( byte[] aRawData )
       
   169         {
       
   170             iRawData.AddRange( aRawData );
       
   171         }
       
   172         #endregion
       
   173 
       
   174         #region From IEnumerable<FileInfo>
       
   175         public IEnumerator<FileInfo> GetEnumerator()
       
   176         {
       
   177             foreach ( FileInfo file in iAdditionalFiles )
       
   178             {
       
   179                 yield return file;
       
   180             }
       
   181         }
       
   182 
       
   183         IEnumerator IEnumerable.GetEnumerator()
       
   184         {
       
   185             foreach ( FileInfo file in iAdditionalFiles )
       
   186             {
       
   187                 yield return file;
       
   188             }
       
   189         }
       
   190         #endregion
       
   191 
       
   192         #region Data members
       
   193         private FileInfo iFile = null;
       
   194         private List<FileInfo> iAdditionalFiles = new List<FileInfo>();
       
   195         private List<byte> iRawData = new List<byte>( 1024 );
       
   196         private long iLineNumber = KLineNumberNotApplicable;
       
   197         #endregion
       
   198     }
       
   199 }