public override void Install(IDictionary savedState) { if (base.Context == null) { base.Context = new InstallContext(); } base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoTransacted")); try { bool flag = true; try { base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoBeginInstall")); base.Install(savedState); } catch (Exception ex) { flag = false; base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoException")); Installer.LogException(ex, base.Context); base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoBeginRollback")); try { this.Rollback(savedState); } catch (Exception) { } base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoRollbackDone")); throw new InvalidOperationException(Res.GetString("InstallRollback"), ex); } if (flag) { base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoBeginCommit")); try { this.Commit(savedState); } finally { base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoCommitDone")); } } } finally { base.Context.LogMessage(Environment.NewLine + Res.GetString("InstallInfoTransactedDone")); } }
// A transacted install will either completely succeed or fail and leave the // machine in its initial state. The Install method is called on each of the // installers. If they all succeed, then the Commit method is called on each // of them. If any of the Install methods fails, then that installer's Rollback // method is called, as are the Rollback methods on all the installers whose // Install methods ran before the failure. /// <include file='doc\TransactedInstaller.uex' path='docs/doc[@for="TransactedInstaller.Install"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override void Install(IDictionary savedState) { if (Context == null) { Context = new InstallContext(); } Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoTransacted)); try { bool success = true; try { Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoBeginInstall)); base.Install(savedState); } catch (Exception e) { success = false; Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoException)); Installer.LogException(e, Context); Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoBeginRollback)); try { Rollback(savedState); } catch (Exception) { } Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoRollbackDone)); // make sure the failure goes all the way to the top. throw new InvalidOperationException(Res.GetString(Res.InstallRollback), e); } if (success) { Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoBeginCommit)); try { Commit(savedState); } finally { Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoCommitDone)); } } } finally { Context.LogMessage(Environment.NewLine + Res.GetString(Res.InstallInfoTransactedDone)); } }
/// <include file='doc\AssemblyInstaller.uex' path='docs/doc[@for="AssemblyInstaller.InitializeFromAssembly"]/*' /> /// <devdoc> /// this is common code that's called from Install, Commit, Rollback, and Uninstall. It /// loads the assembly, finds all Installer types in it, and adds them to the Installers /// collection. It also prints some useful information to the Context log. /// </devdoc> private void InitializeFromAssembly() { // Get the set of installers to use out of the assembly. This will load the assembly // so that its types are accessible later. An assembly cannot be unloaded. Type[] installerTypes = null; try { installerTypes = GetInstallerTypes(assembly); } catch (Exception e) { Context.LogMessage(Res.GetString(Res.InstallException, Path)); Installer.LogException(e, Context); Context.LogMessage(Res.GetString(Res.InstallAbort, Path)); throw new InvalidOperationException(Res.GetString(Res.InstallNoInstallerTypes, Path), e); } if (installerTypes == null || installerTypes.Length == 0) { Context.LogMessage(Res.GetString(Res.InstallNoPublicInstallers, Path)); // this is not an error, so don't throw. Just don't do anything. return; } // create instances of each of those, and add them to the Installers collection. for (int i = 0; i < installerTypes.Length; i++) { try { Installer installer = (Installer)Activator.CreateInstance(installerTypes[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, new object[0], null); Installers.Add(installer); } catch (Exception e) { Context.LogMessage(Res.GetString(Res.InstallCannotCreateInstance, installerTypes[i].FullName)); Installer.LogException(e, Context); throw new InvalidOperationException(Res.GetString(Res.InstallCannotCreateInstance, installerTypes[i].FullName), e); } } initialized = true; }
private void InitializeFromAssembly() { Type[] installerTypes = null; try { installerTypes = GetInstallerTypes(this.assembly); } catch (Exception exception) { base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallException", new object[] { this.Path })); Installer.LogException(exception, base.Context); base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallAbort", new object[] { this.Path })); throw new InvalidOperationException(System.Configuration.Install.Res.GetString("InstallNoInstallerTypes", new object[] { this.Path }), exception); } if ((installerTypes == null) || (installerTypes.Length == 0)) { base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallNoPublicInstallers", new object[] { this.Path })); } else { for (int i = 0; i < installerTypes.Length; i++) { try { Installer installer = (Installer)Activator.CreateInstance(installerTypes[i], BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, new object[0], null); base.Installers.Add(installer); } catch (Exception exception2) { base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallCannotCreateInstance", new object[] { installerTypes[i].FullName })); Installer.LogException(exception2, base.Context); throw new InvalidOperationException(System.Configuration.Install.Res.GetString("InstallCannotCreateInstance", new object[] { installerTypes[i].FullName }), exception2); } } this.initialized = true; } }
private void InitializeFromAssembly() { Type[] installerTypes; try { installerTypes = AssemblyInstaller.GetInstallerTypes(Assembly); } catch (Exception ex) { Context.LogMessage(Res.GetString("InstallException", (object)Path)); Installer.LogException(ex, Context); Context.LogMessage(Res.GetString("InstallAbort", (object)Path)); throw new InvalidOperationException(Res.GetString("InstallNoInstallerTypes", (object)Path), ex); } if (installerTypes == null || installerTypes.Length == 0) { Context.LogMessage(Res.GetString("InstallNoPublicInstallers", (object)Path)); } else { for (var index = 0; index < installerTypes.Length; ++index) { try { Installers.Add((Installer)Activator.CreateInstance(installerTypes[index], BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, new object[0], null)); } catch (Exception ex) { Context.LogMessage(Res.GetString("InstallCannotCreateInstance", (object)installerTypes[index].FullName)); Installer.LogException(ex, Context); throw new InvalidOperationException(Res.GetString("InstallCannotCreateInstance", (object)installerTypes[index].FullName), ex); } } _initialized = true; } }
private void WriteEventHandlerError(string severity, string eventName, Exception e) { this.Context.LogMessage(Res.GetString("InstallLogError", (object)severity, (object)eventName, (object)this.GetType().FullName)); Installer.LogException(e, this.Context); }
public virtual void Uninstall(IDictionary savedState) { Exception exception1 = (Exception)null; try { this.OnBeforeUninstall(savedState); } catch (Exception ex) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeUninstall", ex); this.Context.LogMessage(Res.GetString("InstallUninstallException")); exception1 = ex; } IDictionary[] dictionaryArray; if (savedState != null) { dictionaryArray = (IDictionary[])savedState[(object)"_reserved_nestedSavedStates"]; if (dictionaryArray == null || dictionaryArray.Length != this.Installers.Count) { throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[1] { (object)"savedState" })); } } else { dictionaryArray = new IDictionary[this.Installers.Count]; } for (int index = this.Installers.Count - 1; index >= 0; --index) { this.Installers[index].Context = this.Context; } for (int index = this.Installers.Count - 1; index >= 0; --index) { try { this.Installers[index].Uninstall(dictionaryArray[index]); } catch (Exception ex) { if (!this.IsWrappedException(ex)) { this.Context.LogMessage(Res.GetString("InstallLogUninstallException", new object[1] { (object)this.Installers[index].ToString() })); Installer.LogException(ex, this.Context); this.Context.LogMessage(Res.GetString("InstallUninstallException")); } exception1 = ex; } } try { this.OnAfterUninstall(savedState); } catch (Exception ex) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterUninstall", ex); this.Context.LogMessage(Res.GetString("InstallUninstallException")); exception1 = ex; } if (exception1 == null) { return; } Exception exception2 = exception1; if (!this.IsWrappedException(exception1)) { exception2 = (Exception) new InstallException(Res.GetString("InstallUninstallException"), exception1); exception2.Source = "WrappedExceptionSource"; } throw exception2; }
public virtual void Rollback(IDictionary savedState) { if (savedState == null) { throw new ArgumentException(Res.GetString("InstallNullParameter", new object[1] { (object)"savedState" })); } else if (savedState[(object)"_reserved_lastInstallerAttempted"] == null || savedState[(object)"_reserved_nestedSavedStates"] == null) { throw new ArgumentException(Res.GetString("InstallDictionaryMissingValues", new object[1] { (object)"savedState" })); } else { Exception exception1 = (Exception)null; try { this.OnBeforeRollback(savedState); } catch (Exception ex) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeRollback", ex); this.Context.LogMessage(Res.GetString("InstallRollbackException")); exception1 = ex; } int num = (int)savedState[(object)"_reserved_lastInstallerAttempted"]; IDictionary[] dictionaryArray = (IDictionary[])savedState[(object)"_reserved_nestedSavedStates"]; if (num + 1 != dictionaryArray.Length || num >= this.Installers.Count) { throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[1] { (object)"savedState" })); } else { for (int index = this.Installers.Count - 1; index >= 0; --index) { this.Installers[index].Context = this.Context; } for (int index = num; index >= 0; --index) { try { this.Installers[index].Rollback(dictionaryArray[index]); } catch (Exception ex) { if (!this.IsWrappedException(ex)) { this.Context.LogMessage(Res.GetString("InstallLogRollbackException", new object[1] { (object)this.Installers[index].ToString() })); Installer.LogException(ex, this.Context); this.Context.LogMessage(Res.GetString("InstallRollbackException")); } exception1 = ex; } } try { this.OnAfterRollback(savedState); } catch (Exception ex) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterRollback", ex); this.Context.LogMessage(Res.GetString("InstallRollbackException")); exception1 = ex; } if (exception1 == null) { return; } Exception exception2 = exception1; if (!this.IsWrappedException(exception1)) { exception2 = (Exception) new InstallException(Res.GetString("InstallRollbackException"), exception1); exception2.Source = "WrappedExceptionSource"; } throw exception2; } } }
public virtual void Commit(IDictionary savedState) { if (savedState == null) { throw new ArgumentException(Res.GetString("InstallNullParameter", "savedState")); } if (savedState["_reserved_lastInstallerAttempted"] != null && savedState["_reserved_nestedSavedStates"] != null) { Exception ex = null; try { this.OnCommitting(savedState); } catch (Exception ex2) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitting", ex2); this.Context.LogMessage(Res.GetString("InstallCommitException")); ex = ex2; } int num = (int)savedState["_reserved_lastInstallerAttempted"]; IDictionary[] array = (IDictionary[])savedState["_reserved_nestedSavedStates"]; if (num + 1 == array.Length && num < this.Installers.Count) { for (int i = 0; i < this.Installers.Count; i++) { this.Installers[i].Context = this.Context; } for (int j = 0; j <= num; j++) { try { this.Installers[j].Commit(array[j]); } catch (Exception ex3) { if (!this.IsWrappedException(ex3)) { this.Context.LogMessage(Res.GetString("InstallLogCommitException", this.Installers[j].ToString())); Installer.LogException(ex3, this.Context); this.Context.LogMessage(Res.GetString("InstallCommitException")); } ex = ex3; } } savedState["_reserved_nestedSavedStates"] = array; savedState.Remove("_reserved_lastInstallerAttempted"); try { this.OnCommitted(savedState); } catch (Exception ex4) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitted", ex4); this.Context.LogMessage(Res.GetString("InstallCommitException")); ex = ex4; } if (ex == null) { return; } Exception ex5 = ex; if (!this.IsWrappedException(ex)) { ex5 = new InstallException(Res.GetString("InstallCommitException"), ex); ex5.Source = "WrappedExceptionSource"; } throw ex5; } throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", "savedState")); } throw new ArgumentException(Res.GetString("InstallDictionaryMissingValues", "savedState")); }
public virtual void Uninstall(IDictionary savedState) { Exception ex = null; try { this.OnBeforeUninstall(savedState); } catch (Exception ex2) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeUninstall", ex2); this.Context.LogMessage(Res.GetString("InstallUninstallException")); ex = ex2; } IDictionary[] array; if (savedState != null) { array = (IDictionary[])savedState["_reserved_nestedSavedStates"]; if (array != null && array.Length == this.Installers.Count) { goto IL_0091; } throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", "savedState")); } array = new IDictionary[this.Installers.Count]; goto IL_0091; IL_0091: for (int num = this.Installers.Count - 1; num >= 0; num--) { this.Installers[num].Context = this.Context; } for (int num2 = this.Installers.Count - 1; num2 >= 0; num2--) { try { this.Installers[num2].Uninstall(array[num2]); } catch (Exception ex3) { if (!this.IsWrappedException(ex3)) { this.Context.LogMessage(Res.GetString("InstallLogUninstallException", this.Installers[num2].ToString())); Installer.LogException(ex3, this.Context); this.Context.LogMessage(Res.GetString("InstallUninstallException")); } ex = ex3; } } try { this.OnAfterUninstall(savedState); } catch (Exception ex4) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterUninstall", ex4); this.Context.LogMessage(Res.GetString("InstallUninstallException")); ex = ex4; } if (ex == null) { return; } Exception ex5 = ex; if (!this.IsWrappedException(ex)) { ex5 = new InstallException(Res.GetString("InstallUninstallException"), ex); ex5.Source = "WrappedExceptionSource"; } throw ex5; }
public virtual void Rollback(IDictionary savedState) { if (savedState == null) { throw new ArgumentException(Res.GetString("InstallNullParameter", "savedState")); } if (savedState["_reserved_lastInstallerAttempted"] != null && savedState["_reserved_nestedSavedStates"] != null) { Exception ex = null; try { this.OnBeforeRollback(savedState); } catch (Exception ex2) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeRollback", ex2); this.Context.LogMessage(Res.GetString("InstallRollbackException")); ex = ex2; } int num = (int)savedState["_reserved_lastInstallerAttempted"]; IDictionary[] array = (IDictionary[])savedState["_reserved_nestedSavedStates"]; if (num + 1 == array.Length && num < this.Installers.Count) { for (int num2 = this.Installers.Count - 1; num2 >= 0; num2--) { this.Installers[num2].Context = this.Context; } for (int num3 = num; num3 >= 0; num3--) { try { this.Installers[num3].Rollback(array[num3]); } catch (Exception ex3) { if (!this.IsWrappedException(ex3)) { this.Context.LogMessage(Res.GetString("InstallLogRollbackException", this.Installers[num3].ToString())); Installer.LogException(ex3, this.Context); this.Context.LogMessage(Res.GetString("InstallRollbackException")); } ex = ex3; } } try { this.OnAfterRollback(savedState); } catch (Exception ex4) { this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterRollback", ex4); this.Context.LogMessage(Res.GetString("InstallRollbackException")); ex = ex4; } if (ex == null) { return; } Exception ex5 = ex; if (!this.IsWrappedException(ex)) { ex5 = new InstallException(Res.GetString("InstallRollbackException"), ex); ex5.Source = "WrappedExceptionSource"; } throw ex5; } throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", "savedState")); } throw new ArgumentException(Res.GetString("InstallDictionaryMissingValues", "savedState")); }
private void WriteEventHandlerError(string severity, string eventName, Exception e) { Context.LogMessage(Res.GetString("InstallLogError", severity, eventName, GetType().FullName)); Installer.LogException(e, Context); }