示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LayoutScriptException"/> class.
        /// </summary>
        /// <typeparam name="T">The type of <see cref="LayoutScriptException"/> to create.</typeparam>
        /// <param name="layout">The <see cref="LayoutScript"/> that caused the exception.</param>
        /// <param name="innerException">The <see cref="Exception"/> that caused this exception.</param>
        /// <param name="srcElem">The <see cref="ISourceEntity"/> that caused the exception.</param>
        /// <param name="msg">A message that describes the error.</param>
        /// <returns>The new <see cref="LayoutScriptException"/> instance.</returns>
        internal static T Create <T>(LayoutScript layout, Exception innerException, ISourceEntity srcElem, string msg)
            where T : LayoutScriptException
        {
            string detailedMsg = BuildDetailedMessage(msg, innerException, layout, srcElem);

            return(CreateException <T>(layout, msg, detailedMsg, innerException, srcElem));
        }
示例#2
0
        /// <typeparam name="T">The type of <see cref="LayoutScriptException"/> to create.</typeparam>
        /// <param name="layout">The <see cref="LayoutScript"/> whose XML data caused the exception.</param>
        /// <param name="msg">A brief message that describes the error.</param>
        /// <param name="detailedMsg">A detailed message that describes the error.</param>
        /// <param name="innerException">The <see cref="Exception"/> that caused this exception.</param>
        /// <param name="srcElem">The <see cref="ISourceEntity"/> that caused the exception.</param>
        /// <returns></returns>
        private static T CreateException <T>(
            LayoutScript layout, string msg, string detailedMsg, Exception innerException, ISourceEntity srcElem)
            where T : LayoutScriptException
        {
            if (srcElem != null && srcElem.LineNumber > 0 && srcElem.LinePosition > 0)
            {
                msg += string.Format(" Line {0}, position {1}.", srcElem.LineNumber, srcElem.LinePosition);
            }

            T ex = (T)Activator.CreateInstance(
                typeof(T),
                BindingFlags.NonPublic | BindingFlags.Instance,
                null,
                new object[] { msg, innerException },
                CultureInfo.InvariantCulture);

            ex.LayoutFile = layout;

            if (!string.IsNullOrWhiteSpace(detailedMsg))
            {
                ex.DetailedMessage = detailedMsg;
            }

            if (srcElem != null)
            {
                ex.LineNumber   = srcElem.LineNumber;
                ex.LinePosition = srcElem.LinePosition;
            }

            return(ex);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LayoutScriptException"/> class.
        /// </summary>
        /// <typeparam name="T">The type of <see cref="LayoutScriptException"/> to create.</typeparam>
        /// <param name="layout">The <see cref="LayoutScript"/> that caused the exception.</param>
        /// <param name="srcElem">The <see cref="ISourceEntity"/> that caused the exception.</param>
        /// <param name="msgFmt">A composite format string for the message that describes the error.</param>
        /// <param name="fmtArgs">An object array that contains zero or more objects to format.</param>
        /// <returns>The new <see cref="LayoutScriptException"/> instance.</returns>
        internal static T Create <T>(LayoutScript layout, ISourceEntity srcElem, string msgFmt, params object[] fmtArgs)
            where T : LayoutScriptException
        {
            string msg;
            string detailedMsg;

            msg         = string.Format(msgFmt, fmtArgs);
            detailedMsg = BuildDetailedMessage(msg, null, layout, srcElem);

            return(CreateException <T>(layout, msg, detailedMsg, null, srcElem));
        }
示例#4
0
        /// <summary>
        /// Creates a descriptive and easy-to-read error message.
        /// </summary>
        /// <param name="exceptionMessage">A message describing the error.</param>
        /// <param name="innerException">The <see cref="Exception"/> that caused the error.</param>
        /// <param name="layout">The <see cref="LayoutScript"/> that caused the error.</param>
        /// /// <param name="srcElem">The <see cref="ISourceEntity"/> that caused the error.</param>
        /// <returns>The newly-created error message.</returns>
        private static string BuildDetailedMessage(
            string exceptionMessage, Exception innerException, LayoutScript layout, ISourceEntity srcElem)
        {
            if (exceptionMessage == null)
            {
                exceptionMessage = "";
            }

            exceptionMessage = exceptionMessage.Trim();

            bool hasExceptionMessage = !string.IsNullOrEmpty(exceptionMessage);
            bool hasInnerException   = innerException != null;
            bool hasLayout           = layout != null;
            bool hasPath             = hasLayout && layout.SourcePath != null;
            bool hasLineInfo         = srcElem != null && srcElem.LineNumber > 0 && srcElem.LinePosition > 0;

            string msg = "";

            if (hasExceptionMessage)
            {
                msg = exceptionMessage;
            }

            if (hasInnerException)
            {
                msg += Environment.NewLine + "Caused by:";
                msg += Environment.NewLine + "  " + innerException.GetType().Name + ": ";
                msg += innerException.Message.Replace(Environment.NewLine, Environment.NewLine + "    ");
            }

            if (hasLayout && hasPath)
            {
                msg += Environment.NewLine + "In Layout:";
                if (hasPath)
                {
                    msg += Environment.NewLine + "  Path: " + layout.SourcePath;
                }
            }

            if (hasLineInfo)
            {
                msg += Environment.NewLine + "Occurred at:";
                msg += Environment.NewLine + "  Line: " + srcElem.LineNumber;
                msg += Environment.NewLine + "  Position: " + srcElem.LinePosition;
            }

            return(msg);
        }
示例#5
0
        /// <summary>
        /// Executes a <see cref="LayoutScript"/> on the binary data.
        /// <param name="script">The layout script to run.</param>
        /// <param name="scriptOutputWriter">A <see cref="TextWriter"/> to which
        /// textual output from the script will be written.</param>
        /// </summary>
        public void RunLayoutScript(LayoutScript script, TextWriter scriptOutputWriter)
        {
            LayoutInterpreter interpreter = new LayoutInterpreter(script, scriptOutputWriter);

            interpreter.Execute(fileStructure.Symbol, this);
        }
示例#6
0
 /// <summary>
 /// Executes a <see cref="LayoutScript"/> on the binary data.
 /// Any textual output from the script will be written to
 /// <see cref="Console.Out"/>.
 /// <param name="script">The layout script to run.</param>
 /// </summary>
 public void RunLayoutScript(LayoutScript script)
 {
     RunLayoutScript(script, Console.Out);
 }