コード例 #1
0
        public override void Install(IDictionary stateSaver)
        {
            if (_installers != null)
            {
                Installers.AddRange(_installers);
            }

            var serviceName = BuildServiceName(_settings);

            _logWriter.InfoFormat(Properties.Resources.InstallingServiceIsStarted, serviceName);

            try
            {
                base.Install(stateSaver);

                _installTransaction.Execute(_settings);

                _logWriter.InfoFormat(Properties.Resources.InstallingServiceIsSuccessfullyCompleted, serviceName);
            }
            catch (Exception error)
            {
                error = new InstallException(string.Format(Properties.Resources.InstallingServiceFailed, serviceName), error);
                _logWriter.ErrorFormat(Properties.Resources.InstallingServiceIsCompletedWithErrors, serviceName, error);
                throw error;
            }
        }
コード例 #2
0
        /// <include file='doc\Installer.uex' path='docs/doc[@for="Installer.Commit"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Completes the install transaction.
        ///    </para>
        /// </devdoc>
        public virtual void Commit(IDictionary savedState)
        {
            // check arguments
            if (savedState == null)
            {
                throw new ArgumentException(Res.GetString(Res.InstallNullParameter, "savedState"));
            }
            if (savedState["_reserved_lastInstallerAttempted"] == null || savedState["_reserved_nestedSavedStates"] == null)
            {
                throw new ArgumentException(Res.GetString(Res.InstallDictionaryMissingValues, "savedState"));
            }

            Exception savedException = null;

            // raise the OnCommitting event
            try {
                OnCommitting(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnCommitting", e);
                Context.LogMessage(Res.GetString(Res.InstallCommitException));
                savedException = e;
            }

            // do the commit

            int lastInstallerAttempted = (int)savedState["_reserved_lastInstallerAttempted"];

            IDictionary[] nestedSavedStates = (IDictionary[])savedState["_reserved_nestedSavedStates"];
            // do more validation
            if (lastInstallerAttempted + 1 != nestedSavedStates.Length || lastInstallerAttempted >= Installers.Count)
            {
                throw new ArgumentException(Res.GetString(Res.InstallDictionaryCorrupted, "savedState"));
            }
            for (int i = 0; i < Installers.Count; i++)
            {
                // set all the contexts first.  see note in Install
                Installers[i].Context = Context;
            }
            for (int i = 0; i <= lastInstallerAttempted; i++)
            {
                try {
                    Installers[i].Commit(nestedSavedStates[i]);
                }
                catch (Exception e) {
                    if (!IsWrappedException(e))
                    {
                        // only print the message if this is not a wrapper around an exception we already printed out.
                        Context.LogMessage(Res.GetString(Res.InstallLogCommitException, Installers[i].ToString()));
                        LogException(e, Context);
                        Context.LogMessage(Res.GetString(Res.InstallCommitException));
                    }
                    savedException = e;
                }
            }
            // make sure if the nested installers changed thier state, that gets saved out.
            savedState["_reserved_nestedSavedStates"] = nestedSavedStates;
            // no point in keeping this around, since we know they all succeeded.
            savedState.Remove("_reserved_lastInstallerAttempted");

            // raise the OnCommitted event
            try {
                OnCommitted(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnCommitted", e);
                Context.LogMessage(Res.GetString(Res.InstallCommitException));
                savedException = e;
            }

            if (savedException != null)
            {
                Exception wrappedException = savedException;
                if (!IsWrappedException(savedException))
                {
                    wrappedException        = new InstallException(Res.GetString(Res.InstallCommitException), savedException);
                    wrappedException.Source = wrappedExceptionSource;
                }
                throw wrappedException;
            }
        }
コード例 #3
0
 public virtual void Uninstall(IDictionary savedState)
 {
     Exception e = null;
     IDictionary[] dictionaryArray;
     try
     {
         this.OnBeforeUninstall(savedState);
     }
     catch (Exception exception2)
     {
         this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeUninstall", exception2);
         this.Context.LogMessage(Res.GetString("InstallUninstallException"));
         e = exception2;
     }
     if (savedState != null)
     {
         dictionaryArray = (IDictionary[]) savedState["_reserved_nestedSavedStates"];
         if ((dictionaryArray == null) || (dictionaryArray.Length != this.Installers.Count))
         {
             throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[] { "savedState" }));
         }
     }
     else
     {
         dictionaryArray = new IDictionary[this.Installers.Count];
     }
     for (int i = this.Installers.Count - 1; i >= 0; i--)
     {
         this.Installers[i].Context = this.Context;
     }
     for (int j = this.Installers.Count - 1; j >= 0; j--)
     {
         try
         {
             this.Installers[j].Uninstall(dictionaryArray[j]);
         }
         catch (Exception exception3)
         {
             if (!this.IsWrappedException(exception3))
             {
                 this.Context.LogMessage(Res.GetString("InstallLogUninstallException", new object[] { this.Installers[j].ToString() }));
                 LogException(exception3, this.Context);
                 this.Context.LogMessage(Res.GetString("InstallUninstallException"));
             }
             e = exception3;
         }
     }
     try
     {
         this.OnAfterUninstall(savedState);
     }
     catch (Exception exception4)
     {
         this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterUninstall", exception4);
         this.Context.LogMessage(Res.GetString("InstallUninstallException"));
         e = exception4;
     }
     if (e != null)
     {
         Exception exception5 = e;
         if (!this.IsWrappedException(e))
         {
             exception5 = new InstallException(Res.GetString("InstallUninstallException"), e) {
                 Source = "WrappedExceptionSource"
             };
         }
         throw exception5;
     }
 }
