/// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ASender"></param>
        /// <param name="AEventArgs"></param>
        public void OnThreadException(object ASender, ThreadExceptionEventArgs AEventArgs)
        {
            TUnhandledExceptionForm UEDialogue;
            string FunctionalityNotImplementedMsg = Catalog.GetString("This functionality is not yet implemented in OpenPetra.");

            if ((AEventArgs.Exception is NotImplementedException))
            {
                if (AEventArgs.Exception.Message != String.Empty)
                {
                    FunctionalityNotImplementedMsg = AEventArgs.Exception.Message;
                }

                TLogging.Log(FunctionalityNotImplementedMsg);
                TLogging.Log(AEventArgs.Exception.StackTrace);

                MessageBox.Show(FunctionalityNotImplementedMsg,
                                Catalog.GetString("Not Yet Implemented in OpenPetra"),
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if ((AEventArgs.Exception is ESecurityAccessDeniedException))
            {
                if (ProcessSecurityAccessDeniedException != null)
                {
                    ProcessSecurityAccessDeniedException((ESecurityAccessDeniedException)AEventArgs.Exception, ASender.GetType());
                }
                else
                {
                    MessageBox.Show(
                        "Unhandled Thread Exception Handler: encountered ESecurityAccessDeniedException, but Delegate " +
                        "'ProcessSecurityAccessDeniedException' isn't set up - which is a mistake that needs to be corrected." +
                        Environment.NewLine +
                        "Message of the ProcessSecurityAccessDeniedException instance:" + Environment.NewLine +
                        ProcessSecurityAccessDeniedException.ToString());
                }
            }
            else
            {
//                MessageBox.Show(
//                    "TUnhandledThreadExceptionHandler.OnThreadException  Unhandled Exception: \r\n\r\n" + AEventArgs.Exception.ToString());

                ExceptionHandling.LogException(AEventArgs.Exception, "Reported by TUnhandledThreadExceptionHandler.OnThreadException");
                UEDialogue = new TUnhandledExceptionForm();

                UEDialogue.NonRecoverable = false;
                UEDialogue.TheException   = AEventArgs.Exception;
                UEDialogue.ShowDialog();
            }
        }
Beispiel #2
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ASender"></param>
        /// <param name="AEventArgs"></param>
        public void OnThreadException(object ASender, ThreadExceptionEventArgs AEventArgs)
        {
            TUnhandledExceptionForm UEDialogue;
            string    FunctionalityNotImplementedMsg = AppCoreResourcestrings.StrFunctionalityNotAvailableYet;
            string    Reason       = String.Empty;
            Exception TheException = ((Exception)AEventArgs.Exception);

            // 'Unwrap' the Exception if it is contained inside a TargetInvocationException
            if ((TheException is TargetInvocationException) &&
                (TheException.InnerException != null))
            {
                TheException = TheException.InnerException;
            }

            if (TExceptionHelper.IsExceptionCausedByUnavailableDBConnectionClientSide(TheException))
            {
                TExceptionHelper.ShowExceptionCausedByUnavailableDBConnectionMessage(false);

                return;
            }

            if (TheException is NotImplementedException)
            {
                if (TheException.Message != String.Empty)
                {
                    FunctionalityNotImplementedMsg = TheException.Message;
                }

                TLogging.Log(FunctionalityNotImplementedMsg);
                TLogging.Log(TheException.StackTrace);

                MessageBox.Show(FunctionalityNotImplementedMsg, AppCoreResourcestrings.StrFunctionalityNotAvailableYetTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (TDBExceptionHelper.IsTransactionSerialisationException(TheException))
            {
                TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog();
            }
            else if ((TheException is EOPDBException) &&
                     ((TheException.InnerException != null) &&
                      (TheException.InnerException is EDBAccessLackingCoordinationException)))
            {
                TExceptionHandlingCommon.ProcessEDBAccessLackingCoordinationExc((EDBAccessLackingCoordinationException)TheException.InnerException);
            }
            else if (TheException is EDBAccessLackingCoordinationException)
            {
                TExceptionHandlingCommon.ProcessEDBAccessLackingCoordinationExc((EDBAccessLackingCoordinationException)TheException);
            }
            else if (TheException is ECachedDataTableLoadingRetryGotCancelledException)
            {
                if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_COORDINATED_DB_ACCESS)
                {
                    TLogging.Log(Catalog.GetString(
                                     TLogging.LOG_PREFIX_INFO +
                                     "The OpenPetra Server was too busy to retrieve the data for a Cacheable DataTable and the user cancelled the loading after the retry attempts were exhausted."));
                    TLogging.Log(TheException.StackTrace);
                }

                TServerBusyHelperGui.ShowLoadingOfDataGotCancelledDialog();
            }
            else if (TheException is ESecurityAccessDeniedException)
            {
                if (ProcessSecurityAccessDeniedException != null)
                {
                    ProcessSecurityAccessDeniedException((ESecurityAccessDeniedException)TheException, ASender.GetType());
                }
                else
                {
                    MessageBox.Show(
                        "Unhandled Thread Exception Handler: encountered ESecurityAccessDeniedException, but Delegate " +
                        "'ProcessSecurityAccessDeniedException' isn't set up - which is a mistake that needs to be corrected." +
                        Environment.NewLine +
                        "Message of the ProcessSecurityAccessDeniedException instance:" + Environment.NewLine +
                        ProcessSecurityAccessDeniedException.ToString());
                }
            }
            else if (TheException is System.OutOfMemoryException)
            {
                TExceptionHelper.ShowExceptionCausedByOutOfMemoryMessage(false);

                TLogging.Log(TheException.ToString());
            }
            else if ((TheException is InvalidOperationException) &&
                     (Application.OpenForms.Count == 0) &&
                     (TheException.Message == "DragDrop registration did not succeed."))
            {
                // This happens during testing because the apartment model is MTA
                // Do nothing because we do not want to show a dialog
            }
            else
            {
                //                MessageBox.Show(
                //                    "TUnhandledThreadExceptionHandler.OnThreadException  Unhandled Exception: \r\n\r\n" + TheException.ToString());

                ExceptionHandling.LogException(TheException, "Reported by TUnhandledThreadExceptionHandler.OnThreadException");
                UEDialogue = new TUnhandledExceptionForm();

                UEDialogue.NonRecoverable = false;
                UEDialogue.TheException   = TheException;

                //Would normally use the code below but cannot due to circular referencing.
                //Form MainMenuForm = TFormsList.GFormsList.MainMenuForm;

                if (Application.OpenForms.Count != 0)              // in the Main Menu Form Test this will be false...
                {
                    Form MainMenuForm = Application.OpenForms[0];  // This gets the first ever opened Form, which is the Main Menu

                    // Ensure UEDialogue is shown on the UI Thread!
                    if (MainMenuForm.InvokeRequired)
                    {
                        MainMenuForm.Invoke((MethodInvoker) delegate
                        {
                            UEDialogue.ShowDialog();
                        });
                    }
                    else
                    {
                        UEDialogue.ShowDialog();
                    }
                }
                else
                {
                    UEDialogue.ShowDialog();
                }
            }
        }
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ASender"></param>
        /// <param name="AEventArgs"></param>
        public void OnThreadException(object ASender, ThreadExceptionEventArgs AEventArgs)
        {
            TUnhandledExceptionForm UEDialogue;
            string FunctionalityNotImplementedMsg = AppCoreResourcestrings.StrFunctionalityNotAvailableYet;
            string Reason = String.Empty;

            if ((AEventArgs.Exception is NotImplementedException))
            {
                if (AEventArgs.Exception.Message != String.Empty)
                {
                    FunctionalityNotImplementedMsg = AEventArgs.Exception.Message;
                }

                TLogging.Log(FunctionalityNotImplementedMsg);
                TLogging.Log(AEventArgs.Exception.StackTrace);

                MessageBox.Show(FunctionalityNotImplementedMsg, AppCoreResourcestrings.StrFunctionalityNotAvailableYetTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if ((AEventArgs.Exception is EDBAccessLackingCoordinationException))
            {
                //Would normally use the code below but cannot due to circular referencing.
                //Form MainMenuForm = TFormsList.GFormsList.MainMenuForm;
                Form MainMenuForm = Application.OpenForms[0];  // This gets the first ever opened Form, which is the Main Menu

                // Ensure MessageBox is shown on the UI Thread!
                if (MainMenuForm.InvokeRequired)
                {
                    MainMenuForm.Invoke((MethodInvoker) delegate {
                        TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                            (EDBAccessLackingCoordinationException)AEventArgs.Exception, out Reason);
                    });
                }
                else
                {
                    TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                        (EDBAccessLackingCoordinationException)AEventArgs.Exception, out Reason);
                }

                if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_COORDINATED_DB_ACCESS)
                {
                    TLogging.Log(String.Format(Catalog.GetString(
                                                   TLogging.LOG_PREFIX_INFO + "The OpenPetra Server was too busy to perform the requested action. (Reason: {0})"),
                                               Reason));
                    TLogging.Log((AEventArgs.Exception).StackTrace);
                }
            }
            else if (((Exception)AEventArgs.Exception is ECachedDataTableLoadingRetryGotCancelledException))
            {
                if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_COORDINATED_DB_ACCESS)
                {
                    TLogging.Log(Catalog.GetString(
                                     TLogging.LOG_PREFIX_INFO +
                                     "The OpenPetra Server was too busy to retrieve the data for a Cacheable DataTable and the user cancelled the loading after the retry attempts were exhausted."));
                    TLogging.Log(((Exception)AEventArgs.Exception).StackTrace);
                }

                TServerBusyHelperGui.ShowLoadingOfDataGotCancelledDialog();
            }
            else if ((AEventArgs.Exception is ESecurityAccessDeniedException))
            {
                if (ProcessSecurityAccessDeniedException != null)
                {
                    ProcessSecurityAccessDeniedException((ESecurityAccessDeniedException)AEventArgs.Exception, ASender.GetType());
                }
                else
                {
                    MessageBox.Show(
                        "Unhandled Thread Exception Handler: encountered ESecurityAccessDeniedException, but Delegate " +
                        "'ProcessSecurityAccessDeniedException' isn't set up - which is a mistake that needs to be corrected." +
                        Environment.NewLine +
                        "Message of the ProcessSecurityAccessDeniedException instance:" + Environment.NewLine +
                        ProcessSecurityAccessDeniedException.ToString());
                }
            }
            else
            {
//                MessageBox.Show(
//                    "TUnhandledThreadExceptionHandler.OnThreadException  Unhandled Exception: \r\n\r\n" + AEventArgs.Exception.ToString());

                ExceptionHandling.LogException(AEventArgs.Exception, "Reported by TUnhandledThreadExceptionHandler.OnThreadException");
                UEDialogue = new TUnhandledExceptionForm();

                UEDialogue.NonRecoverable = false;
                UEDialogue.TheException   = AEventArgs.Exception;

                //Would normally use the code below but cannot due to circular referencing.
                //Form MainMenuForm = TFormsList.GFormsList.MainMenuForm;
                Form MainMenuForm = Application.OpenForms[0];  // This gets the first ever opened Form, which is the Main Menu

                // Ensure UEDialogue is shown on the UI Thread!
                if (MainMenuForm.InvokeRequired)
                {
                    MainMenuForm.Invoke((MethodInvoker) delegate { UEDialogue.ShowDialog(); });
                }
                else
                {
                    UEDialogue.ShowDialog();
                }
            }
        }