Bagikan melalui


TransactedInstaller Kelas

Definisi

Mendefinisikan alat penginstal yang berhasil sepenuhnya atau gagal dan meninggalkan komputer dalam keadaan awal.

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
Warisan

Contoh

Contoh berikut menunjukkan TransactedInstallermetode , Install dan Uninstall kelas TransactedInstaller .

Contoh ini menyediakan implementasi yang mirip dengan Installutil.exe (Alat Penginstal). Ini menginstal rakitan dengan opsi sebelum perakitan tertentu. Jika opsi tidak ditentukan untuk assembly, opsi assembly sebelumnya digunakan jika ada assembly sebelumnya dalam daftar. Jika opsi "/u" atau "/uninstall" ditentukan, rakitan akan dihapus. Jika opsi "/?" atau "/help" disediakan, informasi bantuan ditampilkan ke konsol.

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

Keterangan

Untuk menjalankan alat penginstal dalam transaksi, tambahkan ke Installers properti instans ini TransactedInstaller .

Konstruktor

TransactedInstaller()

Menginisialisasi instans baru kelas TransactedInstaller.

Properti

CanRaiseEvents

Mendapatkan nilai yang menunjukkan apakah komponen dapat menaikkan peristiwa.

(Diperoleh dari Component)
Container

IContainer Mendapatkan yang berisi Component.

(Diperoleh dari Component)
Context

Mendapatkan atau mengatur informasi tentang penginstalan saat ini.

(Diperoleh dari Installer)
DesignMode

Mendapatkan nilai yang menunjukkan apakah Component saat ini dalam mode desain.

(Diperoleh dari Component)
Events

Mendapatkan daftar penanganan aktivitas yang dilampirkan ke ini Component.

(Diperoleh dari Component)
HelpText

Mendapatkan teks bantuan untuk semua penginstal dalam koleksi alat penginstal.

(Diperoleh dari Installer)
Installers

Mendapatkan kumpulan alat penginstal yang dikandung alat penginstal ini.

(Diperoleh dari Installer)
Parent

Mendapatkan atau mengatur alat penginstal yang berisi koleksi tempat alat penginstal ini berada.

(Diperoleh dari Installer)
Site

Mendapatkan atau mengatur ISite dari Component.

(Diperoleh dari Component)

Metode

Commit(IDictionary)

Ketika ditimpa di kelas turunan, menyelesaikan transaksi penginstalan.

(Diperoleh dari Installer)
CreateObjRef(Type)

Membuat objek yang berisi semua informasi relevan yang diperlukan untuk menghasilkan proksi yang digunakan untuk berkomunikasi dengan objek jarak jauh.

(Diperoleh dari MarshalByRefObject)
Dispose()

Merilis semua sumber daya yang Componentdigunakan oleh .

(Diperoleh dari Component)
Dispose(Boolean)

Merilis sumber daya tidak terkelola yang digunakan oleh Component dan secara opsional merilis sumber daya terkelola.

(Diperoleh dari Component)
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetLifetimeService()
Kedaluwarsa.

Mengambil objek layanan seumur hidup saat ini yang mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
GetService(Type)

Mengembalikan objek yang mewakili layanan yang disediakan oleh Component atau oleh Container.

(Diperoleh dari Component)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
InitializeLifetimeService()
Kedaluwarsa.

Mendapatkan objek layanan seumur hidup untuk mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
Install(IDictionary)

Melakukan penginstalan.

MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
MemberwiseClone(Boolean)

Membuat salinan dangkal objek saat ini MarshalByRefObject .

(Diperoleh dari MarshalByRefObject)
OnAfterInstall(IDictionary)

Memunculkan kejadian AfterInstall.

(Diperoleh dari Installer)
OnAfterRollback(IDictionary)

Memunculkan kejadian AfterRollback.

(Diperoleh dari Installer)
OnAfterUninstall(IDictionary)

Memunculkan kejadian AfterUninstall.

(Diperoleh dari Installer)
OnBeforeInstall(IDictionary)

Memunculkan kejadian BeforeInstall.

(Diperoleh dari Installer)
OnBeforeRollback(IDictionary)

Memunculkan kejadian BeforeRollback.

(Diperoleh dari Installer)
OnBeforeUninstall(IDictionary)

Memunculkan kejadian BeforeUninstall.

(Diperoleh dari Installer)
OnCommitted(IDictionary)

Memunculkan kejadian Committed.

(Diperoleh dari Installer)
OnCommitting(IDictionary)

Memunculkan kejadian Committing.

(Diperoleh dari Installer)
Rollback(IDictionary)

Ketika ditimpa di kelas turunan, memulihkan status pra-instalasi komputer.

(Diperoleh dari Installer)
ToString()

Mengembalikan yang String berisi nama Component, jika ada. Metode ini tidak boleh ditimpa.

(Diperoleh dari Component)
Uninstall(IDictionary)

Menghapus penginstalan.

Acara

AfterInstall

Terjadi setelah Install(IDictionary) metode semua penginstal di Installers properti telah berjalan.

(Diperoleh dari Installer)
AfterRollback

Terjadi setelah penginstalan semua penginstal di Installers properti digulung balik.

(Diperoleh dari Installer)
AfterUninstall

Terjadi setelah semua penginstal di Installers properti melakukan operasi penghapusan instalasi mereka.

(Diperoleh dari Installer)
BeforeInstall

Terjadi sebelum Install(IDictionary) metode setiap alat penginstal dalam koleksi alat penginstal telah berjalan.

(Diperoleh dari Installer)
BeforeRollback

Terjadi sebelum alat penginstal di Installers properti digulung balik.

(Diperoleh dari Installer)
BeforeUninstall

Terjadi sebelum alat penginstal di Installers properti melakukan operasi penghapusan instalasinya.

(Diperoleh dari Installer)
Committed

Terjadi setelah semua penginstal di Installers properti telah melakukan penginstalan mereka.

(Diperoleh dari Installer)
Committing

Terjadi sebelum penginstal di Installers properti melakukan penginstalan mereka.

(Diperoleh dari Installer)
Disposed

Terjadi ketika komponen dibuang oleh panggilan ke Dispose() metode .

(Diperoleh dari Component)

Berlaku untuk