Esempio n. 1
0
        /// <summary>
        /// A generic error handling helper method.
        /// </summary>
        /// <remarks>
        /// If we have an IngresException then we pass off the handling to the HandleIngresException method.
        /// Otherwise we throw the exception if is a provider exception. If the exception is not a provider
        /// exception then we throw a provider exception with a generic message.
        /// </remarks>
        /// <param name="ex">The exception that we wish to handle.</param>
        /// <param name="provider">The provider that we are handling the exception for.</param>
        /// <param name="method">The method that caused the exception to be thrown.</param>
        private static void HandleException(Exception ex, IngresAspNetProvider provider, Enum method)
        {
            // Determine the error type and handle it appropriately.
            Type exceptionType = ex.GetType();

            // if the exception is an Ingres exception then we handle it differently...
            if (exceptionType == typeof(IngresException))
            {
                switch (provider)
                {
                case IngresAspNetProvider.Role:
                    HandleIngresException((IngresException)ex, IngresAspNetProvider.Role, method.ToString());
                    break;

                case IngresAspNetProvider.Membership:
                    HandleIngresException((IngresException)ex, IngresAspNetProvider.Membership, method.ToString());
                    break;
                }
            }
            else if (exceptionType == typeof(ArgumentException) ||
                     exceptionType == typeof(ArgumentNullException) ||
                     exceptionType == typeof(ProviderException) ||
                     exceptionType == typeof(MembershipPasswordException))
            {
                // re-thow errors if they are known errors that we have explicitly thrown (or the .NET
                // framework throws on out behalf.)
                throw ex;
            }
            else
            {
                // re-wrap unknown errors as ProviderExceptions - keeping the original exception
                // as an inner exception.
                throw new ProviderException(String.Format(Messages.UnknownError), ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Manages error handling when we encounter an IngresException. If we are debugging we
        /// simply rethro the exception - otherwise log the error and throw a "friendly" error to
        /// the user.
        /// </summary>
        /// <param name="ex">The Ingres exception to handle.</param>
        /// <param name="provider">The Ingres ASP.NET provider that caused the exception to be thrown.</param>
        /// <param name="detail">The detail of the exception.</param>
        private static void HandleIngresException(IngresException ex, IngresAspNetProvider provider, string detail)
        {
            #if DEBUG // The debugging constant is automatically handled by Visual Studio for us
            // When we are debugging we want to actually throw the errors rather than just writing the
            // details to the event log and throwing a generic provider error.
            throw ex;
            #else
            // This code becomes reachable when we are not in debug mode
            LogError(ExceptionDetailReport(ex, detail), provider);

            throw new ProviderException(Messages.IngresExceptionErrorMessage);
            #endif
        }
Esempio n. 3
0
        /// <summary>
        /// A helper function that writes exception detail to the event log. Exceptions are written
        /// to the event log as a security measure to avoid private database details from being
        /// returned to the browser. If a method does not return a status or boolean indicating the
        /// action succeeded or failed, a generic exception is also thrown by the caller.
        /// </summary>
        /// <param name="eventMessage">The message to write to the log.</param>
        /// <param name="type">The event log entry type.</param>
        /// <param name="provider">The provider that we are providing logging for.</param>
        private static void WriteEvent(string eventMessage, EventLogEntryType type, IngresAspNetProvider provider)
        {
            try
            {
                string source;

                switch (provider)
                {
                case IngresAspNetProvider.Membership:
                    source = Messages.IngresMembershipProvider;
                    break;

                case IngresAspNetProvider.Role:
                    source = Messages.IngresRoleProvider;
                    break;

                default:
                    source = Messages.UnkownIngresAspNetProvider;
                    break;
                }

                const string Log = "log";

                // If the source for this application log entries is not present then attempt to create it.
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, Log);
                }

                // Write the entry if we could create the source.
                if (EventLog.SourceExists(source))
                {
                    EventLog.WriteEntry(source, eventMessage, type);
                }
            }
            catch
            {
                // suppress any errors in writing to the event logs
            }
        }
        /// <summary>
        /// A helper function that writes exception detail to the event log. Exceptions are written
        /// to the event log as a security measure to avoid private database details from being 
        /// returned to the browser. If a method does not return a status or boolean indicating the
        /// action succeeded or failed, a generic exception is also thrown by the caller.
        /// </summary>
        /// <param name="eventMessage">The message to write to the log.</param>
        /// <param name="type">The event log entry type.</param>
        /// <param name="provider">The provider that we are providing logging for.</param>
        private static void WriteEvent(string eventMessage, EventLogEntryType type, IngresAspNetProvider provider)
        {
            try
            {
                string source;

                switch (provider)
                {
                    case IngresAspNetProvider.Membership:
                        source = Messages.IngresMembershipProvider;
                        break;
                    case IngresAspNetProvider.Role:
                        source = Messages.IngresRoleProvider;
                        break;
                    default:
                        source = Messages.UnkownIngresAspNetProvider;
                        break;
                }

                const string Log = "log";

                // If the source for this application log entries is not present then attempt to create it.
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, Log);
                }

                // Write the entry if we could create the source.
                if (EventLog.SourceExists(source))
                {
                    EventLog.WriteEntry(source, eventMessage, type);
                }
            }
            catch
            {
                // suppress any errors in writing to the event logs
            }
        }
        /// <summary>
        /// Manages error handling when we encounter an IngresException. If we are debugging we
        /// simply rethro the exception - otherwise log the error and throw a "friendly" error to
        /// the user.
        /// </summary>
        /// <param name="ex">The Ingres exception to handle.</param>
        /// <param name="provider">The Ingres ASP.NET provider that caused the exception to be thrown.</param>
        /// <param name="detail">The detail of the exception.</param>
        private static void HandleIngresException(IngresException ex, IngresAspNetProvider provider, string detail)
        {
            #if DEBUG // The debugging constant is automatically handled by Visual Studio for us

            // When we are debugging we want to actually throw the errors rather than just writing the
            // details to the event log and throwing a generic provider error.
            throw ex;

            #else

            // This code becomes reachable when we are not in debug mode
            LogError(ExceptionDetailReport(ex, detail), provider);

            throw new ProviderException(Messages.IngresExceptionErrorMessage);

            #endif
        }
        /// <summary>
        /// A generic error handling helper method.
        /// </summary>
        /// <remarks>
        /// If we have an IngresException then we pass off the handling to the HandleIngresException method.
        /// Otherwise we throw the exception if is a provider exception. If the exception is not a provider
        /// exception then we throw a provider exception with a generic message.
        /// </remarks>
        /// <param name="ex">The exception that we wish to handle.</param>
        /// <param name="provider">The provider that we are handling the exception for.</param>
        /// <param name="method">The method that caused the exception to be thrown.</param>
        private static void HandleException(Exception ex, IngresAspNetProvider provider, Enum method)
        {
            // Determine the error type and handle it appropriately.
            Type exceptionType = ex.GetType();

            // if the exception is an Ingres exception then we handle it differently...
            if (exceptionType == typeof(IngresException))
            {
                switch (provider)
                {
                    case IngresAspNetProvider.Role:
                        HandleIngresException((IngresException)ex, IngresAspNetProvider.Role, method.ToString());
                        break;
                    case IngresAspNetProvider.Membership:
                        HandleIngresException((IngresException)ex, IngresAspNetProvider.Membership, method.ToString());
                        break;
                }
            }
            else if (exceptionType == typeof(ArgumentException)     ||
                     exceptionType == typeof(ArgumentNullException) ||
                     exceptionType == typeof(ProviderException)     ||
                     exceptionType == typeof(MembershipPasswordException))
            {
                // re-thow errors if they are known errors that we have explicitly thrown (or the .NET
                // framework throws on out behalf.)
                throw ex;
            }
            else
            {
                // re-wrap unknown errors as ProviderExceptions - keeping the original exception
                // as an inner exception.
                throw new ProviderException(String.Format(Messages.UnknownError), ex);
            }
        }
 /// <summary>
 /// Log a warning for an Ingres ASP.NET provider.
 /// </summary>
 /// <param name="message">[IN] The event message.</param>
 /// <param name="providerType">The provider that we are logging a warning for.</param>
 internal static void LogWarning(string message, IngresAspNetProvider providerType)
 {
     WriteEvent(message, EventLogEntryType.Warning, providerType);
 }
 /// <summary>
 /// Log information for an Ingres ASP.NET provider.
 /// </summary>
 /// <param name="message">[IN] The event message.</param>
 /// <param name="providerType">The provider that we are logging the information for.</param>
 internal static void LogInformation(string message, IngresAspNetProvider providerType)
 {
     WriteEvent(message, EventLogEntryType.Information, providerType);
 }
Esempio n. 9
0
 /// <summary>
 /// Log an error for an Ingres ASP.NET provider.
 /// </summary>
 /// <param name="message">[IN] The event message.</param>
 /// <param name="providerType">The provider that we are logging the error for.</param>
 internal static void LogError(string message, IngresAspNetProvider providerType)
 {
     WriteEvent(message, EventLogEntryType.Error, providerType);
 }
Esempio n. 10
0
 /// <summary>
 /// Log information for an Ingres ASP.NET provider.
 /// </summary>
 /// <param name="message">[IN] The event message.</param>
 /// <param name="providerType">The provider that we are logging the information for.</param>
 internal static void LogInformation(string message, IngresAspNetProvider providerType)
 {
     WriteEvent(message, EventLogEntryType.Information, providerType);
 }