crashanalysercmd/Libraries/Engine/CrashItemLib/Engine/Primer/CIEnginePrimer.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 System.Reflection;
       
    22 using SymbianDebugLib.Engine;
       
    23 using CrashItemLib.Crash;
       
    24 using CrashItemLib.PluginAPI;
       
    25 using CrashItemLib.Engine.Sources;
       
    26 
       
    27 namespace CrashItemLib.Engine.Primer
       
    28 {
       
    29     public class CIEnginePrimer
       
    30     {
       
    31         #region Constructors
       
    32         internal CIEnginePrimer( CIEngine aEngine )
       
    33 		{
       
    34             iEngine = aEngine;
       
    35             iWorkingSet = new CIPrimerWorkingSet( aEngine );
       
    36         }
       
    37 		#endregion
       
    38 
       
    39         #region API
       
    40         public bool Prime( FileInfo aFile )
       
    41         {
       
    42             Clear();
       
    43             //
       
    44             CFFFileList otherFiles = new CFFFileList();
       
    45             bool success = PrimeOne( aFile, otherFiles );
       
    46             Flush();
       
    47             //
       
    48             return success;
       
    49         }
       
    50 
       
    51         public bool Prime( DirectoryInfo aDirectory )
       
    52         {
       
    53             int successCount = 0;
       
    54             //
       
    55             Clear();
       
    56             //
       
    57             CFFFileList otherFiles = new CFFFileList( aDirectory );
       
    58             while ( !otherFiles.IsEmpty )
       
    59             {
       
    60                 FileInfo file = otherFiles.Dequeue();
       
    61                 //
       
    62                 try
       
    63                 {
       
    64                     bool success = PrimeOne( file, otherFiles );
       
    65                     if ( success )
       
    66                     {
       
    67                         ++successCount;
       
    68                     }
       
    69                 }
       
    70                 catch ( Exception )
       
    71                 {
       
    72                 }
       
    73             }
       
    74             //
       
    75             Flush();
       
    76             //
       
    77             return ( successCount > 0 );
       
    78         }
       
    79 
       
    80         public bool PrimeRecursive( DirectoryInfo aDirectory )
       
    81         {
       
    82             int successCount = 0;
       
    83             //
       
    84             Clear();
       
    85             //
       
    86             CFFFileList otherFiles = new CFFFileList( aDirectory, SearchOption.AllDirectories );
       
    87             while ( !otherFiles.IsEmpty )
       
    88             {
       
    89                 FileInfo file = otherFiles.Dequeue();
       
    90                 //
       
    91                 try
       
    92                 {
       
    93                     bool success = PrimeOne( file, otherFiles );
       
    94                     if ( success )
       
    95                     {
       
    96                         ++successCount;
       
    97                     }
       
    98                 }
       
    99                 catch ( Exception )
       
   100                 {
       
   101                 }
       
   102             }
       
   103             //
       
   104             Flush();
       
   105             //
       
   106             return ( successCount > 0 );
       
   107         }
       
   108         #endregion
       
   109 
       
   110         #region Properties
       
   111         internal CFFPluginRegistry PluginLoader
       
   112         {
       
   113             get { return iEngine.PluginRegistry; }
       
   114         }
       
   115 
       
   116         internal CIEngineSourceCollection Sources
       
   117         {
       
   118             get { return iEngine.Sources; }
       
   119         }
       
   120         #endregion
       
   121 
       
   122         #region Internal methods
       
   123         private void Clear()
       
   124         {
       
   125             // Start with a clear list
       
   126             iWorkingSet.Clear();
       
   127         }
       
   128 
       
   129         private void Flush()
       
   130         {
       
   131             // This populates the engine's source list
       
   132             iWorkingSet.Rationalise();
       
   133             iWorkingSet.Clear();
       
   134         }
       
   135 
       
   136         private bool PrimeOne( FileInfo aFile, CFFFileList aOtherFiles )
       
   137         {
       
   138             bool success = false;
       
   139 
       
   140             // Check with the plugin loader to find all handlers
       
   141             CFFSourceAndConfidence[] handlers = PluginLoader.GetHandlers( aFile, aOtherFiles );
       
   142             if ( handlers.Length > 0 )
       
   143             {
       
   144                 iWorkingSet.Add( handlers );
       
   145                 success = true;
       
   146             }
       
   147             //
       
   148             return success;
       
   149         }
       
   150         #endregion
       
   151 
       
   152         #region Data members
       
   153         private readonly CIEngine iEngine;
       
   154         private readonly CIPrimerWorkingSet iWorkingSet;
       
   155 		#endregion
       
   156     }
       
   157 }