TransactedInstaller 类

定义

定义要么完全成功要么失败后将计算机保留在其初始状态的安装程序。Defines an installer that either succeeds completely or fails and leaves the computer in its initial state.

public ref class TransactedInstaller : System::Configuration::Install::Installer
public class TransactedInstaller : System.Configuration.Install.Installer
type TransactedInstaller = class
    inherit Installer
Public Class TransactedInstaller
Inherits Installer
继承

示例

下面的TransactedInstaller示例演示TransactedInstaller类的InstallUninstall和方法。The following example demonstrates the TransactedInstaller, Install and Uninstall methods of the TransactedInstaller class.

此示例提供类似于installutil.exe (安装程序工具)的实现。This example provides an implementation similar to that of Installutil.exe (Installer Tool). 它在该特定程序集之前安装具有选项的程序集。It installs assemblies with the options preceding that particular assembly. 如果没有为程序集指定选项, 则如果列表中有以前的程序集, 则使用以前的程序集选项。If an option is not specified for an assembly, the previous assembly's options are used if there is a previous assembly in the list. 如果指定了 "/u" 或 "/uninstall" 选项, 则会卸载程序集。If either the "/u" or "/uninstall" option is specified, the assemblies are uninstalled. 如果 "/?"If the "/?" 如果提供了 "/help" 选项, 则会向控制台显示帮助信息。or "/help" option is provided, the help information is displayed to the console.

array<String^>^ args = Environment::GetCommandLineArgs();
ArrayList^ myOptions = gcnew ArrayList;
String^ myOption;
bool toUnInstall = false;
bool toPrintHelp = false;
TransactedInstaller^ myTransactedInstaller = gcnew TransactedInstaller;
AssemblyInstaller^ myAssemblyInstaller;
InstallContext^ myInstallContext;

try
{
   for ( int i = 1; i < args->Length; i++ )
   {
      // Process the arguments.
      if ( args[ i ]->StartsWith( "/" ) || args[ i ]->StartsWith( "-" ) )
      {
         myOption = args[ i ]->Substring( 1 );
         // Determine whether the option is to 'uninstall' an assembly.
         if ( String::Compare( myOption, "u", true ) == 0 ||
            String::Compare( myOption, "uninstall", true ) == 0 )
         {
            toUnInstall = true;
            continue;
         }
         // Determine whether the option is for printing help information.
         if ( String::Compare( myOption, "?", true ) == 0 ||
            String::Compare( myOption, "help", true ) == 0 )
         {
            toPrintHelp = true;
            continue;
         }
         // Add the option encountered to the list of all options
         // encountered for the current assembly.
         myOptions->Add( myOption );
      }
      else
      {
         // Determine whether the assembly file exists.
         if (  !File::Exists( args[ i ] ) )
         {
            // If assembly file doesn't exist then print error.
            Console::WriteLine( "\nError : {0} - Assembly file doesn't exist.",
               args[ i ] );
            return 0;
         }
         
         // Create a instance of 'AssemblyInstaller' that installs the given assembly.
         myAssemblyInstaller =
            gcnew AssemblyInstaller( args[ i ],
               (array<String^>^)( myOptions->ToArray( String::typeid ) ) );
         // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
         myTransactedInstaller->Installers->Add( myAssemblyInstaller );
      }
   }
   
   // If user requested help or didn't provide any assemblies to install
   // then print help message.
   if ( toPrintHelp || myTransactedInstaller->Installers->Count == 0 )
   {
      PrintHelpMessage();
      return 0;
   }
   
   // Create a instance of 'InstallContext' with the options specified.
   myInstallContext =
      gcnew InstallContext( "Install.log",
         (array<String^>^)( myOptions->ToArray( String::typeid ) ) );
   myTransactedInstaller->Context = myInstallContext;
   
   // Install or Uninstall an assembly depending on the option provided.
   if (  !toUnInstall )
   {
      myTransactedInstaller->Install( gcnew Hashtable );
   }
   else
   {
      myTransactedInstaller->Uninstall( nullptr );
   }
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "\nException raised : {0}", e->Message );
}
ArrayList myOptions = new ArrayList();
String myOption;
bool toUnInstall = false;
bool toPrintHelp = false;
TransactedInstaller myTransactedInstaller = new TransactedInstaller();
AssemblyInstaller myAssemblyInstaller;
InstallContext myInstallContext;

