none
Comment mesurer ce qui est alloué dans le tas RRS feed

  • Question

  • bonjour,

    Je cherche à savoir ce qui est alloué dans le tas. J'ai maintenant deux phases dans mon programme. entre la première phase et la deuxième phase je désalloue toutes les ressources allouées dans la première phase. Comment en être sûr. Il y a notamment deux tas: le tas managé et le tas non managé. Si un moyen existe de savoir les ressources qui sont allouée à un moment donné notamment au départ du projet et à ce point de désallocation, et si en plus on a le nom des symboles allouées, je pourrais faire une passe de contrôle effectif.

    J'ai bien essayé une primitive au départ de ce projet mais ça faisait planter l'application. Quel est le bon moyen de monitorer les tas?


    Jean Noël Martin

    dimanche 27 octobre 2013 06:40

Réponses

  • J'ai mesuré le tas avec la procédure décrite ci dessus Le code qui est là me montre que les désallocations sont bonne. il reste à vérifier le code de la deuxième phase

    #pragma managed 
    #include "StdAfx.h"
    #include "Macro.h"
    #include "AlignStructure.h"
    #include "Enumerations.hpp"
    #include "Structure.h"
    #include "TypeDefs.hpp"
    #include "POS.h"
    #include "Layout.h"
    #include "ClassesAligner.hpp"
    #include "LinkDescription.h"
    #include "Manager.h"
    #include "Aligner.h"
    #include "WordManager.h"
    #include "OpenAFile.h"
    #include "MainMenue.h"
    
    extern std::wstring wsFileToOpen;
    extern std::wstring wsPathOfTheFile;
    extern std::wstring wsDiskOfTheFile;
    extern std::wstring wsLanguage;
    extern std::wstring wsTypeDocument;
    extern std::wstring wsDatabaseName;
    extern std::wstring wsDatabaseFileName;
    extern int nParagraph;
    extern int iSize;
    
    struct _CrtMemState Heap;
    unsigned long ulCounts;
    unsigned long ulSizes;
    unsigned long ulCount;
    unsigned long ulSize;
    unsigned long ulTotal;
    
    namespace SpecificationLoader
    {
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Threading;
    	using namespace System::DirectoryServices;
    	namespace Word = Microsoft::Office::Interop::Word;
    	
    	bool bIsDbConnected;
    	erc ulDocSize;
    	bool bNewDoc = false;
    	erc ulTotalNbWords;
    	
    
    	MainMenue::MainMenue(void)
    	{
    		int i;
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		Console::WriteLine("Constructeur MainMenue");
    		MainMenue::InitializeComponent();
    		//
    		//TODO: ajoutez ici le code du constructeur
    		//
    		MainMenue::InitializeProgressBar();
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		progressBar1->Visible = false;
    		bIsDbConnected = false;
    	}
    
    	MainMenue::~MainMenue()
    	{
    		if (components)
    		{
    			delete components;
    		}
    	}
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
    		/// le contenu de cette méthode avec l'éditeur de code.
    		/// </summary>
    		void MainMenue::InitializeComponent(void)
    		{
    			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
    			this->filesToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->openAFileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
    			this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
    			this->ResultLabel = (gcnew System::Windows::Forms::Label());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->label3 = (gcnew System::Windows::Forms::Label());
    			this->label4 = (gcnew System::Windows::Forms::Label());
    			this->label6 = (gcnew System::Windows::Forms::Label());
    			this->label7 = (gcnew System::Windows::Forms::Label());
    			this->menuStrip1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// menuStrip1
    			// 
    			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->filesToolStripMenuItem, 
    				this->helpToolStripMenuItem});
    			this->menuStrip1->Location = System::Drawing::Point(0, 0);
    			this->menuStrip1->Name = L"menuStrip1";
    			this->menuStrip1->Size = System::Drawing::Size(1018, 24);
    			this->menuStrip1->TabIndex = 0;
    			this->menuStrip1->Text = L"menuStrip1";
    			// 
    			// filesToolStripMenuItem
    			// 
    			this->filesToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->openAFileToolStripMenuItem, 
    				this->exitToolStripMenuItem});
    			this->filesToolStripMenuItem->Name = L"filesToolStripMenuItem";
    			this->filesToolStripMenuItem->Size = System::Drawing::Size(40, 20);
    			this->filesToolStripMenuItem->Text = L"Files";
    			// 
    			// openAFileToolStripMenuItem
    			// 
    			this->openAFileToolStripMenuItem->Name = L"openAFileToolStripMenuItem";
    			this->openAFileToolStripMenuItem->Size = System::Drawing::Size(137, 22);
    			this->openAFileToolStripMenuItem->Text = L"Open a file";
    			this->openAFileToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::openAFileToolStripMenuItem_Click);
    			// 
    			// exitToolStripMenuItem
    			// 
    			this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
    			this->exitToolStripMenuItem->Size = System::Drawing::Size(137, 22);
    			this->exitToolStripMenuItem->Text = L"Exit";
    			this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::exitToolStripMenuItem_Click);
    			// 
    			// helpToolStripMenuItem
    			// 
    			this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
    			this->helpToolStripMenuItem->Size = System::Drawing::Size(40, 20);
    			this->helpToolStripMenuItem->Text = L"Help";
    			this->helpToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::helpToolStripMenuItem_Click);
    			// 
    			// progressBar1
    			// 
    			this->progressBar1->Location = System::Drawing::Point(36, 116);
    			this->progressBar1->Name = L"progressBar1";
    			this->progressBar1->Size = System::Drawing::Size(927, 19);
    			this->progressBar1->TabIndex = 1;
    			// 
    			// ResultLabel
    			// 
    			this->ResultLabel->AutoSize = true;
    			this->ResultLabel->Location = System::Drawing::Point(66, 418);
    			this->ResultLabel->Name = L"ResultLabel";
    			this->ResultLabel->Size = System::Drawing::Size(0, 13);
    			this->ResultLabel->TabIndex = 2;
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(761, 418);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(0, 13);
    			this->label1->TabIndex = 3;
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Location = System::Drawing::Point(509, 233);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(0, 13);
    			this->label2->TabIndex = 4;
    			// 
    			// label3
    			// 
    			this->label3->AutoSize = true;
    			this->label3->Location = System::Drawing::Point(432, 418);
    			this->label3->Name = L"label3";
    			this->label3->Size = System::Drawing::Size(0, 13);
    			this->label3->TabIndex = 5;
    			// 
    			// label4
    			// 
    			this->label4->AutoSize = true;
    			this->label4->Location = System::Drawing::Point(41, 88);
    			this->label4->Name = L"label4";
    			this->label4->Size = System::Drawing::Size(0, 13);
    			this->label4->TabIndex = 6;
    			// 
    			// label6
    			// 
    			this->label6->AutoSize = true;
    			this->label6->Location = System::Drawing::Point(36, 154);
    			this->label6->Name = L"label6";
    			this->label6->Size = System::Drawing::Size(0, 13);
    			this->label6->TabIndex = 8;
    			// 
    			// label7
    			// 
    			this->label7->AutoSize = true;
    			this->label7->Location = System::Drawing::Point(216, 154);
    			this->label7->Name = L"label7";
    			this->label7->Size = System::Drawing::Size(0, 13);
    			this->label7->TabIndex = 9;
    			// 
    			// MainMenue
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(1018, 479);
    			this->Controls->Add(this->label7);
    			this->Controls->Add(this->label6);
    			this->Controls->Add(this->label4);
    			this->Controls->Add(this->label3);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->ResultLabel);
    			this->Controls->Add(this->progressBar1);
    			this->Controls->Add(this->menuStrip1);
    			this->MainMenuStrip = this->menuStrip1;
    			this->Name = L"MainMenue";
    			this->Text = L"MainMenue";
    			this->menuStrip1->ResumeLayout(false);
    			this->menuStrip1->PerformLayout();
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    
    	System::Void MainMenue::openAFileToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    		int i;
    		OpenAFile^ newWindow = gcnew OpenAFile( this);
    		newWindow->ShowDialog();
    		progressBar1->Visible = true;
    		// c'est ici qu'on démarre l'aligner.
    		// erc CAligner::AlignDocumentsPairs(bool bMMIMode, std::wstring sSourceFileName, std::wstring sDocType, std::wstring *sDatabaseType, std::wstring *sDatabaseFileName);
    		bIsDbConnected = SpecificationLoader::objAligner.InitiateDbTransaction( wsDiskOfTheFile + wsPathOfTheFile + wsFileToOpen, bIsDbConnected, bNewDoc, wsTypeDocument, &wsDatabaseName, &wsDatabaseFileName);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		objWordManager = gcnew SpecificationLoader::CWManager;
    		objWordManager->StartWordApi();
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		ulDocSize = objWordManager->OpenWordDocument( wsDiskOfTheFile + wsPathOfTheFile + wsFileToOpen);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		backgroundWorker1->RunWorkerAsync();
    	}
    	
    	System::Void MainMenue::exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    		objAligner.CloseDBTransaction();
    		this->Close();
    	}
    
    	System::Void MainMenue::helpToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    	}
    
    	void MainMenue::InitializeProgressBar()
    	{
    		Shown += gcnew EventHandler(  this, &MainMenue::Form1_Shown);
    		// To report progress from the background worker we need to set this property
    		backgroundWorker1->WorkerReportsProgress = true;
    		// This event will be raised when we call ReportProgress
    		backgroundWorker1->ProgressChanged += gcnew ProgressChangedEventHandler( this, &MainMenue::backgroundWorker1_ProgressChanged);
    		backgroundWorker1->DoWork += gcnew DoWorkEventHandler( this, &MainMenue::backgroundWorker1_DoWork );
    	}
    
    	void MainMenue::Form1_Shown( System::Object^ sender, System::EventArgs^ e)
    	{
    		// Start the background worker
    		progressBar1->Visible = false;
    	}
    	
    	// Back on the 'UI' thread so we can update the progress bar
    	void MainMenue::backgroundWorker1_ProgressChanged( System::Object^ sender, ProgressChangedEventArgs^ e)
    	{
    		System::String^ msg;
    		// The progress percentage is a property of e
    		progressBar1->Value = e->ProgressPercentage;
    		msg = L"Progress is " + e->ProgressPercentage + L"%";
    		ResultLabel->Text = msg;
    		msg = L"Paragraph progress is: " + nParagraph;
    		label1->Text = msg;
    		msg = L"Number of Word processed is: " + ulTotalNbWords;
    		label3->Text = msg;
    		msg = L"Specification loading Process";
    		
    	}
    	// Back on the 'UI' thread so we can update the progress bar
    	void MainMenue::backgroundWorker2_ProgressChanged( System::Object^ sender, ProgressChangedEventArgs^ e)
    	{
    		System::String^ msg;
    		label4->Text = msg;
    		if( e->ProgressPercentage == 100)
    			label6->Text = L"Start of the Coherence assertion step";
    		if (iSize > 0)
    		{
    			msg = L"Number of Semantic Element Loaded: " + iSize + L" Elements";
    			label7->Text = msg;
    		}
    	}
    
    	System::Void MainMenue::backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e)
    	{
    		// The progress percentage is a property of e
    		// This event handler is where the actual, 
    		// potentially time-consuming work is done. 
    		// Get the BackgroundWorker that raised this event.
    		int i;
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
    		// C'est ici qu'on démarre l'anlyse en tâche de fond.
    		objWordManager->StartDocAnalysis( backgroundWorker1, ulDocSize, bNewDoc);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		objSoftwareManager.Termination();
    		objWordManager->StartCoherenceAssertion( backgroundWorker1, ulDocSize);
    	}
    }


    Jean Noël Martin

    • Marqué comme réponse JeanNoel53 jeudi 31 octobre 2013 10:01
    jeudi 31 octobre 2013 10:00

