Beispiel #1
0
 /// <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);
         }
     }
 }
Beispiel #2
0
        /// <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);
        }