/// <summary> /// Event Handler that gets called before the Common Language Runtime (CLR) begins searching for Event /// Handlers. This special Event gets hooked up for all AppDomains of the server (incl. the Default /// Application Domain of the server exe). /// <para> /// In case an Exception was caused by an unavailable DB Connection the <see cref="DBConnectionBrokenCallback"/> /// Event gets raised, which gets subscribed to in the TServerManager.StartServer Method and in the /// Constructor of the 'TRemoteLoader' Class in order to kick off the attempts of restoring the broken /// DB Connection. /// </para> /// </summary> /// <param name="ASource">Provided automatically by .NET.</param> /// <param name="AEventArgs">Provided automatically by .NET. (The Exception Property of this Argument /// holds the Exception that just occurred.)</param> public static void FirstChanceHandler(object ASource, FirstChanceExceptionEventArgs AEventArgs) { if (TExceptionHelper.IsExceptionCausedByUnavailableDBConnectionServerSide(AEventArgs.Exception)) { if (DBConnectionBrokenCallback != null) { DBConnectionBrokenCallback(ASource, AEventArgs.Exception); } } else if (AEventArgs.Exception is OutOfMemoryException) { TLogging.Log(String.Format("FirstChanceException event raised because of an *out of memory condition* in {0}: {1}", AppDomain.CurrentDomain.FriendlyName, AEventArgs.Exception.Message)); TLogging.LogStackTrace(TLoggingType.ToLogfile); } else { if (TLogging.DebugLevel >= 5) { TLogging.Log(String.Format("FirstChanceException event raised in {0}: {1}", AppDomain.CurrentDomain.FriendlyName, AEventArgs.Exception.Message)); TLogging.LogStackTrace(TLoggingType.ToLogfile); } } }
/// <summary> /// Establishes a new Database connection to the Database /// for TTimedProcessing. /// </summary> /// <remarks> /// We don't want to use the global Ict.Common.DB.DBAccess.GDBAccessObj object in the Default /// AppDomain because this is reserved for OpenPetraServer's internal use (eg. verifying Client /// connection reqests)! /// </remarks> /// <returns>the database connection object</returns> private static TDataBase EstablishDBConnection() { TDataBase FDBAccessObj; bool ExceptionCausedByUnavailableDBConn; try { FDBAccessObj = DBAccess.SimpleEstablishDBConnection("Servers's DB Connection for TimedProcessing"); } catch (Exception Exc) { ExceptionCausedByUnavailableDBConn = TExceptionHelper.IsExceptionCausedByUnavailableDBConnectionServerSide(Exc); if (!ExceptionCausedByUnavailableDBConn) { TLogging.Log("Timed Processing: Exception occured while establishing connection to Database Server: " + Exc.ToString()); throw; } else { FDBAccessObj = null; // This gets handled in the calling Method! } } return(FDBAccessObj); }
/// <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); } }
private DataTable GetReportDataTable(string AReportName, Dictionary <String, TVariant> AParamsDictionary, ref bool AThreadFinished) { DataTable ReturnTable = null; try { ReturnTable = TRemote.MReporting.WebConnectors.GetReportDataTable(AReportName, AParamsDictionary); } catch (System.OutOfMemoryException Exc) { TExceptionHelper.ShowExceptionCausedByOutOfMemoryMessage(true); TLogging.Log(Exc.ToString()); } AThreadFinished = true; return(ReturnTable); }
/// <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(); } } }