InstallEventArgs Class
Assembly: System.Configuration.Install (in system.configuration.install.dll)
InstallEventArgs contains an IDictionary that holds information about the current state of the installation. The BeforeInstall, AfterInstall, Committing, Committed, BeforeRollback, AfterRollback, BeforeUninstall, and AfterUninstall event handlers use this information.
The following example demonstrates the InstallEventArgs constructors and the SavedState property of the InstallEventArgs class.
There are two new events called BeforeCommit and AfterCommit. The handlers of these events are invoked from the protected methods named OnBeforeCommit and OnAfterCommit respectively. These events are raised when the Commit method is called.
Imports System Imports System.ComponentModel Imports System.Collections Imports System.Configuration.Install Imports System.IO Imports Microsoft.VisualBasic <RunInstaller(True)> Public Class MyInstaller Inherits Installer ' Simple events to handle before and after commit handlers. Public Event BeforeCommit As InstallEventHandler Public Event AfterCommit As InstallEventHandler Public Sub New() ' Add handlers to the events. AddHandler BeforeCommit, AddressOf BeforeCommitHandler AddHandler AfterCommit, AddressOf AfterCommitHandler End Sub Public Overrides Sub Install(savedState As IDictionary) MyBase.Install(savedState) Console.WriteLine("Install ..." + ControlChars.Newline) End Sub Public Overrides Sub Commit(savedState As IDictionary) Console.WriteLine("Before Committing ..." + ControlChars.Newline) ' Call the 'OnBeforeCommit' protected method. OnBeforeCommit(savedState) MyBase.Commit(savedState) Console.WriteLine("Committing ..." + ControlChars.Newline) ' Call the 'OnAfterCommit' protected method. OnAfterCommit(savedState) Console.WriteLine("After Committing ..." + ControlChars.Newline) End Sub Public Overrides Sub Rollback(savedState As IDictionary) MyBase.Rollback(savedState) Console.WriteLine("RollBack ..." + ControlChars.Newline) End Sub Public Overrides Sub Uninstall(savedState As IDictionary) MyBase.Uninstall(savedState) Console.WriteLine("UnInstall ..." + ControlChars.Newline) End Sub ' Protected method that invoke the handlers associated with the 'BeforeCommit' event. Protected Overridable Sub OnBeforeCommit(savedState As IDictionary) RaiseEvent BeforeCommit(Me, New InstallEventArgs(savedState)) End Sub ' Protected method that invoke the handlers associated with the 'AfterCommit' event. Protected Overridable Sub OnAfterCommit(savedState As IDictionary) RaiseEvent AfterCommit(Me, New InstallEventArgs()) End Sub ' A simple event handler to exemplify the example. Private Sub BeforeCommitHandler(sender As Object, e As InstallEventArgs) Console.WriteLine("BeforeCommitHandler event handler has been called" + _ ControlChars.Newline) Console.WriteLine("The count of saved state objects are : {0" + _ ControlChars.Newline, e.SavedState.Count) End Sub ' A simple event handler to exemplify the example. Private Sub AfterCommitHandler(sender As Object, e As InstallEventArgs) Console.WriteLine("AfterCommitHandler event handler has been called" + _ ControlChars.Newline) End Sub End Class
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
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
InstallEventArgs MembersSystem.Configuration.Install Namespace
Installer.AfterInstall Event
Installer.AfterRollback Event
Installer.AfterUninstall Event
Installer.BeforeInstall Event
Installer.BeforeRollback Event
Installer.BeforeUninstall Event
Commit
Installer.Committed Event
Installer.Committing Event
Install
Installer Class
InstallEventHandler
Rollback
Uninstall