sysperfana/heapanalyser/Libraries/UI/HeapComparisonUiLib/Progress/ComparisonProgressDialogCSV.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.Collections.Generic;
       
    42 using System.ComponentModel;
       
    43 using System.Windows.Forms;
       
    44 using SymbianUtils;
       
    45 using HeapComparisonLib.CSV;
       
    46 
       
    47 namespace HeapComparisonUiLib.Progress
       
    48 {
       
    49 	public class ComparisonProgressDialogCSV : System.Windows.Forms.Form
       
    50 	{
       
    51 		#region Windows Form Designer generated code
       
    52         private IContainer components;
       
    53         private Timer iTimer_OpStart;
       
    54         private System.Windows.Forms.ProgressBar iProgressBar;
       
    55 		#endregion
       
    56 
       
    57 		#region Static constructor
       
    58 		public static void Compare( List<string> aSource, string aDestinationDir )
       
    59 		{
       
    60             ComparisonProgressDialogCSV self = new ComparisonProgressDialogCSV( aSource, aDestinationDir );
       
    61 			self.ShowDialog();
       
    62 		}
       
    63 		#endregion
       
    64 
       
    65         #region Constructors & destructor
       
    66         private ComparisonProgressDialogCSV( List<string> aSource, string aDestinationDir )
       
    67         {
       
    68             iEngine = new CSVComparisonEngine( aSource, aDestinationDir );
       
    69             iEngine.eExceptionHandler += new CSVComparisonEngine.ExceptionHandler( Engine_ExceptionHandler );
       
    70             iEngine.eEventHandler += new CSVComparisonEngine.EventHandler( Engine_EventHandler );
       
    71             iEngine.eIndexedProgressHandler += new CSVComparisonEngine.IndexedProgressHandler( Engine_IndexedProgressHandler );
       
    72             iEngine.ePercentageProgressHandler += new CSVComparisonEngine.PercentageProgressHandler( Engine_PercentageProgressHandler );
       
    73             //
       
    74             InitializeComponent();
       
    75             //
       
    76             iTimer_OpStart.Start();
       
    77         }
       
    78 
       
    79         protected override void Dispose( bool disposing )
       
    80         {
       
    81             if ( disposing )
       
    82             {
       
    83                 if ( components != null )
       
    84                 {
       
    85                     components.Dispose();
       
    86                 }
       
    87             }
       
    88             base.Dispose( disposing );
       
    89         }
       
    90         #endregion
       
    91 
       
    92         #region Windows Form Designer generated code
       
    93 		private void InitializeComponent()
       
    94 		{
       
    95             this.components = new System.ComponentModel.Container();
       
    96             this.iProgressBar = new System.Windows.Forms.ProgressBar();
       
    97             this.iTimer_OpStart = new System.Windows.Forms.Timer( this.components );
       
    98             this.SuspendLayout();
       
    99             // 
       
   100             // iProgressBar
       
   101             // 
       
   102             this.iProgressBar.Location = new System.Drawing.Point( 8, 8 );
       
   103             this.iProgressBar.Name = "iProgressBar";
       
   104             this.iProgressBar.Size = new System.Drawing.Size( 376, 24 );
       
   105             this.iProgressBar.TabIndex = 0;
       
   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             // ComparisonProgressDialogCSV
       
   113             // 
       
   114             this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13 );
       
   115             this.ClientSize = new System.Drawing.Size( 392, 39 );
       
   116             this.ControlBox = false;
       
   117             this.Controls.Add( this.iProgressBar );
       
   118             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
       
   119             this.MaximizeBox = false;
       
   120             this.MinimizeBox = false;
       
   121             this.Name = "ComparisonProgressDialogCSV";
       
   122             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       
   123             this.Text = "Analysing...";
       
   124             this.ResumeLayout( false );
       
   125 
       
   126 		}
       
   127 		#endregion
       
   128 
       
   129         #region Event handlers
       
   130         private void iTimer_OpStart_Tick( object sender, EventArgs e )
       
   131         {
       
   132             iTimer_OpStart.Stop();
       
   133             iTimer_OpStart.Enabled = false;
       
   134             //
       
   135             iEngine.CompareAsync();
       
   136         }
       
   137         #endregion
       
   138 
       
   139         #region Engine observer
       
   140         void Engine_PercentageProgressHandler( CSVComparisonEngine.TEvent aEvent, CSVComparisonEngine aSender, int aProgressPercent )
       
   141         {
       
   142             if ( InvokeRequired )
       
   143             {
       
   144                 CSVComparisonEngine.PercentageProgressHandler observer = new CSVComparisonEngine.PercentageProgressHandler( Engine_PercentageProgressHandler );
       
   145                 this.BeginInvoke( observer, new object[] { aEvent, aSender, aProgressPercent } );
       
   146             }
       
   147             else
       
   148             {
       
   149                 iProgressBar.Value = aProgressPercent;
       
   150             }
       
   151         }
       
   152 
       
   153         void Engine_IndexedProgressHandler( CSVComparisonEngine.TEvent aEvent, CSVComparisonEngine aSender, int aCurrentIndex, int aMaxIndex )
       
   154         {
       
   155             if ( InvokeRequired )
       
   156             {
       
   157                 CSVComparisonEngine.IndexedProgressHandler observer = new CSVComparisonEngine.IndexedProgressHandler( Engine_IndexedProgressHandler );
       
   158                 this.BeginInvoke( observer, new object[] { aEvent, aSender, aCurrentIndex, aMaxIndex } );
       
   159             }
       
   160             else
       
   161             {
       
   162                 if ( aEvent == CSVComparisonEngine.TEvent.EEventComparingMovedToNewDataSet )
       
   163                 {
       
   164                     Text = string.Format( "Performing comparsion {0}/{1}", aCurrentIndex, aMaxIndex );
       
   165                 }
       
   166                 else if ( aEvent == CSVComparisonEngine.TEvent.EEventSplittingMovedToNewFile )
       
   167                 {
       
   168                     Text = string.Format( "Extracting data set(s) from file {0}/{1}", aCurrentIndex, aMaxIndex ); 
       
   169                 }
       
   170 
       
   171                 // Reset progress
       
   172                 iProgressBar.Maximum = 100; //%
       
   173                 iProgressBar.Minimum = 0; //%
       
   174                 iProgressBar.Value = 0;
       
   175             }
       
   176         }
       
   177 
       
   178         void Engine_EventHandler( CSVComparisonEngine.TEvent aEvent, CSVComparisonEngine aSender )
       
   179         {
       
   180             if ( InvokeRequired )
       
   181             {
       
   182                 CSVComparisonEngine.EventHandler observer = new CSVComparisonEngine.EventHandler( Engine_EventHandler );
       
   183                 this.BeginInvoke( observer, new object[] { aEvent, aSender } );
       
   184             }
       
   185             else
       
   186             {
       
   187                 if ( aEvent == CSVComparisonEngine.TEvent.EEventOperationStarted )
       
   188                 {
       
   189                 }
       
   190                 else if ( aEvent == CSVComparisonEngine.TEvent.EEventOperationComplete )
       
   191                 {
       
   192                     iProgressBar.Value = 100;
       
   193                     Close();
       
   194                 }
       
   195             }
       
   196         }
       
   197 
       
   198         void Engine_ExceptionHandler( string aTitle, string aBody )
       
   199         {
       
   200             if ( InvokeRequired )
       
   201             {
       
   202                 CSVComparisonEngine.ExceptionHandler observer = new CSVComparisonEngine.ExceptionHandler( Engine_ExceptionHandler );
       
   203                 this.BeginInvoke( observer, new object[] { aTitle, aBody } );
       
   204             }
       
   205             else
       
   206             {
       
   207                 MessageBox.Show( aBody, aBody, MessageBoxButtons.OK );
       
   208                 Close();
       
   209             }
       
   210         }
       
   211         #endregion
       
   212 
       
   213 		#region Data members
       
   214         private readonly CSVComparisonEngine iEngine;
       
   215 		#endregion
       
   216 	}
       
   217 }