Exemplo n.º 1
0
        /// <summary>
        /// connect the client
        /// </summary>
        /// <param name="AUserName"></param>
        /// <param name="APassword"></param>
        /// <param name="AProcessID"></param>
        /// <param name="AWelcomeMessage"></param>
        /// <param name="ASystemEnabled"></param>
        /// <param name="AError"></param>
        /// <param name="AUserInfo"></param>
        /// <returns></returns>
        virtual protected eLoginEnum ConnectClient(String AUserName,
                                                   String APassword,
                                                   out Int32 AProcessID,
                                                   out String AWelcomeMessage,
                                                   out Boolean ASystemEnabled,
                                                   out String AError,
                                                   out IPrincipal AUserInfo)
        {
            AError          = "";
            ASystemEnabled  = false;
            AWelcomeMessage = "";
            AProcessID      = -1;
            AUserInfo       = null;

            try
            {
                eLoginEnum result = FClientManager.ConnectClient(AUserName, APassword,
                                                                 TClientInfo.ClientComputerName,
                                                                 TClientInfo.ClientIPAddress,
                                                                 new Version(TClientInfo.ClientAssemblyVersion),
                                                                 DetermineClientServerConnectionType(),
                                                                 out FClientID,
                                                                 out AWelcomeMessage,
                                                                 out ASystemEnabled,
                                                                 out AUserInfo);

                if (result != eLoginEnum.eLoginSucceeded)
                {
                    AError = result.ToString();
                }

                return(result);
            }
            catch (Exception Exc)
            {
                if (TExceptionHelper.IsExceptionCausedByUnavailableDBConnectionClientSide(Exc))
                {
                    TExceptionHelper.ShowExceptionCausedByUnavailableDBConnectionMessage(true);

                    AError = Exc.Message;
                    return(eLoginEnum.eLoginFailedForUnspecifiedError);
                }

                TLogging.Log(Exc.ToString() + Environment.NewLine + Exc.StackTrace, TLoggingType.ToLogfile);
                AError = Exc.Message;
                return(eLoginEnum.eLoginFailedForUnspecifiedError);
            }
        }
Exemplo n.º 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();
                }
            }
        }