Toutes les réponses

  • Bonjour

    Pour le code non managée la réponse c'est que vous ne pouvez pas faire ça avec du code.

    C++ c'est un système très démocratique – vous pouvez faire tout ce que vous voulez, mais vous êtes responsable pour ce que vous faites. Avec certitude, si vous faites des erreurs le système vas vous punir.
    Vous pouvez utiliser des systèmes externes – Heap Profiler pour inspecter l’allocation de la mémoire et corriger les possibles erreurs : voir les réponses ici :
    http://stackoverflow.com/questions/700097/memory-allocation-profiling-in-c

    Pour le code managée la réponse c’est que vous n’avez pas besoin de faire ça,  il y a GarbageCollector  qui libère la mémoire allouée quand les objets ne sont plus utilisées.  

    Cordialement,


    Aurel BERA, MSFT
    MSDN Community Support. LE CONTENU EST FOURNI "TEL QUEL" SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE.
    S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution.

    lundi 28 octobre 2013 09:17
  • Pour aller plus loin j'aurais besoin de trouver ou est écrit cout

    Jean Noël Martin

    lundi 28 octobre 2013 10:59
  • Bonjour

    Les applications MFC n'ont pas une console.
    Ici vous avez le code pour créer une console : http://www.codeproject.com/Articles/612/Creating-a-console-for-your-MFC-app-s-debug-output
    Si vous voulez le résultat seulement pour debug, veuillez utiliser http://msdn.microsoft.com/en-us/library/windows/desktop/aa363362(v=vs.85).aspx

    Cordialement,


    Aurel BERA, MSFT
    MSDN Community Support. LE CONTENU EST FOURNI "TEL QUEL" SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE.
    S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution.

    lundi 28 octobre 2013 12:18
  • bonjour,

    J'ai donc téléchargé l'outil sur le net

    J'ai fait un contrôle après la desallocation, il semble qu'il n'y ai rien.

    Je vais faire le contre test avant et je reviens vous en parler

    en attendant je donne le code qu j'ai adapté;

    on est obligé de faire une passe par variable recherchée

    template<class T>
    class Stats {
      static int instance_count;
    public:
      Stats() {
        instance_count++;
      }
      ~Stats() {
        instance_count--;
      }
      static void print() 
      {
    	int iTemp;
    	{
    		msg += " instances of ";
    		msg += typeid(T).name();
    		msg += ", nombre ";
    		iSize = instance_count;
    		msg += iSize;
    		msg += " de taille ";
    		iSize = sizeof(T);
    		msg += iSize;
    		msg += " bytes each.";
    		throw Doc_exception( msg.c_str(), nParagraph);
    	}
      }
    };
    
    template<class T>
    int Stats<T>::instance_count = 0;
    	class AnalysedChunk : Stats<CAnalysedChunk>
    	{
    	};
        class AnalysedWord : Stats<CAnalysedWord>
    	{
    	};
        class ListSegment : Stats<ListSegment>
    	{
    	};
    	void print_stats() 
    	{
    		//Stats<CAnalysedChunk>::print();
    		Stats<CAnalysedWord>::print();
    		Stats<ListSegment>::print();
    	}

    Apres le contre test il  n'y a rien d'alloué avant non plus donc ce test ne marche pas J'ai aussi trouvé sur le net un autre test je vais essayer.

    J'ai donc changé de stratégie en suivant ce qui est dit dans le site msdn et j'ai inclus ce code:

    typedef struct _CrtMemState { // Pointer to the most recently allocated block: struct _CrtMemBlockHeader * pBlockHeader; // A counter for each of the 5 types of block: size_t lCounts[_MAX_BLOCKS]; // Total bytes allocated in each block type: size_t lSizes[_MAX_BLOCKS]; // The most bytes allocated at a time up to now: size_t lHighWaterCount; // The total bytes allocated at present: size_t lTotalCount; } _CrtMemState; _CrtMemState Heap; unsigned long ulCounts = 0; unsigned long ulSizes = 0; for( i = 0; i < _MAX_BLOCKS; i++) { ulCounts += Heap.lCounts[i]; ulSizes += Heap.lSizes[i]; } unsigned long ulTotal = ulCounts * ulSizes;

    objSchedulerGlobal.ClearListGrammaire( pListSegment);

    ulCounts = 0; ulSizes = 0; for( i = 0; i < _MAX_BLOCKS; i++) { ulCounts += Heap.lCounts[i]; ulSizes += Heap.lSizes[i]; } ulTotal -= ulCounts * ulSizes;

    et malgré la désallocation des objets faite à la ligne
    objSchedulerGlobal.ClearListGrammaire( pListSegment);
    les objets alloués après la libération sont les mêmes. Quid de la libération?


    Jean Noël Martin



    mardi 29 octobre 2013 06:14
  • j'ai ajouté dans la boucle delete Heap.pBlockHeader;

    mais ca n'a rien changé. C'est comme si le champ était toujours alloué

    j'ai d'ailleurs le message du linker

    1>     Création de la bibliothèque E:\usr\Memoria\dev\ALN_Kernel\make\SpecificationLoader\Release\SpecificationLoader.lib et de l'objet E:\usr\Memoria\dev\ALN_Kernel\make\SpecificationLoader\Release\SpecificationLoader.exp
    1>WordManager.obj : warning LNK4248: jeton typeref non résolu (0100002F) pour '_CrtMemBlockHeader' ; l'image risque de ne pas s'exécuter
    1>  SpecificationLoader.vcxproj -> E:\usr\Memoria\dev\ALN_Kernel\make\SpecificationLoader\Release\SpecificationLoader.exe

    comment résoudre ce problème?


    Jean Noël Martin


    mardi 29 octobre 2013 14:26
  • J'ai mesuré le tas avec la procédure décrite ci dessus Le code qui est là me montre que les désallocations sont bonne. il reste à vérifier le code de la deuxième phase

    #pragma managed 
    #include "StdAfx.h"
    #include "Macro.h"
    #include "AlignStructure.h"
    #include "Enumerations.hpp"
    #include "Structure.h"
    #include "TypeDefs.hpp"
    #include "POS.h"
    #include "Layout.h"
    #include "ClassesAligner.hpp"
    #include "LinkDescription.h"
    #include "Manager.h"
    #include "Aligner.h"
    #include "WordManager.h"
    #include "OpenAFile.h"
    #include "MainMenue.h"
    
    extern std::wstring wsFileToOpen;
    extern std::wstring wsPathOfTheFile;
    extern std::wstring wsDiskOfTheFile;
    extern std::wstring wsLanguage;
    extern std::wstring wsTypeDocument;
    extern std::wstring wsDatabaseName;
    extern std::wstring wsDatabaseFileName;
    extern int nParagraph;
    extern int iSize;
    
    struct _CrtMemState Heap;
    unsigned long ulCounts;
    unsigned long ulSizes;
    unsigned long ulCount;
    unsigned long ulSize;
    unsigned long ulTotal;
    
    namespace SpecificationLoader
    {
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Threading;
    	using namespace System::DirectoryServices;
    	namespace Word = Microsoft::Office::Interop::Word;
    	
    	bool bIsDbConnected;
    	erc ulDocSize;
    	bool bNewDoc = false;
    	erc ulTotalNbWords;
    	
    
    	MainMenue::MainMenue(void)
    	{
    		int i;
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		Console::WriteLine("Constructeur MainMenue");
    		MainMenue::InitializeComponent();
    		//
    		//TODO: ajoutez ici le code du constructeur
    		//
    		MainMenue::InitializeProgressBar();
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		progressBar1->Visible = false;
    		bIsDbConnected = false;
    	}
    
    	MainMenue::~MainMenue()
    	{
    		if (components)
    		{
    			delete components;
    		}
    	}
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
    		/// le contenu de cette méthode avec l'éditeur de code.
    		/// </summary>
    		void MainMenue::InitializeComponent(void)
    		{
    			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
    			this->filesToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->openAFileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
    			this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
    			this->ResultLabel = (gcnew System::Windows::Forms::Label());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->label3 = (gcnew System::Windows::Forms::Label());
    			this->label4 = (gcnew System::Windows::Forms::Label());
    			this->label6 = (gcnew System::Windows::Forms::Label());
    			this->label7 = (gcnew System::Windows::Forms::Label());
    			this->menuStrip1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// menuStrip1
    			// 
    			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->filesToolStripMenuItem, 
    				this->helpToolStripMenuItem});
    			this->menuStrip1->Location = System::Drawing::Point(0, 0);
    			this->menuStrip1->Name = L"menuStrip1";
    			this->menuStrip1->Size = System::Drawing::Size(1018, 24);
    			this->menuStrip1->TabIndex = 0;
    			this->menuStrip1->Text = L"menuStrip1";
    			// 
    			// filesToolStripMenuItem
    			// 
    			this->filesToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->openAFileToolStripMenuItem, 
    				this->exitToolStripMenuItem});
    			this->filesToolStripMenuItem->Name = L"filesToolStripMenuItem";
    			this->filesToolStripMenuItem->Size = System::Drawing::Size(40, 20);
    			this->filesToolStripMenuItem->Text = L"Files";
    			// 
    			// openAFileToolStripMenuItem
    			// 
    			this->openAFileToolStripMenuItem->Name = L"openAFileToolStripMenuItem";
    			this->openAFileToolStripMenuItem->Size = System::Drawing::Size(137, 22);
    			this->openAFileToolStripMenuItem->Text = L"Open a file";
    			this->openAFileToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::openAFileToolStripMenuItem_Click);
    			// 
    			// exitToolStripMenuItem
    			// 
    			this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
    			this->exitToolStripMenuItem->Size = System::Drawing::Size(137, 22);
    			this->exitToolStripMenuItem->Text = L"Exit";
    			this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::exitToolStripMenuItem_Click);
    			// 
    			// helpToolStripMenuItem
    			// 
    			this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
    			this->helpToolStripMenuItem->Size = System::Drawing::Size(40, 20);
    			this->helpToolStripMenuItem->Text = L"Help";
    			this->helpToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainMenue::helpToolStripMenuItem_Click);
    			// 
    			// progressBar1
    			// 
    			this->progressBar1->Location = System::Drawing::Point(36, 116);
    			this->progressBar1->Name = L"progressBar1";
    			this->progressBar1->Size = System::Drawing::Size(927, 19);
    			this->progressBar1->TabIndex = 1;
    			// 
    			// ResultLabel
    			// 
    			this->ResultLabel->AutoSize = true;
    			this->ResultLabel->Location = System::Drawing::Point(66, 418);
    			this->ResultLabel->Name = L"ResultLabel";
    			this->ResultLabel->Size = System::Drawing::Size(0, 13);
    			this->ResultLabel->TabIndex = 2;
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(761, 418);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(0, 13);
    			this->label1->TabIndex = 3;
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Location = System::Drawing::Point(509, 233);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(0, 13);
    			this->label2->TabIndex = 4;
    			// 
    			// label3
    			// 
    			this->label3->AutoSize = true;
    			this->label3->Location = System::Drawing::Point(432, 418);
    			this->label3->Name = L"label3";
    			this->label3->Size = System::Drawing::Size(0, 13);
    			this->label3->TabIndex = 5;
    			// 
    			// label4
    			// 
    			this->label4->AutoSize = true;
    			this->label4->Location = System::Drawing::Point(41, 88);
    			this->label4->Name = L"label4";
    			this->label4->Size = System::Drawing::Size(0, 13);
    			this->label4->TabIndex = 6;
    			// 
    			// label6
    			// 
    			this->label6->AutoSize = true;
    			this->label6->Location = System::Drawing::Point(36, 154);
    			this->label6->Name = L"label6";
    			this->label6->Size = System::Drawing::Size(0, 13);
    			this->label6->TabIndex = 8;
    			// 
    			// label7
    			// 
    			this->label7->AutoSize = true;
    			this->label7->Location = System::Drawing::Point(216, 154);
    			this->label7->Name = L"label7";
    			this->label7->Size = System::Drawing::Size(0, 13);
    			this->label7->TabIndex = 9;
    			// 
    			// MainMenue
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(1018, 479);
    			this->Controls->Add(this->label7);
    			this->Controls->Add(this->label6);
    			this->Controls->Add(this->label4);
    			this->Controls->Add(this->label3);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->ResultLabel);
    			this->Controls->Add(this->progressBar1);
    			this->Controls->Add(this->menuStrip1);
    			this->MainMenuStrip = this->menuStrip1;
    			this->Name = L"MainMenue";
    			this->Text = L"MainMenue";
    			this->menuStrip1->ResumeLayout(false);
    			this->menuStrip1->PerformLayout();
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    
    	System::Void MainMenue::openAFileToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    		int i;
    		OpenAFile^ newWindow = gcnew OpenAFile( this);
    		newWindow->ShowDialog();
    		progressBar1->Visible = true;
    		// c'est ici qu'on démarre l'aligner.
    		// erc CAligner::AlignDocumentsPairs(bool bMMIMode, std::wstring sSourceFileName, std::wstring sDocType, std::wstring *sDatabaseType, std::wstring *sDatabaseFileName);
    		bIsDbConnected = SpecificationLoader::objAligner.InitiateDbTransaction( wsDiskOfTheFile + wsPathOfTheFile + wsFileToOpen, bIsDbConnected, bNewDoc, wsTypeDocument, &wsDatabaseName, &wsDatabaseFileName);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		objWordManager = gcnew SpecificationLoader::CWManager;
    		objWordManager->StartWordApi();
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		ulDocSize = objWordManager->OpenWordDocument( wsDiskOfTheFile + wsPathOfTheFile + wsFileToOpen);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		backgroundWorker1->RunWorkerAsync();
    	}
    	
    	System::Void MainMenue::exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    		objAligner.CloseDBTransaction();
    		this->Close();
    	}
    
    	System::Void MainMenue::helpToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    	{
    	}
    
    	void MainMenue::InitializeProgressBar()
    	{
    		Shown += gcnew EventHandler(  this, &MainMenue::Form1_Shown);
    		// To report progress from the background worker we need to set this property
    		backgroundWorker1->WorkerReportsProgress = true;
    		// This event will be raised when we call ReportProgress
    		backgroundWorker1->ProgressChanged += gcnew ProgressChangedEventHandler( this, &MainMenue::backgroundWorker1_ProgressChanged);
    		backgroundWorker1->DoWork += gcnew DoWorkEventHandler( this, &MainMenue::backgroundWorker1_DoWork );
    	}
    
    	void MainMenue::Form1_Shown( System::Object^ sender, System::EventArgs^ e)
    	{
    		// Start the background worker
    		progressBar1->Visible = false;
    	}
    	
    	// Back on the 'UI' thread so we can update the progress bar
    	void MainMenue::backgroundWorker1_ProgressChanged( System::Object^ sender, ProgressChangedEventArgs^ e)
    	{
    		System::String^ msg;
    		// The progress percentage is a property of e
    		progressBar1->Value = e->ProgressPercentage;
    		msg = L"Progress is " + e->ProgressPercentage + L"%";
    		ResultLabel->Text = msg;
    		msg = L"Paragraph progress is: " + nParagraph;
    		label1->Text = msg;
    		msg = L"Number of Word processed is: " + ulTotalNbWords;
    		label3->Text = msg;
    		msg = L"Specification loading Process";
    		
    	}
    	// Back on the 'UI' thread so we can update the progress bar
    	void MainMenue::backgroundWorker2_ProgressChanged( System::Object^ sender, ProgressChangedEventArgs^ e)
    	{
    		System::String^ msg;
    		label4->Text = msg;
    		if( e->ProgressPercentage == 100)
    			label6->Text = L"Start of the Coherence assertion step";
    		if (iSize > 0)
    		{
    			msg = L"Number of Semantic Element Loaded: " + iSize + L" Elements";
    			label7->Text = msg;
    		}
    	}
    
    	System::Void MainMenue::backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e)
    	{
    		// The progress percentage is a property of e
    		// This event handler is where the actual, 
    		// potentially time-consuming work is done. 
    		// Get the BackgroundWorker that raised this event.
    		int i;
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
    		// C'est ici qu'on démarre l'anlyse en tâche de fond.
    		objWordManager->StartDocAnalysis( backgroundWorker1, ulDocSize, bNewDoc);
    		for( i = 0; i < _MAX_BLOCKS; i++)
    		{
    			ulCounts += Heap.lCounts[i];
    			ulSizes += Heap.lSizes[i];
    		}
    		ulTotal = ulCounts * ulSizes;
    		objSoftwareManager.Termination();
    		objWordManager->StartCoherenceAssertion( backgroundWorker1, ulDocSize);
    	}
    }


    Jean Noël Martin

    • Marqué comme réponse JeanNoel53 jeudi 31 octobre 2013 10:01
    jeudi 31 octobre 2013 10:00