Example #1
0
        } // end _DoStaging()

        public async Task InstallAsync(IInstallCallback installCallback)
        {
            try
            {
                await Task.Factory.StartNew(() => _DoInstall( installCallback ),
                                            m_cancelToken,
                                            TaskCreationOptions.LongRunning,
                                            TaskScheduler.Default);
            }
            catch (FabrikamException fe)
            {
                // Note that if an "update" fails to install, it is reported through the
                // installCallback.ReportInstallResult method. Only a more serious problem
                // representing a complete infrastructure failure should be reported by
                // throwing a ClusterUpdateException.
                throw new ClusterUpdateException(String.Format(CultureInfo.CurrentCulture,
                                                               "Installing node \"{0}\" failed: {1}",
                                                               m_machine,
                                                               fe.Message),
                                                 "InstallFailed",
                                                 ErrorCategory.NotSpecified,
                                                 fe);
            }
        } // end InstallAsync()
        } // end InstallAsync()


        private void _DoInstall( IInstallCallback installCallback )
        {
            installCallback.WriteVerbose( String.Format( CultureInfo.CurrentCulture,
                                                         "Attempting to run this command on {0}: {1}",
                                                         m_machine,
                                                         m_command ) );
            Exception e = null;
            int errorCode = 0;
            UpdateInstallResult uir = null;
            try
            {
                errorCode = _RunCommand( m_command, false, installCallback );
            }
            catch( Win32Exception w32e ) { e = w32e; }
            catch( ManagementException me ) { e = me; }
            catch( OperationCanceledException )
            {
                uir = new UpdateInstallResult( m_update,
                                               ResultCode.Canceled,
                                               0,                 // error code
                                               false,             // reboot required
                                               false,             // long reboot hint
                                               DateTime.UtcNow ); // All timestamps should be UTC.
                installCallback.ReportInstallResult( uir );
                throw;
            }

            if( null != e )
            {
                throw new FabrikamException( String.Format( CultureInfo.CurrentCulture,
                                                            "Failed to run command: {0}: {1}",
                                                            e.GetType().Name,
                                                            e.Message ),
                                             e );
            }

            bool rebootRequired = false;
            bool succeeded = false;
            const int ERROR_SUCCESS_REBOOT_REQUIRED  = 3010;
            const int ERROR_SUCCESS_RESTART_REQUIRED = 3011;
            const int ERROR_FAIL_REBOOT_REQUIRED     = 3017;

            if( 0 == errorCode )
            {
                succeeded = true;
            }
            else if( (ERROR_SUCCESS_REBOOT_REQUIRED == errorCode) ||
                     (ERROR_SUCCESS_RESTART_REQUIRED == errorCode) )
            {
                succeeded = true;
                rebootRequired = true;
            }
            else if( 0 != errorCode )
            {
                succeeded = false;
                if( ERROR_FAIL_REBOOT_REQUIRED == errorCode )
                {
                    rebootRequired = true;
                }
            }

            uir = new UpdateInstallResult( m_update,
                                           succeeded ? ResultCode.Succeeded : ResultCode.Failed,
                                           errorCode,
                                           rebootRequired,
                                           false,
                                           DateTime.UtcNow ); // All timestamps should be UTC.
            installCallback.ReportInstallResult( uir );
        } // end _DoInstall()
        } // end _DoStaging()


        public async Task InstallAsync( IInstallCallback installCallback )
        {
            try
            {
                await Task.Factory.StartNew( () => _DoInstall( installCallback ),
                                             m_cancelToken,
                                             TaskCreationOptions.LongRunning,
                                             TaskScheduler.Default );
            }
            catch( FabrikamException fe )
            {
                // Note that if an "update" fails to install, it is reported through the
                // installCallback.ReportInstallResult method. Only a more serious problem
                // representing a complete infrastructure failure should be reported by
                // throwing a ClusterUpdateException.
                throw new ClusterUpdateException( String.Format( CultureInfo.CurrentCulture,
                                                                 "Installing node \"{0}\" failed: {1}",
                                                                 m_machine,
                                                                 fe.Message ),
                                                  "InstallFailed",
                                                  ErrorCategory.NotSpecified,
                                                  fe );
            }
        } // end InstallAsync()
Example #4
0
        } // end InstallAsync()

        private void _DoInstall(IInstallCallback installCallback)
        {
            installCallback.WriteVerbose(String.Format(CultureInfo.CurrentCulture,
                                                       "Attempting to run this command on {0}: {1}",
                                                       m_machine,
                                                       m_command));
            Exception           e         = null;
            int                 errorCode = 0;
            UpdateInstallResult uir       = null;

            try
            {
                errorCode = _RunCommand(m_command, false, installCallback);
            }
            catch (Win32Exception w32e) { e = w32e; }
            catch (ManagementException me) { e = me; }
            catch (OperationCanceledException)
            {
                uir = new UpdateInstallResult(m_update,
                                              ResultCode.Canceled,
                                              0,                  // error code
                                              false,              // reboot required
                                              false,              // long reboot hint
                                              DateTime.UtcNow);   // All timestamps should be UTC.
                installCallback.ReportInstallResult(uir);
                throw;
            }

            if (null != e)
            {
                throw new FabrikamException(String.Format(CultureInfo.CurrentCulture,
                                                          "Failed to run command: {0}: {1}",
                                                          e.GetType().Name,
                                                          e.Message),
                                            e);
            }

            bool      rebootRequired = false;
            bool      succeeded      = false;
            const int ERROR_SUCCESS_REBOOT_REQUIRED  = 3010;
            const int ERROR_SUCCESS_RESTART_REQUIRED = 3011;
            const int ERROR_FAIL_REBOOT_REQUIRED     = 3017;

            if (0 == errorCode)
            {
                succeeded = true;
            }
            else if ((ERROR_SUCCESS_REBOOT_REQUIRED == errorCode) ||
                     (ERROR_SUCCESS_RESTART_REQUIRED == errorCode))
            {
                succeeded      = true;
                rebootRequired = true;
            }
            else if (0 != errorCode)
            {
                succeeded = false;
                if (ERROR_FAIL_REBOOT_REQUIRED == errorCode)
                {
                    rebootRequired = true;
                }
            }

            uir = new UpdateInstallResult(m_update,
                                          succeeded ? ResultCode.Succeeded : ResultCode.Failed,
                                          errorCode,
                                          rebootRequired,
                                          false,
                                          DateTime.UtcNow);   // All timestamps should be UTC.
            installCallback.ReportInstallResult(uir);
        } // end _DoInstall()