TransactedInstaller Classe

Definizione

Definisce un programma di installazione che ha esito positivo o negativo, lasciando il computer, in quest'ultimo caso, nello stato iniziale.

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
Ereditarietà

Esempio

Nell'esempio seguente vengono illustrati i TransactedInstallermetodi e InstallUninstall della TransactedInstaller classe .

In questo esempio viene fornita un'implementazione simile a quella di Installutil.exe (strumento di installazione). Installa gli assembly con le opzioni precedenti a quel particolare assembly. Se non viene specificata un'opzione per un assembly, le opzioni dell'assembly precedente vengono utilizzate se è presente un assembly precedente nell'elenco. Se viene specificata l'opzione "/u" o "/uninstall", gli assembly vengono disinstallati. Se viene fornita l'opzione "/?" o "/help", le informazioni della Guida vengono visualizzate nella 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 );
}
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

Commenti

Per eseguire i programmi di installazione in una transazione, aggiungerli alla Installers proprietà di questa TransactedInstaller istanza.

Costruttori

TransactedInstaller()

Inizializza una nuova istanza della classe TransactedInstaller.

Proprietà

CanRaiseEvents

Ottiene un valore che indica se il componente può generare un evento.

(Ereditato da Component)
Container

Ottiene l'oggetto IContainer che contiene Component.

(Ereditato da Component)
Context

Ottiene o imposta le informazioni sull'installazione corrente.

(Ereditato da Installer)
DesignMode

Ottiene un valore che indica se il Component si trova in modalità progettazione.

(Ereditato da Component)
Events

Ottiene l'elenco dei gestori eventi allegati a questo Component.

(Ereditato da Component)
HelpText

Ottiene il testo della Guida per tutti i programmi di installazione della raccolta Installer.

(Ereditato da Installer)
Installers

Ottiene la raccolta dei programmi di installazione contenuti nel programma.

(Ereditato da Installer)
Parent

Ottiene o imposta il programma di installazione contenente la raccolta cui appartiene questo programma di installazione.

(Ereditato da Installer)
Site

Ottiene o imposta l'oggetto ISite di Component.

(Ereditato da Component)

Metodi

Commit(IDictionary)

Quando ne viene eseguito l'override in una classe derivata, completa la transazione di installazione.

(Ereditato da Installer)
CreateObjRef(Type)

Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto remoto.

(Ereditato da MarshalByRefObject)
Dispose()

Rilascia tutte le risorse usate da Component.

(Ereditato da Component)
Dispose(Boolean)

Rilascia le risorse non gestite usate da Component e, facoltativamente, le risorse gestite.

(Ereditato da Component)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetLifetimeService()
Obsoleti.

Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza.

(Ereditato da MarshalByRefObject)
GetService(Type)

Consente di restituire un oggetto che rappresenta un servizio fornito da Component o dal relativo Container.

(Ereditato da Component)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
InitializeLifetimeService()
Obsoleti.

Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza.

(Ereditato da MarshalByRefObject)
Install(IDictionary)

Esegue l'installazione.

MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
MemberwiseClone(Boolean)

Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente.

(Ereditato da MarshalByRefObject)
OnAfterInstall(IDictionary)

Genera l'evento AfterInstall.

(Ereditato da Installer)
OnAfterRollback(IDictionary)

Genera l'evento AfterRollback.

(Ereditato da Installer)
OnAfterUninstall(IDictionary)

Genera l'evento AfterUninstall.

(Ereditato da Installer)
OnBeforeInstall(IDictionary)

Genera l'evento BeforeInstall.

(Ereditato da Installer)
OnBeforeRollback(IDictionary)

Genera l'evento BeforeRollback.

(Ereditato da Installer)
OnBeforeUninstall(IDictionary)

Genera l'evento BeforeUninstall.

(Ereditato da Installer)
OnCommitted(IDictionary)

Genera l'evento Committed.

(Ereditato da Installer)
OnCommitting(IDictionary)

Genera l'evento Committing.

(Ereditato da Installer)
Rollback(IDictionary)

Quando ne viene eseguito l'override in una classe derivata, ripristina lo stato del computer prima dell'installazione.

(Ereditato da Installer)
ToString()

Restituisce un oggetto String che contiene il nome dell'eventuale oggetto Component. Questo metodo non deve essere sottoposto a override.

(Ereditato da Component)
Uninstall(IDictionary)

Rimuove un'installazione.

Eventi

AfterInstall

Si verifica dopo l'esecuzione dei metodi Install(IDictionary) di tutti i programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
AfterRollback

Si verifica dopo il rollback delle installazioni di tutti i programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
AfterUninstall

Si verifica dopo l'esecuzione delle operazioni di disinstallazione di tutti i programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
BeforeInstall

Si verifica dopo l'esecuzione del metodo Install(IDictionary) di ogni programma di installazione contenuto nella raccolta Installer.

(Ereditato da Installer)
BeforeRollback

Si verifica prima del rollback dei programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
BeforeUninstall

Si verifica prima dell'esecuzione delle operazioni di disinstallazione dei programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
Committed

Si verifica dopo l'esecuzione del commit delle installazioni di tutti i programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
Committing

Si verifica prima dell'esecuzione del commit delle installazioni dei programmi di installazione contenuti nella proprietà Installers.

(Ereditato da Installer)
Disposed

Si verifica quando il componente viene eliminato da una chiamata al metodo Dispose().

(Ereditato da Component)

Si applica a