コード例 #4
0
 public virtual void Commit(IDictionary savedState)
 {
     if (savedState == null)
     {
         throw new ArgumentException(Res.GetString("InstallNullParameter", new object[] { "savedState" }));
     }
     if ((savedState["_reserved_lastInstallerAttempted"] == null) || (savedState["_reserved_nestedSavedStates"] == null))
     {
         throw new ArgumentException(Res.GetString("InstallDictionaryMissingValues", new object[] { "savedState" }));
     }
     Exception e = null;
     try
     {
         this.OnCommitting(savedState);
     }
     catch (Exception exception2)
     {
         this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitting", exception2);
         this.Context.LogMessage(Res.GetString("InstallCommitException"));
         e = exception2;
     }
     int num = (int) savedState["_reserved_lastInstallerAttempted"];
     IDictionary[] dictionaryArray = (IDictionary[]) savedState["_reserved_nestedSavedStates"];
     if (((num + 1) != dictionaryArray.Length) || (num >= this.Installers.Count))
     {
         throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[] { "savedState" }));
     }
     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(dictionaryArray[j]);
         }
         catch (Exception exception3)
         {
             if (!this.IsWrappedException(exception3))
             {
                 this.Context.LogMessage(Res.GetString("InstallLogCommitException", new object[] { this.Installers[j].ToString() }));
                 LogException(exception3, this.Context);
                 this.Context.LogMessage(Res.GetString("InstallCommitException"));
             }
             e = exception3;
         }
     }
     savedState["_reserved_nestedSavedStates"] = dictionaryArray;
     savedState.Remove("_reserved_lastInstallerAttempted");
     try
     {
         this.OnCommitted(savedState);
     }
     catch (Exception exception4)
     {
         this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitted", exception4);
         this.Context.LogMessage(Res.GetString("InstallCommitException"));
         e = exception4;
     }
     if (e != null)
     {
         Exception exception5 = e;
         if (!this.IsWrappedException(e))
         {
             exception5 = new InstallException(Res.GetString("InstallCommitException"), e) {
                 Source = "WrappedExceptionSource"
             };
         }
         throw exception5;
     }
 }
