/************************************************************************************ * * Umbraco Data Layer * MIT Licensed work * ©2008 Ruben Verborgh * ***********************************************************************************/ using System; using System.Diagnostics; using System.Reflection; namespace umbraco { /// /// Represents an exception that is generated in an Umbraco module. /// /// This should be moved out of the data layer for general use. public class UmbracoException : Exception { #region Private Fields /// The Umbraco component that generated the exception. private readonly UmbracoComponent m_Component; #endregion #region Public Properties /// /// Gets the Umbraco component that generated the exception. /// /// The component. public UmbracoComponent Component { get { return m_Component; } } /// /// Gets a message that describes the current exception. /// /// The error message that explains the reason for the exception. public override string Message { get { return String.Format("Umbraco Exception ({0}): {1}", Component, base.Message); } } #endregion #region Public Constructors /// /// Initializes a new instance of the class. /// /// The message. public UmbracoException(string message) : this(message, null) { } /// /// Initializes a new instance of the class. /// /// The message. /// The inner exception. public UmbracoException(string message, Exception innerException) : base(message, innerException) { // get the calling assembly Assembly assembly = new StackFrame(1).GetMethod().ReflectedType.Assembly; string assemblyName = assembly.FullName.Split(",".ToCharArray())[0]; // try to determine the component try { string componentName = assemblyName.ToLower().Replace("umbraco.", String.Empty); m_Component = (UmbracoComponent)Enum.Parse(typeof(UmbracoComponent), componentName, true); } // do nothing if parsing fails, default value is UmbracoComponent.External catch (ArgumentException) { } } #endregion } /// /// Enum of all Umbraco components /// public enum UmbracoComponent { /// Unknown component External, /// Business logic component BusinessLogic, /// CMS component CMS, /// Controls component Controls, /// Data layer component DataLayer, /// Editor controls component EditorControls, /// Presentation component Presentation, /// Providers component Providers } }