This commit is contained in:
parent
38dbd7a31a
commit
f689cc42c5
@ -1,201 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Volian.Controls.Library
|
|
||||||
{
|
|
||||||
public static class vlnStackTrace
|
|
||||||
{
|
|
||||||
public static string GetStack(string str, params object[] objects)
|
|
||||||
{
|
|
||||||
return string.Format(str, objects) + StackToString();
|
|
||||||
}
|
|
||||||
public static void ShowStack(string str, params object[] objects)
|
|
||||||
{
|
|
||||||
Console.WriteLine(string.Format(str, objects) + StackToString());
|
|
||||||
}
|
|
||||||
public static string GetStack()
|
|
||||||
{
|
|
||||||
return StackToString();
|
|
||||||
}
|
|
||||||
public static void ShowStack()
|
|
||||||
{
|
|
||||||
Console.WriteLine(StackToString());
|
|
||||||
}
|
|
||||||
private static string StackToString()
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
StackTrace st = new StackTrace(true);
|
|
||||||
StackFrame[] sfs = st.GetFrames();
|
|
||||||
int ii = 0;
|
|
||||||
string sLast = "";
|
|
||||||
string sThis = "";
|
|
||||||
int imax = MatchingStackFrame(sfs);
|
|
||||||
foreach (StackFrame sf in sfs)
|
|
||||||
{
|
|
||||||
if (imax == 0)
|
|
||||||
sb.Append(string.Format("\r\n{0}---------", "".PadLeft(ii++ * 2)));
|
|
||||||
imax--;
|
|
||||||
if (ii < 2) ii++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string sMethod = sf.GetMethod().Name;
|
|
||||||
string sNamespace = sf.GetMethod().ReflectedType.Namespace;
|
|
||||||
string sType = sf.GetMethod().ReflectedType.Name;
|
|
||||||
if (sf.GetFileLineNumber() != 0)
|
|
||||||
{
|
|
||||||
sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber());
|
|
||||||
sThis = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sThis = sNamespace;
|
|
||||||
}
|
|
||||||
if (sLast == sThis && sThis != "")
|
|
||||||
sb.Append(string.Format("\t*.{0}.{1}", sType, sMethod));
|
|
||||||
else
|
|
||||||
sb.Append(string.Format("\r\n{0}{1}.{2}.{3}", "".PadLeft(ii++ * 2), sNamespace, sType, sMethod));
|
|
||||||
}
|
|
||||||
sLast = sThis;
|
|
||||||
}
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
public static void ShowStackFirstLocal(string str)
|
|
||||||
{
|
|
||||||
Console.WriteLine(str + " " + StackToStringLocal(3,0));
|
|
||||||
}
|
|
||||||
public static void ShowStackLocal(string str,int start)
|
|
||||||
{
|
|
||||||
Console.WriteLine(str + " " + StackToStringLocal(start,1));
|
|
||||||
}
|
|
||||||
public static void ShowStackLocal(string str,int start, int limit)
|
|
||||||
{
|
|
||||||
Console.WriteLine(str + " " + StackToStringLocal(start, limit));
|
|
||||||
}
|
|
||||||
private static string StackToStringLocal(int start, int limit)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
string sep = "Local Method - ";
|
|
||||||
StackTrace st = new StackTrace(true);
|
|
||||||
StackFrame[] sfs = st.GetFrames();
|
|
||||||
int count = 0;
|
|
||||||
int localCount = 0;
|
|
||||||
foreach (StackFrame sf in sfs)
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
if (count > start)
|
|
||||||
{
|
|
||||||
if (sf.GetFileLineNumber() != 0)
|
|
||||||
{
|
|
||||||
string sMethod = sf.GetMethod().Name;
|
|
||||||
string sNamespace = sf.GetMethod().ReflectedType.Namespace;
|
|
||||||
string sType = sf.GetMethod().ReflectedType.Name;
|
|
||||||
sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber());
|
|
||||||
sb.Append(sep + string.Format("{0}.{1}.{2}", sNamespace, sType, sMethod));
|
|
||||||
localCount ++;
|
|
||||||
if (localCount >= limit)
|
|
||||||
return sb.ToString();
|
|
||||||
sep = "\r\n" + "".PadRight(localCount *2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (localCount > 0)
|
|
||||||
return sb.ToString();
|
|
||||||
return "No Local Method";
|
|
||||||
}
|
|
||||||
public static string CalledFrom
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
StackTrace st = new StackTrace(true);
|
|
||||||
StackFrame[] sfs = st.GetFrames();
|
|
||||||
int count = 0;
|
|
||||||
foreach (StackFrame sf in sfs)
|
|
||||||
{
|
|
||||||
if (sf.GetFileLineNumber() != 0)
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
{
|
|
||||||
string sMethod = sf.GetMethod().Name;
|
|
||||||
string sNamespace = sf.GetMethod().ReflectedType.Namespace;
|
|
||||||
string sType = sf.GetMethod().ReflectedType.Name;
|
|
||||||
sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber());
|
|
||||||
if (count > 3)
|
|
||||||
return string.Format("{0}.{1}.{2}", sNamespace, sType, sMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "No Local Method";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static StackFrame[] _LastSFS;
|
|
||||||
private static int MatchingStackFrame(StackFrame[] sfs)
|
|
||||||
{
|
|
||||||
int iFound = -1;
|
|
||||||
if (_LastSFS != null)
|
|
||||||
{
|
|
||||||
// start at the far end and work backward
|
|
||||||
for (int i = 1; iFound < 0 && i <= sfs.Length && i <= _LastSFS.Length; i++)
|
|
||||||
{
|
|
||||||
if (!Match(sfs[sfs.Length - i],_LastSFS[_LastSFS.Length - i]))
|
|
||||||
iFound = 1+ sfs.Length - i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iFound < 0) iFound = sfs.Length;
|
|
||||||
_LastSFS = (StackFrame[])sfs.Clone();
|
|
||||||
return iFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool Match(StackFrame stackFrame1, StackFrame stackFrame2)
|
|
||||||
{
|
|
||||||
if (stackFrame1.GetMethod().Name != stackFrame2.GetMethod().Name) return false;
|
|
||||||
if (stackFrame1.GetMethod().DeclaringType.FullName != stackFrame2.GetMethod().DeclaringType.FullName) return false;
|
|
||||||
if (stackFrame1.GetILOffset() != stackFrame2.GetILOffset()) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public static bool ScrollInStack()
|
|
||||||
{
|
|
||||||
StackTrace st = new StackTrace(true);
|
|
||||||
StackFrame[] sfs = st.GetFrames();
|
|
||||||
bool retval = false;
|
|
||||||
foreach (StackFrame sf in sfs)
|
|
||||||
{
|
|
||||||
string sMethod = sf.GetMethod().Name;
|
|
||||||
string sNamespace = sf.GetMethod().ReflectedType.Namespace;
|
|
||||||
string sType = sf.GetMethod().ReflectedType.Name;
|
|
||||||
if (sMethod.ToUpper().Contains("SCROLL") || sType.ToUpper().Contains("SCROLL"))
|
|
||||||
{
|
|
||||||
retval = true;
|
|
||||||
Console.WriteLine("{0}.{1}.{2}", sNamespace, sType, sMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// This will clear the Output window when run in the Development Environment
|
|
||||||
/// Add EnvDTE and EnvDTE80 to references from .NET
|
|
||||||
/// </summary>
|
|
||||||
public static void ClearOutputWindow()
|
|
||||||
{
|
|
||||||
#if (DEBUG)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0");
|
|
||||||
dte2.ToolWindows.OutputWindow.ActivePane.Clear();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("ClearOutputWindow {0} - {1}\r\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
private static bool _DebugMode = true;
|
|
||||||
|
|
||||||
public static bool DebugMode
|
|
||||||
{
|
|
||||||
get { return vlnStackTrace._DebugMode; }
|
|
||||||
set { vlnStackTrace._DebugMode = value; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user