コード例 #5
0
    // Uninstall and return to a previously saved state.
    public virtual void Uninstall(IDictionary savedState)
			{
				Exception e = null;
				int index;
				IDictionary nestedState;

				// Validate the parameter.
				CheckNullState(savedState);

				// Raise the "BeforeUninstall" event.
				try
				{
					OnBeforeUninstall(savedState);
				}
				catch(SystemException e1)
				{
					LogException("OnBeforeUninstall", e1);
					e = e1;
				}

				// Copy the parent's context down to the children.
				for(index = Installers.Count - 1; index >= 0; --index)
				{
					Installers[index].Context = Context;
				}

				// Uninstall each of the installers in turn, in reverse order.
				for(index = Installers.Count - 1; index >= 0; --index)
				{
					nestedState = GetNestedState(savedState, index);
					try
					{
						Installers[index].Uninstall(nestedState);
					}
					catch(SystemException e2)
					{
						if(e2.InnerException == null)
						{
							LogException("Uninstall", e2);
						}
						e = e2;
					}
				}

				// Raise the "AfterUninstall" event.
				try
				{
					OnAfterUninstall(savedState);
				}
				catch(SystemException e3)
				{
					LogException("OnAfterUninstall", e3);
					e = e3;
				}

				// Re-throw the last-occurring exception.
				if(e != null)
				{
					if(e.InnerException == null)
					{
						e = new InstallException(e.Message, e);
					}
					throw e;
				}
			}
コード例 #6
0
    // Perform the installation process, saving the previous
    // state in the "stateSaver" object.
    public virtual void Install(IDictionary stateSaver)
			{
				Exception e = null;
				int index;
				IDictionary nestedState;

				// Validate the parameter.
				if(stateSaver == null)
				{
					throw new ArgumentException
						(S._("Installer_InvalidSavedState"), "stateSaver");
				}

				// Raise the "BeforeInstall" event.
				try
				{
					OnBeforeInstall(stateSaver);
				}
				catch(SystemException e1)
				{
					LogException("OnBeforeInstall", e1);
					e = e1;
				}

				// Copy the parent's context down to the children.
				for(index = 0; index < Installers.Count; ++index)
				{
					Installers[index].Context = Context;
				}

				// Run each of the installers in turn.
				for(index = 0; index < Installers.Count; ++index)
				{
					nestedState = GetNestedState(stateSaver, index);
					try
					{
						Installers[index].Install(nestedState);
					}
					catch(SystemException e2)
					{
						if(e2.InnerException == null)
						{
							LogException("Install", e2);
						}
						e = e2;
					}
				}

				// Raise the "AfterInstall" event.
				try
				{
					OnAfterInstall(stateSaver);
				}
				catch(SystemException e3)
				{
					LogException("OnAfterInstall", e3);
					e = e3;
				}

				// Re-throw the last-occurring exception.
				if(e != null)
				{
					if(e.InnerException == null)
					{
						e = new InstallException(e.Message, e);
					}
					throw e;
				}
			}
コード例 #7
0
    // Commit the installation transaction.
    public virtual void Commit(IDictionary savedState)
			{
				Exception e = null;
				int index;
				IDictionary nestedState;

				// Validate the parameter.
				CheckNullState(savedState);

				// Raise the "Committing" event.
				try
				{
					OnCommitting(savedState);
				}
				catch(SystemException e1)
				{
					LogException("OnCommitting", e1);
					e = e1;
				}

				// Copy the parent's context down to the children.
				for(index = 0; index < Installers.Count; ++index)
				{
					Installers[index].Context = Context;
				}

				// Commit each of the installers in turn.
				for(index = 0; index < Installers.Count; ++index)
				{
					nestedState = GetNestedState(savedState, index);
					try
					{
						Installers[index].Commit(nestedState);
					}
					catch(SystemException e2)
					{
						if(e2.InnerException == null)
						{
							LogException("Commit", e2);
						}
						e = e2;
					}
				}

				// Raise the "Committed" event.
				try
				{
					OnCommitted(savedState);
				}
				catch(SystemException e3)
				{
					LogException("OnCommitted", e3);
					e = e3;
				}

				// Re-throw the last-occurring exception.
				if(e != null)
				{
					if(e.InnerException == null)
					{
						e = new InstallException(e.Message, e);
					}
					throw e;
				}
			}
