crashanalysercmd/Libraries/Engine/CrashItemLib/PluginAPI/Internal/CFFPluginRegistry.cs
changeset 0 818e61de6cd1
child 1 7a31f7298d8f
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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-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 SymbianUtils.PluginManager;
       
    23 using SymbianDebugLib.Engine;
       
    24 using CrashItemLib.Crash;
       
    25 using CrashItemLib.Engine;
       
    26 
       
    27 namespace CrashItemLib.PluginAPI
       
    28 {
       
    29     public class CFFPluginRegistry : CFFDataProvider, IEnumerable<CFFPlugin>
       
    30 	{
       
    31 		#region Constructors
       
    32         public CFFPluginRegistry( CIEngine aEngine )
       
    33 		{
       
    34             iEngine = aEngine;
       
    35             LoadPlugins();
       
    36 		}
       
    37 		#endregion
       
    38 
       
    39         #region API
       
    40         public string GetSupportedCrashFileTypes()
       
    41         {
       
    42             StringBuilder ret = new StringBuilder();
       
    43 
       
    44             // First get a list of all supported extensions
       
    45             List<CFFFileSpecification> initialList = new List<CFFFileSpecification>();
       
    46             foreach ( CFFPlugin plugin in this )
       
    47             {
       
    48                 plugin.GetSupportedFileTypes( initialList );
       
    49             }
       
    50 
       
    51             // Identify duplicate entries and filter them out
       
    52             Dictionary<string, CFFFileSpecification> finalList = new Dictionary<string, CFFFileSpecification>();
       
    53             foreach ( CFFFileSpecification entry in initialList )
       
    54             {
       
    55                 if ( !finalList.ContainsKey( entry.Description ) )
       
    56                 {
       
    57                     finalList.Add( entry.Description, entry );
       
    58                 }
       
    59             }
       
    60 
       
    61             // Convert each entry into dialog-like format list specification.
       
    62             foreach ( KeyValuePair<string, CFFFileSpecification> kvp in finalList )
       
    63             {
       
    64                 CFFFileSpecification spec = kvp.Value;
       
    65                 //
       
    66                 ret.AppendFormat( "{0} ({1})|{2}", spec.Description, spec.Extensions, spec.Extensions );
       
    67                 ret.Append( "|" );
       
    68             }
       
    69 
       
    70             // Remove last trailing pipe
       
    71             if ( ret.Length > 0 )
       
    72             {
       
    73                 ret.Remove( ret.Length - 1, 1 );
       
    74             }
       
    75 
       
    76             string finalVal = ret.ToString();
       
    77             return finalVal;
       
    78         }
       
    79 
       
    80         public CFFSourceAndConfidence[] GetHandlers( FileInfo aFile, CFFFileList aOtherFiles )
       
    81         {
       
    82             List<CFFSourceAndConfidence> ret = new List<CFFSourceAndConfidence>();
       
    83             //
       
    84             foreach ( CFFPlugin plugin in iPlugins )
       
    85             {
       
    86                 try
       
    87                 {
       
    88                     CFFSourceAndConfidence conf = plugin.GetConfidence( aFile, aOtherFiles );
       
    89                     //
       
    90                     if ( conf.IsSupported )
       
    91                     {
       
    92                         ret.Add( conf );
       
    93                     }
       
    94                 }
       
    95                 catch ( Exception e )
       
    96                 {
       
    97                     iEngine.Trace( "CFFPrimerRegistry.GetHandlers() - aFile: {0}, message: {1}, stack: {2}", aFile.FullName, e.Message, e.StackTrace );
       
    98                 }
       
    99             }
       
   100             //
       
   101             return ret.ToArray();
       
   102         }
       
   103         #endregion
       
   104 
       
   105         #region Properties
       
   106         public int Count
       
   107         {
       
   108             get { return iPlugins.Count; }
       
   109         }
       
   110 
       
   111         public CFFPlugin this[ int aIndex ]
       
   112         {
       
   113             get { return iPlugins[ aIndex ]; }
       
   114         }
       
   115         #endregion
       
   116 
       
   117         #region Internal methods
       
   118         private void LoadPlugins()
       
   119         {
       
   120             object[] parameters = new object[ 1 ];
       
   121             parameters[ 0 ] = this;
       
   122             //
       
   123             iPlugins.Load( parameters );
       
   124         }
       
   125         #endregion
       
   126 
       
   127         #region From CFFDataProvider
       
   128         public override CIEngine Engine
       
   129         {
       
   130             get { return iEngine; }
       
   131         }
       
   132         #endregion
       
   133 
       
   134         #region From IEnumerable<CFFPlugin>
       
   135         public IEnumerator<CFFPlugin> GetEnumerator()
       
   136         {
       
   137             return iPlugins.GetEnumerator();
       
   138         }
       
   139 
       
   140         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   141         {
       
   142             return iPlugins.GetEnumerator();
       
   143         }
       
   144         #endregion
       
   145 
       
   146         #region Data members
       
   147         private readonly CIEngine iEngine;
       
   148         private PluginManager<CFFPlugin> iPlugins = new PluginManager<CFFPlugin>();
       
   149 		#endregion
       
   150     }
       
   151 }