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); }
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); }