示例#1
0
        /// <summary>
        /// Gets the description of a specified error.
        /// </summary>
        /// <typeparam name="TErrorCodeEnum">The type of the enum that lists all the valid error
        /// codes.</typeparam>
        /// <param name="codeToLookup">Error code whose description is to be returned.</param>
        /// <param name="systemSettings">Settings read from a custom section of the config file
        /// that contains connection information for the database.</param>
        /// <returns>The description for the specified error code.  If the specified error code is
        /// not found, returns an empty string.</returns>
        public static string GetErrorDescription <TErrorCodeEnum>(TErrorCodeEnum codeToLookup,
                                                                  SystemCoreSettings systemSettings)
            where TErrorCodeEnum : IComparable, IFormattable, IConvertible
        {
            DatabaseManager2 databaseManager = null;

            lock (_lockGetErrorDescription_1)
            {
                databaseManager = BBDatabase.GetDatabaseManager(systemSettings);
                if (databaseManager == null)
                {
                    return(string.Empty);
                }
            }
            return(GetErrorDescription <TErrorCodeEnum>(codeToLookup, databaseManager));
        }
示例#2
0
        /// <summary>
        /// Returns the error message in an ErrorInfo object.  If the error message is blank and
        /// an error has occurred then returns the description of the error.
        /// </summary>
        /// <typeparam name="T">The type of the enum that lists all the valid error codes.</typeparam>
        /// <param name="errorInfo">ErrorInfo object containing information about an error.</param>
        /// <param name="successErrorCode">The error code that represents success.</param>
        /// <param name="defaultErrorCode">The default error that the ErrorInfo object may be set
        /// to.</param>
        /// <param name="systemSettings">Settings read from a custom section of the config file
        /// that contains connection information for the database.</param>
        /// <returns>An error message.</returns>
        public static string GetErrorMessage <TErrorCodeEnum>(ErrorInfo <TErrorCodeEnum> errorInfo,
                                                              TErrorCodeEnum successErrorCode, TErrorCodeEnum defaultErrorCode,
                                                              SystemCoreSettings systemSettings)
            where TErrorCodeEnum : IComparable, IFormattable, IConvertible
        {
            DatabaseManager2 databaseManager = null;

            lock (_lockGetErrorMessage_1)
            {
                databaseManager = BBDatabase.GetDatabaseManager(systemSettings);
                if (databaseManager == null)
                {
                    return(string.Empty);
                }
            }

            return(BBError.GetErrorMessage <TErrorCodeEnum>(errorInfo, successErrorCode,
                                                            defaultErrorCode, databaseManager));
        }
示例#3
0
        /// <summary>
        /// Sets up the TraceListener used to write log messages to the database.
        /// </summary>
        /// <param name="traceSource">A TraceSource that raises log messages.</param>
        /// <param name="databaseListenerName">The name of the TraceListener the TraceSource uses
        /// to write to the database.</param>
        /// <param name="configSettingsSectionName">The name of the section in the config file
        /// that contains connection information for the database.</param>
        /// <remarks>Only need to call this once, for one of the trace sources, as the
        /// TraceListener is shared between all the trace sources.</remarks>
        public static void SetupDatabaseLogging(TraceSource traceSource,
                                                string databaseListenerName, SystemCoreSettings systemSettings)
        {
            lock (_lockSetupDatabaseLogging)
            {
                DatabaseManager2      databaseManager = BBDatabase.GetDatabaseManager(systemSettings);
                DatabaseTraceListener databaseLogger  =
                    (DatabaseTraceListener)(traceSource.Listeners[databaseListenerName]);
                databaseLogger.DatabaseManager = databaseManager;

                Assembly callingAssembly             = Assembly.GetCallingAssembly();
                AssemblyTitleAttribute assemblyTitle =
                    ReflectionHelper.GetAssemblyAttribute <AssemblyTitleAttribute>(callingAssembly);
                databaseLogger.ApplicationName     = assemblyTitle.Title;
                databaseLogger.TraceOutputOptions |= TraceOptions.ProcessId;
                databaseLogger.TraceOutputOptions |= TraceOptions.ThreadId;

                // Skip the following helper methods when determining the name of the method that
                //	raised the log message.
                databaseLogger.MethodNameMethodsToIgnore.Add(LogMethodsToIgnore.LogException);
                databaseLogger.MethodNameMethodsToIgnore.Add(
                    LogMethodsToIgnore.LogStoredProcResults);
            }
        }