Condividi tramite


TransactedInstaller Classe

Definizione

Definisce un programma di installazione che ha esito positivo o negativo e lascia il computer 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 , Install e Uninstall della TransactedInstaller classe .

Questo esempio fornisce un'implementazione simile a quella di Installutil.exe (strumento di installazione). Vengono installati 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

Nome Descrizione
TransactedInstaller()

Inizializza una nuova istanza della classe TransactedInstaller.

Proprietà

Nome Descrizione
CanRaiseEvents

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

(Ereditato da Component)
Container

Ottiene l'oggetto IContainer contenente l'oggetto Component.

(Ereditato da Component)
Context

Ottiene o imposta informazioni sull'installazione corrente.

(Ereditato da Installer)
DesignMode

Ottiene un valore che indica se è Component attualmente in modalità progettazione.

(Ereditato da Component)
Events

Ottiene l'elenco dei gestori eventi associati a questo Componentoggetto .

(Ereditato da Component)
HelpText

Ottiene il testo della Guida per tutti i programmi di installazione nella raccolta del programma di installazione.

(Ereditato da Installer)
Installers

Ottiene la raccolta di programmi di installazione contenuti nel programma di installazione.

(Ereditato da Installer)
Parent

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

(Ereditato da Installer)
Site

Ottiene o imposta l'oggetto ISite dell'oggetto Component.

(Ereditato da Component)

Metodi

Nome Descrizione
Commit(IDictionary)

Quando sottoposto a override in una classe derivata, completa la transazione di installazione.

(Ereditato da Installer)
CreateObjRef(Type)

Crea un oggetto che contiene tutte le informazioni pertinenti necessarie per generare un proxy utilizzato per comunicare 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, rilascia 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.

Recupera l'oggetto servizio di durata corrente che controlla i criteri di durata per questa istanza.

(Ereditato da MarshalByRefObject)
GetService(Type)

Restituisce un oggetto che rappresenta un servizio fornito da Component o da Container.

(Ereditato da Component)
GetType()

Ottiene il 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 del Objectcorrente.

(Ereditato da Object)
MemberwiseClone(Boolean)

Crea una copia superficiale dell'oggetto corrente MarshalByRefObject .

(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 sottoposto a override in una classe derivata, ripristina lo stato di preinstallazione del computer.

(Ereditato da Installer)
ToString()

Restituisce un oggetto String contenente il nome dell'oggetto Component, se presente. Questo metodo non deve essere sottoposto a override.

(Ereditato da Component)
Uninstall(IDictionary)

Rimuove un'installazione.

Eventi

Nome Descrizione
AfterInstall

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

(Ereditato da Installer)
AfterRollback

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

(Ereditato da Installer)
AfterUninstall

Si verifica dopo che tutti i programmi di installazione nella Installers proprietà eseguono le operazioni di disinstallazione.

(Ereditato da Installer)
BeforeInstall

Si verifica prima dell'esecuzione Install(IDictionary) del metodo di ogni programma di installazione nella raccolta del programma di installazione.

(Ereditato da Installer)
BeforeRollback

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

(Ereditato da Installer)
BeforeUninstall

Si verifica prima che i programmi di installazione nella Installers proprietà eseguano le operazioni di disinstallazione.

(Ereditato da Installer)
Committed

Si verifica dopo che tutti i programmi di installazione nella proprietà hanno eseguito il Installers commit delle installazioni.

(Ereditato da Installer)
Committing

Si verifica prima che i programmi di installazione nella proprietà eseseguono il commit delle Installers installazioni.

(Ereditato da Installer)
Disposed

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

(Ereditato da Component)

Si applica a