TransactedInstaller クラス

定義

インストーラーによるインストールが正常終了したか、失敗してコンピューターが初期状態のままのいずれであるかを明確にします。

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
継承

次の例では、 クラスの メソッドTransactedInstallerInstall、および Uninstall メソッドをTransactedInstaller示します。

この例では、 Installutil.exe (インストーラー ツール) と同様の実装を提供します。 特定のアセンブリの前にオプションがあるアセンブリがインストールされます。 アセンブリにオプションが指定されていない場合、リストに以前のアセンブリがある場合は、前のアセンブリのオプションが使用されます。 "/u" または "/uninstall" オプションが指定されている場合、アセンブリはアンインストールされます。 "/?" または "/help" オプションが指定されている場合は、ヘルプ情報がコンソールに表示されます。

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 );
}
using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;

public class TransactedInstaller_Example
{
   public static void Main(String[] args)
   {
      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);
      }
   }

   public static void PrintHelpMessage()
   {
      Console.WriteLine("Usage : TransactedInstaller [/u | /uninstall] [option [...]] assembly" +
         "[[option [...]] assembly] [...]]");
      Console.WriteLine("TransactedInstaller executes the installers in each of" +
         " the given assembly. If /u or /uninstall option" +
         " is given it uninstalls the assemblies.");
   }
}
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

注釈

トランザクションでインストーラーを実行するには、このTransactedInstallerインスタンスの プロパティにインストーラーをInstallers追加します。

コンストラクター

TransactedInstaller()

TransactedInstaller クラスの新しいインスタンスを初期化します。

プロパティ

CanRaiseEvents

コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。

(継承元 Component)
Container

IContainer を含む Component を取得します。

(継承元 Component)
Context

現在のインストールに関する情報を取得または設定します。

(継承元 Installer)
DesignMode

Component が現在デザイン モードかどうかを示す値を取得します。

(継承元 Component)
Events

Component に結び付けられているイベント ハンドラーのリストを取得します。

(継承元 Component)
HelpText

インストーラー コレクション内のすべてのインストーラーに関するヘルプ テキストを取得します。

(継承元 Installer)
Installers

インストーラーが格納しているインストーラーのコレクションを取得します。

(継承元 Installer)
Parent

インストーラーが属しているコレクションを格納しているインストーラーを取得または設定します。

(継承元 Installer)
Site

ComponentISite を取得または設定します。

(継承元 Component)

メソッド

Commit(IDictionary)

派生クラスによってオーバーライドされた場合、インストール トランザクションを完了します。

(継承元 Installer)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

Component によって使用されているすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)

Component によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 Component)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetService(Type)

Component またはその Container で提供されるサービスを表すオブジェクトを返します。

(継承元 Component)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
Install(IDictionary)

インストールを実行します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
OnAfterInstall(IDictionary)

AfterInstall イベントを発生させます。

(継承元 Installer)
OnAfterRollback(IDictionary)

AfterRollback イベントを発生させます。

(継承元 Installer)
OnAfterUninstall(IDictionary)

AfterUninstall イベントを発生させます。

(継承元 Installer)
OnBeforeInstall(IDictionary)

BeforeInstall イベントを発生させます。

(継承元 Installer)
OnBeforeRollback(IDictionary)

BeforeRollback イベントを発生させます。

(継承元 Installer)
OnBeforeUninstall(IDictionary)

BeforeUninstall イベントを発生させます。

(継承元 Installer)
OnCommitted(IDictionary)

Committed イベントを発生させます。

(継承元 Installer)
OnCommitting(IDictionary)

Committing イベントを発生させます。

(継承元 Installer)
Rollback(IDictionary)

派生クラスによってオーバーライドされた場合、インストール前のコンピューターの状態を復元します。

(継承元 Installer)
ToString()

Component の名前 (存在する場合) を格納する String を返します。 このメソッドはオーバーライドできません。

(継承元 Component)
Uninstall(IDictionary)

インストールした内容を削除します。

イベント

AfterInstall

Installers プロパティ内のすべてのインストーラーの Install(IDictionary) メソッドが実行された後で発生します。

(継承元 Installer)
AfterRollback

Installers プロパティ内のすべてのインストーラーによるインストールがロールバックされた後で発生します。

(継承元 Installer)
AfterUninstall

Installers プロパティ内のすべてのインストーラーのアンインストールが実行された後で発生します。

(継承元 Installer)
BeforeInstall

インストーラー コレクション内の各インストーラーの Install(IDictionary) メソッドが実行される前に発生します。

(継承元 Installer)
BeforeRollback

Installers プロパティ内のインストーラーがロールバックされる前に発生します。

(継承元 Installer)
BeforeUninstall

Installers プロパティ内のインストーラーのアンインストールが実行される前に発生します。

(継承元 Installer)
Committed

Installers プロパティ内のすべてのインストーラーがインストールをコミットした後で発生します。

(継承元 Installer)
Committing

Installers プロパティ内のインストーラーがインストールをコミットする前に発生します。

(継承元 Installer)
Disposed

Dispose() メソッドの呼び出しによってコンポーネントが破棄されるときに発生します。

(継承元 Component)

適用対象