コード例 #8
0
        public virtual void Uninstall(IDictionary savedState)
        {
            Exception e = null;

            IDictionary[] dictionaryArray;
            try
            {
                this.OnBeforeUninstall(savedState);
            }
            catch (Exception exception2)
            {
                this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnBeforeUninstall", exception2);
                this.Context.LogMessage(Res.GetString("InstallUninstallException"));
                e = exception2;
            }
            if (savedState != null)
            {
                dictionaryArray = (IDictionary[])savedState["_reserved_nestedSavedStates"];
                if ((dictionaryArray == null) || (dictionaryArray.Length != this.Installers.Count))
                {
                    throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[] { "savedState" }));
                }
            }
            else
            {
                dictionaryArray = new IDictionary[this.Installers.Count];
            }
            for (int i = this.Installers.Count - 1; i >= 0; i--)
            {
                this.Installers[i].Context = this.Context;
            }
            for (int j = this.Installers.Count - 1; j >= 0; j--)
            {
                try
                {
                    this.Installers[j].Uninstall(dictionaryArray[j]);
                }
                catch (Exception exception3)
                {
                    if (!this.IsWrappedException(exception3))
                    {
                        this.Context.LogMessage(Res.GetString("InstallLogUninstallException", new object[] { this.Installers[j].ToString() }));
                        LogException(exception3, this.Context);
                        this.Context.LogMessage(Res.GetString("InstallUninstallException"));
                    }
                    e = exception3;
                }
            }
            try
            {
                this.OnAfterUninstall(savedState);
            }
            catch (Exception exception4)
            {
                this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnAfterUninstall", exception4);
                this.Context.LogMessage(Res.GetString("InstallUninstallException"));
                e = exception4;
            }
            if (e != null)
            {
                Exception exception5 = e;
                if (!this.IsWrappedException(e))
                {
                    exception5 = new InstallException(Res.GetString("InstallUninstallException"), e)
                    {
                        Source = "WrappedExceptionSource"
                    };
                }
                throw exception5;
            }
        }
コード例 #9
0
        // Perform the installation process, saving the previous
        // state in the "stateSaver" object.
        public virtual void Install(IDictionary stateSaver)
        {
            Exception   e = null;
            int         index;
            IDictionary nestedState;

            // Validate the parameter.
            if (stateSaver == null)
            {
                throw new ArgumentException
                          (S._("Installer_InvalidSavedState"), "stateSaver");
            }

            // Raise the "BeforeInstall" event.
            try
            {
                OnBeforeInstall(stateSaver);
            }
            catch (SystemException e1)
            {
                LogException("OnBeforeInstall", e1);
                e = e1;
            }

            // Copy the parent's context down to the children.
            for (index = 0; index < Installers.Count; ++index)
            {
                Installers[index].Context = Context;
            }

            // Run each of the installers in turn.
            for (index = 0; index < Installers.Count; ++index)
            {
                nestedState = GetNestedState(stateSaver, index);
                try
                {
                    Installers[index].Install(nestedState);
                }
                catch (SystemException e2)
                {
                    if (e2.InnerException == null)
                    {
                        LogException("Install", e2);
                    }
                    e = e2;
                }
            }

            // Raise the "AfterInstall" event.
            try
            {
                OnAfterInstall(stateSaver);
            }
            catch (SystemException e3)
            {
                LogException("OnAfterInstall", e3);
                e = e3;
            }

            // Re-throw the last-occurring exception.
            if (e != null)
            {
                if (e.InnerException == null)
                {
                    e = new InstallException(e.Message, e);
                }
                throw e;
            }
        }
