crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/TextUtilities/Readers/Types/Array/AsyncEnumerableReader.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.IO;
       
    19 using System.Text;
       
    20 using System.Threading;
       
    21 using System.Collections.Generic;
       
    22 using SymbianUtils.Tracer;
       
    23 
       
    24 namespace SymbianUtils.TextUtilities.Readers.Types.Array
       
    25 {
       
    26 	public abstract class AsyncEnumerableReader<TType> : AsyncReaderBase
       
    27 	{
       
    28 		#region Constructors
       
    29         protected AsyncEnumerableReader( ITracer aTracer )
       
    30             : base( aTracer )
       
    31         {
       
    32         }
       
    33 
       
    34         protected AsyncEnumerableReader( int aCount, IEnumerator<TType> aEnumerator )
       
    35             : this( aCount, aEnumerator, null )
       
    36         {
       
    37         }
       
    38 
       
    39         protected AsyncEnumerableReader( int aCount, IEnumerator<TType> aEnumerator, ITracer aTracer )
       
    40             : base( aTracer )
       
    41 		{
       
    42             Setup( aCount, aEnumerator );
       
    43 		}
       
    44 		#endregion
       
    45 
       
    46         #region API
       
    47         protected void Setup( long aCount, IEnumerator<TType> aEnumerator )
       
    48         {
       
    49             iCount = aCount;
       
    50             iEnumerator = aEnumerator;
       
    51         }
       
    52         #endregion
       
    53 
       
    54         #region Abstract reading framework
       
    55         protected abstract void HandleObject( TType aObject, long aIndex, long aCount );
       
    56 		#endregion
       
    57 
       
    58         #region From AsyncReaderBase
       
    59         protected override long Size
       
    60         {
       
    61             get { return iCount; }
       
    62         }
       
    63 
       
    64         protected override long Position
       
    65         {
       
    66             get { return iCurrentIndex; }
       
    67         }
       
    68         #endregion
       
    69 
       
    70         #region Properties
       
    71         #endregion
       
    72 
       
    73 		#region Internal methods
       
    74 		protected override void PerformOperation()
       
    75 		{
       
    76 #if DEBUG
       
    77             System.DateTime tenPercentTime = DateTime.Now;
       
    78 #endif
       
    79             iCurrentIndex = -1;
       
    80             int newProgress = 0;
       
    81             int oldProgress = 0;
       
    82             //
       
    83             bool hasEntry = iEnumerator.MoveNext();
       
    84             while ( hasEntry )
       
    85             {
       
    86                 ++iCurrentIndex;
       
    87                 TType entry = iEnumerator.Current;
       
    88                 HandleObject( entry, iCurrentIndex, iCount );
       
    89                 newProgress = Progress;
       
    90                 //
       
    91                 if ( newProgress != oldProgress )
       
    92                 {
       
    93 #if DEBUG
       
    94                     if ( newProgress > 0 && ( newProgress % 10 ) == 0 )
       
    95                     {
       
    96                         System.DateTime now = DateTime.Now;
       
    97                         long intermediateTickDuration = ( ( now.Ticks - tenPercentTime.Ticks ) / 100 );
       
    98                         System.Diagnostics.Debug.WriteLine( newProgress.ToString( "d2" ) + " % COMPLETE - " + intermediateTickDuration.ToString( "d12" ) );
       
    99                         tenPercentTime = now;
       
   100                     }
       
   101 #endif
       
   102                     NotifyEvent( TEvent.EReadingProgress );
       
   103                     oldProgress = newProgress;
       
   104                 }
       
   105 
       
   106                 // Move to next item
       
   107                 hasEntry = iEnumerator.MoveNext();
       
   108             }
       
   109 
       
   110 #if DEBUG
       
   111             System.DateTime endTime = DateTime.Now;
       
   112             long tickDuration = ( ( endTime.Ticks - iOperationStartTime.Ticks ) / 100 );
       
   113             System.Diagnostics.Debug.WriteLine( "ARRAY READ COMPLETE - " + tickDuration.ToString( "d12" ) );
       
   114 #endif
       
   115         }
       
   116 		#endregion
       
   117 
       
   118         #region Data members
       
   119         private long iCount = 0;
       
   120         private IEnumerator<TType> iEnumerator = null;
       
   121         private long iCurrentIndex = -1;
       
   122         #endregion
       
   123 	}
       
   124 }