Cette documentation est archivée et n’est pas conservée.

InstallEventArgs, classe

Mise à jour : novembre 2007

Fournit des données pour les événements suivants : BeforeInstall, AfterInstall, Committing, Committed, BeforeRollback, AfterRollback, BeforeUninstall, AfterUninstall.

Espace de noms :  System.Configuration.Install
Assembly :  System.Configuration.Install (dans System.Configuration.Install.dll)

public class InstallEventArgs : EventArgs
public class InstallEventArgs extends EventArgs
public class InstallEventArgs extends EventArgs

InstallEventArgs contient un IDictionary qui détient des informations sur l'état actuel de l'installation. Les gestionnaires d'événements BeforeInstall, AfterInstall, Committing, Committed, BeforeRollback, AfterRollback, BeforeUninstall, et AfterUninstall utilisent ces informations.

L'exemple suivant illustre les constructeurs InstallEventArgs et la propriété SavedState de la classe InstallEventArgs.

Il existe deux nouveaux événements nommés BeforeCommit et AfterCommit. Les gestionnaires de ces événements sont appelés à partir des méthodes protégées nommées OnBeforeCommit et OnAfterCommit, respectivement. Ces événements sont déclenchés lors de l'appel à la méthode Commit.


using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;

[RunInstaller(true)]
public class MyInstaller : Installer
{
   // Simple events to handle before and after commit handlers.
   public event InstallEventHandler BeforeCommit;
   public event InstallEventHandler AfterCommit;

   public MyInstaller()
   {
      // Add handlers to the events.
      BeforeCommit += new InstallEventHandler(BeforeCommitHandler);
      AfterCommit += new InstallEventHandler(AfterCommitHandler);
   }

   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
      Console.WriteLine("Install ...\n");
   }

   public override void Commit(IDictionary savedState)
   {
      Console.WriteLine("Before Committing ...\n");
      // Call the 'OnBeforeCommit' protected method.
      OnBeforeCommit(savedState);
      base.Commit(savedState);
      Console.WriteLine("Committing ...\n");
      // Call the 'OnAfterCommit' protected method.
      OnAfterCommit(savedState);
      Console.WriteLine("After Committing ...\n");
   }

   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
      Console.WriteLine("RollBack ...\n");
   }

   public override void Uninstall(IDictionary savedState)
   {
      base.Uninstall(savedState);
      Console.WriteLine("UnInstall ...\n");
   }

   // Protected method that invoke the handlers associated with the 'BeforeCommit' event.
   protected virtual void OnBeforeCommit(IDictionary savedState)
   {
      if(BeforeCommit != null)
         BeforeCommit(this, new InstallEventArgs(savedState)); 
   }

   // Protected method that invoke the handlers associated with the 'AfterCommit' event.
   protected virtual void OnAfterCommit(IDictionary savedState)
   {
      if(AfterCommit != null)
         AfterCommit(this, new InstallEventArgs());
   }

   // A simple event handler to exemplify the example.
   private void BeforeCommitHandler(Object sender, InstallEventArgs e)
   {
      Console.WriteLine("BeforeCommitHandler event handler has been called\n");
      Console.WriteLine("The count of saved state objects are : {0}\n",
         e.SavedState.Count);
   }

   // A simple event handler to exemplify the example.
   private void AfterCommitHandler(Object sender, InstallEventArgs e)
   {
      Console.WriteLine("AfterCommitHandler event handler has been called\n");
   }
}


import System.*;
import System.ComponentModel.*;
import System.Collections.*;
import System.Configuration.Install.*;
import System.IO.*;

/** @attribute RunInstaller(true)
 */
public class MyInstaller extends Installer
{
    // Simple events to handle before and after commit handlers.
    public InstallEventHandler beforeCommit = null;
    public InstallEventHandler afterCommit = null;


    /** @event 
     */
    public void add_beforeCommitHandler(InstallEventHandler p)
    {
        beforeCommit = 
            (InstallEventHandler)System.Delegate.Combine(beforeCommit, p);
    }

    /** @event 
     */
    public void remove_beforeCommitHandler(InstallEventHandler p)
    {
        beforeCommit = 
            (InstallEventHandler)System.Delegate.Remove(beforeCommit, p);
    }

    /** @event 
     */
    public void add_afterCommitHandler(InstallEventHandler p)
    {
        afterCommit = 
            (InstallEventHandler)System.Delegate.Combine(afterCommit, p);
    }

    /** @event 
     */
    public void remove_afterCommitHandler(InstallEventHandler p)
    {
        afterCommit = 
            (InstallEventHandler)System.Delegate.Remove(afterCommit, p);
    }

    public MyInstaller()
    {
        // Add handlers to the events.
        add_beforeCommitHandler(new InstallEventHandler(BeforeCommitHandler));
        add_afterCommitHandler(new InstallEventHandler(AfterCommitHandler));
    } //MyInstaller

    public void Install(IDictionary savedState)
    {
        super.Install(savedState);
        Console.WriteLine("Install ...\n");
    } //Install

    public void Commit(IDictionary savedState)
    {
        Console.WriteLine("Before Committing ...\n");

        // Call the 'OnBeforeCommit' protected method.
        OnBeforeCommit(savedState);
        super.Commit(savedState);
        Console.WriteLine("Committing ...\n");

        // Call the 'OnAfterCommit' protected method.
        OnAfterCommit(savedState);
        Console.WriteLine("After Committing ...\n");
    } //Commit

    public void Rollback(IDictionary savedState)
    {
        super.Rollback(savedState);
        Console.WriteLine("RollBack ...\n");
    } //Rollback

    public void Uninstall(IDictionary savedState)
    {
        super.Uninstall(savedState);
        Console.WriteLine("UnInstall ...\n");
    } //Uninstall

    // Protected method that invoke the handlers associated 
    // with the 'BeforeCommit' event.
    protected void OnBeforeCommit(IDictionary savedState)
    {
        if (beforeCommit != null) {
            beforeCommit.Invoke(this, new InstallEventArgs(savedState));
        }
    } //OnBeforeCommit

    // Protected method that invoke the handlers associated 
    // with the 'AfterCommit' event.
    protected void OnAfterCommit(IDictionary savedState)
    {
        if (afterCommit != null) {
            afterCommit.Invoke(this, new InstallEventArgs());
        }
    } //OnAfterCommit

    // A simple event handler to exemplify the example.
    private void BeforeCommitHandler(Object sender, InstallEventArgs e)
    {
        Console.WriteLine("BeforeCommitHandler event "
            +"handler has been called\n");
        Console.WriteLine("The count of saved state objects are : {0}\n",
            System.Convert.ToString(e.get_SavedState().get_Count()));
    } //BeforeCommitHandler

    // A simple event handler to exemplify the example.
    private void AfterCommitHandler(Object sender, InstallEventArgs e)
    {
        Console.WriteLine("AfterCommitHandler event handler has been called\n");
    } //AfterCommitHandler
} //MyInstaller


System.Object
  System.EventArgs
    System.Configuration.Install.InstallEventArgs

Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0, 1.1, 1.0
Afficher: