sysperfana/heapanalyser/Libraries/UI/HeapComparisonUiLib/Progress/ComparisonProgressDialogData.cs
changeset 8 15296fd0af4a
equal deleted inserted replaced
7:8e12a575a9b5 8:15296fd0af4a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * Redistribution and use in source and binary forms, with or without
       
     6 * modification, are permitted provided that the following conditions are met:
       
     7 *
       
     8 * - Redistributions of source code must retain the above copyright notice,
       
     9 *   this list of conditions and the following disclaimer.
       
    10 * - Redistributions in binary form must reproduce the above copyright notice,
       
    11 *   this list of conditions and the following disclaimer in the documentation
       
    12 *   and/or other materials provided with the distribution.
       
    13 * - Neither the name of Nokia Corporation nor the names of its contributors
       
    14 *   may be used to endorse or promote products derived from this software
       
    15 *   without specific prior written permission.
       
    16 *
       
    17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
       
    18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
       
    21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       
    25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       
    26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    27 * POSSIBILITY OF SUCH DAMAGE.
       
    28 * 
       
    29 * Initial Contributors:
       
    30 * Nokia Corporation - initial contribution.
       
    31 *
       
    32 * Contributors:
       
    33 *
       
    34 * Description: 
       
    35 *
       
    36 */
       
    37 
       
    38 using System;
       
    39 using System.Drawing;
       
    40 using System.Collections;
       
    41 using System.ComponentModel;
       
    42 using System.Windows.Forms;
       
    43 using SymbianUtils;
       
    44 using HeapLib;
       
    45 using HeapLib.Reconstructor;
       
    46 using HeapComparisonLib.Data;
       
    47 
       
    48 namespace HeapComparisonUiLib.Progress
       
    49 {
       
    50     public class ComparisonProgressDialogData : System.Windows.Forms.Form
       
    51     {
       
    52         #region Windows Form Designer generated code
       
    53         private IContainer components;
       
    54         private ProgressBar iProgBar;
       
    55         private Timer iTimer_OpStart;
       
    56         #endregion
       
    57 
       
    58         #region Static API
       
    59         public static void Compare( HeapReconstructor aReconstructor1, HeapReconstructor aReconstructor2, string aFileName )
       
    60         {
       
    61             ComparisonProgressDialogData self = new ComparisonProgressDialogData( aReconstructor1, aReconstructor2, aFileName );
       
    62             self.ShowDialog();
       
    63         }
       
    64         #endregion
       
    65 
       
    66         #region Constructors & destructor
       
    67         private ComparisonProgressDialogData( HeapReconstructor aReconstructor1, HeapReconstructor aReconstructor2, string aFileName )
       
    68         {
       
    69             iReconstructor1 = aReconstructor1;
       
    70             iReconstructor2 = aReconstructor2;
       
    71             //
       
    72             InitializeComponent();
       
    73             //
       
    74             iReconstructor1.iObserver += new HeapReconstructor.Observer( HeapReconstructorObserver );
       
    75             iReconstructor2.iObserver += new HeapReconstructor.Observer( HeapReconstructorObserver );
       
    76             //
       
    77             iComparisonEngine = new ComparsionEngine( iReconstructor1, iReconstructor2 );
       
    78             iComparisonEngine.iObserver += new AsyncReaderBase.Observer( ComparisonEngineObserver );
       
    79             //
       
    80             iComparisonWriter = new ComparisonWriter( iComparisonEngine, aFileName );
       
    81             iComparisonWriter.iObserver += new AsyncTextWriterBase.Observer( ComparsionWriterObserver );
       
    82             //
       
    83             iTimer_OpStart.Start();
       
    84         }
       
    85 
       
    86         protected override void Dispose( bool disposing )
       
    87         {
       
    88             if ( disposing )
       
    89             {
       
    90                 if ( components != null )
       
    91                 {
       
    92                     components.Dispose();
       
    93                 }
       
    94             }
       
    95             base.Dispose( disposing );
       
    96         }
       
    97         #endregion
       
    98 
       
    99         #region Windows Form Designer generated code
       
   100         private void InitializeComponent()
       
   101         {
       
   102             this.components = new System.ComponentModel.Container();
       
   103             this.iTimer_OpStart = new System.Windows.Forms.Timer( this.components );
       
   104             this.iProgBar = new System.Windows.Forms.ProgressBar();
       
   105             this.SuspendLayout();
       
   106             // 
       
   107             // iTimer_OpStart
       
   108             // 
       
   109             this.iTimer_OpStart.Interval = 10;
       
   110             this.iTimer_OpStart.Tick += new System.EventHandler( this.iTimer_OpStart_Tick );
       
   111             // 
       
   112             // iProgBar
       
   113             // 
       
   114             this.iProgBar.Dock = System.Windows.Forms.DockStyle.Fill;
       
   115             this.iProgBar.Location = new System.Drawing.Point( 3, 3 );
       
   116             this.iProgBar.Margin = new System.Windows.Forms.Padding( 0 );
       
   117             this.iProgBar.Name = "iProgBar";
       
   118             this.iProgBar.Size = new System.Drawing.Size( 351, 26 );
       
   119             this.iProgBar.TabIndex = 2;
       
   120             // 
       
   121             // ComparisonProgressDialogData
       
   122             // 
       
   123             this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13 );
       
   124             this.ClientSize = new System.Drawing.Size( 357, 32 );
       
   125             this.ControlBox = false;
       
   126             this.Controls.Add( this.iProgBar );
       
   127             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
       
   128             this.MaximizeBox = false;
       
   129             this.MinimizeBox = false;
       
   130             this.Name = "ComparisonProgressDialogData";
       
   131             this.Padding = new System.Windows.Forms.Padding( 3 );
       
   132             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       
   133             this.Text = "Analysing...";
       
   134             this.ResumeLayout( false );
       
   135 
       
   136         }
       
   137         #endregion
       
   138 
       
   139         #region Event handlers
       
   140         private void iTimer_OpStart_Tick( object sender, EventArgs e )
       
   141         {
       
   142             iTimer_OpStart.Stop();
       
   143             iTimer_OpStart.Enabled = false;
       
   144 
       
   145             // Start process by analysing the first heap
       
   146             iReconstructor1.Reconstruct();
       
   147         }
       
   148         #endregion
       
   149 
       
   150         #region Heap reconstructor callback
       
   151         private void HeapReconstructorObserver( HeapReconstructor.TEvent aEvent, HeapReconstructor aReconstructor )
       
   152         {
       
   153             if ( InvokeRequired )
       
   154             {
       
   155                 HeapReconstructor.Observer observer = new HeapReconstructor.Observer( HeapReconstructorObserver );
       
   156                 this.BeginInvoke( observer, new object[] { aEvent, aReconstructor } );
       
   157             }
       
   158             else
       
   159             {
       
   160                 // Select correct progress bar...
       
   161                 string title = "Reading Heap 1...";
       
   162                 if ( aReconstructor == iReconstructor2 )
       
   163                 {
       
   164                     title = "Reading Heap 2...";
       
   165                 }
       
   166                 //
       
   167                 switch ( aEvent )
       
   168                 {
       
   169                 case HeapReconstructor.TEvent.EReconstructingStarted:
       
   170                     this.Text = title;
       
   171                     iProgBar.Maximum = 100; //%
       
   172                     iProgBar.Minimum = 0; //%
       
   173                     iProgBar.Value = 0;
       
   174                     break;
       
   175                 case HeapReconstructor.TEvent.EReconstructingProgress:
       
   176                     iProgBar.Value = aReconstructor.Progress;
       
   177                     break;
       
   178                 case HeapReconstructor.TEvent.EReconstructingComplete:
       
   179                     iProgBar.Value = 100;
       
   180 
       
   181                     if ( aReconstructor == iReconstructor1 )
       
   182                     {
       
   183                         // Finished first heap, now move on to second
       
   184                         iReconstructor2.Reconstruct();
       
   185                     }
       
   186                     else
       
   187                     {
       
   188                         // Start output engine
       
   189                         iComparisonEngine.Compare();
       
   190                     }
       
   191                     break;
       
   192                 }
       
   193             }
       
   194         }
       
   195         #endregion
       
   196 
       
   197         #region Comparsion engine observer
       
   198         private void ComparisonEngineObserver( AsyncReaderBase.TEvent aEvent, AsyncReaderBase aSender )
       
   199         {
       
   200             if ( InvokeRequired )
       
   201             {
       
   202                 SymbianUtils.AsyncReaderBase.Observer observer = new SymbianUtils.AsyncReaderBase.Observer( ComparisonEngineObserver );
       
   203                 this.BeginInvoke( observer, new object[] { aEvent, aSender } );
       
   204             }
       
   205             else
       
   206             {
       
   207                 switch ( aEvent )
       
   208                 {
       
   209                 case SymbianUtils.AsyncReaderBase.TEvent.EReadingStarted:
       
   210                     this.Text = "Comparing Heaps...";
       
   211                     iProgBar.Maximum = 100; //%
       
   212                     iProgBar.Minimum = 0; //%
       
   213                     iProgBar.Value = 0;
       
   214                     break;
       
   215                 case SymbianUtils.AsyncReaderBase.TEvent.EReadingProgress:
       
   216                     iProgBar.Value = aSender.Progress;
       
   217                     break;
       
   218                 case SymbianUtils.AsyncReaderBase.TEvent.EReadingComplete:
       
   219                     iProgBar.Value = 100;
       
   220                     iComparisonWriter.SaveAsExcel();
       
   221                     break;
       
   222                 }
       
   223             }
       
   224         }
       
   225         #endregion
       
   226 
       
   227         #region Comparsion writer observer
       
   228         private void ComparsionWriterObserver( AsyncTextWriterBase.TEvent aEvent, AsyncTextWriterBase aObject )
       
   229         {
       
   230             if ( InvokeRequired )
       
   231             {
       
   232                 SymbianUtils.AsyncTextWriterBase.Observer observer = new SymbianUtils.AsyncTextWriterBase.Observer( ComparsionWriterObserver );
       
   233                 this.BeginInvoke( observer, new object[] { aEvent, aObject } );
       
   234             }
       
   235             else
       
   236             {
       
   237                 switch ( aEvent )
       
   238                 {
       
   239                 case SymbianUtils.AsyncTextWriterBase.TEvent.EWritingStarted:
       
   240                     this.Text = "Creating Excel File...";
       
   241                     iProgBar.Maximum = 100; //%
       
   242                     iProgBar.Minimum = 0; //%
       
   243                     iProgBar.Value = 0;
       
   244                     break;
       
   245                 case SymbianUtils.AsyncTextWriterBase.TEvent.EWritingProgress:
       
   246                     iProgBar.Value = aObject.Progress;
       
   247                     break;
       
   248                 case SymbianUtils.AsyncTextWriterBase.TEvent.EWritingComplete:
       
   249                     iProgBar.Value = 100;
       
   250                     Close();
       
   251                     break;
       
   252                 }
       
   253             }
       
   254         }
       
   255         #endregion
       
   256 
       
   257         #region Data members
       
   258         private readonly HeapReconstructor iReconstructor1;
       
   259         private readonly HeapReconstructor iReconstructor2;
       
   260         private readonly ComparsionEngine iComparisonEngine;
       
   261         private readonly ComparisonWriter iComparisonWriter;
       
   262         #endregion
       
   263     }
       
   264 }