crashanalysercmd/UI/CrashServer/Engine/Files/CACmdLineFileSource.cs
changeset 0 818e61de6cd1
child 2 0c91f0baec58
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 CrashItemLib.Crash.Container;
       
    22 using CrashItemLib.Engine.Sources;
       
    23 
       
    24 namespace CrashAnalyserServerExe.Engine
       
    25 {
       
    26     internal class CACmdLineFileSource : CACmdLineFSEntity, IEnumerable<CIContainer>
       
    27     {
       
    28         #region Internal enumerations
       
    29         public enum TState
       
    30         {
       
    31             EStateUninitialized = -1,
       
    32             EStateProcessedAndReadyToBeArchived = 0,
       
    33             EStateSkippedDueToMissingSymbols,
       
    34             EStateSkippedDueToNotBeingRecognized
       
    35         }
       
    36         #endregion
       
    37 
       
    38         #region Constructors
       
    39         public CACmdLineFileSource()
       
    40 		{
       
    41 		}
       
    42         #endregion
       
    43 
       
    44 		#region API
       
    45         public OutputEntry AddOutput( CIContainer aContainer, string aFileName, TOutputStatus aStatus )
       
    46         {
       
    47             OutputEntry output = new OutputEntry( aContainer, aFileName, aStatus );
       
    48             iOutputs.Add( output );
       
    49             return output;
       
    50         }
       
    51 
       
    52         public void Add( CIContainer aContainer )
       
    53         {
       
    54             // If we're adding a container, then it must be because
       
    55             // there wasn't a source associated with this file (crash engine
       
    56             // could not understand input file).
       
    57             System.Diagnostics.Debug.Assert( iSource == null );
       
    58 
       
    59             if ( iContainers == null )
       
    60             {
       
    61                 iContainers = new CIContainerCollection();
       
    62             }
       
    63             iContainers.Add( aContainer );
       
    64         }
       
    65         #endregion
       
    66 
       
    67 		#region Properties
       
    68         public CIEngineSource Source
       
    69         {
       
    70             get { return iSource; }
       
    71             set { iSource = value; }
       
    72         }
       
    73 
       
    74         public int OutputCount
       
    75         {
       
    76             get { return iOutputs.Count; }
       
    77         }
       
    78 
       
    79         public OutputEntry this[ int aIndex ]
       
    80         {
       
    81             get { return iOutputs[ aIndex ]; }
       
    82         }
       
    83 
       
    84         public OutputEntry[] Outputs
       
    85         {
       
    86             get { return iOutputs.ToArray(); }
       
    87         }
       
    88 
       
    89         public int ContainerCount
       
    90         {
       
    91             get
       
    92             {
       
    93                 int ret = 0;
       
    94                 //
       
    95                 if ( Source != null )
       
    96                 {
       
    97                     ret = Source.ContainerCount;
       
    98                 }
       
    99                 else if ( iContainers != null )
       
   100                 {
       
   101                     ret = iContainers.Count;
       
   102                 }
       
   103                 //
       
   104                 return ret;
       
   105             }
       
   106         }
       
   107 
       
   108         public IEnumerable<CIContainer> Containers
       
   109         {
       
   110             get
       
   111             {
       
   112                 CIContainerCollection ret = iContainers;
       
   113                 //
       
   114                 if ( Source != null )
       
   115                 {
       
   116                     return Source;
       
   117                 }
       
   118                 else if ( ret == null )
       
   119                 {
       
   120                     ret = new CIContainerCollection();
       
   121                 }
       
   122                 //
       
   123                 return ret;
       
   124             }
       
   125         }
       
   126 
       
   127         public TState State
       
   128         {
       
   129             get { return iState; }
       
   130             set { iState = value; }
       
   131         }
       
   132         #endregion
       
   133 
       
   134         #region Internal methods
       
   135         #endregion
       
   136 
       
   137         #region Output class
       
   138         public class OutputEntry : CACmdLineMessageList
       
   139         {
       
   140             #region Constructors
       
   141             internal OutputEntry( CIContainer aContainer, string aOutputFileName, TOutputStatus aXmlOutputStatus )
       
   142             {
       
   143                 iContainer = aContainer;
       
   144                 iXmlOutputStatus = aXmlOutputStatus;
       
   145                 iOutputFileName = aOutputFileName;
       
   146             }
       
   147             #endregion
       
   148 
       
   149             #region Properties
       
   150             public CIContainer Container
       
   151             {
       
   152                 get { return iContainer; }
       
   153             }
       
   154 
       
   155             public TOutputStatus Status
       
   156             {
       
   157                 get
       
   158                 {
       
   159                     // There are two different statuses. One is the container-level status, 
       
   160                     // i.e. whether the container refers to a 'real' crash or just a dummy (i.e. a 'failed' xml file).
       
   161                     //
       
   162                     // Then, there is the actual success associated with whether or not we could write
       
   163                     // the xml output. 
       
   164                     TOutputStatus ret = iXmlOutputStatus;
       
   165                     //
       
   166                     if ( ret == TOutputStatus.ESuccess )
       
   167                     {
       
   168                         // Check container level status then...
       
   169                         if ( Container.Status == CIContainer.TStatus.EStatusDefault )
       
   170                         {
       
   171                             ret = TOutputStatus.ESuccess;
       
   172                         }
       
   173                         else if ( Container.Status == CIContainer.TStatus.EStatusErrorContainer )
       
   174                         {
       
   175                             ret = TOutputStatus.EFailed;
       
   176                         }
       
   177                     }
       
   178                     //
       
   179                     return ret; 
       
   180                 }
       
   181             }
       
   182 
       
   183             public string OutputFileName
       
   184             {
       
   185                 get { return iOutputFileName; }
       
   186             }
       
   187             #endregion
       
   188 
       
   189             #region Data members
       
   190             private readonly TOutputStatus iXmlOutputStatus;
       
   191             private readonly CIContainer iContainer;
       
   192             private readonly string iOutputFileName;
       
   193             #endregion
       
   194         }
       
   195         #endregion
       
   196 
       
   197         #region From IEnumerable<CIContainer>
       
   198         public new IEnumerator<CIContainer> GetEnumerator()
       
   199         {
       
   200             foreach ( CIContainer container in Containers )
       
   201             {
       
   202                 yield return container;
       
   203             }
       
   204         }
       
   205 
       
   206         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   207         {
       
   208             foreach ( CIContainer container in Containers )
       
   209             {
       
   210                 yield return container;
       
   211             }
       
   212         }
       
   213         #endregion
       
   214 
       
   215         #region Data members
       
   216         private TState iState = TState.EStateUninitialized; 
       
   217         private CIEngineSource iSource = null;
       
   218         private List<OutputEntry> iOutputs = new List<OutputEntry>();
       
   219         private CIContainerCollection iContainers = null;
       
   220         #endregion
       
   221     }
       
   222 
       
   223     public enum TOutputStatus
       
   224     {
       
   225         ESuccess = 0,
       
   226         EFailed
       
   227     }
       
   228 }