/// <summary>
        /// Returns the value of the specified System Default.
        /// For that, the whole System Defaults DB table is read from the server - that's not a problem so long as there's not
        /// thousands of system defaults, and this method isn't called too often!
        /// </summary>
        /// <param name="ASystemDefaultName">The System Default for which the value should be returned.</param>
        /// <returns>The value of the System Default, or SYSDEFAULT_NOT_FOUND if the
        /// specified System Default was not found.</returns>
        public static String GetSystemDefault(String ASystemDefaultName)
        {
            SSystemDefaultsTable SystemDefaultsDT = null;
            SSystemDefaultsRow   FoundSystemDefaultsRow;
            bool ServerCallSuccessful = false;

            TServerBusyHelper.CoordinatedAutoRetryCall("System Defaults", ref ServerCallSuccessful,
                                                       delegate
            {
                SystemDefaultsDT = TRemote.MSysMan.Maintenance.SystemDefaults.WebConnectors.GetSystemDefaults();

                ServerCallSuccessful = true;
            });

            if (!ServerCallSuccessful)
            {
                TServerBusyHelperGui.ShowLoadingOfDataGotCancelledDialog();

                return(SharedConstants.SYSDEFAULT_NOT_FOUND);
            }

            if (SystemDefaultsDT != null)
            {
                // Look up the System Default
                FoundSystemDefaultsRow = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(ASystemDefaultName);

                return(FoundSystemDefaultsRow != null ? FoundSystemDefaultsRow.DefaultValue : SharedConstants.SYSDEFAULT_NOT_FOUND);
            }
            else
            {
                // 'Back-stop' - should never get here
                return(SharedConstants.SYSDEFAULT_NOT_FOUND);
            }
        }
Exemple #2
0
        public static void ProcessEDBAccessLackingCoordinationExc(EDBAccessLackingCoordinationException AException)
        {
            string Reason = String.Empty;

            //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 MessageBox is shown on the UI Thread!
                if (MainMenuForm.InvokeRequired)
                {
                    MainMenuForm.Invoke((MethodInvoker) delegate
                    {
                        TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                            AException, out Reason);
                    });
                }
                else
                {
                    TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                        AException, out Reason);
                }
            }
            else
            {
                TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                    AException, 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(AException.StackTrace);
            }
        }
Exemple #3
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 static void UnhandledExceptionHandler(object ASender, UnhandledExceptionEventArgs AEventArgs)
        {
            TUnhandledExceptionForm UEDialogue;
            string FunctionalityNotImplementedMsg = AppCoreResourcestrings.StrFunctionalityNotAvailableYet;
            string Reason = String.Empty;

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

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

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

                // Ensure MessageBox is shown on the UI Thread!
                if (MainMenuForm.InvokeRequired)
                {
                    MainMenuForm.Invoke((MethodInvoker) delegate {
                        TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                            (EDBAccessLackingCoordinationException)AEventArgs.ExceptionObject, out Reason);
                    });
                }
                else
                {
                    TServerBusyHelperGui.ShowDBAccessLackingActionNotPossibleDialog(
                        (EDBAccessLackingCoordinationException)AEventArgs.ExceptionObject, 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(((Exception)AEventArgs.ExceptionObject).StackTrace);
                }
            }
            else if (((Exception)AEventArgs.ExceptionObject 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.ExceptionObject).StackTrace);
                }

                TServerBusyHelperGui.ShowLoadingOfDataGotCancelledDialog();
            }
            else if (((Exception)AEventArgs.ExceptionObject is ESecurityAccessDeniedException))
            {
                if (ProcessSecurityAccessDeniedException != null)
                {
                    ProcessSecurityAccessDeniedException((ESecurityAccessDeniedException)AEventArgs.ExceptionObject, 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("UnhandledExceptionHandler  Unhandled Exception: \r\n\r\n" +
                //                      ((Exception)(AEventArgs.ExceptionObject)).ToString() + "\r\n\r\n"+
                //      "IsTerminating: " + AEventArgs.IsTerminating.ToString());

                LogException((Exception)AEventArgs.ExceptionObject,
                             "Reported by UnhandledExceptionHandler: (Application is terminating: " + AEventArgs.IsTerminating.ToString() + ')');
                UEDialogue = new TUnhandledExceptionForm();

                UEDialogue.NonRecoverable = AEventArgs.IsTerminating;
                UEDialogue.TheException   = (Exception)AEventArgs.ExceptionObject;

                //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();
                }
            }
        }