diff -r 000000000000 -r 818e61de6cd1 crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/Source/CISource.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/Source/CISource.cs Thu Feb 11 15:50:58 2010 +0200 @@ -0,0 +1,199 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +using System; +using System.Text; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using CrashItemLib.Crash; +using CrashItemLib.Crash.Base; + +namespace CrashItemLib.Crash.Source +{ + /// + /// Base class for all crash sources + /// + public abstract class CISource : IEnumerable + { + #region Constructors + protected CISource( FileInfo aFile ) + { + iFile = aFile; + } + #endregion + + #region Constants + public static readonly string[] KExtensionsTrace = new string[] { ".txt", ".log", ".trace" }; + #endregion + + #region API + public void AddAdditionalFile( FileInfo aFile ) + { + iAdditionalFiles.Add( aFile ); + } + + public static bool SubstringMatch( string aText, string[] aCandidates ) + { + string text = aText.ToUpper(); + foreach ( string candidate in aCandidates ) + { + if ( text.Contains( candidate.ToUpper() ) ) + { + return true; + } + } + + return false; + } + #endregion + + #region Properties + /// + /// The primary file which essentially describes the crash. + /// + public FileInfo MasterFile + { + get { return iFile; } + } + + public string MasterFileName + { + get + { + string ret = string.Empty; + // + if ( MasterFile != null ) + { + ret = MasterFile.FullName; + } + // + return ret; + } + } + + /// + /// Get other files which may be related to the master file. + /// For example, D_EXC stores it stack file separately to + /// the main text file, therefore the STK file would be present + /// only within the 'all files' array. + /// + public FileInfo[] AllFiles + { + get + { + List ret = new List( this.iAdditionalFiles ); + ret.Insert( 0, MasterFile ); + return ret.ToArray(); + } + } + + public string Extension + { + get { return Path.GetExtension( MasterFileName ).ToLower(); } + } + + public int AdditionalFileCount + { + get { return iAdditionalFiles.Count; } + } + + public long LineNumber + { + get { return iLineNumber; } + set { iLineNumber = value; } + } + + public bool Exists + { + get { return File.Exists( MasterFileName ); } + } + + public bool IsTraceExtension + { + get + { + string extn = Extension; + bool ret = SubstringMatch( extn, KExtensionsTrace ); + return ret; + } + } + + public bool IsLineNumberAvailable + { + get { return iLineNumber != KLineNumberNotApplicable; } + } + #endregion + + #region Framework properties + public abstract Version ImplementorVersion + { + get; + } + + public abstract string ImplementorName + { + get; + } + #endregion + + #region Internal constants + private const long KLineNumberNotApplicable = -1; + #endregion + + #region Internal methods + internal void RawDataClear() + { + iRawData.Clear(); + } + + internal byte[] RawData + { + get { return iRawData.ToArray(); } + } + + internal void RawDataAdd( byte[] aRawData ) + { + iRawData.AddRange( aRawData ); + } + #endregion + + #region From IEnumerable + public IEnumerator GetEnumerator() + { + foreach ( FileInfo file in iAdditionalFiles ) + { + yield return file; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + foreach ( FileInfo file in iAdditionalFiles ) + { + yield return file; + } + } + #endregion + + #region Data members + private FileInfo iFile = null; + private List iAdditionalFiles = new List(); + private List iRawData = new List( 1024 ); + private long iLineNumber = KLineNumberNotApplicable; + #endregion + } +}