コード例 #10
0
        // Commit the installation transaction.
        public virtual void Commit(IDictionary savedState)
        {
            Exception   e = null;
            int         index;
            IDictionary nestedState;

            // Validate the parameter.
            CheckNullState(savedState);

            // Raise the "Committing" event.
            try
            {
                OnCommitting(savedState);
            }
            catch (SystemException e1)
            {
                LogException("OnCommitting", e1);
                e = e1;
            }

            // Copy the parent's context down to the children.
            for (index = 0; index < Installers.Count; ++index)
            {
                Installers[index].Context = Context;
            }

            // Commit each of the installers in turn.
            for (index = 0; index < Installers.Count; ++index)
            {
                nestedState = GetNestedState(savedState, index);
                try
                {
                    Installers[index].Commit(nestedState);
                }
                catch (SystemException e2)
                {
                    if (e2.InnerException == null)
                    {
                        LogException("Commit", e2);
                    }
                    e = e2;
                }
            }

            // Raise the "Committed" event.
            try
            {
                OnCommitted(savedState);
            }
            catch (SystemException e3)
            {
                LogException("OnCommitted", e3);
                e = e3;
            }

            // Re-throw the last-occurring exception.
            if (e != null)
            {
                if (e.InnerException == null)
                {
                    e = new InstallException(e.Message, e);
                }
                throw e;
            }
        }
コード例 #11
0
 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"));
 }
コード例 #12
0
        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;
        }
コード例 #13
0
 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"));
 }
コード例 #14
0
        public override void Uninstall(IDictionary savedState)
        {
            if (_installers != null)
            {
                Installers.AddRange(_installers);
            }

            var serviceName = BuildServiceName(_settings);

            _logWriter.InfoFormat(Properties.Resources.UninstallingServiceIsStarted, serviceName);

            var errors = new List<Exception>();

            try
            {
                _installTransaction.Rollback(_settings);
            }
            catch (Exception error)
            {
                errors.Add(error);
            }

            try
            {
                base.Uninstall(savedState);
            }
            catch (Exception error)
            {
                errors.Add(error);
            }

            if (errors.Count > 1)
            {
                Exception error = new AggregateException(string.Format(Properties.Resources.UninstallingServiceFailed, serviceName), errors);
                error = new InstallException(string.Format(Properties.Resources.UninstallingServiceFailed, serviceName), error);
                _logWriter.ErrorFormat(Properties.Resources.UninstallingServiceIsCompletedWithErrors, serviceName, error);
                throw error;
            }

            if (errors.Count == 1)
            {
                var error = new InstallException(string.Format(Properties.Resources.UninstallingServiceFailed, serviceName), errors[0]);
                _logWriter.ErrorFormat(Properties.Resources.UninstallingServiceIsCompletedWithErrors, serviceName, error);
                throw error;
            }

            _logWriter.InfoFormat(Properties.Resources.UninstallingServiceIsSuccessfullyCompleted, serviceName);
        }
