Esempio n. 1
0
        private static string _renderStackTrace(List <StackTraceItem> stackTrace, bool htmlOut, StackTraceFormat format, bool fileSystemLog = true)
        {
            List <string> result  = new List <string>();
            int           counter = 0;

            int[] textLengths = new int[] { 0, 0 };
            if (format != StackTraceFormat.Html)
            {
                List <StackTraceItem> newStackTrace = new List <StackTraceItem>();
                StackTraceItem        newStackTraceItem;
                foreach (StackTraceItem stackTraceItem in stackTrace)
                {
                    newStackTraceItem = new StackTraceItem(stackTraceItem);
                    if (newStackTraceItem.Method.Length > textLengths[0])
                    {
                        textLengths[0] = newStackTraceItem.Method.Length;
                    }
                    if (htmlOut && format == StackTraceFormat.Json && newStackTraceItem.File.ToString().Length > 0)
                    {
                        newStackTraceItem.File = new string[] {
                            newStackTraceItem.File.ToString(),
                                Tools.RelativeSourceFullPath(newStackTraceItem.File.ToString())
                        };
                    }
                    else
                    {
                        newStackTraceItem.File = Tools.RelativeSourceFullPath(newStackTraceItem.File.ToString());
                    }
                    if (newStackTraceItem.File.ToString().Length > textLengths[1])
                    {
                        textLengths[1] = newStackTraceItem.File.ToString().Length;
                    }
                    newStackTrace.Add(newStackTraceItem);
                }
                stackTrace = newStackTrace;
            }
            foreach (StackTraceItem stackTraceItem in stackTrace)
            {
                result.Add(
                    Exceptions._renderStackTraceLine(stackTraceItem, format, textLengths)
                    );
                counter++;
            }
            if (format == StackTraceFormat.Html)
            {
                string resultStr = @"<div class=""table callstack""><b class=""title"">Call Stack:</b>"
                                   + @"<div class=""calls""><div><table>" + String.Join("", result.ToArray()) + "</table></div></div>"
                                   + "</div>";
                return(resultStr);
            }
            else if (format == StackTraceFormat.Text)
            {
                return(System.Environment.NewLine + "      " + String.Join(System.Environment.NewLine + "      ", result.ToArray()));
            }
            else if (format == StackTraceFormat.Json)
            {
                return("[" + String.Join(",", result.ToArray()) + "]");
            }
            return("");
        }
Esempio n. 2
0
 internal StackTraceItem(StackTraceItem item)
 {
     this.Method = item.Method;
     this.File   = item.File;
     this.Line   = item.Line;
     this.Column = item.Column;
 }