try
{
   for(int i = 0; i < args.Length; i++)
   {
      // Process the arguments.
      if(args[i].StartsWith("/") || args[i].StartsWith("-"))
      {
         myOption = args[i].Substring(1);
         // Determine whether the option is to 'uninstall' an assembly.
         if(String.Compare(myOption, "u", true) == 0 ||
            String.Compare(myOption, "uninstall", true) == 0)
         {
            toUnInstall = true;
            continue;
         }
         // Determine whether the option is for printing help information.
         if(String.Compare(myOption, "?", true) == 0 ||
            String.Compare(myOption, "help", true) == 0)
         {
            toPrintHelp = true;
            continue;
         }
         // Add the option encountered to the list of all options
         // encountered for the current assembly.
         myOptions.Add(myOption);
      }
      else
      {
         // Determine whether the assembly file exists.
         if(!File.Exists(args[i]))
         {
            // If assembly file doesn't exist then print error.
            Console.WriteLine("\nError : {0} - Assembly file doesn't exist.",
               args[i]);
            return;
         }
      
         // Create a instance of 'AssemblyInstaller' that installs the given assembly.
         myAssemblyInstaller = 
            new AssemblyInstaller(args[i], 
            (string[]) myOptions.ToArray(typeof(string)));
         // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.  
         myTransactedInstaller.Installers.Add(myAssemblyInstaller);
      }
   }
   // If user requested help or didn't provide any assemblies to install
   // then print help message.
   if(toPrintHelp || myTransactedInstaller.Installers.Count == 0)
   {
      PrintHelpMessage();
      return;
   }

   // Create a instance of 'InstallContext' with the options specified.
   myInstallContext = 
      new InstallContext("Install.log", 
      (string[]) myOptions.ToArray(typeof(string)));
   myTransactedInstaller.Context = myInstallContext;

   // Install or Uninstall an assembly depending on the option provided.
   if(!toUnInstall)
      myTransactedInstaller.Install(new Hashtable());
   else
      myTransactedInstaller.Uninstall(null);
}
catch(Exception e)
{
   Console.WriteLine("\nException raised : {0}", e.Message);
}  
Dim options As New ArrayList()
Dim myOption As String
Dim toUnInstall As Boolean = False
Dim toPrintHelp As Boolean = False
Dim myTransactedInstaller As New TransactedInstaller()
Dim myAssemblyInstaller As AssemblyInstaller
Dim myInstallContext As InstallContext

Try
   Dim i As Integer
   For i = 1 To args.Length - 1
      ' Process the arguments.
      If args(i).StartsWith("/") Or args(i).StartsWith("-") Then
         myOption = args(i).Substring(1)
         ' Determine whether the option is to 'uninstall' an assembly.
         If String.Compare(myOption, "u", True) = 0 Or _
            String.Compare(myOption,"uninstall", True) = 0 Then
            toUnInstall = True
            GoTo ContinueFor1
         End If
         ' Determine whether the option is for printing help information.
         If String.Compare(myOption, "?", True) = 0 Or _
            String.Compare(myOption, "help", True) = 0 Then
            toPrintHelp = True
            GoTo ContinueFor1
         End If
         ' Add the option encountered to the list of all options
         ' encountered for the current assembly.
         options.Add(myOption)
      Else
         ' Determine whether the assembly file exists.
         If Not File.Exists(args(i)) Then
            ' If assembly file doesn't exist then print error.
            Console.WriteLine(ControlChars.Newline + _
                     "Error : {0} - Assembly file doesn't exist.", args(i))
            Return
         End If

         ' Create a instance of 'AssemblyInstaller' that installs the given assembly.
         myAssemblyInstaller = New AssemblyInstaller(args(i), _
                        CType(options.ToArray(GetType(String)), String()))
         ' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
         myTransactedInstaller.Installers.Add(myAssemblyInstaller)
      End If
   ContinueFor1:
   Next i
   ' If user requested help or didn't provide any assemblies to install
   ' then print help message.
   If toPrintHelp Or myTransactedInstaller.Installers.Count = 0 Then
      PrintHelpMessage()
      Return
   End If

   ' Create a instance of 'InstallContext' with the options specified.
   myInstallContext = New InstallContext("Install.log", _
               CType(options.ToArray(GetType(String)), String()))
   myTransactedInstaller.Context = myInstallContext

   ' Install or Uninstall an assembly depending on the option provided.
   If Not toUnInstall Then
      myTransactedInstaller.Install(New Hashtable())
   Else
      myTransactedInstaller.Uninstall(Nothing)
   End If
