Volian.Base.Library & Baseline
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -9,31 +8,9 @@ namespace Volian.Base.Library
|
||||
// This provides a more robust stack trace than what visual studio offers
|
||||
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 string GetStack(bool showSame)
|
||||
{
|
||||
return StackToString(showSame);
|
||||
}
|
||||
public static void ShowStack()
|
||||
{
|
||||
Console.WriteLine(StackToString());
|
||||
}
|
||||
public static string StackToString()
|
||||
{
|
||||
return StackToString(true);
|
||||
}
|
||||
private static string StackToString(bool showSame)
|
||||
public static string GetStack(bool showSame) => StackToString(showSame);
|
||||
public static string StackToString() => StackToString(true);
|
||||
private static string StackToString(bool showSame)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StackTrace st = new StackTrace(true);
|
||||
@@ -71,22 +48,6 @@ namespace Volian.Base.Library
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static void ShowStackLocal(string str, params object[] objects)
|
||||
{
|
||||
Console.WriteLine(string.Format(str, objects) + StackToStringLocal(2,10));
|
||||
}
|
||||
public static void ShowStackFirstLocal(string str)
|
||||
{
|
||||
Console.WriteLine(str + "\r\n" + StackToStringLocal(3, 0));
|
||||
}
|
||||
public static void ShowStackLocal(string str,int start)
|
||||
{
|
||||
Console.WriteLine(str + "\r\n" + StackToStringLocal(start,1));
|
||||
}
|
||||
public static void ShowStackLocal(int start, int limit, string str, params object[] objects)
|
||||
{
|
||||
Console.WriteLine(string.Format(str, objects) + StackToStringLocal(start, limit));
|
||||
}
|
||||
public static string StackToStringLocal(int start, int limit)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -118,36 +79,12 @@ namespace Volian.Base.Library
|
||||
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) // Only look at Local Methods
|
||||
{
|
||||
count++;
|
||||
if (count > 4) // The fourth entry should be the Calling Method
|
||||
{
|
||||
string sType = sf.GetMethod().ReflectedType.Name;
|
||||
string sMethod = sf.GetMethod().Name;
|
||||
return string.Format("{0}.{1}[{2}]", sType, sMethod, sf.GetFileLineNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
return "No Local Method";
|
||||
}
|
||||
}
|
||||
public static string CalledFromCSLA
|
||||
{
|
||||
get
|
||||
{
|
||||
StackTrace st = new StackTrace(true);
|
||||
StackFrame[] sfs = st.GetFrames();
|
||||
int count = 0;
|
||||
string lastWasCSLA = null;
|
||||
foreach (StackFrame sf in sfs)
|
||||
{
|
||||
@@ -187,71 +124,5 @@ namespace Volian.Base.Library
|
||||
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
|
||||
}
|
||||
}
|
||||
public static class HWndCounter
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern IntPtr GetCurrentProcess();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
|
||||
|
||||
private enum ResourceType
|
||||
{
|
||||
Gdi = 0,
|
||||
User = 1
|
||||
}
|
||||
public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd)
|
||||
{
|
||||
GetWindowHandlesForCurrentProcess(hWnd, "");
|
||||
}
|
||||
private static uint lastUserObject = 0;
|
||||
public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd, string str, params object[] objects)
|
||||
{
|
||||
IntPtr processHandle = GetCurrentProcess();
|
||||
uint gdiObjects = GetGuiResources(processHandle, (uint)ResourceType.Gdi);
|
||||
uint userObjects = GetGuiResources(processHandle, (uint)ResourceType.User);
|
||||
if (lastUserObject != userObjects)
|
||||
Console.WriteLine("winhandle count = {0} GDIObjs {1} UserObjs {2} dif {3} {4}", gdiObjects + userObjects, gdiObjects, userObjects,(int)userObjects - (int)lastUserObject, string.Format(str, objects));
|
||||
lastUserObject = userObjects;
|
||||
//return Convert.ToInt32(gdiObjects + userObjects);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user