Beispiel #1
0
        /// <summary>
        /// Retrieves information about a database that the application is currently connected to.
        /// </summary>
        /// <param name="databaseManager">Database manager object that handles the connection to
        /// the database.</param>
        /// <param name="commonDatabaseErrorCode">Structure holding the common database-related
        /// error codes.</param>
        /// <param name="oErrorInfo">Output parameter: Details of any error that may have
        /// occurred.</param>
        /// <returns>A structure containing the database metadata.</returns>
        public static DatabaseInfo GetDatabaseInfo <T>(DatabaseManager2 databaseManager,
                                                       CommonDatabaseErrorCode <T> commonDatabaseErrorCode, out ErrorInfo <T> oErrorInfo)
            where T : IComparable, IFormattable, IConvertible
        {
            DatabaseInfo  dbInfo    = new DatabaseInfo();
            ErrorInfo <T> errorInfo = new ErrorInfo <T>();

            lock (_lockGetDatabaseInfo)
            {
                try
                {
                    errorInfo.ErrorCode = commonDatabaseErrorCode.GeneralError;
                    errorInfo.Message   = string.Empty;
                    // Cannot convert generic type to int directly so cheat by using object.
                    object value = commonDatabaseErrorCode.Success;
                    errorInfo.DatabaseErrorValue = (int)value;

                    DataTable dbMetaData = databaseManager.GetDataTable("p_GetDatabaseInfo",
                                                                        out errorInfo.DatabaseErrorValue, out errorInfo.Message);

                    // Check for unrecognised error code from the database.
                    errorInfo.ErrorCode = BBError.ValidateDBErrorValue <T>(
                        errorInfo.DatabaseErrorValue, commonDatabaseErrorCode.GeneralDBError);

                    if (dbMetaData != null && dbMetaData.Rows.Count > 0)
                    {
                        dbInfo.DatabaseTitle   = (dbMetaData.Rows[0]["DatabaseTitle"]).ToString();
                        dbInfo.DatabaseVersion = (int)dbMetaData.Rows[0]["DatabaseVersion"];

                        // Check that database type is valid.
                        string       databaseTypeText = (dbMetaData.Rows[0]["DatabaseType"]).ToString();
                        DatabaseType databaseType     = DatabaseType.NotFound;
                        if (MiscUtilities.ValidateEnumValue <DatabaseType>(databaseTypeText,
                                                                           out databaseType))
                        {
                            dbInfo.DatabaseType = databaseType;
                            errorInfo.ErrorCode = commonDatabaseErrorCode.Success;
                        }
                        else
                        {
                            dbInfo.DatabaseType = DatabaseType.Invalid;
                            errorInfo.ErrorCode = commonDatabaseErrorCode.InvalidType;
                        }
                    }
                    else
                    {
                        dbInfo.DatabaseType = DatabaseType.NotFound;
                        errorInfo.ErrorCode = commonDatabaseErrorCode.NoInfo;
                    }
                }
                catch
                {
                    errorInfo.ErrorCode = commonDatabaseErrorCode.GeneralError;
                }
            }

            oErrorInfo = errorInfo;
            return(dbInfo);
        }
 /// <summary>
 /// Initializes a new instance of the ServiceDeskObject class.
 /// </summary>
 /// <param name="databaseManager">DatabaseManager that handles the connection with a
 /// database containing a dictionary table.</param>
 /// <param name="commonDatabaseErrorCode">Structure to hold the enum values for common
 /// database error codes.</param>
 public BBApplicationDictionary(DatabaseManager2 databaseManager,
                                CommonDatabaseErrorCode <TErrorCodeEnum> commonDatabaseErrorCode)
 {
     _databaseManager         = databaseManager;
     _commonDatabaseErrorCode = commonDatabaseErrorCode;
 }