Catch e As Exception
   Console.WriteLine(ControlChars.Newline + "Exception raised : {0}", e.Message)
End Try

注解

若要在事务中运行安装程序, 请将Installers其添加到TransactedInstaller此实例的属性中。To run installers in a transaction, add them to the Installers property of this TransactedInstaller instance.

构造函数

TransactedInstaller()

初始化 TransactedInstaller 类的新实例。Initializes a new instance of the TransactedInstaller class.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
Context

获取或设置关于当前安装的信息。Gets or sets information about the current installation.

(继承自 Installer)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
HelpText

获取安装程序集合中所有安装程序的帮助文字。Gets the help text for all the installers in the installer collection.

(继承自 Installer)
Installers

获取该安装程序包含的安装程序的集合。Gets the collection of installers that this installer contains.

(继承自 Installer)
Parent

获取或设置包含该安装程序所属的集合的安装程序。Gets or sets the installer containing the collection that this installer belongs to.

(继承自 Installer)
Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)

方法

Commit(IDictionary)

在派生类中重写时,完成安装事务。When overridden in a derived class, completes the install transaction.

(继承自 Installer)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
Install(IDictionary)

执行安装。Performs the installation.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnAfterInstall(IDictionary)

引发 AfterInstall 事件。Raises the AfterInstall event.

(继承自 Installer)
OnAfterRollback(IDictionary)

引发 AfterRollback 事件。Raises the AfterRollback event.

(继承自 Installer)
OnAfterUninstall(IDictionary)

引发 AfterUninstall 事件。Raises the AfterUninstall event.

(继承自 Installer)
OnBeforeInstall(IDictionary)

引发 BeforeInstall 事件。Raises the BeforeInstall event.

(继承自 Installer)
OnBeforeRollback(IDictionary)

引发 BeforeRollback 事件。Raises the BeforeRollback event.

(继承自 Installer)
OnBeforeUninstall(IDictionary)

引发 BeforeUninstall 事件。Raises the BeforeUninstall event.

(继承自 Installer)
OnCommitted(IDictionary)

引发 Committed 事件。Raises the Committed event.

(继承自 Installer)
OnCommitting(IDictionary)

引发 Committing 事件。Raises the Committing event.

(继承自 Installer)
Rollback(IDictionary)

在派生类中重写时,还原计算机的安装前状态。When overridden in a derived class, restores the pre-installation state of the computer.

(继承自 Installer)
ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)
Uninstall(IDictionary)

移除安装。Removes an installation.

事件

AfterInstall

Install(IDictionary) 属性中的所有安装程序的 Installers 方法都运行后发生。Occurs after the Install(IDictionary) methods of all the installers in the Installers property have run.

(继承自 Installer)
AfterRollback

在回滚 Installers 属性中所有安装程序的安装后发生。Occurs after the installations of all the installers in the Installers property are rolled back.

(继承自 Installer)
AfterUninstall

Installers 属性中所有安装程序都执行它们的卸载操作后发生。Occurs after all the installers in the Installers property perform their uninstallation operations.

(继承自 Installer)
BeforeInstall

在安装程序集合中每个安装程序的 Install(IDictionary) 方法运行前发生。Occurs before the Install(IDictionary) method of each installer in the installer collection has run.

(继承自 Installer)
BeforeRollback

在回滚 Installers 属性中的安装程序前发生。Occurs before the installers in the Installers property are rolled back.

(继承自 Installer)
BeforeUninstall

Installers 属性中的安装程序执行它们的卸载操作前发生。Occurs before the installers in the Installers property perform their uninstall operations.

(继承自 Installer)
Committed

Installers 属性中的所有安装程序均提交它们的安装后发生。Occurs after all the installers in the Installers property have committed their installations.

(继承自 Installer)
Committing

Installers 属性中的安装程序提交它们的安装前发生。Occurs before the installers in the Installers property commit their installations.

(继承自 Installer)
Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

适用于