Esempio n. 3
0
        private static string _renderStackTraceLine(StackTraceItem stackTraceItem, StackTraceFormat format, int[] textLengths)
        {
            string result       = "";
            string fileNameLink = "";
            bool   fileDefined  = stackTraceItem.File.ToString().Length > 0 && stackTraceItem.Line.ToString().Length > 0;

            if (format == StackTraceFormat.Html)
            {
                if (fileDefined)
                {
                    fileNameLink = @"<a href=""editor://open/?file=" + HttpUtility.UrlEncode(stackTraceItem.File.ToString())
                                   + "&line=" + stackTraceItem.Line
                                   + "&editor=" + Tools.Editor
                                   + @""">" + Tools.RelativeSourceFullPath(stackTraceItem.File.ToString()) + "</a>";
                }
                result = (fileNameLink.Length > 0 ? @"<tr class=""known""> " : "<tr>")
                         + @"<td class=""file"">" + fileNameLink + "</td>"
                         + @"<td class=""line"">" + stackTraceItem.Line + "</td>"
                         + @"<td class=""method""><i>" + stackTraceItem.Method.Replace(".", "&#8203;.") + " </i></td>"
                         + "</tr>";
            }
            else if (format == StackTraceFormat.Text)
            {
                if (fileDefined)
                {
                    result = stackTraceItem.Method + Tools.SpaceIndent(textLengths[0] - stackTraceItem.Method.Length, false)
                             + " " + stackTraceItem.File + Tools.SpaceIndent(textLengths[1] - stackTraceItem.File.ToString().Length, false)
                             + " " + stackTraceItem.Line;
                }
                else
                {
                    result = stackTraceItem.Method + Tools.SpaceIndent(textLengths[0] - stackTraceItem.Method.Length, false)
                             + " " + stackTraceItem.File;
                }
            }
            else if (format == StackTraceFormat.Json)
            {
                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                result = "{method:" + jsonSerializer.Serialize(stackTraceItem.Method);
                if (fileDefined)
                {
                    result += ",file:" + jsonSerializer.Serialize(stackTraceItem.File);
                    result += ",line:" + stackTraceItem.Line;
                }
                result += "}";
            }
            return(result);
        }
Esempio n. 4
0
 internal static string Render(StackTraceItem stackTraceItem, bool htmlOut)
 {
     if (stackTraceItem.File.ToString().Length == 0 && stackTraceItem.Line.ToString().Length == 0)
     {
         return("");
     }
     if (htmlOut)
     {
         return(@"<a class=""desharp-dump desharp-dump-link"" href=""editor://open/?file=" + HttpUtility.UrlEncode(stackTraceItem.File.ToString())
                + "&line=" + stackTraceItem.Line
                + "&editor=" + Tools.Editor
                + @""">" + Tools.RelativeSourceFullPath(stackTraceItem.File.ToString()) + "</a>");
     }
     else
     {
         return(Tools.RelativeSourceFullPath(stackTraceItem.File.ToString()) + ":" + stackTraceItem.Line);
     }
 }
Esempio n. 5
0
        internal static StackTraceItem CompleteCallerPoint()
        {
            StackTraceItem result = new StackTraceItem();

            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(1, true);
            string fileName;
            string line;

            foreach (var stackItem in stackTrace.GetFrames())
            {
                fileName = stackItem.GetFileName() ?? "";
                fileName = fileName.Replace('\\', '/');
                if (fileName.Length > 0)
                {
                    if (fileName.IndexOf(FireDump.SELF_FILENAME) > -1 & fileName.IndexOf(FireDump.SELF_FILENAME) == fileName.Length - FireDump.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                    if (fileName.IndexOf(StackTrace.SELF_FILENAME) > -1 & fileName.IndexOf(StackTrace.SELF_FILENAME) == fileName.Length - StackTrace.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                    if (fileName.IndexOf(Exceptions.SELF_FILENAME) > -1 & fileName.IndexOf(Exceptions.SELF_FILENAME) == fileName.Length - Exceptions.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                    if (fileName.IndexOf(Debug.SELF_FILENAME) > -1 & fileName.IndexOf(Debug.SELF_FILENAME) == fileName.Length - Debug.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                }
                line = stackItem.GetFileLineNumber().ToString().Trim();
                if (line.Length == 0)
                {
                    line = "";
                }
                result = new StackTraceItem {
                    File = fileName,
                    Line = line
                };
                break;
            }
            return(result);
        }
Esempio n. 6
0
        bool IsSpecialMessage(string id, string data)
        {
            bool res = false;

            try
            {
                if (data == RuntimeCommandReadlnSignal)
                {
                    ReadStringRequest(id);
                    return(true);
                }
                if (data.IndexOf(RuntimeCommandCodePage) == 0)
                {
                    int      t           = data.IndexOf(']');
                    int      encodingNum = Convert.ToInt32(data.Substring(RuntimeCommandCodePage.Length, t - RuntimeCommandCodePage.Length));
                    Encoding NewEncoding = Encoding.GetEncoding(encodingNum);
                    Encoding OldEncoding = EventedStreamReaderList.GetEncoding(OutputStreamId + id);
                    EventedStreamReaderList.SetEncoding(OutputStreamId + id, NewEncoding);
                    EventedStreamReaderList.SetEncoding(ErrorStreamId + id, NewEncoding);
                    if (data.Length > t + 1)
                    {
                        data = data.Substring(t + 1);
                        data = NewEncoding.GetString(OldEncoding.GetBytes(data));
                        if (data == RuntimeCommandReadlnSignal)
                        {
                            ReadStringRequest(id);
                            return(true);
                        }
                        res = true;
                    }
                    else
                    {
                        return(true);
                    }
                }
                if (data == '\n'.ToString())
                {
                    return(true);
                }
                if (data.IndexOf(StackOverflowExceptionText) >= 0)
                {
                    RunnerManagerUnhanledRuntimeException(id, StackOverflowExceptionType, StackOverflowExceptionText, null, new List <StackTraceItem>());
                    return(true);
                }
                if ((waitSpecialMessageText != "" || (data.Length >= RuntimeExceptionDelimer1.Length && data.Substring(0, RuntimeExceptionDelimer1.Length) == RuntimeExceptionDelimer1)) && RunnerManagerUnhanledRuntimeException != null)
                {
                    if (data.IndexOf(RuntimeExceptionDelimer4) < 0)
                    {
                        waitSpecialMessageText += data;
                        return(true);
                    }
                    if (waitSpecialMessageText != "")
                    {
                        data = waitSpecialMessageText + data;
                    }
                    int    Section1Begin             = RuntimeExceptionDelimer1.Length;
                    int    Section1Length            = data.IndexOf(RuntimeExceptionDelimer2) - Section1Begin;
                    int    Section2Begin             = Section1Begin + Section1Length + RuntimeExceptionDelimer2.Length;
                    int    Section2Length            = data.IndexOf(RuntimeExceptionDelimer3) - Section2Begin;
                    int    Section3Begin             = Section2Begin + Section2Length + RuntimeExceptionDelimer3.Length;
                    int    Section3Length            = data.IndexOf(RuntimeExceptionDelimer4) - Section3Begin;
                    string ExceptionType             = data.Substring(Section1Begin, Section1Length);
                    string ExceptionMessage          = data.Substring(Section2Begin, Section2Length);
                    string StackTraceData            = data.Substring(Section3Begin, Section3Length);
                    List <StackTraceItem> StackTrace = new List <StackTraceItem>();
                    string[] delimer = new string[1];
                    delimer[0] = Environment.NewLine;
                    string[] StackItemsData = StackTraceData.Split(delimer, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string StackItemData in StackItemsData)
                    {
                        StackTraceItem StackTraceItem = new StackTraceItem();
                        string         str            = StackItemData.TrimStart(' ');
                        int            beg            = str.IndexOf(' ');
                        int            end            = str.IndexOf(')');
                        StackTraceItem.FunctionName = str.Substring(beg + 1, end - beg);
                        if (end + 1 < str.Length)
                        {
                            str = str.Substring(end + 1);
                            str = str.TrimStart(' ');
                            beg = str.IndexOf(' ');
                            end = str.IndexOf(':');
                            end = str.IndexOf(':', end + 1);
                            StackTraceItem.SourceFileName = str.Substring(beg + 1, end - beg - 1);
                            beg = str.IndexOf(' ', end);
                            if (beg > 0)
                            {
                                string slnum = str.Substring(beg + 1).Replace(".", "");
                                StackTraceItem.LineNumber = Convert.ToInt32(slnum);
                                if (StackTraceItem.LineNumber >= 16777214)
                                {
                                    StackTraceItem.LineNumber     = 0;
                                    StackTraceItem.SourceFileName = null;
                                }
                            }
                        }

                        /*int RuntimeExceptionInIdentIndex = StackItemData.IndexOf(RuntimeExceptionInIdent);
                         * int FunctionNameBegin = StackItemData.IndexOf(RuntimeExceptionAtIdent) + RuntimeExceptionAtIdent.Length;
                         * if (RuntimeExceptionInIdentIndex > 0)
                         * {
                         *  StackTraceItem.FunctionName = StackItemData.Substring(FunctionNameBegin, RuntimeExceptionInIdentIndex - FunctionNameBegin);
                         *  int RuntimeExceptionLineIdentIndex = StackItemData.IndexOf(RuntimeExceptionLineIdent);
                         *  int RuntimeExceptionInIdentEndPos = RuntimeExceptionInIdentIndex + RuntimeExceptionInIdent.Length;
                         *  StackTraceItem.SourceFileName = StackItemData.Substring(RuntimeExceptionInIdentEndPos, RuntimeExceptionLineIdentIndex - RuntimeExceptionInIdentEndPos);
                         *  int LineNumberStartPos = RuntimeExceptionLineIdentIndex + RuntimeExceptionLineIdent.Length;
                         *  int LineNumberLength = 0;
                         *  int i = LineNumberStartPos;
                         *  while (i < StackItemData.Length && !char.IsWhiteSpace(StackItemData[i]))
                         *  {
                         *      LineNumberLength++;
                         *      i++;
                         *  }
                         *  StackTraceItem.LineNumber = Convert.ToInt32(StackItemData.Substring(LineNumberStartPos, LineNumberLength));
                         *  if (StackTraceItem.LineNumber >= 16777214)
                         *  {
                         *      StackTraceItem.LineNumber = 0;
                         *      StackTraceItem.SourceFileName = null;
                         *  }
                         * }
                         * else
                         * {
                         *  StackTraceItem.FunctionName = StackItemData.Substring(FunctionNameBegin, StackItemData.Length - FunctionNameBegin);
                         * }*/
                        StackTrace.Add(StackTraceItem);
                    }
                    RunnerManagerUnhanledRuntimeException(id, ExceptionType, ExceptionMessage, StackTraceData, StackTrace);
                    waitSpecialMessageText = "";
                    return(true);
                }
            }
            catch (Exception e)
            {
                //OutputStringReceived(id, StreamType.Output,e.ToString());
            }
            return(res);
        }
Esempio n. 7
0
        bool IsSpecialMessage(string id, string data)
        {
            bool res = false;

            try
            {
                if (data == RuntimeCommandReadlnSignal)
                {
                    ReadStringRequest(id);
                    return(true);
                }
                if (data.IndexOf(RuntimeCommandCodePage) == 0)
                {
                    int      t           = data.IndexOf(']');
                    int      encodingNum = Convert.ToInt32(data.Substring(RuntimeCommandCodePage.Length, t - RuntimeCommandCodePage.Length));
                    Encoding NewEncoding = Encoding.GetEncoding(encodingNum);
                    Encoding OldEncoding = EventedStreamReaderList.GetEncoding(OutputStreamId + id);
                    EventedStreamReaderList.SetEncoding(OutputStreamId + id, NewEncoding);
                    EventedStreamReaderList.SetEncoding(ErrorStreamId + id, NewEncoding);
                    if (data.Length > t + 1)
                    {
                        data = data.Substring(t + 1);
                        data = NewEncoding.GetString(OldEncoding.GetBytes(data));
                        if (data == RuntimeCommandReadlnSignal)
                        {
                            ReadStringRequest(id);
                            return(true);
                        }
                        res = true;
                    }
                    else
                    {
                        return(true);
                    }
                }
                if (data == '\n'.ToString())
                {
                    return(true);
                }
                if (data.IndexOf(StackOverflowExceptionText) >= 0)
                {
                    RunnerManagerUnhanledRuntimeException(id, StackOverflowExceptionType, StackOverflowExceptionText, null, new List <StackTraceItem>());
                    return(true);
                }
                if ((waitSpecialMessageText != "" || (data.Length >= RuntimeExceptionDelimer1.Length && data.Substring(0, RuntimeExceptionDelimer1.Length) == RuntimeExceptionDelimer1)) && RunnerManagerUnhanledRuntimeException != null)
                {
                    if (data.IndexOf(RuntimeExceptionDelimer4) < 0)
                    {
                        waitSpecialMessageText += data;
                        return(true);
                    }
                    if (waitSpecialMessageText != "")
                    {
                        data = waitSpecialMessageText + data;
                    }
                    int    Section1Begin             = RuntimeExceptionDelimer1.Length;
                    int    Section1Length            = data.IndexOf(RuntimeExceptionDelimer2) - Section1Begin;
                    int    Section2Begin             = Section1Begin + Section1Length + RuntimeExceptionDelimer2.Length;
                    int    Section2Length            = data.IndexOf(RuntimeExceptionDelimer3) - Section2Begin;
                    int    Section3Begin             = Section2Begin + Section2Length + RuntimeExceptionDelimer3.Length;
                    int    Section3Length            = data.IndexOf(RuntimeExceptionDelimer4) - Section3Begin;
                    string ExceptionType             = data.Substring(Section1Begin, Section1Length);
                    string ExceptionMessage          = data.Substring(Section2Begin, Section2Length);
                    string StackTraceData            = data.Substring(Section3Begin, Section3Length);
                    List <StackTraceItem> StackTrace = new List <StackTraceItem>();
                    string[] delimer = new string[1];
                    delimer[0] = Environment.NewLine;
                    string[] StackItemsData = StackTraceData.Split(delimer, StringSplitOptions.RemoveEmptyEntries);

                    try
                    {
                        foreach (string StackItemData in StackItemsData)
                        {
                            StackTraceItem StackTraceItem = new StackTraceItem();
                            string         str            = StackItemData.TrimStart(' ');
                            int            beg            = str.IndexOf(' ');
                            int            end            = str.IndexOf(") ");
                            if (end == -1)
                            {
                                end = str.IndexOf(")");
                            }
                            if (end == -1)
                            {
                                end = str.Length - 1;
                            }
                            StackTraceItem.FunctionName = str.Substring(beg + 1, end - beg);
                            if (end + 1 < str.Length)
                            {
                                str = str.Substring(end + 1);
                                str = str.TrimStart(' ');
                                beg = str.IndexOf(' ');
                                end = str.IndexOf(':');
                                end = str.IndexOf(':', end + 1);
                                if (end == -1)
                                {
                                    continue;
                                }
                                StackTraceItem.SourceFileName = str.Substring(beg + 1, end - beg - 1);
                                beg = str.IndexOf(' ', end);
                                if (beg > 0)
                                {
                                    string slnum = str.Substring(beg + 1).Replace(".", "");
                                    StackTraceItem.LineNumber = Convert.ToInt32(slnum);
                                    if (StackTraceItem.LineNumber >= 16777214)
                                    {
                                        StackTraceItem.LineNumber     = 0;
                                        StackTraceItem.SourceFileName = null;
                                    }
                                }
                            }
                            StackTrace.Add(StackTraceItem);
                        }
                    }
                    catch (Exception e)
                    {
                        StackTraceItem StackTraceItem = new StackTraceItem();
                        StackTraceItem.FunctionName = "Исключение при формировании стека исключений. Проверьте код RunManager.cs";
                        StackTrace.Add(StackTraceItem);
                        //e = e;
                    }

                    RunnerManagerUnhanledRuntimeException(id, ExceptionType, ExceptionMessage, StackTraceData, StackTrace);
                    waitSpecialMessageText = "";
                    return(true);
                }
            }
            catch (Exception e)
            {
                //OutputStringReceived(id, StreamType.Output,e.ToString());
            }
            return(res);
        }
Esempio n. 8
0
        internal static string Render(StackTraceItem errorFileStackTrace, StackTraceFormat format)
        {
            string result         = "";
            string rawFileContent = ErrorFile._readErrorFile(errorFileStackTrace.File.ToString());

            rawFileContent = rawFileContent.Replace("\r", "");
            string[] allFileLines = Regex.Split(rawFileContent, "\n");
            int[]    linesCount   = ErrorFile._errorFileLineDisplayArea;
            int      lineInt      = -1;
            int      columnInt    = -1;

            try {
                if (errorFileStackTrace.Line.Length > 0)
                {
                    lineInt = Convert.ToInt32(errorFileStackTrace.Line);
                }
                if (errorFileStackTrace.Column.Length > 0)
                {
                    columnInt = Convert.ToInt32(errorFileStackTrace.Column);
                }
            } catch { }
            if (lineInt > -1)
            {
                int beginLine;
                int endLine;
                if (lineInt - 1 - linesCount[0] < 0)
                {
                    beginLine      = 1;
                    linesCount[1] += linesCount[0] - (lineInt - 1);
                }
                else
                {
                    beginLine = lineInt - linesCount[0];
                }
                if (lineInt + linesCount[1] > allFileLines.Length)
                {
                    endLine    = allFileLines.Length;
                    beginLine -= (lineInt + linesCount[1]) - allFileLines.Length;
                    if (beginLine < 1)
                    {
                        beginLine = 1;
                    }
                }
                else
                {
                    endLine = lineInt + linesCount[1];
                }
                List <dynamic> linesToRender = new List <dynamic>();
                bool           current;
                for (int i = 1, l = allFileLines.Length + 1; i < l; i++)
                {
                    if (i < beginLine)
                    {
                        continue;
                    }
                    if (i > endLine)
                    {
                        break;
                    }
                    current = (i == lineInt) ? true : false;
                    linesToRender.Add(new {
                        text    = allFileLines[i - 1],
                        current = current,
                        num     = i,
                    });
                }
                result = ErrorFile.RenderErrorLines(errorFileStackTrace.File.ToString(), lineInt, columnInt, linesToRender, format);
            }
            return(result);
        }
Esempio n. 9
0
        internal static RenderingCollection CompleteStackTraceForCurrentApplicationPoint(string message = "", string exceptionType = "", bool fileSystemLog = true, bool htmlOut = false)
        {
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true);
            string                fileName;
            string                line;
            string                column;
            string                method;
            StackTraceItem        stackTraceItem;
            StackTraceItem?       errorFile       = null;
            List <StackTraceItem> stackTraceItems = new List <StackTraceItem>();
            int counter = 0;

            foreach (StackFrame stackItem in stackTrace.GetFrames())
            {
                fileName = stackItem.GetFileName() ?? "";
                fileName = fileName.Replace('\\', '/');

                if (fileName.Length > 0)
                {
                    if (fileName.IndexOf(StackTrace.SELF_FILENAME) > -1 & fileName.IndexOf(StackTrace.SELF_FILENAME) == fileName.Length - StackTrace.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                    if (fileName.IndexOf(Exceptions.SELF_FILENAME) > -1 & fileName.IndexOf(Exceptions.SELF_FILENAME) == fileName.Length - Exceptions.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                    if (fileName.IndexOf(Debug.SELF_FILENAME) > -1 & fileName.IndexOf(Debug.SELF_FILENAME) == fileName.Length - Debug.SELF_FILENAME.Length)
                    {
                        continue;
                    }
                }

                line   = stackItem.GetFileLineNumber().ToString().Trim();
                column = stackItem.GetFileColumnNumber().ToString().Trim();
                method = stackItem.GetMethod().ToString().Trim();

                if (line.Length == 0)
                {
                    line = "?";
                }

                stackTraceItem = new StackTraceItem {
                    File   = fileName,
                    Line   = line,
                    Column = column,
                    Method = method
                };
                if (
                    !errorFile.HasValue &
                    fileName.Length > 0 &
                    line != "?"
                    )
                {
                    errorFile = stackTraceItem;
                }

                stackTraceItems.Add(stackTraceItem);
                counter++;
            }
            return(new RenderingCollection {
                ErrorFileStackTrace = errorFile,
                AllStackTraces = stackTraceItems,
                ExceptionMessage = message,
                ExceptionType = exceptionType.Length > 0 ? exceptionType : "",
                ExceptionHash = "",
                CausedByHash = "",
                CausedByMessage = "",
                CausedByType = "",
            });
        }
Esempio n. 10
0
        internal static RenderingCollection RenderStackTraceForException(ExceptionToRender exceptionToRender, bool fileSystemLog = true, bool htmlOut = false, int index = 0)
        {
            //StackTraceItem? possibleViewExceptionStackTrace;
            List <StackTraceItem> stackTraceItems = StackTrace._completeStackTraceForSingleException(exceptionToRender.Exception);
            StackTraceItem?       errorFile       = null;
            string causedByHash     = "";
            string causedByType     = "";
            string causedByMessage  = "";
            string exceptionMessage = exceptionToRender.Exception.Message;

            if (index == 0 && !fileSystemLog)
            {
                // there is possible view exception

                /*possibleViewExceptionStackTrace = StackTrace._getPossibleViewExceptionInfo(exceptionToRender.Exception);
                 * if (possibleViewExceptionStackTrace.HasValue) {
                 *      errorFile = possibleViewExceptionStackTrace;
                 * }*/
                if (exceptionToRender.Exception is HttpCompileException)
                {
                    PropertyInfo[] props = exceptionToRender.Exception.GetType().GetProperties(
                        BindingFlags.NonPublic | BindingFlags.Instance
                        );
                    PropertyInfo prop;
                    for (int i = 0, l = props.Length; i < l; i += 1)
                    {
                        prop = props[i];
                        if (prop.Name == "FirstCompileError")
                        {
                            CompilerError compileError = prop.GetValue(exceptionToRender.Exception, null) as CompilerError;
                            if (compileError is CompilerError)
                            {
                                exceptionMessage = compileError.ErrorText;
                                errorFile        = new StackTraceItem {
                                    File   = compileError.FileName,
                                    Line   = compileError.Line.ToString(),
                                    Column = compileError.Column.ToString()
                                };
                            }
                            break;
                        }
                    }
                }
            }
            if (errorFile == null && !fileSystemLog)
            {
                foreach (StackTraceItem stackTraceItem in stackTraceItems)
                {
                    if (
                        stackTraceItem.File.ToString().Length > 0 &&
                        stackTraceItem.Line != "?"
                        )
                    {
                        errorFile = stackTraceItem;
                        break;
                    }
                }
            }
            if (htmlOut)
            {
                exceptionMessage = exceptionMessage
                                   .Replace("&", "&amp;")
                                   .Replace("<", "&lt;")
                                   .Replace(">", "&gt;");
            }
            if (exceptionToRender.CausedBy is Exception)
            {
                causedByHash    = exceptionToRender.CausedBy.GetHashCode().ToString();
                causedByType    = exceptionToRender.CausedBy.GetType().FullName;
                causedByMessage = exceptionToRender.CausedBy.Message;
            }
            return(new RenderingCollection {
                ErrorFileStackTrace = errorFile,
                AllStackTraces = stackTraceItems,
                Catched = exceptionToRender.Catched,
                ExceptionHash = exceptionToRender.Exception.GetHashCode().ToString(),
                ExceptionType = exceptionToRender.Exception.GetType().FullName,
                ExceptionMessage = exceptionMessage,
                CausedByHash = causedByHash,
                CausedByType = causedByType,
                CausedByMessage = causedByMessage,
            });
        }
Esempio n. 11
0
 bool IsSpecialMessage(string id, string data)
 {
     bool res = false;
     try
     {
         if (data == RuntimeCommandReadlnSignal)
         {
             ReadStringRequest(id);
             return true;
         }
         if (data.IndexOf(RuntimeCommandCodePage)==0)
         {
             int t = data.IndexOf(']');
             int encodingNum = Convert.ToInt32(data.Substring(RuntimeCommandCodePage.Length, t - RuntimeCommandCodePage.Length));
             Encoding NewEncoding = Encoding.GetEncoding(encodingNum);
             Encoding OldEncoding = EventedStreamReaderList.GetEncoding(OutputStreamId + id); 
             EventedStreamReaderList.SetEncoding(OutputStreamId + id, NewEncoding);
             EventedStreamReaderList.SetEncoding(ErrorStreamId + id, NewEncoding);
             if (data.Length > t + 1)
             {
                 data = data.Substring(t + 1);
                 data = NewEncoding.GetString(OldEncoding.GetBytes(data));
                 if (data == RuntimeCommandReadlnSignal)
         		{
             		ReadStringRequest(id);
             		return true;
         		}
                 res = true;
             }
             else
                 return true;
         }
         if (data == '\n'.ToString())
         {
             return true;
         }
         if (data.IndexOf(StackOverflowExceptionText) >= 0)
         {
             RunnerManagerUnhanledRuntimeException(id, StackOverflowExceptionType, StackOverflowExceptionText, null, new List<StackTraceItem>());
             return true;
         }
         if ((waitSpecialMessageText != "" || (data.Length >= RuntimeExceptionDelimer1.Length && data.Substring(0, RuntimeExceptionDelimer1.Length) == RuntimeExceptionDelimer1)) && RunnerManagerUnhanledRuntimeException != null)
         {
             if (data.IndexOf(RuntimeExceptionDelimer4) < 0)
             {
                 waitSpecialMessageText += data;
                 return true;
             }
             if (waitSpecialMessageText != "")
                 data = waitSpecialMessageText + data;
             int Section1Begin = RuntimeExceptionDelimer1.Length;
             int Section1Length = data.IndexOf(RuntimeExceptionDelimer2) - Section1Begin;
             int Section2Begin = Section1Begin + Section1Length + RuntimeExceptionDelimer2.Length;
             int Section2Length = data.IndexOf(RuntimeExceptionDelimer3) - Section2Begin;
             int Section3Begin = Section2Begin + Section2Length + RuntimeExceptionDelimer3.Length;
             int Section3Length = data.IndexOf(RuntimeExceptionDelimer4) - Section3Begin;
             string ExceptionType = data.Substring(Section1Begin, Section1Length);
             string ExceptionMessage = data.Substring(Section2Begin, Section2Length);
             string StackTraceData = data.Substring(Section3Begin, Section3Length);
             List<StackTraceItem> StackTrace = new List<StackTraceItem>();
             string[] delimer = new string[1];
             delimer[0] = Environment.NewLine;
             string[] StackItemsData = StackTraceData.Split(delimer, StringSplitOptions.RemoveEmptyEntries);
             foreach (string StackItemData in StackItemsData)
             {
                 StackTraceItem StackTraceItem = new StackTraceItem();
                 string str = StackItemData.TrimStart(' ');
                 int beg = str.IndexOf(' ');
                 int end = str.IndexOf(')');
                 StackTraceItem.FunctionName = str.Substring(beg + 1, end - beg);
                 if (end + 1 < str.Length)
                 {
                     str = str.Substring(end + 1);
                     str = str.TrimStart(' ');
                     beg = str.IndexOf(' ');
                     end = str.IndexOf(':');
                     end = str.IndexOf(':', end + 1);
                     StackTraceItem.SourceFileName = str.Substring(beg + 1, end - beg-1);
                     beg = str.IndexOf(' ',end);
                     if (beg > 0)
                     {
                         string slnum = str.Substring(beg + 1).Replace(".", "");                                
                         StackTraceItem.LineNumber = Convert.ToInt32(slnum);
                         if (StackTraceItem.LineNumber >= 16777214)
                         {
                             StackTraceItem.LineNumber = 0;
                             StackTraceItem.SourceFileName = null;
                         }
                     }
                 }
                 /*int RuntimeExceptionInIdentIndex = StackItemData.IndexOf(RuntimeExceptionInIdent);
                 int FunctionNameBegin = StackItemData.IndexOf(RuntimeExceptionAtIdent) + RuntimeExceptionAtIdent.Length;
                 if (RuntimeExceptionInIdentIndex > 0)
                 {
                     StackTraceItem.FunctionName = StackItemData.Substring(FunctionNameBegin, RuntimeExceptionInIdentIndex - FunctionNameBegin);
                     int RuntimeExceptionLineIdentIndex = StackItemData.IndexOf(RuntimeExceptionLineIdent);
                     int RuntimeExceptionInIdentEndPos = RuntimeExceptionInIdentIndex + RuntimeExceptionInIdent.Length;
                     StackTraceItem.SourceFileName = StackItemData.Substring(RuntimeExceptionInIdentEndPos, RuntimeExceptionLineIdentIndex - RuntimeExceptionInIdentEndPos);
                     int LineNumberStartPos = RuntimeExceptionLineIdentIndex + RuntimeExceptionLineIdent.Length;
                     int LineNumberLength = 0;
                     int i = LineNumberStartPos;
                     while (i < StackItemData.Length && !char.IsWhiteSpace(StackItemData[i]))
                     {
                         LineNumberLength++;
                         i++;
                     }
                     StackTraceItem.LineNumber = Convert.ToInt32(StackItemData.Substring(LineNumberStartPos, LineNumberLength));
                     if (StackTraceItem.LineNumber >= 16777214)
                     {
                         StackTraceItem.LineNumber = 0;
                         StackTraceItem.SourceFileName = null;
                     }
                 }
                 else
                 {
                     StackTraceItem.FunctionName = StackItemData.Substring(FunctionNameBegin, StackItemData.Length - FunctionNameBegin);
                 }*/
                 StackTrace.Add(StackTraceItem);
             }
             RunnerManagerUnhanledRuntimeException(id, ExceptionType, ExceptionMessage, StackTraceData, StackTrace);
             waitSpecialMessageText = "";
             return true;
         }
     }
     catch (Exception e)
     {
         //OutputStringReceived(id, StreamType.Output,e.ToString());
     }
     return res;
 }