コード例 #15
0
        /// <include file='doc\Installer.uex' path='docs/doc[@for="Installer.Rollback"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Restores the machine to the state it was in before
        ///       the <see cref='System.Configuration.Install.Installer.Install'/>
        ///       method was called.
        ///    </para>
        /// </devdoc>
        public virtual void Rollback(IDictionary savedState)
        {
            // check arguments
            if (savedState == null)
            {
                throw new ArgumentException(Res.GetString(Res.InstallNullParameter, "savedState"));
            }
            if (savedState["_reserved_lastInstallerAttempted"] == null || savedState["_reserved_nestedSavedStates"] == null)
            {
                throw new ArgumentException(Res.GetString(Res.InstallDictionaryMissingValues, "savedState"));
            }

            // raise the OnBeforeRollback event
            Exception savedException = null;

            try {
                OnBeforeRollback(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnBeforeRollback", e);
                Context.LogMessage(Res.GetString(Res.InstallRollbackException));
                savedException = e;
            }

            // do the rollback

            int lastInstallerAttempted = (int)savedState["_reserved_lastInstallerAttempted"];

            IDictionary[] nestedSavedStates = (IDictionary[])savedState["_reserved_nestedSavedStates"];
            // do more validation
            if (lastInstallerAttempted + 1 != nestedSavedStates.Length || lastInstallerAttempted >= Installers.Count)
            {
                throw new ArgumentException(Res.GetString(Res.InstallDictionaryCorrupted, "savedState"));
            }
            for (int i = Installers.Count - 1; i >= 0; i--)
            {
                // set all the contexts first.  see note in Install
                Installers[i].Context = Context;
            }
            for (int i = lastInstallerAttempted; i >= 0; i--)
            {
                try {
                    Installers[i].Rollback(nestedSavedStates[i]);
                }
                catch (Exception e) {
                    if (!IsWrappedException(e))
                    {
                        // only print the message if this is not a wrapper around an exception we already printed out.
                        Context.LogMessage(Res.GetString(Res.InstallLogRollbackException, Installers[i].ToString()));
                        LogException(e, Context);
                        Context.LogMessage(Res.GetString(Res.InstallRollbackException));
                    }
                    savedException = e;
                }
            }
            // no point in doing anything to the saved state, because it'll all be
            // thrown away at the top anyway.

            // raise the OnAfterRollback event
            try {
                OnAfterRollback(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnAfterRollback", e);
                Context.LogMessage(Res.GetString(Res.InstallRollbackException));
                savedException = e;
            }

            if (savedException != null)
            {
                Exception wrappedException = savedException;
                if (!IsWrappedException(savedException))
                {
                    wrappedException        = new InstallException(Res.GetString(Res.InstallRollbackException), savedException);
                    wrappedException.Source = wrappedExceptionSource;
                }
                throw wrappedException;
            }
        }
コード例 #16
0
        // Uninstall and return to a previously saved state.
        public virtual void Uninstall(IDictionary savedState)
        {
            Exception   e = null;
            int         index;
            IDictionary nestedState;

            // Validate the parameter.
            CheckNullState(savedState);

            // Raise the "BeforeUninstall" event.
            try
            {
                OnBeforeUninstall(savedState);
            }
            catch (SystemException e1)
            {
                LogException("OnBeforeUninstall", e1);
                e = e1;
            }

            // Copy the parent's context down to the children.
            for (index = Installers.Count - 1; index >= 0; --index)
            {
                Installers[index].Context = Context;
            }

            // Uninstall each of the installers in turn, in reverse order.
            for (index = Installers.Count - 1; index >= 0; --index)
            {
                nestedState = GetNestedState(savedState, index);
                try
                {
                    Installers[index].Uninstall(nestedState);
                }
                catch (SystemException e2)
                {
                    if (e2.InnerException == null)
                    {
                        LogException("Uninstall", e2);
                    }
                    e = e2;
                }
            }

            // Raise the "AfterUninstall" event.
            try
            {
                OnAfterUninstall(savedState);
            }
            catch (SystemException e3)
            {
                LogException("OnAfterUninstall", e3);
                e = e3;
            }

            // Re-throw the last-occurring exception.
            if (e != null)
            {
                if (e.InnerException == null)
                {
                    e = new InstallException(e.Message, e);
                }
                throw e;
            }
        }
コード例 #17
0
        /// <include file='doc\Installer.uex' path='docs/doc[@for="Installer.Uninstall"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Removes an installation.
        ///    </para>
        /// </devdoc>
        public virtual void Uninstall(IDictionary savedState)
        {
            // raise the OnBeforeUninstall event
            Exception savedException = null;

            try {
                OnBeforeUninstall(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnBeforeUninstall", e);
                Context.LogMessage(Res.GetString(Res.InstallUninstallException));
                savedException = e;
            }

            // do the uninstall

            // uninstall is special: savedState can be null. (The state file may have been deleted since
            // the application was installed.) If it isn't, we read state out as usual. Otherwise we create
            // some new, empty state to pass to the contained installers.
            IDictionary[] nestedSavedStates;
            if (savedState != null)
            {
                nestedSavedStates = (IDictionary[])savedState["_reserved_nestedSavedStates"];
                if (nestedSavedStates == null || nestedSavedStates.Length != Installers.Count)
                {
                    throw new ArgumentException(Res.GetString(Res.InstallDictionaryCorrupted, "savedState"));
                }
            }
            else
            {
                nestedSavedStates = new IDictionary[Installers.Count];
            }
            //go in reverse order when uninstalling
            for (int i = Installers.Count - 1; i >= 0; i--)
            {
                // set all the contexts first.  see note in Install
                Installers[i].Context = Context;
            }

            for (int i = Installers.Count - 1; i >= 0; i--)
            {
                try {
                    Installers[i].Uninstall(nestedSavedStates[i]);
                }
                catch (Exception e) {
                    if (!IsWrappedException(e))
                    {
                        // only print the message if this is not a wrapper around an exception we already printed out.
                        Context.LogMessage(Res.GetString(Res.InstallLogUninstallException, Installers[i].ToString()));
                        LogException(e, Context);
                        Context.LogMessage(Res.GetString(Res.InstallUninstallException));
                    }
                    savedException = e;
                }
            }

            // raise the OnAfterUninstall event
            try {
                OnAfterUninstall(savedState);
            }
            catch (Exception e) {
                WriteEventHandlerError(Res.GetString(Res.InstallSeverityWarning), "OnAfterUninstall", e);
                Context.LogMessage(Res.GetString(Res.InstallUninstallException));
                savedException = e;
            }

            if (savedException != null)
            {
                Exception wrappedException = savedException;
                if (!IsWrappedException(savedException))
                {
                    wrappedException        = new InstallException(Res.GetString(Res.InstallUninstallException), savedException);
                    wrappedException.Source = wrappedExceptionSource;
                }
                throw wrappedException;
            }
        }
コード例 #18
0
        public virtual void Commit(IDictionary savedState)
        {
            if (savedState == null)
            {
                throw new ArgumentException(Res.GetString("InstallNullParameter", new object[] { "savedState" }));
            }
            if ((savedState["_reserved_lastInstallerAttempted"] == null) || (savedState["_reserved_nestedSavedStates"] == null))
            {
                throw new ArgumentException(Res.GetString("InstallDictionaryMissingValues", new object[] { "savedState" }));
            }
            Exception e = null;

            try
            {
                this.OnCommitting(savedState);
            }
            catch (Exception exception2)
            {
                this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitting", exception2);
                this.Context.LogMessage(Res.GetString("InstallCommitException"));
                e = exception2;
            }
            int num = (int)savedState["_reserved_lastInstallerAttempted"];

            IDictionary[] dictionaryArray = (IDictionary[])savedState["_reserved_nestedSavedStates"];
            if (((num + 1) != dictionaryArray.Length) || (num >= this.Installers.Count))
            {
                throw new ArgumentException(Res.GetString("InstallDictionaryCorrupted", new object[] { "savedState" }));
            }
            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(dictionaryArray[j]);
                }
                catch (Exception exception3)
                {
                    if (!this.IsWrappedException(exception3))
                    {
                        this.Context.LogMessage(Res.GetString("InstallLogCommitException", new object[] { this.Installers[j].ToString() }));
                        LogException(exception3, this.Context);
                        this.Context.LogMessage(Res.GetString("InstallCommitException"));
                    }
                    e = exception3;
                }
            }
            savedState["_reserved_nestedSavedStates"] = dictionaryArray;
            savedState.Remove("_reserved_lastInstallerAttempted");
            try
            {
                this.OnCommitted(savedState);
            }
            catch (Exception exception4)
            {
                this.WriteEventHandlerError(Res.GetString("InstallSeverityWarning"), "OnCommitted", exception4);
                this.Context.LogMessage(Res.GetString("InstallCommitException"));
                e = exception4;
            }
            if (e != null)
            {
                Exception exception5 = e;
                if (!this.IsWrappedException(e))
                {
                    exception5 = new InstallException(Res.GetString("InstallCommitException"), e)
                    {
                        Source = "WrappedExceptionSource"
                    };
                }
                throw exception5;
            }
        }